Skip to contentSkip to conversation

selftest/powerpc/ptrace/core-pkey: Remove duplicate macros

PATCH Applied Madhavan Srinivasan 2 participants 5 messages Dec 16, 2024 – Jan 1, 2025

Subsystems (2)
lore
Share & tools
lore

Madhavan Srinivasan

author maintainer
#0 lore raw

PATCH v2 1/3 selftest/powerpc/ptrace/core-pkey: Remove duplicate macros

./powerpc/ptrace/Makefile includes flags.mk. In flags.mk, -I$(selfdir)/powerpc/include is always included as part of CFLAGS. So it will pick up the "pkeys.h" defined in powerpc/include.

core-pkey.c test has couple of macros defined which are part of "pkeys.h" header file. Remove those duplicates and include "pkeys.h"

---
Changelog v1:
- Added Reviewed-by tag
- made changes to commit message

 .../selftests/powerpc/ptrace/core-pkey.c      | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)
tools/testing/selftests/powerpc/ptrace/core-pkey.c +1 -18
index f6da4cb30cd6..31c9bf6d95db 100644
@@ -16,14 +16,7 @@
 #include <unistd.h>
 #include "ptrace.h"
 #include "child.h"
-
-#ifndef __NR_pkey_alloc
-#define __NR_pkey_alloc		384
-#endif
-
-#ifndef __NR_pkey_free
-#define __NR_pkey_free		385
-#endif
+#include "pkeys.h"
 
 #ifndef NT_PPC_PKEY
 #define NT_PPC_PKEY		0x110
@@ -61,16 +54,6 @@ struct shared_info {
 	time_t core_time;
 };
 
