[Skiboot] [PATCH] external/opal-prd: Ensure that struct host_interfaces matches the thunk

Jeremy Kerr jk at ozlabs.org
Thu Apr 14 12:43:32 AEST 2016


Currently, we don't describe the reserved area at the end of struct
host_interfaces; it's in the thunk, but not the struct itself.

This change adds the reserved area, and adds a set of runtime asserts to
ensure that the struct layout matches the thunk.

Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
---
 external/opal-prd/hostboot-interface.h |  3 ++-
 external/opal-prd/opal-prd.c           | 20 ++++++++++++++++++++
 external/opal-prd/thunk.S              |  6 ++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/external/opal-prd/hostboot-interface.h b/external/opal-prd/hostboot-interface.h
index 0d268d3..0393152 100644
--- a/external/opal-prd/hostboot-interface.h
+++ b/external/opal-prd/hostboot-interface.h
@@ -277,7 +277,8 @@ struct host_interfaces {
 	int (*memory_error)( uint64_t i_startAddr, uint64_t i_endAddr,
 					  enum MemoryError_t i_errorType );
 
-
+	/* Reserve some space for future growth. */
+	void (*reserved[32])(void);
 };
 
 struct runtime_interfaces {
diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c
index 7c11c9a..d3dbc16 100644
--- a/external/opal-prd/opal-prd.c
+++ b/external/opal-prd/opal-prd.c
@@ -221,6 +221,24 @@ static void pr_log_daemon_init(void)
 	}
 }
 
+/**
+ * ABI check that we can't perform at build-time: we want to ensure that the
+ * layout of struct host_interfaces matches that defined in the thunk.
+ */
+static void check_abi(void)
+{
+	extern unsigned char __hinterface_start, __hinterface_pad,
+	       __hinterface_end;
+
+	/* ensure our struct size matches the thunk definition */
+	assert((&__hinterface_end - &__hinterface_start)
+			== sizeof(struct host_interfaces));
+
+	/* ensure the padding layout is as expected */
+	assert((void *)&__hinterface_start == (void *)&hinterface);
+	assert((void *)&__hinterface_pad == (void *)&hinterface.reserved);
+}
+
 /* HBRT init wrappers */
 extern struct runtime_interfaces *call_hbrt_init(struct host_interfaces *);
 
@@ -1960,6 +1978,8 @@ int main(int argc, char *argv[])
 	enum action action;
 	int rc;
 
+	check_abi();
+
 	ctx = &_ctx;
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->vlog = pr_log_stdio;
diff --git a/external/opal-prd/thunk.S b/external/opal-prd/thunk.S
index 7549efc..f25afde 100644
--- a/external/opal-prd/thunk.S
+++ b/external/opal-prd/thunk.S
@@ -157,6 +157,8 @@ name##_thunk:									;\
 	 */
 	.data
 	.globl hinterface
+	.globl __hinterface_start
+__hinterface_start:
 hinterface:
 	/* HBRT interface version */
 	.llong 1
@@ -184,8 +186,12 @@ hinterface:
 	CALLBACK_THUNK(hservice_i2c_write)
 	CALLBACK_THUNK(hservice_ipmi_msg)
 	CALLBACK_THUNK(hservice_memory_error)
+.globl __hinterface_pad
+__hinterface_pad:
 	/* Reserved space for future growth */
 	.space 32*8,0
+.globl __hinterface_end
+__hinterface_end:
 	/* Eye catcher for debugging */
 	.llong 0xdeadbeef
 
-- 
2.5.0



More information about the Skiboot mailing list