[Skiboot] [PATCH 6/9] move opal_branch_table, opal_num_args to .rodata section

Nicholas Piggin npiggin at gmail.com
Thu Feb 27 05:34:05 AEDT 2020


.head is for code and data which must reside at a fixed low address,
mainly entry points.

These are moved into .rodata. Despite being modified at runtime, this
facilitates these tables being write-protected in a later patch.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 asm/head.S  |  7 -------
 asm/misc.S  | 10 ++++++++++
 core/opal.c | 12 ++++++------
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/asm/head.S b/asm/head.S
index 143f8af53..5ada79971 100644
--- a/asm/head.S
+++ b/asm/head.S
@@ -299,13 +299,6 @@ exception_entry_foo:
 	b	.
 
 	.= EXCEPTION_VECTORS_END
-	/* This is the OPAL branch table. It's populated at boot time
-	 * with function pointers to the various OPAL functions from
-	 * the content of the .opal_table section, indexed by Token.
-	 */
-.global opal_branch_table
-opal_branch_table:
-	.space	8 * (OPAL_LAST + 1)
 
 /* Stores the offset we were started from.  Used later on if we want to
  * read any unrelocated code/data such as the built-in kernel image
diff --git a/asm/misc.S b/asm/misc.S
index 9904b806f..058560a33 100644
--- a/asm/misc.S
+++ b/asm/misc.S
@@ -9,9 +9,19 @@
 #include <asm-offsets.h>
 #include <processor.h>
 #include <stack.h>
+#include <opal-api.h>
 
 #define OLD_BINUTILS 1
 
+	.section ".rodata"
+	/* This is the OPAL branch table. It's populated at boot time
+	 * with function pointers to the various OPAL functions from
+	 * the content of the .opal_table section, indexed by Token.
+	 */
+.global opal_branch_table
+opal_branch_table:
+	.space	8 * (OPAL_LAST + 1)
+
 	.section ".text","ax"
 	.balign	0x10
 
diff --git a/core/opal.c b/core/opal.c
index dc9944dca..d6ff6027b 100644
--- a/core/opal.c
+++ b/core/opal.c
@@ -28,10 +28,10 @@
 uint64_t opal_pending_events;
 
 /* OPAL dispatch table defined in head.S */
-extern uint64_t opal_branch_table[];
+extern const uint64_t opal_branch_table[];
 
 /* Number of args expected for each call. */
-static u8 opal_num_args[OPAL_LAST+1];
+static const u8 opal_num_args[OPAL_LAST+1];
 
 /* OPAL anchor node */
 struct dt_node *opal_node;
@@ -53,8 +53,8 @@ void opal_table_init(void)
 	prlog(PR_DEBUG, "OPAL table: %p .. %p, branch table: %p\n",
 	      s, e, opal_branch_table);
 	while(s < e) {
-		opal_branch_table[s->token] = function_entry_address(s->func);
-		opal_num_args[s->token] = s->nargs;
+		((uint64_t *)opal_branch_table)[s->token] = function_entry_address(s->func);
+		((u8 *)opal_num_args)[s->token] = s->nargs;
 		s++;
 	}
 }
@@ -321,8 +321,8 @@ void __opal_register(uint64_t token, void *func, unsigned int nargs)
 {
 	assert(token <= OPAL_LAST);
 
-	opal_branch_table[token] = function_entry_address(func);
-	opal_num_args[token] = nargs;
+	((uint64_t *)opal_branch_table)[token] = function_entry_address(func);
+	((u8 *)opal_num_args)[token] = nargs;
 }
 
 /*
-- 
2.23.0



More information about the Skiboot mailing list