From patchwork Thu Apr 14 02:43:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 610341 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qllPP0qMFz9s5w for ; Thu, 14 Apr 2016 12:44:25 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3qllPN70WszDqBS for ; Thu, 14 Apr 2016 12:44:24 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3qllPK4cWlzDq5y for ; Thu, 14 Apr 2016 12:44:21 +1000 (AEST) Received: by ozlabs.org (Postfix, from userid 1023) id 3qllPK3sZJz9s5w; Thu, 14 Apr 2016 12:44:21 +1000 (AEST) From: Jeremy Kerr To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2016 10:43:32 +0800 Message-Id: <1460601812-9730-1-git-send-email-jk@ozlabs.org> X-Mailer: git-send-email 2.5.0 Subject: [Skiboot] [PATCH] external/opal-prd: Ensure that struct host_interfaces matches the thunk X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel M Crowell , Corey Swenson MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 Acked-by: Balbir Singh --- 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