[PATCH v2 09/14] powerpc: Add NULLIFY_GPRS macros for register clears

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE1488d

3 messages, 3 authors, 2022-08-08 · open the first message on its own page

[PATCH v2 09/14] powerpc: Add NULLIFY_GPRS macros for register clears

From: Rohan McLure <hidden>
Date: 2022-07-25 06:30:47

Macros for restoring and saving registers to and from the stack exist.
Provide macros with the same interface for clearing a range of gprs by
setting each register's value in that range to zero.

The resulting macros are called NULLIFY_GPRS and NULLIFY_NVGPRS, keeping
with the naming of the accompanying restore and save macros, and usage
of nullify to describe this operation elsewhere in the kernel.

Signed-off-by: Rohan McLure <redacted>
---
V1 -> V2: Change 'ZERO' usage in naming to 'NULLIFY', a more obvious verb
---
 arch/powerpc/include/asm/ppc_asm.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
index 83c02f5a7f2a..d6c46082bf7f 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -33,6 +33,20 @@
 	.endr
 .endm
 
+/*
+ * This expands to a sequence of register clears for regs start to end
+ * inclusive, of the form:
+ *
+ *   li rN, 0
+ */
+.macro NULLIFY_REGS start, end
+	.Lreg=\start
+	.rept (\end - \start + 1)
+	li	.Lreg, 0
+	.Lreg=.Lreg+1
+	.endr
+.endm
+
 /*
  * Macros for storing registers into and loading registers from
  * exception frames.
@@ -49,6 +63,14 @@
 #define REST_NVGPRS(base)		REST_GPRS(13, 31, base)
 #endif
 
+#define	NULLIFY_GPRS(start, end)	NULLIFY_REGS start, end
+#ifdef __powerpc64__
+#define	NULLIFY_NVGPRS()		NULLIFY_GPRS(14, 31)
+#else
+#define	NULLIFY_NVGPRS()		NULLIFY_GPRS(13, 31)
+#endif
+#define	NULLIFY_GPR(n)			NULLIFY_GPRS(n, n)
+
 #define SAVE_GPR(n, base)		SAVE_GPRS(n, n, base)
 #define REST_GPR(n, base)		REST_GPRS(n, n, base)
 
-- 
2.34.1

Re: [PATCH v2 09/14] powerpc: Add NULLIFY_GPRS macros for register clears

From: Andrew Donnellan <hidden>
Date: 2022-08-08 07:43:34

On Mon, 2022-07-25 at 16:29 +1000, Rohan McLure wrote:
Macros for restoring and saving registers to and from the stack
exist.
Provide macros with the same interface for clearing a range of gprs
by
setting each register's value in that range to zero.

The resulting macros are called NULLIFY_GPRS and NULLIFY_NVGPRS,
keeping
with the naming of the accompanying restore and save macros, and
usage
of nullify to describe this operation elsewhere in the kernel.

Signed-off-by: Rohan McLure <redacted>
---
V1 -> V2: Change 'ZERO' usage in naming to 'NULLIFY', a more obvious
verb
And I see you've addressed my comment re 32 v 64 bit from V1 as well.

Reviewed-by: Andrew Donnellan <redacted>
quoted hunk
---
 arch/powerpc/include/asm/ppc_asm.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff --git a/arch/powerpc/include/asm/ppc_asm.h
b/arch/powerpc/include/asm/ppc_asm.h
index 83c02f5a7f2a..d6c46082bf7f 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -33,6 +33,20 @@
        .endr
 .endm
 
+/*
+ * This expands to a sequence of register clears for regs start to
end
+ * inclusive, of the form:
+ *
+ *   li rN, 0
+ */
+.macro NULLIFY_REGS start, end
+       .Lreg=\start
+       .rept (\end - \start + 1)
+       li      .Lreg, 0
+       .Lreg=.Lreg+1
+       .endr
+.endm
+
I suppose this could be done using the existing OP_REGS macro,
something like OP_REGS li, 0, start, end, 0, 0 - but a load immediate
is semantically a bit different from the existing uses of OP_REGS so I
don't mind either way
quoted hunk
 /*
  * Macros for storing registers into and loading registers from
  * exception frames.
@@ -49,6 +63,14 @@
 #define REST_NVGPRS(base)              REST_GPRS(13, 31, base)
 #endif
 
+#define        NULLIFY_GPRS(start, end)        NULLIFY_REGS start,
end
+#ifdef __powerpc64__
+#define        NULLIFY_NVGPRS()                NULLIFY_GPRS(14, 31)
+#else
+#define        NULLIFY_NVGPRS()                NULLIFY_GPRS(13, 31)
+#endif
+#define        NULLIFY_GPR(n)                  NULLIFY_GPRS(n, n)
+
 #define SAVE_GPR(n, base)              SAVE_GPRS(n, n, base)
 #define REST_GPR(n, base)              REST_GPRS(n, n, base)
 
-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited

Re: [PATCH v2 09/14] powerpc: Add NULLIFY_GPRS macros for register clears

From: Christophe Leroy <hidden>
Date: 2022-08-08 10:56:41


Le 08/08/2022 à 09:42, Andrew Donnellan a écrit :
On Mon, 2022-07-25 at 16:29 +1000, Rohan McLure wrote:
quoted
Macros for restoring and saving registers to and from the stack
exist.
Provide macros with the same interface for clearing a range of gprs
by
setting each register's value in that range to zero.

The resulting macros are called NULLIFY_GPRS and NULLIFY_NVGPRS,
keeping
with the naming of the accompanying restore and save macros, and
usage
of nullify to describe this operation elsewhere in the kernel.

Signed-off-by: Rohan McLure <redacted>
---
V1 -> V2: Change 'ZERO' usage in naming to 'NULLIFY', a more obvious
verb
And I see you've addressed my comment re 32 v 64 bit from V1 as well.

Reviewed-by: Andrew Donnellan <redacted>
quoted
---
  arch/powerpc/include/asm/ppc_asm.h | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)
diff --git a/arch/powerpc/include/asm/ppc_asm.h
b/arch/powerpc/include/asm/ppc_asm.h
index 83c02f5a7f2a..d6c46082bf7f 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -33,6 +33,20 @@
         .endr
  .endm
  
+/*
+ * This expands to a sequence of register clears for regs start to
end
+ * inclusive, of the form:
+ *
+ *   li rN, 0
+ */
+.macro NULLIFY_REGS start, end
+       .Lreg=\start
+       .rept (\end - \start + 1)
+       li      .Lreg, 0
+       .Lreg=.Lreg+1
+       .endr
+.endm
+
I suppose this could be done using the existing OP_REGS macro,
something like OP_REGS li, 0, start, end, 0, 0 - but a load immediate
is semantically a bit different from the existing uses of OP_REGS so I
don't mind either way
Not sure it would work. You'd get:

	li	.Lreg, 0 + 0 * .Lreg(0)


Even if it works that would be odd.
quoted
  /*
   * Macros for storing registers into and loading registers from
   * exception frames.
@@ -49,6 +63,14 @@
  #define REST_NVGPRS(base)              REST_GPRS(13, 31, base)
  #endif
  
+#define        NULLIFY_GPRS(start, end)        NULLIFY_REGS start,
end
+#ifdef __powerpc64__
+#define        NULLIFY_NVGPRS()                NULLIFY_GPRS(14, 31)
+#else
+#define        NULLIFY_NVGPRS()                NULLIFY_GPRS(13, 31)
+#endif
+#define        NULLIFY_GPR(n)                  NULLIFY_GPRS(n, n)
+
  #define SAVE_GPR(n, base)              SAVE_GPRS(n, n, base)
  #define REST_GPR(n, base)              REST_GPRS(n, n, base)
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help