mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: Jiaqi Yan <jiaqiyan@google.com>
Cc: <osalvador@suse.de>, <lorenzo.stoakes@oracle.com>,
	<jackmanb@google.com>, <hannes@cmpxchg.org>,
	<nao.horiguchi@gmail.com>, <david@kernel.org>,
	<william.roche@oracle.com>, <tony.luck@intel.com>,
	<wangkefeng.wang@huawei.com>, <jane.chu@oracle.com>,
	<akpm@linux-foundation.org>, <muchun.song@linux.dev>,
	<liam@infradead.org>, <rientjes@google.com>, <duenwen@google.com>,
	<jthoughton@google.com>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <vbabka@suse.cz>,
	<rppt@kernel.org>, <shuah@kernel.org>, <surenb@google.com>,
	<mhocko@suse.com>, <boudewijn@delta-utec.com>, <ljs@kernel.org>,
	<osalvador@kernel.org>, <ziy@nvidia.com>, <harry.yoo@oracle.com>,
	<willy@infradead.org>
Subject: Re: [PATCH v5 4/4] selftests/mm: add hard memory failure anonymous 1G HugeTLB page test
Date: Wed, 17 Jun 2026 15:38:00 +0800	[thread overview]
Message-ID: <d1333353-b615-2dc1-ecff-8093d237cba7@huawei.com> (raw)
In-Reply-To: <20260531055829.3636554-5-jiaqiyan@google.com>

On 2026/5/31 13:58, Jiaqi Yan wrote:
> Add a new testcase to validate memory failure recovery for HWPoison
> anonymous 1G HugeTLB page, including proper SIGBUS delivery,
> releasing a 1G HugeTLB page containing one HWPoison page to buddy
> allocator, and isolation of the raw HWPoison page.
> 
> Although can be added in future, this patch does not support testing
> the MADV_SOFT variant.
> 

Thanks for your patch. Some comments below.

> Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
> ---
>  tools/testing/selftests/mm/memory-failure.c | 73 +++++++++++++++++++--
>  1 file changed, 68 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/memory-failure.c b/tools/testing/selftests/mm/memory-failure.c
> index 032ed952057c..ea43b2877c81 100644
> --- a/tools/testing/selftests/mm/memory-failure.c
> +++ b/tools/testing/selftests/mm/memory-failure.c
> @@ -18,6 +18,7 @@
>  #include <linux/magic.h>
>  #include <errno.h>
>  
> +#include "hugepage_settings.h"
>  #include "vm_util.h"
>  
>  enum inject_type {
> @@ -27,6 +28,7 @@ enum inject_type {
>  
>  enum result_type {
>  	MADV_HARD_ANON,
> +	MADV_HARD_ANON_HUGETLB,
>  	MADV_HARD_CLEAN_PAGECACHE,
>  	MADV_HARD_DIRTY_PAGECACHE,
>  	MADV_SOFT_ANON,
> @@ -47,6 +49,8 @@ FIXTURE(memory_failure)
>  	int pagemap_fd;
>  	int kpageflags_fd;
>  	bool triggered;
> +	/* Number of initial HugeTLB pages with default page size. */
> +	unsigned long nr_hugetlb_pages;
>  };
>  
>  FIXTURE_VARIANT(memory_failure)
> @@ -157,11 +161,11 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failure
>  		  void *vaddr, enum result_type type, int setjmp)
>  {
>  	unsigned long size;
> +	unsigned long nr_hugetlb_pages;
>  	uint64_t pfn_flags;
>  
>  	switch (type) {
>  	case MADV_SOFT_ANON:
> -	case MADV_HARD_CLEAN_PAGECACHE:
>  	case MADV_SOFT_CLEAN_PAGECACHE:
>  	case MADV_SOFT_DIRTY_PAGECACHE:
>  		/* It is not expected to receive a SIGBUS signal. */
> @@ -174,6 +178,7 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failure
>  		ASSERT_NE(pagemap_get_pfn(self->pagemap_fd, vaddr), self->pfn);
>  		break;
>  	case MADV_HARD_ANON:
> +	case MADV_HARD_ANON_HUGETLB:
>  	case MADV_HARD_DIRTY_PAGECACHE:
>  		/* The SIGBUS signal should have been received. */
>  		ASSERT_EQ(setjmp, 1);
> @@ -183,17 +188,36 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failure
>  		ASSERT_EQ(siginfo.si_code, BUS_MCEERR_AR);
>  		ASSERT_EQ(1UL << siginfo.si_addr_lsb, self->page_size);
>  		ASSERT_EQ(siginfo.si_addr, vaddr);
> -
> -		/* XXX Check backing pte is hwpoison entry when supported. */
> -		ASSERT_TRUE(pagemap_is_swapped(self->pagemap_fd, vaddr));

Can we write this as something like:

		if (type != MADV_HARD_ANON_HUGETLB)
			/*
			 * XXX Check backing pte is hwpoison entry when supported.
			 * Check backing pte is hwpoison entry when supported.
			 * Although try_to_unmap_one() also installs hwpoison entry
			 * for HugeTLB, pagemap_hugetlb_range() doesn't parse
 			 * swap entries at all.
			 */
			ASSERT_TRUE(pagemap_is_swapped(self->pagemap_fd, vaddr));

So we don't need to modify the if condition when more base page size tests are added?

>  		break;
>  	default:
>  		SKIP(return, "unexpected inject type %d.\n", type);
>  	}
>  
> +	if (type == MADV_HARD_ANON || type == MADV_HARD_DIRTY_PAGECACHE) {
> +		/*
> +		 * Check backing pte is hwpoison entry when supported.
> +		 * Although try_to_unmap_one() also installs hwpoison entry
> +		 * for HugeTLB, pagemap_hugetlb_range() doesn't parse
> +		 * swap entries at all.
> +		 */
> +		ASSERT_TRUE(pagemap_is_swapped(self->pagemap_fd, vaddr));
> +	}
> +
>  	/* Check if the value of HardwareCorrupted has increased. */
>  	ASSERT_EQ(get_hardware_corrupted_size(&size), 0);
> -	ASSERT_EQ(size, self->corrupted_size + self->page_size / 1024);
> +
> +	if (type == MADV_HARD_ANON_HUGETLB) {
> +		/*
> +		 * Only one page is hardware corrupted; the rest should all be
> +		 * released to buddy allocator.
> +		 */
> +		ASSERT_EQ(size, self->corrupted_size + getpagesize() / 1024);
> +		/* HugeTLB should have lost the HWPoison HugeTLB page. */
> +		nr_hugetlb_pages = hugetlb_nr_default_pages();
> +		ASSERT_EQ(nr_hugetlb_pages + 1, self->nr_hugetlb_pages);
> +	} else {
> +		ASSERT_EQ(size, self->corrupted_size + self->page_size / 1024);
> +	}
>  
>  	/* Check if HWPoison flag is set. */
>  	ASSERT_EQ(pageflags_get(self->pfn, self->kpageflags_fd, &pfn_flags), 0);
> @@ -247,6 +271,45 @@ TEST_F(memory_failure, anon)
>  	ASSERT_EQ(munmap(addr, self->page_size), 0);
>  }
>  
> +TEST_F(memory_failure, anon_hugetlb)
> +{
> +	char *addr;
> +	int ret;
> +	const unsigned long nr_alloc_hugetlb_pages = 4;
> +	unsigned long alloc_size;
> +
> +	if (variant->type == MADV_SOFT)
> +		SKIP(return, "Soft offline test is not implemented");
> +
> +	/* HugeTLB settings will be automatically restored when test exits. */
> +	hugetlb_setup_default(nr_alloc_hugetlb_pages);
> +
> +	alloc_size = default_huge_page_size() * nr_alloc_hugetlb_pages;
> +	self->page_size = default_huge_page_size();
> +	self->nr_hugetlb_pages = hugetlb_nr_default_pages();
> +
> +	addr = mmap(0, alloc_size, PROT_READ | PROT_WRITE,
> +		    MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB, -1, 0);
> +	if (addr == MAP_FAILED)
> +		SKIP(return, "mmap failed, not enough memory or 1G hugetlb not supported.\n");

This test is no longer 1G specific, so "1G" should be removed too?

> +	memset(addr, 0xce, alloc_size);

For 1G hugetlb, alloc_size will be 4G. Would memset() here take a long time to finish its work?
Same issue in check_memory(). Should we try to enhance this or it is just acceptable?

Thanks.
.

  parent reply	other threads:[~2026-06-17  7:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-31  5:58 [PATCH v5 0/4] Only free healthy pages in high-order has_hwpoisoned folio Jiaqi Yan
2026-05-31  5:58 ` [PATCH v5 1/4] mm/page_alloc: only " Jiaqi Yan
2026-06-09  3:44   ` Miaohe Lin
2026-06-12 18:34     ` Zi Yan
2026-06-16  3:23       ` Jiaqi Yan
2026-06-16  6:53         ` Miaohe Lin
2026-06-18 15:02           ` Vlastimil Babka (SUSE)
2026-06-22  1:12             ` Jiaqi Yan
2026-06-22  8:30               ` Vlastimil Babka (SUSE)
2026-07-05 17:58                 ` Jiaqi Yan
2026-06-22  1:12           ` Jiaqi Yan
2026-06-17  1:56         ` Zi Yan
2026-06-18 14:52           ` Vlastimil Babka (SUSE)
2026-06-18 16:04             ` Zi Yan
2026-06-22  1:13               ` Jiaqi Yan
2026-06-22  8:35                 ` Vlastimil Babka (SUSE)
2026-06-22 15:20                   ` Zi Yan
2026-06-22 15:32                     ` Zi Yan
2026-07-05 17:58                       ` Jiaqi Yan
2026-06-15  2:03     ` Jiaqi Yan
2026-05-31  5:58 ` [PATCH v5 2/4] mm/memory-failure: set has_hwpoisoned flags on dissolved HugeTLB folio Jiaqi Yan
2026-06-09  6:34   ` Miaohe Lin
2026-05-31  5:58 ` [PATCH v5 3/4] mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page Jiaqi Yan
2026-06-09  7:21   ` Miaohe Lin
2026-06-15  0:16     ` Jiaqi Yan
2026-06-16  7:05       ` Miaohe Lin
2026-05-31  5:58 ` [PATCH v5 4/4] selftests/mm: add hard memory failure anonymous 1G HugeTLB page test Jiaqi Yan
2026-06-01 18:04   ` Jiaqi Yan
2026-06-17  7:38   ` Miaohe Lin [this message]
2026-07-05 17:58     ` Jiaqi Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d1333353-b615-2dc1-ecff-8093d237cba7@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=boudewijn@delta-utec.com \
    --cc=david@kernel.org \
    --cc=duenwen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=harry.yoo@oracle.com \
    --cc=jackmanb@google.com \
    --cc=jane.chu@oracle.com \
    --cc=jiaqiyan@google.com \
    --cc=jthoughton@google.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@kernel.org \
    --cc=osalvador@suse.de \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=tony.luck@intel.com \
    --cc=vbabka@suse.cz \
    --cc=wangkefeng.wang@huawei.com \
    --cc=william.roche@oracle.com \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox