From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97EAA26059D for ; Wed, 17 Jun 2026 07:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781681909; cv=none; b=UsUZNVP0dw71WPqh/D5X51x2ERm3+NiDB5qI4VS54NvynWz4OnFDiDlUNp2LftZGLkWN2uzrrsfLcFl6uBsI+YJXaWTd/xQeZoe08GByBj7CqVHl7O/jBnoG8zB4dUEubOlNYsrcy5AXweHiUgtZbT6na2DrX6Qa/m//Jheechs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781681909; c=relaxed/simple; bh=gt6cUt4o1tC4fREwOKZr3pl1KMs3XezQlPyPKv/mE7k=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=Cz9vsvwb9mF/7SWsij4YilW1vtGhRnOvl9TgcAaZYJ76zjm3hifStDxKa2r8K+CSYJ6IHhtnekEuKcAnJCRHdK9Y/KR2mM+GEe48efXjcI9luE4fIAZeUR3rh3KE+eW/0CIWULxhR09a4Unce14SDFjsVgvzFMNjKUzLPjnrcQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=L1cW5Lko; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="L1cW5Lko" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=OlHpfhG6RtHov9Iyyi+B0BO0xvSLE7bwTX2Gg1r93rs=; b=L1cW5Lko8NTkoTU61zFAqQl6tc/dqLCfB1VusVhd8zgxxrESR45LRPCFHhA01wV2X8PlyYFT/ QRBgnpC43exbQnQN4Fg6iPly0OzYZupdlflCdX5g6MmYd7jZLdxArz0s9TQsK/I8FulUzIubeU5 SHoTN5mNfSkoR4XOIMVgPJQ= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4ggFqB2WH9z12LDV; Wed, 17 Jun 2026 15:29:26 +0800 (CST) Received: from dggemv705-chm.china.huawei.com (unknown [10.3.19.32]) by mail.maildlp.com (Postfix) with ESMTPS id 6676340575; Wed, 17 Jun 2026 15:38:17 +0800 (CST) Received: from kwepemq500010.china.huawei.com (7.202.194.235) by dggemv705-chm.china.huawei.com (10.3.19.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 17 Jun 2026 15:38:02 +0800 Received: from [10.173.124.160] (10.173.124.160) by kwepemq500010.china.huawei.com (7.202.194.235) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 17 Jun 2026 15:38:00 +0800 Subject: Re: [PATCH v5 4/4] selftests/mm: add hard memory failure anonymous 1G HugeTLB page test To: Jiaqi Yan CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260531055829.3636554-1-jiaqiyan@google.com> <20260531055829.3636554-5-jiaqiyan@google.com> From: Miaohe Lin Message-ID: Date: Wed, 17 Jun 2026 15:38:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20260531055829.3636554-5-jiaqiyan@google.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemq500010.china.huawei.com (7.202.194.235) 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 > --- > 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 > #include > > +#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. .