linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Brodsky <kevin.brodsky@arm.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
	Kevin Brodsky <kevin.brodsky@arm.com>,
	akpm@linux-foundation.org, aruna.ramakrishna@oracle.com,
	catalin.marinas@arm.com, dave.hansen@linux.intel.com,
	joey.gouly@arm.com, keith.lucas@oracle.com, ryan.roberts@arm.com,
	shuah@kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kselftest@vger.kernel.org, x86@kernel.org
Subject: [PATCH 08/14] selftests/mm: Ensure pkey-*.h define inline functions only
Date: Mon,  9 Dec 2024 09:50:13 +0000	[thread overview]
Message-ID: <20241209095019.1732120-9-kevin.brodsky@arm.com> (raw)
In-Reply-To: <20241209095019.1732120-1-kevin.brodsky@arm.com>

Headers should not define non-inline functions, as this prevents
them from being included more than once in a given program.
pkey-helpers.h and the arch-specific headers it includes currently
define multiple such non-inline functions.

In most cases those functions can simply be made inline - this patch
does just that. read_ptr() is an exception as it must not be
inlined. Since it is only called from protection_keys.c, we just move it
there.

Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
 tools/testing/selftests/mm/pkey-arm64.h      | 4 ++--
 tools/testing/selftests/mm/pkey-helpers.h    | 8 +-------
 tools/testing/selftests/mm/pkey-powerpc.h    | 4 ++--
 tools/testing/selftests/mm/pkey-x86.h        | 6 +++---
 tools/testing/selftests/mm/protection_keys.c | 7 +++++++
 5 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/mm/pkey-arm64.h b/tools/testing/selftests/mm/pkey-arm64.h
index d9d2100eafc0..9897e31f16dd 100644
--- a/tools/testing/selftests/mm/pkey-arm64.h
+++ b/tools/testing/selftests/mm/pkey-arm64.h
@@ -81,11 +81,11 @@ static inline int get_arch_reserved_keys(void)
 	return NR_RESERVED_PKEYS;
 }
 
-void expect_fault_on_read_execonly_key(void *p1, int pkey)
+static inline void expect_fault_on_read_execonly_key(void *p1, int pkey)
 {
 }
 
-void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
+static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
 {
 	return PTR_ERR_ENOTSUP;
 }
diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
index 84376ab09545..bc81275a89d9 100644
--- a/tools/testing/selftests/mm/pkey-helpers.h
+++ b/tools/testing/selftests/mm/pkey-helpers.h
@@ -84,13 +84,7 @@ extern void abort_hooks(void);
 # define noinline __attribute__((noinline))
 #endif
 
-noinline int read_ptr(int *ptr)
-{
-	/* Keep GCC from optimizing this away somehow */
-	barrier();
-	return *ptr;
-}
-
+noinline int read_ptr(int *ptr);
 void expected_pkey_fault(int pkey);
 int sys_pkey_alloc(unsigned long flags, unsigned long init_val);
 int sys_pkey_free(unsigned long pkey);
diff --git a/tools/testing/selftests/mm/pkey-powerpc.h b/tools/testing/selftests/mm/pkey-powerpc.h
index 3d0c0bdae5bc..1bad310d282a 100644
--- a/tools/testing/selftests/mm/pkey-powerpc.h
+++ b/tools/testing/selftests/mm/pkey-powerpc.h
@@ -91,7 +91,7 @@ static inline int get_arch_reserved_keys(void)
 			return NR_RESERVED_PKEYS_64K_3KEYS;
 }
 