-static int sys_pkey_alloc(unsigned long flags, unsigned long init_access_rights)
-{
-	return syscall(__NR_pkey_alloc, flags, init_access_rights);
-}
-
-static int sys_pkey_free(int pkey)
-{
-	return syscall(__NR_pkey_free, pkey);
-}
-
 static int increase_core_file_limit(void)
 {
 	struct rlimit rlim;
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH v2 2/3 selftest/powerpc/ptrace/ptrace-pkey: Remove duplicate macros

./powerpc/ptrace/Makefile includes flags.mk.
In flags.mk, -I$(selfdir)/powerpc/include is always included as part of CFLAGS. So it will pick up the "pkeys.h" defined in powerpc/include.

ptrace-pkey.c test has macros defined which
are part of "pkeys.h" header file. Remove those duplicates and include "pkeys.h"

---
Changelog v1:
- Added Reviewed-by tag
- made changes to commit message

 .../testing/selftests/powerpc/ptrace/ptrace-pkey.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +1 -13
index d89474377f11..6893ed096457 100644
@@ -7,14 +7,7 @@
  */
 #include "ptrace.h"
 #include "child.h"
-
-#ifndef __NR_pkey_alloc
-#define __NR_pkey_alloc		384
-#endif
-
-#ifndef __NR_pkey_free
-#define __NR_pkey_free		385
-#endif
+#include "pkeys.h"
 
 #ifndef NT_PPC_PKEY
 #define NT_PPC_PKEY		0x110
@@ -61,11 +54,6 @@ struct shared_info {
 	unsigned long invalid_uamor;
 };
 
-static int sys_pkey_alloc(unsigned long flags, unsigned long init_access_rights)
-{
-	return syscall(__NR_pkey_alloc, flags, init_access_rights);
-}
-
 static int child(struct shared_info *info)
 {
 	unsigned long reg;
Signature · 1 line
2.47.0
author maintainer
#2 lore raw

PATCH v2 3/3 selftest/powerpc/ptrace: Cleanup duplicate macro definitions

In reply to Madhavan Srinivasan

Both core-pkey.c and ptrace-pkey.c tests have
similar macro definitions, move them to "pkeys.h"
and remove the macro definitions from the C file.

---
Changelog v1:
- Removed additional macros pointed out by Ritesh which are duplicates and are avilable in "pkeys.h"

 tools/testing/selftests/powerpc/include/pkeys.h      |  8 ++++++++
 tools/testing/selftests/powerpc/ptrace/core-pkey.c   | 12 ------------
 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c | 12 ------------
 3 files changed, 8 insertions(+), 24 deletions(-)
tools/testing/selftests/powerpc/include/pkeys.h +8 -0
index 51729d9a7111..3a0129467de6 100644
@@ -35,10 +35,18 @@
 #define __NR_pkey_alloc		384
 #define __NR_pkey_free		385
 
+#ifndef NT_PPC_PKEY
+#define NT_PPC_PKEY		0x110
+#endif
+
 #define PKEY_BITS_PER_PKEY	2
 #define NR_PKEYS		32
 #define PKEY_BITS_MASK		((1UL << PKEY_BITS_PER_PKEY) - 1)
 
+#define AMR_BITS_PER_PKEY 2
+#define PKEY_REG_BITS (sizeof(u64) * 8)
+#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))
+
 inline unsigned long pkeyreg_get(void)
 {
 	return mfspr(SPRN_AMR);
tools/testing/selftests/powerpc/ptrace/core-pkey.c +0 -12
index 31c9bf6d95db..f061434af452 100644
@@ -18,18 +18,6 @@
 #include "child.h"
 #include "pkeys.h"
 
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
-#ifndef PKEY_DISABLE_EXECUTE
-#define PKEY_DISABLE_EXECUTE	0x4
-#endif
-
-#define AMR_BITS_PER_PKEY 2
-#define PKEY_REG_BITS (sizeof(u64) * 8)
-#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))
-
 #define CORE_FILE_LIMIT	(5 * 1024 * 1024)	/* 5 MB should be enough */
 
 static const char core_pattern_file[] = "/proc/sys/kernel/core_pattern";
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +0 -12
index 6893ed096457..fc633014424f 100644
@@ -9,18 +9,6 @@
 #include "child.h"
 #include "pkeys.h"
 
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
-#ifndef PKEY_DISABLE_EXECUTE
-#define PKEY_DISABLE_EXECUTE	0x4
-#endif
-
-#define AMR_BITS_PER_PKEY 2
-#define PKEY_REG_BITS (sizeof(u64) * 8)
-#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))
-
 static const char user_read[] = "[User Read (Running)]";
 static const char user_write[] = "[User Write (Running)]";
 static const char ptrace_read_running[] = "[Ptrace Read (Running)]";
Signature · 1 line
2.47.0
reviewer Reviewed-by on v2 3/3
#3 lore raw

Re: [PATCH v2 3/3] selftest/powerpc/ptrace: Cleanup duplicate macro definitions

Quoted 9 lines · Madhavan Srinivasan

Both core-pkey.c and ptrace-pkey.c tests have
similar macro definitions, move them to "pkeys.h"
and remove the macro definitions from the C file.

---
Changelog v1:
- Removed additional macros pointed out by Ritesh which are duplicates and are avilable in "pkeys.h"

Thanks! The changes looks good to me.

Please feel free to add -

Gave a quick run on my lpar too -

# selftests: powerpc/ptrace: core-pkey
# test: core_pkey
# [User Write (Running)] AMR: 3cffffffffffffff pkey1: 4 pkey2: 5 pkey3: 6
# success: core_pkey
ok 9 selftests: powerpc/ptrace: core-pkey
# selftests: powerpc/ptrace: ptrace-pkey
# test: ptrace_pkey
# [User Write (Running)] AMR: 3cffffffffffffff pkey1: 4 pkey2: 5 pkey3: 6
# success: ptrace_pkey
ok 13 selftests: powerpc/ptrace: ptrace-pkey

-ritesh

Quoted 77 lines
 tools/testing/selftests/powerpc/include/pkeys.h      |  8 ++++++++
 tools/testing/selftests/powerpc/ptrace/core-pkey.c   | 12 ------------
 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c | 12 ------------
 3 files changed, 8 insertions(+), 24 deletions(-)
tools/testing/selftests/powerpc/include/pkeys.h +8 -0
index 51729d9a7111..3a0129467de6 100644
@@ -35,10 +35,18 @@
 #define __NR_pkey_alloc		384
 #define __NR_pkey_free		385
 
+#ifndef NT_PPC_PKEY
+#define NT_PPC_PKEY		0x110
+#endif
+
 #define PKEY_BITS_PER_PKEY	2
 #define NR_PKEYS		32
 #define PKEY_BITS_MASK		((1UL << PKEY_BITS_PER_PKEY) - 1)
 
+#define AMR_BITS_PER_PKEY 2
+#define PKEY_REG_BITS (sizeof(u64) * 8)
+#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))
+
 inline unsigned long pkeyreg_get(void)
 {
 	return mfspr(SPRN_AMR);
tools/testing/selftests/powerpc/ptrace/core-pkey.c +0 -12
index 31c9bf6d95db..f061434af452 100644
@@ -18,18 +18,6 @@
 #include "child.h"
 #include "pkeys.h"
 
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
-#ifndef PKEY_DISABLE_EXECUTE
-#define PKEY_DISABLE_EXECUTE	0x4
-#endif
-
-#define AMR_BITS_PER_PKEY 2
-#define PKEY_REG_BITS (sizeof(u64) * 8)
-#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))
-
 #define CORE_FILE_LIMIT	(5 * 1024 * 1024)	/* 5 MB should be enough */
 
 static const char core_pattern_file[] = "/proc/sys/kernel/core_pattern";
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +0 -12
index 6893ed096457..fc633014424f 100644
@@ -9,18 +9,6 @@
 #include "child.h"
 #include "pkeys.h"
 
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
-#ifndef PKEY_DISABLE_EXECUTE
-#define PKEY_DISABLE_EXECUTE	0x4
-#endif
-
-#define AMR_BITS_PER_PKEY 2
-#define PKEY_REG_BITS (sizeof(u64) * 8)
-#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))
-
 static const char user_read[] = "[User Read (Running)]";
 static const char user_write[] = "[User Write (Running)]";
 static const char ptrace_read_running[] = "[Ptrace Read (Running)]";
Signature · 1 line
2.47.0
author maintainer Applied
#4 lore raw
In reply to Madhavan Srinivasan
Quoted 10 lines · Madhavan Srinivasan

./powerpc/ptrace/Makefile includes flags.mk. In flags.mk, -I$(selfdir)/powerpc/include is always included as part of CFLAGS. So it will pick up the "pkeys.h" defined in powerpc/include.

core-pkey.c test has couple of macros defined which are part of "pkeys.h" header file. Remove those duplicates and include "pkeys.h"

[...]

Applied to powerpc/next.

[1/3] selftest/powerpc/ptrace/core-pkey: Remove duplicate macros

      https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=026ac4dda8f666f737b375731e30ef8f5698b215 
[2/3] selftest/powerpc/ptrace/ptrace-pkey: Remove duplicate macros
      https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=b0e1b95b1597ad3d87ff91d52f6b67cc9423c31e 
[3/3] selftest/powerpc/ptrace: Cleanup duplicate macro definitions
      https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=65f5038352e8f635fb827f7482f1d08fae4d16bf 

Thanks