From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6819C3DA6E for ; Fri, 5 Jan 2024 21:13:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C7FD6B02C8; Fri, 5 Jan 2024 16:13:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1516D6B02CA; Fri, 5 Jan 2024 16:13:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0C2C6B02CC; Fri, 5 Jan 2024 16:13:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D8DB56B02C8 for ; Fri, 5 Jan 2024 16:13:51 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AD4BE1A09D0 for ; Fri, 5 Jan 2024 21:13:51 +0000 (UTC) X-FDA: 81646509462.26.6A73113 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf14.hostedemail.com (Postfix) with ESMTP id E9262100006 for ; Fri, 5 Jan 2024 21:13:48 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TDHOprs7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=jiaqiyan@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704489229; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cGCSFlWKydblwWMOFacS3ACee5xNkQaM8WYvo0xjaiE=; b=0iusvjFvLfPVNMloHT52hnkf2iowK91UuW9eJIsgZMitmbeBWG3KL59GcTd+bbLRnq1kSL bnEKLk/lnmOug0+UJHBTQNYX8/O+9JbrtOwzWOd5iZ4yxsm3NyOKpX6KTqkwnSIW+DZUxf CvIgCdGGLQW/O6n0osdGeALRxgv+r4o= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TDHOprs7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=jiaqiyan@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704489229; a=rsa-sha256; cv=none; b=VSeOi6f4YCK2Ul08cEoTR72LwqO1co+TigkHIKOJlsKLdy59UYEL1fAPxMSNSMvduCpxpu QavoBtGF8sYJI9V/aUFPK76vkQmL6rfa9guzDAiB4qXdGwbnQyLgxfRx1Z5TbRUS+gTF/4 WnDg8teo3P7iEbo1dMrwnUiwViiydmA= Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-dbdc52f2359so1910822276.3 for ; Fri, 05 Jan 2024 13:13:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704489228; x=1705094028; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cGCSFlWKydblwWMOFacS3ACee5xNkQaM8WYvo0xjaiE=; b=TDHOprs7v6qSYp//LK6Jyn7vqASHGPtdIzv31ajd1q0HzrQvY/FrzQ2K8FsRO0ydqk GWkknovSnr1GnPigrXZL3VG3ign5OaTEp0L8xpRBKcRnpe95VUF3voIqcjzQETZujuar ewiF9E40oITI+3JZcby8iiDSyroxxTew8+bPO/3ZzHsn9C7GFGpV2CJFXMGNLNCmLYVD 6pCj6Qb/SlzjHk1cDMeHw77SaBnEf8WjkQQ0aImqsrRUhmcqDW90geRMgRBViozLVRQo 4lErKWrQXoLMl5XNLJcP3yWuvXzJEFsGfCyvJbIP5eaDZXiKDigSoW1TYz7zBn6pLhoB Bk7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704489228; x=1705094028; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cGCSFlWKydblwWMOFacS3ACee5xNkQaM8WYvo0xjaiE=; b=HY/UUeFHNorV3THlTLILRmaiOKzPc/OP+mzYxMWmQhTlMZVXNdNFDcdHZAwKxv37ap iaeBDpiVPZxcpuI4QOreDNQYgSvdYCNXvytq4GiWPVS3ECdX3IRTxzhM3cHQx6GiqksM z5I+qIWh06ttJJkOdAFvv+OvVGFeQoLg8a66Dd5z3qZsWqlpIMrQbI9clHBINDb6pANd 4VbHOYGnXBVyiG2+VBay+p3NZBzvUdNsFzEjokywEpYwYIpQ6aS5J4UJJY+ECPdrXuu9 h6cfTRe8mjgreIpajPZev358g3EyhjYrrKk0eqSbY2kIE7KtQRd6wg8Fa9Rn2SjriWdH +w1A== X-Gm-Message-State: AOJu0YwtT3jP26h9HO+EVWhetQm15pOXX1TfWqrpulfGFlVPJBDmN4nf qBHOt+AbGCckYNClm6RFcxaMu1L94PSo7k2qAXYHS2FWp/+1 X-Google-Smtp-Source: AGHT+IEqps6rRJqqnGzpToplu959Ly9xVwkRQ2+JhIIRSapp4Irsg5E6CKfWOeHY+eq9eK1vb2nCB9Fpg5D2bMM1uyc= X-Received: by 2002:a25:9c46:0:b0:db7:dad0:76db with SMTP id x6-20020a259c46000000b00db7dad076dbmr2491348ybo.119.1704489227807; Fri, 05 Jan 2024 13:13:47 -0800 (PST) MIME-Version: 1.0 References: <20230713001833.3778937-1-jiaqiyan@google.com> <20230713001833.3778937-5-jiaqiyan@google.com> In-Reply-To: From: Jiaqi Yan Date: Fri, 5 Jan 2024 13:13:35 -0800 Message-ID: Subject: Re: [PATCH v4 4/4] selftests/mm: add tests for HWPOISON hugetlbfs read To: Muhammad Usama Anjum Cc: linmiaohe@huawei.com, mike.kravetz@oracle.com, naoya.horiguchi@nec.com, akpm@linux-foundation.org, songmuchun@bytedance.com, shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jthoughton@google.com, "kernel@collabora.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E9262100006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: r637xxmjrmgzpmxpoxgrxxpiseeo5wzc X-HE-Tag: 1704489228-837141 X-HE-Meta: U2FsdGVkX18NcZvNMDPPtPfAAAHTf4kTu23bVn+IeZV2WqqqiLXryDLOaPWrkARFELd3gYuanDYYOvHMdZcSfMXPlHl/GmBYbeqMlFsGoYCmZcz/oX7lxGluzePXKXvwikyMgX5/r8GATkbAni7sb07DXV1pNKSgXObjg4EYHJycDOqgroIUyVkbrKa4lilolRlT9xPdlbx3fNf+Z1CKtlJZ8u0Z4xKG91zx9W8bO+lYkw39PtGjL9mKd6NPUbrCztiJVuZCb2/4etfiRgPRVC749g6nXuqotnSLN2Baq2n8F7bWnoUBPjESu+jZNoQQoISDQj5f3mi0aUKTJ9d0X9N4+QaPsTIqXLYECMDXr3QrNuufzJKyWef61+ZtIW0eWRIHJyp/DY/Wg5Mx526DivAfkQqoPG8Tmq+W3O039vwKu5fFKJIAtOEarJhcmza2G7uKd4MEmnaV2HnLZHRvloH5y6bhVbDtCIBooAN2pOxFgiqH/iko61sOo9X2JpSLq6DKBKvD5oLWw08aSfD1jRek0ZNH93+kKgpDB61j41BTzwyvV0ryFRd+sm6ictH1c9c606BHcQyhs/vLsRVn0xsth6bUvZTZX1c0c7Rh3VIP7qIitB7JWOmAUPTVbyBDCNGJRLHIzfvkZFQV9I7vA8KENDUA69cIbe1/27neonR1jyf+qJDbt2DMPSAsvpglwzOHxyMWaPI6uVGG0Pkw8SI8XjgBXO+jRGHAncJ2AcgBKVvnfNILv20TIN9QdZQYspPvO6zcSnR/VN7pP/e0y/Mx3J5wXDncGjMENuk/ROxsYvMKETvritCc40IjIx5CvJSeirlKlchoGRr6iVexXXZERwbQeRDlcFSHzb5vT6TRw/cdckJVjL4fSxyiJUUf8ZsmD3lz6tOtJJggH4SvHE0e8cZrMdK02IF53+MHPhW3hlKpMadtWv7OwDNUkWQKdqmuLQ+FoIvXNoposQv DNtN7WTA 12YfZFdOwIO427FsZ+nkABFaLEUIY+Ltd+TkJcrQLK2ewz2G6FmGuZuIqKpeMh8okZBifJLr8nOJsZigdhJEzjSez/LuXz+LQMQT393b3c1s35gewuolW2CA9FhK8+r6yCXCxFujCdtUbYWPuoMs2UjVShMal2DHZrBuiXn+3ol0Z2Xn6t1C9UC1eQL1g2X0WdgquyYUyQfAANXYNSNdPOp8y4BXkS4p514VPlCBErCi15BXV37wFu9D55eALZ3RRAnNxEY0nYKwPPsVxHQW+fGeTEEXHH/sZT4KrlmloDPrm30CgBJdNYU8wR4uz+idyO1FQmTViZjLYJqh6zHfRMfXslEDg9ls8mRD5m3QGKvqQTgxNx0DBqzTd0XSZTefURoSPZGy1L1sW0xU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jan 4, 2024 at 10:27=E2=80=AFPM Muhammad Usama Anjum wrote: > > Hi, > > I'm trying to convert this test to TAP as I think the failures sometimes = go > unnoticed on CI systems if we only depend on the return value of the > application. I've enabled the following configurations which aren't alrea= dy > present in tools/testing/selftests/mm/config: > CONFIG_MEMORY_FAILURE=3Dy > CONFIG_HWPOISON_INJECT=3Dm > > I'll send a patch to add these configs later. Right now I'm trying to > investigate the failure when we are trying to inject the poison page by > madvise(MADV_HWPOISON). I'm getting device busy every single time. The te= st > fails as it doesn't expect any business for the hugetlb memory. I'm not > sure if the poison handling code has issues or test isn't robust enough. > > ./hugetlb-read-hwpoison > Write/read chunk size=3D0x800 > ... HugeTLB read regression test... > ... ... expect to read 0x200000 bytes of data in total > ... ... actually read 0x200000 bytes of data in total > ... HugeTLB read regression test...TEST_PASSED > ... HugeTLB read HWPOISON test... > [ 9.280854] Injecting memory failure for pfn 0x102f01 at process virtu= al > address 0x7f28ec101000 > [ 9.282029] Memory failure: 0x102f01: huge page still referenced by 51= 1 > users > [ 9.282987] Memory failure: 0x102f01: recovery action for huge page: F= ailed > ... !!! MADV_HWPOISON failed: Device or resource busy > ... HugeTLB read HWPOISON test...TEST_FAILED > > I'm testing on v6.7-rc8. Not sure if this was working previously or not. Thanks for reporting this, Usama! I am also able to repro MADV_HWPOISON failure at "501a06fe8e4c (akpm/mm-stable, mm-stable) zswap: memcontrol: implement zswap writeback disabling." Then I checked out the earliest commit "ba91e7e5d15a (HEAD -> Base) selftests/mm: add tests for HWPOISON hugetlbfs read". The MADV_HWPOISON injection works and and the test passes: ... HugeTLB read HWPOISON test... ... ... expect to read 0x101000 bytes of data in total ... !!! read failed: Input/output error ... ... actually read 0x101000 bytes of data in total ... HugeTLB read HWPOISON test...TEST_PASSED ... HugeTLB seek then read HWPOISON test... ... ... init val=3D4 with offset=3D0x102000 ... ... expect to read 0xfe000 bytes of data in total ... ... actually read 0xfe000 bytes of data in total ... HugeTLB seek then read HWPOISON test...TEST_PASSED ... [ 2109.209225] Injecting memory failure for pfn 0x3190d01 at process virtual address 0x7f75e3101000 [ 2109.209438] Memory failure: 0x3190d01: recovery action for huge page: Recovered ... I think something in between broken MADV_HWPOISON on hugetlbfs, and we should be able to figure it out via bisection (and of course by reading delta commits between them, probably related to page refcount). That being said, I will be on vacation from tomorrow until the end of next week. So I will get back to this after next weekend. Meanwhile if you want to go ahead and bisect the problematic commit, that will be very much appreciated. Thanks, Jiaqi > > Regards, > Usama > > On 7/13/23 5:18 AM, Jiaqi Yan wrote: > > Add tests for the improvement made to read operation on HWPOISON > > hugetlb page with different read granularities. For each chunk size, > > three read scenarios are tested: > > 1. Simple regression test on read without HWPOISON. > > 2. Sequential read page by page should succeed until encounters the 1st > > raw HWPOISON subpage. > > 3. After skip a raw HWPOISON subpage by lseek, read()s always succeed. > > > > Acked-by: Mike Kravetz > > Reviewed-by: Naoya Horiguchi > > Signed-off-by: Jiaqi Yan > > --- > > tools/testing/selftests/mm/.gitignore | 1 + > > tools/testing/selftests/mm/Makefile | 1 + > > .../selftests/mm/hugetlb-read-hwpoison.c | 322 ++++++++++++++++++ > > 3 files changed, 324 insertions(+) > > create mode 100644 tools/testing/selftests/mm/hugetlb-read-hwpoison.c > > > > diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/self= tests/mm/.gitignore > > index 7e2a982383c0..cdc9ce4426b9 100644 > > --- a/tools/testing/selftests/mm/.gitignore > > +++ b/tools/testing/selftests/mm/.gitignore > > @@ -5,6 +5,7 @@ hugepage-mremap > > hugepage-shm > > hugepage-vmemmap > > hugetlb-madvise > > +hugetlb-read-hwpoison > > khugepaged > > map_hugetlb > > map_populate > > diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selfte= sts/mm/Makefile > > index 66d7c07dc177..b7fce9073279 100644 > > --- a/tools/testing/selftests/mm/Makefile > > +++ b/tools/testing/selftests/mm/Makefile > > @@ -41,6 +41,7 @@ TEST_GEN_PROGS +=3D gup_longterm > > TEST_GEN_PROGS +=3D gup_test > > TEST_GEN_PROGS +=3D hmm-tests > > TEST_GEN_PROGS +=3D hugetlb-madvise > > +TEST_GEN_PROGS +=3D hugetlb-read-hwpoison > > TEST_GEN_PROGS +=3D hugepage-mmap > > TEST_GEN_PROGS +=3D hugepage-mremap > > TEST_GEN_PROGS +=3D hugepage-shm > > diff --git a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c b/tools= /testing/selftests/mm/hugetlb-read-hwpoison.c > > new file mode 100644 > > index 000000000000..ba6cc6f9cabc > > --- /dev/null > > +++ b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c > > @@ -0,0 +1,322 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +#define _GNU_SOURCE > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "../kselftest.h" > > + > > +#define PREFIX " ... " > > +#define ERROR_PREFIX " !!! " > > + > > +#define MAX_WRITE_READ_CHUNK_SIZE (getpagesize() * 16) > > +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) > > + > > +enum test_status { > > + TEST_PASSED =3D 0, > > + TEST_FAILED =3D 1, > > + TEST_SKIPPED =3D 2, > > +}; > > + > > +static char *status_to_str(enum test_status status) > > +{ > > + switch (status) { > > + case TEST_PASSED: > > + return "TEST_PASSED"; > > + case TEST_FAILED: > > + return "TEST_FAILED"; > > + case TEST_SKIPPED: > > + return "TEST_SKIPPED"; > > + default: > > + return "TEST_???"; > > + } > > +} > > + > > +static int setup_filemap(char *filemap, size_t len, size_t wr_chunk_si= ze) > > +{ > > + char iter =3D 0; > > + > > + for (size_t offset =3D 0; offset < len; > > + offset +=3D wr_chunk_size) { > > + iter++; > > + memset(filemap + offset, iter, wr_chunk_size); > > + } > > + > > + return 0; > > +} > > + > > +static bool verify_chunk(char *buf, size_t len, char val) > > +{ > > + size_t i; > > + > > + for (i =3D 0; i < len; ++i) { > > + if (buf[i] !=3D val) { > > + printf(PREFIX ERROR_PREFIX "check fail: buf[%lu] = =3D %u !=3D %u\n", > > + i, buf[i], val); > > + return false; > > + } > > + } > > + > > + return true; > > +} > > + > > +static bool seek_read_hugepage_filemap(int fd, size_t len, size_t wr_c= hunk_size, > > + off_t offset, size_t expected) > > +{ > > + char buf[MAX_WRITE_READ_CHUNK_SIZE]; > > + ssize_t ret_count =3D 0; > > + ssize_t total_ret_count =3D 0; > > + char val =3D offset / wr_chunk_size + offset % wr_chunk_size; > > + > > + printf(PREFIX PREFIX "init val=3D%u with offset=3D0x%lx\n", val, = offset); > > + printf(PREFIX PREFIX "expect to read 0x%lx bytes of data in total= \n", > > + expected); > > + if (lseek(fd, offset, SEEK_SET) < 0) { > > + perror(PREFIX ERROR_PREFIX "seek failed"); > > + return false; > > + } > > + > > + while (offset + total_ret_count < len) { > > + ret_count =3D read(fd, buf, wr_chunk_size); > > + if (ret_count =3D=3D 0) { > > + printf(PREFIX PREFIX "read reach end of the file\= n"); > > + break; > > + } else if (ret_count < 0) { > > + perror(PREFIX ERROR_PREFIX "read failed"); > > + break; > > + } > > + ++val; > > + if (!verify_chunk(buf, ret_count, val)) > > + return false; > > + > > + total_ret_count +=3D ret_count; > > + } > > + printf(PREFIX PREFIX "actually read 0x%lx bytes of data in total\= n", > > + total_ret_count); > > + > > + return total_ret_count =3D=3D expected; > > +} > > + > > +static bool read_hugepage_filemap(int fd, size_t len, > > + size_t wr_chunk_size, size_t expected) > > +{ > > + char buf[MAX_WRITE_READ_CHUNK_SIZE]; > > + ssize_t ret_count =3D 0; > > + ssize_t total_ret_count =3D 0; > > + char val =3D 0; > > + > > + printf(PREFIX PREFIX "expect to read 0x%lx bytes of data in total= \n", > > + expected); > > + while (total_ret_count < len) { > > + ret_count =3D read(fd, buf, wr_chunk_size); > > + if (ret_count =3D=3D 0) { > > + printf(PREFIX PREFIX "read reach end of the file\= n"); > > + break; > > + } else if (ret_count < 0) { > > + perror(PREFIX ERROR_PREFIX "read failed"); > > + break; > > + } > > + ++val; > > + if (!verify_chunk(buf, ret_count, val)) > > + return false; > > + > > + total_ret_count +=3D ret_count; > > + } > > + printf(PREFIX PREFIX "actually read 0x%lx bytes of data in total\= n", > > + total_ret_count); > > + > > + return total_ret_count =3D=3D expected; > > +} > > + > > +static enum test_status > > +test_hugetlb_read(int fd, size_t len, size_t wr_chunk_size) > > +{ > > + enum test_status status =3D TEST_SKIPPED; > > + char *filemap =3D NULL; > > + > > + if (ftruncate(fd, len) < 0) { > > + perror(PREFIX ERROR_PREFIX "ftruncate failed"); > > + return status; > > + } > > + > > + filemap =3D mmap(NULL, len, PROT_READ | PROT_WRITE, > > + MAP_SHARED | MAP_POPULATE, fd, 0); > > + if (filemap =3D=3D MAP_FAILED) { > > + perror(PREFIX ERROR_PREFIX "mmap for primary mapping fail= ed"); > > + goto done; > > + } > > + > > + setup_filemap(filemap, len, wr_chunk_size); > > + status =3D TEST_FAILED; > > + > > + if (read_hugepage_filemap(fd, len, wr_chunk_size, len)) > > + status =3D TEST_PASSED; > > + > > + munmap(filemap, len); > > +done: > > + if (ftruncate(fd, 0) < 0) { > > + perror(PREFIX ERROR_PREFIX "ftruncate back to 0 failed"); > > + status =3D TEST_FAILED; > > + } > > + > > + return status; > > +} > > + > > +static enum test_status > > +test_hugetlb_read_hwpoison(int fd, size_t len, size_t wr_chunk_size, > > + bool skip_hwpoison_page) > > +{ > > + enum test_status status =3D TEST_SKIPPED; > > + char *filemap =3D NULL; > > + char *hwp_addr =3D NULL; > > + const unsigned long pagesize =3D getpagesize(); > > + > > + if (ftruncate(fd, len) < 0) { > > + perror(PREFIX ERROR_PREFIX "ftruncate failed"); > > + return status; > > + } > > + > > + filemap =3D mmap(NULL, len, PROT_READ | PROT_WRITE, > > + MAP_SHARED | MAP_POPULATE, fd, 0); > > + if (filemap =3D=3D MAP_FAILED) { > > + perror(PREFIX ERROR_PREFIX "mmap for primary mapping fail= ed"); > > + goto done; > > + } > > + > > + setup_filemap(filemap, len, wr_chunk_size); > > + status =3D TEST_FAILED; > > + > > + /* > > + * Poisoned hugetlb page layout (assume hugepagesize=3D2MB): > > + * |<---------------------- 1MB ---------------------->| > > + * |<---- healthy page ---->|<---- HWPOISON page ----->| > > + * |<------------------- (1MB - 8KB) ----------------->| > > + */ > > + hwp_addr =3D filemap + len / 2 + pagesize; > > + if (madvise(hwp_addr, pagesize, MADV_HWPOISON) < 0) { > > + perror(PREFIX ERROR_PREFIX "MADV_HWPOISON failed"); > > + goto unmap; > > + } > > + > > + if (!skip_hwpoison_page) { > > + /* > > + * Userspace should be able to read (1MB + 1 page) from > > + * the beginning of the HWPOISONed hugepage. > > + */ > > + if (read_hugepage_filemap(fd, len, wr_chunk_size, > > + len / 2 + pagesize)) > > + status =3D TEST_PASSED; > > + } else { > > + /* > > + * Userspace should be able to read (1MB - 2 pages) from > > + * HWPOISONed hugepage. > > + */ > > + if (seek_read_hugepage_filemap(fd, len, wr_chunk_size, > > + len / 2 + MAX(2 * pagesize= , wr_chunk_size), > > + len / 2 - MAX(2 * pagesize= , wr_chunk_size))) > > + status =3D TEST_PASSED; > > + } > > + > > +unmap: > > + munmap(filemap, len); > > +done: > > + if (ftruncate(fd, 0) < 0) { > > + perror(PREFIX ERROR_PREFIX "ftruncate back to 0 failed"); > > + status =3D TEST_FAILED; > > + } > > + > > + return status; > > +} > > + > > +static int create_hugetlbfs_file(struct statfs *file_stat) > > +{ > > + int fd; > > + > > + fd =3D memfd_create("hugetlb_tmp", MFD_HUGETLB); > > + if (fd < 0) { > > + perror(PREFIX ERROR_PREFIX "could not open hugetlbfs file= "); > > + return -1; > > + } > > + > > + memset(file_stat, 0, sizeof(*file_stat)); > > + if (fstatfs(fd, file_stat)) { > > + perror(PREFIX ERROR_PREFIX "fstatfs failed"); > > + goto close; > > + } > > + if (file_stat->f_type !=3D HUGETLBFS_MAGIC) { > > + printf(PREFIX ERROR_PREFIX "not hugetlbfs file\n"); > > + goto close; > > + } > > + > > + return fd; > > +close: > > + close(fd); > > + return -1; > > +} > > + > > +int main(void) > > +{ > > + int fd; > > + struct statfs file_stat; > > + enum test_status status; > > + /* Test read() in different granularity. */ > > + size_t wr_chunk_sizes[] =3D { > > + getpagesize() / 2, getpagesize(), > > + getpagesize() * 2, getpagesize() * 4 > > + }; > > + size_t i; > > + > > + for (i =3D 0; i < ARRAY_SIZE(wr_chunk_sizes); ++i) { > > + printf("Write/read chunk size=3D0x%lx\n", > > + wr_chunk_sizes[i]); > > + > > + fd =3D create_hugetlbfs_file(&file_stat); > > + if (fd < 0) > > + goto create_failure; > > + printf(PREFIX "HugeTLB read regression test...\n"); > > + status =3D test_hugetlb_read(fd, file_stat.f_bsize, > > + wr_chunk_sizes[i]); > > + printf(PREFIX "HugeTLB read regression test...%s\n", > > + status_to_str(status)); > > + close(fd); > > + if (status =3D=3D TEST_FAILED) > > + return -1; > > + > > + fd =3D create_hugetlbfs_file(&file_stat); > > + if (fd < 0) > > + goto create_failure; > > + printf(PREFIX "HugeTLB read HWPOISON test...\n"); > > + status =3D test_hugetlb_read_hwpoison(fd, file_stat.f_bsi= ze, > > + wr_chunk_sizes[i], fa= lse); > > + printf(PREFIX "HugeTLB read HWPOISON test...%s\n", > > + status_to_str(status)); > > + close(fd); > > + if (status =3D=3D TEST_FAILED) > > + return -1; > > + > > + fd =3D create_hugetlbfs_file(&file_stat); > > + if (fd < 0) > > + goto create_failure; > > + printf(PREFIX "HugeTLB seek then read HWPOISON test...\n"= ); > > + status =3D test_hugetlb_read_hwpoison(fd, file_stat.f_bsi= ze, > > + wr_chunk_sizes[i], tr= ue); > > + printf(PREFIX "HugeTLB seek then read HWPOISON test...%s\= n", > > + status_to_str(status)); > > + close(fd); > > + if (status =3D=3D TEST_FAILED) > > + return -1; > > + } > > + > > + return 0; > > + > > +create_failure: > > + printf(ERROR_PREFIX "Abort test: failed to create hugetlbfs file\= n"); > > + return -1; > > +} > > -- > BR, > Muhammad Usama Anjum