-void expect_fault_on_read_execonly_key(void *p1, int pkey)
+static inline void expect_fault_on_read_execonly_key(void *p1, int pkey)
 {
 	/*
 	 * powerpc does not allow userspace to change permissions of exec-only
@@ -105,7 +105,7 @@ void expect_fault_on_read_execonly_key(void *p1, int pkey)
 /* 4-byte instructions * 16384 = 64K page */
 #define __page_o_noops() asm(".rept 16384 ; nop; .endr")
 
-void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
+static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
 {
 	void *ptr;
 	int ret;
diff --git a/tools/testing/selftests/mm/pkey-x86.h b/tools/testing/selftests/mm/pkey-x86.h
index ac91777c8917..f7ecd335df1e 100644
--- a/tools/testing/selftests/mm/pkey-x86.h
+++ b/tools/testing/selftests/mm/pkey-x86.h
@@ -113,7 +113,7 @@ static inline u32 pkey_bit_position(int pkey)
 #define XSTATE_PKEY	0x200
 #define XSTATE_BV_OFFSET	512
 
-int pkey_reg_xstate_offset(void)
+static inline int pkey_reg_xstate_offset(void)
 {
 	unsigned int eax;
 	unsigned int ebx;
@@ -148,7 +148,7 @@ static inline int get_arch_reserved_keys(void)
 	return NR_RESERVED_PKEYS;
 }
 
-void expect_fault_on_read_execonly_key(void *p1, int pkey)
+static inline void expect_fault_on_read_execonly_key(void *p1, int pkey)
 {
 	int ptr_contents;
 
@@ -157,7 +157,7 @@ void expect_fault_on_read_execonly_key(void *p1, int pkey)
 	expected_pkey_fault(pkey);
 }
 
-void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
+static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
 {
 	return PTR_ERR_ENOTSUP;
 }
diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
index fcbebc4490b4..82ece325b70c 100644
--- a/tools/testing/selftests/mm/protection_keys.c
+++ b/tools/testing/selftests/mm/protection_keys.c
@@ -54,6 +54,13 @@ int test_nr;
 u64 shadow_pkey_reg;
 int dprint_in_signal;
 
+noinline int read_ptr(int *ptr)
+{
+	/* Keep GCC from optimizing this away somehow */
+	barrier();
+	return *ptr;
+}
+
 void cat_into_file(char *str, char *file)
 {
 	int fd = open(file, O_RDWR);
-- 
2.47.0



  parent reply	other threads:[~2024-12-09  9:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-09  9:50 [PATCH 00/14] pkeys kselftests improvements Kevin Brodsky
2024-12-09  9:50 ` [PATCH 01/14] selftests/mm: Fix condition in uffd_move_test_common() Kevin Brodsky
2024-12-09  9:50 ` [PATCH 02/14] selftests/mm: Fix -Wmaybe-uninitialized warnings Kevin Brodsky
2024-12-09  9:50 ` [PATCH 03/14] selftests/mm: Fix strncpy() length Kevin Brodsky
2024-12-09  9:50 ` [PATCH 04/14] selftests/mm: Fix -Warray-bounds warnings in pkey_sighandler_tests Kevin Brodsky
2024-12-18 15:36   ` [PATCH] selftests/mm: Fix -Wnull-dereference on Clang Kevin Brodsky
2024-12-09  9:50 ` [PATCH 05/14] selftests/mm: Build with -O2 Kevin Brodsky
2025-01-07 17:01   ` [PATCH] selftests/mm: silence unused-result warnings Kevin Brodsky
2024-12-09  9:50 ` [PATCH 06/14] selftests/mm: Remove unused pkey helpers Kevin Brodsky
2024-12-09  9:50 ` [PATCH 07/14] selftests/mm: Define types using typedef in pkey-helpers.h Kevin Brodsky
2024-12-09  9:50 ` Kevin Brodsky [this message]
2024-12-09  9:50 ` [PATCH 09/14] selftests/mm: Remove empty pkey helper definition Kevin Brodsky
2024-12-09  9:50 ` [PATCH 10/14] selftests/mm: Ensure non-global pkey symbols are marked static Kevin Brodsky
2024-12-09  9:50 ` [PATCH 11/14] selftests/mm: Use sys_pkey helpers consistently Kevin Brodsky
2024-12-15 22:09   ` Alexander Gordeev
2024-12-16  9:28     ` [PATCH] selftests/mm: fix dependency on pkey_util.c Kevin Brodsky
2024-12-09  9:50 ` [PATCH 12/14] selftests/mm: Rename pkey register macro Kevin Brodsky
2024-12-09  9:50 ` [PATCH 13/14] selftests/mm: Skip pkey_sighandler_tests if support is missing Kevin Brodsky
2024-12-09  9:50 ` [PATCH 14/14] selftests/mm: Remove X permission from sigaltstack mapping Kevin Brodsky

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=20241209095019.1732120-9-kevin.brodsky@arm.com \
    --to=kevin.brodsky@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aruna.ramakrishna@oracle.com \
    --cc=catalin.marinas@arm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=joey.gouly@arm.com \
    --cc=keith.lucas@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=shuah@kernel.org \
    --cc=x86@kernel.org \
    /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