Skip to contentSkip to conversation

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

PATCH Superseded Madhavan Srinivasan 2 participants 9 messages Dec 9, 2024 – Dec 16, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Madhavan Srinivasan

author maintainer
#0 lore raw

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

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

---
 .../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 2/3 selftest/powerpc/ptrace/ptrace-pkey: Remove duplicate macros

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

---
 .../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
#4 lore raw

PATCH 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.

---
 tools/testing/selftests/powerpc/include/pkeys.h      | 8 ++++++++
 tools/testing/selftests/powerpc/ptrace/core-pkey.c   | 8 --------
 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c | 8 --------
 3 files changed, 8 insertions(+), 16 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 -8
index 31c9bf6d95db..f8ff05e5bf6e 100644
@@ -18,18 +18,10 @@
 #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 -8
index 6893ed096457..5d528d0ea9d1 100644
@@ -9,18 +9,10 @@
 #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 v1 1/3
#7 lore raw
In reply to Madhavan Srinivasan
Quoted 8 lines · Madhavan Srinivasan

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

---
 .../selftests/powerpc/ptrace/core-pkey.c      | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

.../powerpc/ptrace/Makefile includes flags.mk. In .../powerpc/flags.mk we anyways add -I$(selfdir)/powerpc/include in CFLAGS - so it will pick up the header files defined in powerpc/include.

It make sense to clean this up and consolidate the common header definitions into pkeys.h header file. The changes looks good to me. Please feel free to add -

-ritesh

reviewer Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] selftest/powerpc/ptrace/ptrace-pkey: Remove duplicate macros

In reply to Madhavan Srinivasan
Quoted 9 lines · Madhavan Srinivasan

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

---
 .../testing/selftests/powerpc/ptrace/ptrace-pkey.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

Similar to previous patch. Cleanup looks good to me.

Please feel free to add -

-ritesh

#5 lore raw

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

In reply to Madhavan Srinivasan
Quoted 39 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.

---
 tools/testing/selftests/powerpc/include/pkeys.h      | 8 ++++++++
 tools/testing/selftests/powerpc/ptrace/core-pkey.c   | 8 --------
 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c | 8 --------
 3 files changed, 8 insertions(+), 16 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 -0
index 31c9bf6d95db..f8ff05e5bf6e 100644

tools/testing/selftests/powerpc/ptrace/core-pkey.c line 23

Quoted 10 lines
tools/testing/selftests/powerpc/ptrace/core-pkey.c +0 -4
@@ -18,18 +18,10 @@
 #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

We could remove this as well right. Since pkeys.h already has this permission defines i.e. PKEY_DISABLE_[ACCESS|WRITE|EXECUTE]

Quoted 14 lines
tools/testing/selftests/powerpc/ptrace/core-pkey.c +0 -4
-#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 -0
index 6893ed096457..5d528d0ea9d1 100644
@@ -9,18 +9,10 @@
 #include "child.h"

tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c line 15

Quoted 10 lines
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +0 -4
 #include "pkeys.h"
 
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
 #ifndef PKEY_DISABLE_EXECUTE
 #define PKEY_DISABLE_EXECUTE	0x4
 #endif
 

Same here. This can be cleaned up, no? Since pkeys already has this defined.

-ritesh

Quoted 9 lines
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +0 -4
-#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
#6 lore raw

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

Quoted 44 lines · Ritesh Harjani (IBM)
Quoted 42 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.

---
 tools/testing/selftests/powerpc/include/pkeys.h      | 8 ++++++++
 tools/testing/selftests/powerpc/ptrace/core-pkey.c   | 8 --------
 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c | 8 --------
 3 files changed, 8 insertions(+), 16 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 -0
index 31c9bf6d95db..f8ff05e5bf6e 100644
@@ -18,18 +18,10 @@
 #include "child.h"
 #include "pkeys.h"
 
Quoted 12 lines

tools/testing/selftests/powerpc/ptrace/core-pkey.c line 23

Quoted 7 lines
tools/testing/selftests/powerpc/ptrace/core-pkey.c +0 -4
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
 #ifndef PKEY_DISABLE_EXECUTE
 #define PKEY_DISABLE_EXECUTE	0x4
 #endif

We could remove this as well right. Since pkeys.h already has this permission defines i.e. PKEY_DISABLE_[ACCESS|WRITE|EXECUTE]

Nice catch. Yes we can drop these too.
Will fix and send a v2

Quoted 39 lines
Quoted 14 lines
tools/testing/selftests/powerpc/ptrace/core-pkey.c +0 -4
-#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 -0
index 6893ed096457..5d528d0ea9d1 100644
@@ -9,18 +9,10 @@
 #include "child.h"

tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c line 15

Quoted 10 lines
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +0 -4
 #include "pkeys.h"
 
-#ifndef NT_PPC_PKEY
-#define NT_PPC_PKEY		0x110
-#endif
-
 #ifndef PKEY_DISABLE_EXECUTE
 #define PKEY_DISABLE_EXECUTE	0x4
 #endif
 

Same here. This can be cleaned up, no? Since pkeys already has this defined.

-ritesh

Quoted 9 lines
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +0 -4
-#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
#3 lore raw

Re: [PATCH 2/3] selftest/powerpc/ptrace/ptrace-pkey: Remove duplicate macros

In reply to Ritesh Harjani (IBM)
Quoted 12 lines · Ritesh Harjani (IBM)
Quoted 9 lines · Madhavan Srinivasan

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

---
 .../testing/selftests/powerpc/ptrace/ptrace-pkey.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
Quoted 5 lines

Similar to previous patch. Cleanup looks good to me.

Please feel free to add -

Thanks

Quoted 1 line

-ritesh

author maintainer
#8 lore raw
In reply to Ritesh Harjani (IBM)
Quoted 15 lines · Ritesh Harjani (IBM)
Quoted 8 lines · Madhavan Srinivasan

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

---
 .../selftests/powerpc/ptrace/core-pkey.c      | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

.../powerpc/ptrace/Makefile includes flags.mk. In .../powerpc/flags.mk we anyways add -I$(selfdir)/powerpc/include in CFLAGS - so it will pick up the header files defined in powerpc/include.

Quoted 5 lines

It make sense to clean this up and consolidate the common header definitions into pkeys.h header file. The changes looks good to me. Please feel free to add -

Thanks

Quoted 2 lines

-ritesh