From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E6D634A3D0; Wed, 7 Jan 2026 16:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804543; cv=none; b=hdmq63wBJHcCk+AG1yqXR10L06Dw5dXRrYlHaGHm3mO9C5XJaskPt8ze5j95TWqmiHrhH1YOKmMPnAOhxi5F8uAv5UataDPXl8TiO/frQF6xK94NUbFAu6qUZgTvJ2+aoS0ws4+A9J8ej0+J5SkJLKXScOJMmO9crlqePuW+KMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804543; c=relaxed/simple; bh=ZNRxNFE32weRNSCQI7tMxuz6rq0DOTVV9Nj6X02kyMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HGFGVvejFn+04gEGYxatp3n+fQzPd3o8U1biJhsAkjirzWRd6gGWsvWNh4YHtmf+v/qob8dcqvnMFyrFETFyvk4CTImvLMXm2Pytww6CEeBe4BvELpWgABRCyDKdSdOa2KoHuDtPQnVxX8IvzbMmZnP8upptMGrsu7H9ursecVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A5ED81595; Wed, 7 Jan 2026 08:48:45 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 434633F5A1; Wed, 7 Jan 2026 08:48:51 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan Subject: [PATCH v2 1/8] selftests/mm: default KDIR to build directory Date: Wed, 7 Jan 2026 16:48:35 +0000 Message-ID: <20260107164842.3289559-2-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" KDIR currently defaults to the running kernel's modules directory when building the page_frag module. The underlying assumption is that most users build the kselftests in order to run them against the system they're built on. This assumption seems questionable, and there is no guarantee that the module can actually be built against the running kernel. Switch the default value of KDIR to the kernel's build directory, i.e. $(O) if O=3D or KBUILD_OUTPUT=3D is used, and the source directory otherwise. This seems like the least surprising option: the test module is built against the kernel that has been previously built. Note: we can't use $(top_srcdir) in mm/Makefile because it is only defined once lib.mk is included. Signed-off-by: Kevin Brodsky --- tools/testing/selftests/mm/Makefile | 2 +- tools/testing/selftests/mm/page_frag/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/= mm/Makefile index eaf9312097f7..bb93101e339e 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -44,7 +44,7 @@ LDLIBS =3D -lrt -lpthread -lm # warnings. CFLAGS +=3D -U_FORTIFY_SOURCE =20 -KDIR ?=3D /lib/modules/$(shell uname -r)/build +KDIR ?=3D $(if $(O),$(O),$(realpath ../../../..)) ifneq (,$(wildcard $(KDIR)/Module.symvers)) ifneq (,$(wildcard $(KDIR)/include/linux/page_frag_cache.h)) TEST_GEN_MODS_DIR :=3D page_frag diff --git a/tools/testing/selftests/mm/page_frag/Makefile b/tools/testing/= selftests/mm/page_frag/Makefile index 8c8bb39ffa28..96e5f646e69b 100644 --- a/tools/testing/selftests/mm/page_frag/Makefile +++ b/tools/testing/selftests/mm/page_frag/Makefile @@ -1,5 +1,5 @@ PAGE_FRAG_TEST_DIR :=3D $(realpath $(dir $(abspath $(lastword $(MAKEFILE_L= IST))))) -KDIR ?=3D /lib/modules/$(shell uname -r)/build +KDIR ?=3D $(if $(O),$(O),$(realpath ../../../../..)) =20 ifeq ($(V),1) Q =3D --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A69F33EAEA; Wed, 7 Jan 2026 16:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804544; cv=none; b=kzGmPZsnVfrjWccZeLPP4VPUYml3kYBQ7zRAOtgSLMsPLonlgiQsiIctrqEBoGLGQsWAUqcjx50nWXq2q6xQIxWFo55PfIvTDCwM6vSaVMH0Bl0Wj8QtCyOys+6SPD+V/rn0iAK9b2GvjR+urM+MNpoIBABijh/JSSLXu2AQxXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804544; c=relaxed/simple; bh=2hMGx95vnh6gsO5PRXVTxc0UWEAyKtwTPhrSM17PS18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GFhMV2cSCfWYjydWp8/NB1ZDxbxWGXpCITKQi5H+xUuOtr8u0C9s/ojx0Y+/7wuk2b/2H7dqMl77MYwvwDtmg9y68A2FbP+Qe3h9M2FXBu6qpp8MH6gXO3LWZGzSNDdybP+4RH0x4uIkz9AbA9lj4xOjQlNU8czo2Q9ciO/lLwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5ACAA1655; Wed, 7 Jan 2026 08:48:47 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B8E433F5A1; Wed, 7 Jan 2026 08:48:52 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan , Paolo Abeni , Yunsheng Lin Subject: [PATCH v2 2/8] selftests/mm: remove flaky header check Date: Wed, 7 Jan 2026 16:48:36 +0000 Message-ID: <20260107164842.3289559-3-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 96ed62ea0298 ("mm: page_frag: fix a compile error when kernel is not compiled") introduced a check to avoid attempting to build the page_frag module if is missing. Unfortunately this check only works if KDIR points to /lib/modules/... or an in-tree kernel build. It always fails if KDIR points to an out-of-tree build (i.e. when the kernel was built with O=3D... make) because only generated headers are present under $KDIR/include/ in that case. A recent commit switched KDIR to default to the kernel's build directory, so that check is no longer justified. Cc: Paolo Abeni Cc: Yunsheng Lin Reviewed-by: Mark Brown Signed-off-by: Kevin Brodsky --- tools/testing/selftests/mm/Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/= mm/Makefile index bb93101e339e..4e5c8a330a0c 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -46,12 +46,8 @@ CFLAGS +=3D -U_FORTIFY_SOURCE =20 KDIR ?=3D $(if $(O),$(O),$(realpath ../../../..)) ifneq (,$(wildcard $(KDIR)/Module.symvers)) -ifneq (,$(wildcard $(KDIR)/include/linux/page_frag_cache.h)) TEST_GEN_MODS_DIR :=3D page_frag else -PAGE_FRAG_WARNING =3D "missing page_frag_cache.h, please use a newer kerne= l" -endif -else PAGE_FRAG_WARNING =3D "missing Module.symvers, please have the kernel buil= t first" endif =20 --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A37B71D9663; Wed, 7 Jan 2026 16:49:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804547; cv=none; b=jjvOmRMb2BWArfdWfQZu8S+uJEL/AP/g9D2w6d+137OXWFDTH7eEiF6eM35xux1v1c7D4PUEdyu/dfAdW/iJ4ASWJEc8d0PWnTXQxWCXmKel00VuBuYH4GNMck9/vjpdMHj3b8Sbyl74+9jEOooGBnAPp7xjZk1bt7aglAej4FM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804547; c=relaxed/simple; bh=cBc+ufD4FRgKpFnCsOOWFlNaSm3j1ngJiKwdJHI4Mbg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qsc+1nRs5iSYiVBRlmxvbQNOZtvIp5vqoTXS24dWilnoHCLwku01PdEP866xD99VmJC6j2yQWXbbspqtX3txBF0NnzmWqkt1HbUue4JAgebfpGXqkKLQlFgNvwD8M6vQT8h66yMVUBMjfCu3qc2/dNBL8jJCA/hGkig/DclbMkc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 10BF6165C; Wed, 7 Jan 2026 08:48:49 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6DF0F3F5A1; Wed, 7 Jan 2026 08:48:54 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan , Jason Gunthorpe , John Hubbard Subject: [PATCH v2 3/8] selftests/mm: pass down full CC and CFLAGS to check_config.sh Date: Wed, 7 Jan 2026 16:48:37 +0000 Message-ID: <20260107164842.3289559-4-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" check_config.sh checks that liburing is available by running the compiler provided as its first argument. This makes two assumptions: 1. CC consists of only one word 2. No extra flag is required Unfortunately, there are many situations where these assumptions don't hold. For instance: - When using Clang, CC consists of multiple words - When cross-compiling, extra flags may be required to allow the compiler to find headers Remove these assumptions by passing down CC and CFLAGS as-is from the Makefile, so that the same command line is used as when actually building the tests. Cc: Jason Gunthorpe Cc: John Hubbard Acked-by: David Hildenbrand (Red Hat) Signed-off-by: Kevin Brodsky Reviewed-by: Mark Brown --- tools/testing/selftests/mm/Makefile | 2 +- tools/testing/selftests/mm/check_config.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/= mm/Makefile index 4e5c8a330a0c..de4afc34e3b1 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -230,7 +230,7 @@ $(OUTPUT)/migration: LDLIBS +=3D -lnuma $(OUTPUT)/rmap: LDLIBS +=3D -lnuma =20 local_config.mk local_config.h: check_config.sh - /bin/sh ./check_config.sh $(CC) + CC=3D"$(CC)" CFLAGS=3D"$(CFLAGS)" ./check_config.sh =20 EXTRA_CLEAN +=3D local_config.mk local_config.h =20 diff --git a/tools/testing/selftests/mm/check_config.sh b/tools/testing/sel= ftests/mm/check_config.sh index 3954f4746161..b84c82bbf875 100755 --- a/tools/testing/selftests/mm/check_config.sh +++ b/tools/testing/selftests/mm/check_config.sh @@ -16,8 +16,7 @@ echo "#include " > $tmpfile_c echo "#include " >> $tmpfile_c echo "int func(void) { return 0; }" >> $tmpfile_c =20 -CC=3D${1:?"Usage: $0 # example compiler: gcc"} -$CC -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1 +$CC $CFLAGS -c $tmpfile_c -o $tmpfile_o =20 if [ -f $tmpfile_o ]; then echo "#define LOCAL_CONFIG_HAVE_LIBURING 1" > $OUTPUT_H_FILE --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57B35344033; Wed, 7 Jan 2026 16:49:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804551; cv=none; b=oEIBESotvML0mcqE7o3VhvsC+XXltl8lp7u97fnqS/JdCpPT7f8/8epAaYL9Hq2YuCaCK/0JZEYtNL3qwyuCI7u3ycaeMeUrxKJ8S7+glVgGmN9VX82ojoG4mv2KnKQQMwPgYZIf0RkEGsDf8/QCgWGrAZjhPpnowaBbY9t/d8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804551; c=relaxed/simple; bh=csI6Rpb4/mFi1tboLbskie8XKOiTZsT2pE/IHuHLI88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hSssuJobAZoR7NumupYmbkkox3IXQTC2CEmo9zYtrc3KnP+FZHJB5P8eSfEs1ClGrYJjxHoJO0OcTsJddGHAUw6b4/M13aFZJEjMkMwEu9belC+7lTu72tw7t/NRXkfwgEWKU8eipHNvACRxr0OiTG+eRjAmnXeeMLW8+n/ioXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85C241682; Wed, 7 Jan 2026 08:48:50 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 232CB3F5A1; Wed, 7 Jan 2026 08:48:56 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan Subject: [PATCH v2 4/8] selftests/mm: fix usage of FORCE_READ() in cow tests Date: Wed, 7 Jan 2026 16:48:38 +0000 Message-ID: <20260107164842.3289559-5-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 5bbc2b785e63 ("selftests/mm: fix FORCE_READ to read input value correctly") modified FORCE_READ() to take a value instead of a pointer. It also changed most of the call sites accordingly, but missed many of them in cow.c. In those cases, we ended up with the pointer itself being read, not the memory it points to. No failure occurred as a result, so it looks like the tests work just fine without faulting in. However, the huge_zeropage tests explicitly check that pages are populated, so those became skipped. Convert all the remaining FORCE_READ() to fault in the mapped page, as was originally intended. This allows the huge_zeropage tests to run again (3 tests in total). Fixes: 5bbc2b785e63 ("selftests/mm: fix FORCE_READ to read input value corr= ectly") Signed-off-by: Kevin Brodsky Acked-by: David Hildenbrand (Red Hat) Acked-by: SeongJae Park Reviewed-by: Dev Jain Reviewed-by: wang lian --- tools/testing/selftests/mm/cow.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/= cow.c index accfd198dbda..83b3563be26b 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -1612,8 +1612,8 @@ static void run_with_huge_zeropage(non_anon_test_fn f= n, const char *desc) * the first sub-page and test if we get another sub-page populated * automatically. */ - FORCE_READ(mem); - FORCE_READ(smem); + FORCE_READ(*mem); + FORCE_READ(*smem); if (!pagemap_is_populated(pagemap_fd, mem + pagesize) || !pagemap_is_populated(pagemap_fd, smem + pagesize)) { ksft_test_result_skip("Did not get THPs populated\n"); @@ -1663,8 +1663,8 @@ static void run_with_memfd(non_anon_test_fn fn, const= char *desc) } =20 /* Fault the page in. */ - FORCE_READ(mem); - FORCE_READ(smem); + FORCE_READ(*mem); + FORCE_READ(*smem); =20 fn(mem, smem, pagesize); munmap: @@ -1719,8 +1719,8 @@ static void run_with_tmpfile(non_anon_test_fn fn, con= st char *desc) } =20 /* Fault the page in. */ - FORCE_READ(mem); - FORCE_READ(smem); + FORCE_READ(*mem); + FORCE_READ(*smem); =20 fn(mem, smem, pagesize); munmap: @@ -1773,8 +1773,8 @@ static void run_with_memfd_hugetlb(non_anon_test_fn f= n, const char *desc, } =20 /* Fault the page in. */ - FORCE_READ(mem); - FORCE_READ(smem); + FORCE_READ(*mem); + FORCE_READ(*smem); =20 fn(mem, smem, hugetlbsize); munmap: --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DC3134B425; Wed, 7 Jan 2026 16:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804555; cv=none; b=dqMMoQEa6f5z8BpegjVZvQRR9MpoMBblhN+D4U7sxjNxsRdMaqtSUD914Gol6py6Y1ZvU3BqOYe0dEP5THLhxOwgy3Ys9JSZhJaNwE2kQdKI0X90XbvmJO8xMADIa3ezGDZqiQc7vXzrQNo0siTrZeJHCvABBzAfxNvGM0IVsx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804555; c=relaxed/simple; bh=hVcrYx1PlEIf89awYzQhAdw/HoIMx6RpxVSkN+eaEgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mJ2YIm7UXUuCXM7CeS/2sP1AZPjzHoKPSrxTszKM8NHziCNQWExkKv+6RUr4TBS2WdwzDWqhmd3eQM6ARfo4vJ5inDZmBb4dHDW5QC2zdAx6JQ55j17ioPq2OaEVWKEC7lK4GeV0esTe1w/W9JON3bSsPfDYMnL/2KpQ/+V7a3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 094C11684; Wed, 7 Jan 2026 08:48:52 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 986943F5A1; Wed, 7 Jan 2026 08:48:57 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan Subject: [PATCH v2 5/8] selftests/mm: introduce helper to read every page in range Date: Wed, 7 Jan 2026 16:48:39 +0000 Message-ID: <20260107164842.3289559-6-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" FORCE_READ(*addr) ensures that the compiler will emit a load from addr. Several tests need to trigger such a load for every page in the range [addr, addr + len), ensuring that every page is faulted in, if it wasn't already. Introduce a new helper force_read_pages_in_range() that does exactly that and replace existing loops with a call to it. Some of those loops have a different step size, but reading from every page is appropriate in all cases. Signed-off-by: Kevin Brodsky Reviewed-by: Dev Jain Reviewed-by: SeongJae Park --- tools/testing/selftests/mm/hugetlb-madvise.c | 9 +-------- tools/testing/selftests/mm/pfnmap.c | 16 ++++++---------- .../testing/selftests/mm/split_huge_page_test.c | 6 +----- tools/testing/selftests/mm/vm_util.h | 6 ++++++ 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/s= elftests/mm/hugetlb-madvise.c index 05d9d2805ae4..1f82568ae262 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -47,14 +47,7 @@ void write_fault_pages(void *addr, unsigned long nr_page= s) =20 void read_fault_pages(void *addr, unsigned long nr_pages) { - unsigned long i; - - for (i =3D 0; i < nr_pages; i++) { - unsigned long *addr2 =3D - ((unsigned long *)(addr + (i * huge_page_size))); - /* Prevent the compiler from optimizing out the entire loop: */ - FORCE_READ(*addr2); - } + force_read_pages_in_range(addr, nr_pages * huge_page_size); } =20 int main(int argc, char **argv) diff --git a/tools/testing/selftests/mm/pfnmap.c b/tools/testing/selftests/= mm/pfnmap.c index f546dfb10cae..35b0e3ed54cd 100644 --- a/tools/testing/selftests/mm/pfnmap.c +++ b/tools/testing/selftests/mm/pfnmap.c @@ -33,20 +33,17 @@ static void signal_handler(int sig) siglongjmp(sigjmp_buf_env, -EFAULT); } =20 -static int test_read_access(char *addr, size_t size, size_t pagesize) +static int test_read_access(char *addr, size_t size) { - size_t offs; int ret; =20 if (signal(SIGSEGV, signal_handler) =3D=3D SIG_ERR) return -EINVAL; =20 ret =3D sigsetjmp(sigjmp_buf_env, 1); - if (!ret) { - for (offs =3D 0; offs < size; offs +=3D pagesize) - /* Force a read that the compiler cannot optimize out. */ - *((volatile char *)(addr + offs)); - } + if (!ret) + force_read_pages_in_range(addr, size); + if (signal(SIGSEGV, SIG_DFL) =3D=3D SIG_ERR) return -EINVAL; =20 @@ -138,7 +135,7 @@ FIXTURE_SETUP(pfnmap) SKIP(return, "Invalid file: '%s'. Not pfnmap'ed\n", file); =20 /* ... and want to be able to read from them. */ - if (test_read_access(self->addr1, self->size1, self->pagesize)) + if (test_read_access(self->addr1, self->size1)) SKIP(return, "Cannot read-access mmap'ed '%s'\n", file); =20 self->size2 =3D 0; @@ -243,8 +240,7 @@ TEST_F(pfnmap, fork) ASSERT_GE(pid, 0); =20 if (!pid) { - EXPECT_EQ(test_read_access(self->addr1, self->size1, - self->pagesize), 0); + EXPECT_EQ(test_read_access(self->addr1, self->size1), 0); exit(0); } =20 diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index 40799f3f0213..65a89ceca4a5 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -652,11 +652,7 @@ static int create_pagecache_thp_and_fd(const char *tes= tfile, size_t fd_size, } madvise(*addr, fd_size, MADV_HUGEPAGE); =20 - for (size_t i =3D 0; i < fd_size; i++) { - char *addr2 =3D *addr + i; - - FORCE_READ(*addr2); - } + force_read_pages_in_range(*addr, fd_size); =20 if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) { ksft_print_msg("No large pagecache folio generated, please provide a fil= esystem supporting large folio\n"); diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index 6ad32b1830f1..74bdf96161d7 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -54,6 +54,12 @@ static inline unsigned int pshift(void) return __page_shift; } =20 +static inline void force_read_pages_in_range(char *addr, size_t len) +{ + for (size_t i =3D 0; i < len; i +=3D psize()) + FORCE_READ(addr[i]); +} + bool detect_huge_zeropage(void); =20 /* --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8279234D917; Wed, 7 Jan 2026 16:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804556; cv=none; b=DHXHSrTiiP0yF1i4ZC2c1D/J8t6XOZqTSrpvQ6Tu8kbcggy+T+pgtyfiKIeFjmCyRGeB0HxmkVpZONXs+hmQEsnqOSoOkOKcQQ+jHdOdDQr7A827VpjTgIDO3/rEr0UvG5QTxdH+LpwwNN/LxttF3p/Y9YqiiDCo3p83NNr10wE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804556; c=relaxed/simple; bh=JThi7RLwAirOPVgwT2JD5p1WRyNKU85M6QrfMprXfB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bPV8YHXGx9B6ybrwATot2O25NCDjMA9W7/xNYeaFhx4Iz4EJXmLP85MGBXkMi9vORU8xS8LpazTCHOc/208YWDcYVamScOh0zSCOVg+MOExH6ugABNoPSTUcshMMk7wl6EYruQVxU5TLw4t3EoeZ8INJ4MrJe83/74FloI9zaOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 98B71168F; Wed, 7 Jan 2026 08:48:53 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 19AA43F5A1; Wed, 7 Jan 2026 08:48:58 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan , Usama Anjum Subject: [PATCH v2 6/8] selftests/mm: fix faulting-in code in pagemap_ioctl test Date: Wed, 7 Jan 2026 16:48:40 +0000 Message-ID: <20260107164842.3289559-7-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" One of the pagemap_ioctl tests attempts to fault in pages by memcpy()'ing them to an unused buffer. This probably worked originally, but since commit 46036188ea1f ("selftests/mm: build with -O2") the compiler is free to optimise away that unused buffer and the memcpy() with it. As a result there might not be any resident page in the mapping and the test may fail. We don't need to copy all that memory anyway. Just fault in every page. Cc: Usama Anjum Signed-off-by: Kevin Brodsky Acked-by: David Hildenbrand (Red Hat) Reviewed-by: Dev Jain --- tools/testing/selftests/mm/pagemap_ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/sel= ftests/mm/pagemap_ioctl.c index 2cb5441f29c7..80d7c391f8f5 100644 --- a/tools/testing/selftests/mm/pagemap_ioctl.c +++ b/tools/testing/selftests/mm/pagemap_ioctl.c @@ -1056,7 +1056,6 @@ int sanity_tests(void) struct page_region *vec; char *mem, *fmem; struct stat sbuf; - char *tmp_buf; =20 /* 1. wrong operation */ mem_size =3D 10 * page_size; @@ -1167,8 +1166,7 @@ int sanity_tests(void) if (fmem =3D=3D MAP_FAILED) ksft_exit_fail_msg("error nomem %d %s\n", errno, strerror(errno)); =20 - tmp_buf =3D malloc(sbuf.st_size); - memcpy(tmp_buf, fmem, sbuf.st_size); + force_read_pages_in_range(fmem, sbuf.st_size); =20 ret =3D pagemap_ioctl(fmem, sbuf.st_size, vec, vec_size, 0, 0, 0, PAGEMAP_NON_WRITTEN_BITS, 0, PAGEMAP_NON_WRITTEN_BITS); --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5062834DB5D; Wed, 7 Jan 2026 16:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804554; cv=none; b=FCfHNi2IBrfaKBphBjHgDlYQKGWqBlqfhUGSkPUuWuFg6huPBNeH134Div623gEejmFsmwvt/SA4D7VQov0GquvLR+/ky/g3AFy9R17W5A06J2UgHczHSN0KU6zli4qrNXuK7HxAhIPQenXYFZ1wuxGE4WH7JrNvVW/ypCwbnCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804554; c=relaxed/simple; bh=CoBX3U6/CdMfDJGL6JKNGPROstMKemI+6RCXCNxZfLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JclapCG/LLTHtWXUDOihQ/58anbAHmcUBJOMIMUap+uZMz0NIDmCkedOKJSVCSE7ZSjgn3/kioiduHPrisaR99XcaScq7mfxT/Ikj8qtkDsboIys/6Aao5829PVFdqgpdYIGPc8iH32AGYEtYQ+PekJ5F+XxwZd7ETaVCRZrpMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 30ED91688; Wed, 7 Jan 2026 08:48:55 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A8FAC3F5A1; Wed, 7 Jan 2026 08:49:00 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan , Usama Anjum Subject: [PATCH v2 7/8] selftests/mm: fix exit code in pagemap_ioctl Date: Wed, 7 Jan 2026 16:48:41 +0000 Message-ID: <20260107164842.3289559-8-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make sure pagemap_ioctl exits with an appropriate value: * If the tests are run, call ksft_finished() to report the right status instead of reporting PASS unconditionally. * Report SKIP if userfaultfd isn't available (in line with other tests) * Report FAIL if we failed to open /proc/self/pagemap, as this file has been added a long time ago and doesn't depend on any CONFIG option (returning -EINVAL from main() is meaningless) Cc: Usama Anjum Reviewed-by: Ryan Roberts Reviewed-by: Mark Brown Acked-by: David Hildenbrand (Red Hat) Signed-off-by: Kevin Brodsky Acked-by: SeongJae Park Reviewed-by: Dev Jain Reviewed-by: wang lian --- tools/testing/selftests/mm/pagemap_ioctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/sel= ftests/mm/pagemap_ioctl.c index 80d7c391f8f5..7b214e8755f7 100644 --- a/tools/testing/selftests/mm/pagemap_ioctl.c +++ b/tools/testing/selftests/mm/pagemap_ioctl.c @@ -1551,7 +1551,7 @@ int main(int __attribute__((unused)) argc, char *argv= []) ksft_print_header(); =20 if (init_uffd()) - ksft_exit_pass(); + ksft_exit_skip("Failed to initialize userfaultfd\n"); =20 ksft_set_plan(117); =20 @@ -1560,7 +1560,7 @@ int main(int __attribute__((unused)) argc, char *argv= []) =20 pagemap_fd =3D open(PAGEMAP, O_RDONLY); if (pagemap_fd < 0) - return -EINVAL; + ksft_exit_fail_msg("Failed to open " PAGEMAP "\n"); =20 /* 1. Sanity testing */ sanity_tests_sd(); @@ -1732,5 +1732,5 @@ int main(int __attribute__((unused)) argc, char *argv= []) zeropfn_tests(); =20 close(pagemap_fd); - ksft_exit_pass(); + ksft_finished(); } --=20 2.51.2 From nobody Sun Feb 8 15:42:04 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 502E034DB47; Wed, 7 Jan 2026 16:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804553; cv=none; b=aPbhOj5TAidb43vtzAUTmuWrr0FHkmdAEpMklJ2g3yW3yT2CMzAYSpddWJMlgiNEuDGqD9/GjOMxB91ehcjM+clSRuSiWMpYP/BEG36yMCK83iG6LDGgiPO4s/jBGkkw5d057RuGjMO0yngNukCQ257cLryfpcy/hcK/JMNYsVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767804553; c=relaxed/simple; bh=vso8txYA5j9rF+IDmtRFs+v78bjUzSYPh0lwSQtU/Ic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GNAKrHgHeoBnmdKZhakjjb4YdgEEO1aAxLUUqmhYytQ1Ululr90zW3vlvDweprUREC08+BSmwUzBoz7GhJPajMk0yCwWAAn5Hrx4uBB8/8J8H5jm8U/O/Q13u9mkcsPfSaYT2xiXXFUf/pdfMNE3gq+Wj/MlS/lem8VaY46b7tw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A97021595; Wed, 7 Jan 2026 08:48:56 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 43EA53F5A1; Wed, 7 Jan 2026 08:49:02 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Mark Brown , Ryan Roberts , Shuah Khan Subject: [PATCH v2 8/8] selftests/mm: report SKIP in pfnmap if a check fails Date: Wed, 7 Jan 2026 16:48:42 +0000 Message-ID: <20260107164842.3289559-9-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107164842.3289559-1-kevin.brodsky@arm.com> References: <20260107164842.3289559-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pfnmap currently checks the target file in FIXTURE_SETUP(pfnmap), meaning once for every test, and skips the test if any check fails. The target file is the same for every test so this is a little overkill. More importantly, this approach means that the whole suite will report PASS even if all the tests are skipped because kernel configuration (e.g. CONFIG_STRICT_DEVMEM=3Dy) prevented /dev/mem from being mapped, for instance. Let's ensure that KSFT_SKIP is returned as exit code if any check fails by performing the checks in pfnmap_init(), run once. That function also takes care of finding the offset of the pages to be mapped and saves it in a global. The file is still mapped/unmapped for every test, as some of them modify the mapping. Signed-off-by: Kevin Brodsky Reviewed-by: Ryan Roberts --- tools/testing/selftests/mm/pfnmap.c | 81 ++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/mm/pfnmap.c b/tools/testing/selftests/= mm/pfnmap.c index 35b0e3ed54cd..e41d5464130b 100644 --- a/tools/testing/selftests/mm/pfnmap.c +++ b/tools/testing/selftests/mm/pfnmap.c @@ -25,8 +25,11 @@ #include "kselftest_harness.h" #include "vm_util.h" =20 +#define DEV_MEM_NPAGES 2 + static sigjmp_buf sigjmp_buf_env; static char *file =3D "/dev/mem"; +static off_t file_offset; =20 static void signal_handler(int sig) { @@ -88,7 +91,7 @@ static int find_ram_target(off_t *offset, break; =20 /* We need two pages. */ - if (end > start + 2 * pagesize) { + if (end > start + DEV_MEM_NPAGES * pagesize) { fclose(file); *offset =3D start; return 0; @@ -97,9 +100,49 @@ static int find_ram_target(off_t *offset, return -ENOENT; } =20 +static void pfnmap_init(void) +{ + size_t pagesize =3D getpagesize(); + size_t size =3D DEV_MEM_NPAGES * pagesize; + int fd; + void *addr; + + if (strncmp(file, "/dev/mem", strlen("/dev/mem")) =3D=3D 0) { + int err =3D find_ram_target(&file_offset, pagesize); + + if (err) + ksft_exit_skip("Cannot find ram target in '/proc/iomem': %s\n", + strerror(-err)); + } else { + file_offset =3D 0; + } + + /* + * Make sure we can open and map the file, and perform some basic + * checks; skip the whole suite if anything goes wrong. + * A fresh mapping is then created for every test case by + * FIXTURE_SETUP(pfnmap). + */ + fd =3D open(file, O_RDONLY); + if (fd < 0) + ksft_exit_skip("Cannot open '%s': %s\n", file, strerror(errno)); + + addr =3D mmap(NULL, size, PROT_READ, MAP_SHARED, fd, file_offset); + if (addr =3D=3D MAP_FAILED) + ksft_exit_skip("Cannot mmap '%s': %s\n", file, strerror(errno)); + + if (!check_vmflag_pfnmap(addr)) + ksft_exit_skip("Invalid file: '%s'. Not pfnmap'ed\n", file); + + if (test_read_access(addr, size)) + ksft_exit_skip("Cannot read-access mmap'ed '%s'\n", file); + + munmap(addr, size); + close(fd); +} + FIXTURE(pfnmap) { - off_t offset; size_t pagesize; int dev_mem_fd; char *addr1; @@ -112,31 +155,13 @@ FIXTURE_SETUP(pfnmap) { self->pagesize =3D getpagesize(); =20 - if (strncmp(file, "/dev/mem", strlen("/dev/mem")) =3D=3D 0) { - /* We'll require two physical pages throughout our tests ... */ - if (find_ram_target(&self->offset, self->pagesize)) - SKIP(return, - "Cannot find ram target in '/proc/iomem'\n"); - } else { - self->offset =3D 0; - } - self->dev_mem_fd =3D open(file, O_RDONLY); - if (self->dev_mem_fd < 0) - SKIP(return, "Cannot open '%s'\n", file); + ASSERT_GE(self->dev_mem_fd, 0); =20 - self->size1 =3D self->pagesize * 2; + self->size1 =3D DEV_MEM_NPAGES * self->pagesize; self->addr1 =3D mmap(NULL, self->size1, PROT_READ, MAP_SHARED, - self->dev_mem_fd, self->offset); - if (self->addr1 =3D=3D MAP_FAILED) - SKIP(return, "Cannot mmap '%s'\n", file); - - if (!check_vmflag_pfnmap(self->addr1)) - SKIP(return, "Invalid file: '%s'. Not pfnmap'ed\n", file); - - /* ... and want to be able to read from them. */ - if (test_read_access(self->addr1, self->size1)) - SKIP(return, "Cannot read-access mmap'ed '%s'\n", file); + self->dev_mem_fd, file_offset); + ASSERT_NE(self->addr1, MAP_FAILED); =20 self->size2 =3D 0; self->addr2 =3D MAP_FAILED; @@ -189,7 +214,7 @@ TEST_F(pfnmap, munmap_split) */ self->size2 =3D self->pagesize; self->addr2 =3D mmap(NULL, self->pagesize, PROT_READ, MAP_SHARED, - self->dev_mem_fd, self->offset); + self->dev_mem_fd, file_offset); ASSERT_NE(self->addr2, MAP_FAILED); } =20 @@ -258,8 +283,12 @@ int main(int argc, char **argv) if (strcmp(argv[i], "--") =3D=3D 0) { if (i + 1 < argc && strlen(argv[i + 1]) > 0) file =3D argv[i + 1]; - return test_harness_run(i, argv); + argc =3D i; + break; } } + + pfnmap_init(); + return test_harness_run(argc, argv); } --=20 2.51.2