From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D440C5DF62 for ; Wed, 6 Nov 2019 07:09:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58FD3206DF for ; Wed, 6 Nov 2019 07:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731458AbfKFHJY (ORCPT ); Wed, 6 Nov 2019 02:09:24 -0500 Received: from isilmar-4.linta.de ([136.243.71.142]:58806 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730804AbfKFHJU (ORCPT ); Wed, 6 Nov 2019 02:09:20 -0500 X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from owl.dominikbrodowski.net (owl-tcp.brodo.linta [10.1.0.111]) by isilmar-4.linta.de (Postfix) with ESMTPSA id 01F1E200A60; Wed, 6 Nov 2019 07:09:16 +0000 (UTC) Received: by owl.dominikbrodowski.net (Postfix, from userid 1000) id 5C22D80462; Wed, 6 Nov 2019 08:06:40 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Matt Fleming , Catalin Marinas , Ingo Molnar , Peter Zijlstra , Kees Cook , Linus Torvalds , Hsin-Yi Wang , Stephen Boyd , Rob Herring , Theodore Ts'o , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-efi@vger.kernel.org, Mario Limonciello Subject: [PATCH 1/2] efi/random: use arch-independent efi_call_proto() Date: Wed, 6 Nov 2019 08:06:12 +0100 Message-Id: <20191106070613.227833-2-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191106070613.227833-1-linux@dominikbrodowski.net> References: <20191106070613.227833-1-linux@dominikbrodowski.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To handle all arch-specific peculiarities when calling an EFI protocol function, a wrapper efi_call_proto() exists on all relevant architectures. On arm/arm64, this is merely a plain function call. On x86, a special EFI entry stub needs to be used, however, as the calling convention differs. To make the efi/random stub arch-independent, use efi_call_proto() instead of the existing non-portable calls to the EFI get_rng protocol function. This also requires the addition of some typedefs. Signed-off-by: Dominik Brodowski Cc: Ard Biesheuvel Cc: Matt Fleming Cc: Catalin Marinas Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Kees Cook Cc: Linus Torvalds Cc: Hsin-Yi Wang Cc: Stephen Boyd Cc: Rob Herring Cc: Theodore Ts'o Cc: Thomas Gleixner Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Cc: --- drivers/firmware/efi/libstub/random.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c index b4b1d1dcb5fd..05cbadab122b 100644 --- a/drivers/firmware/efi/libstub/random.c +++ b/drivers/firmware/efi/libstub/random.c @@ -9,6 +9,16 @@ #include "efistub.h" +typedef struct { + u32 get_info; + u32 get_rng; +} efi_rng_protocol_32_t; + +typedef struct { + u64 get_info; + u64 get_rng; +} efi_rng_protocol_64_t; + struct efi_rng_protocol { efi_status_t (*get_info)(struct efi_rng_protocol *, unsigned long *, efi_guid_t *); @@ -28,7 +38,7 @@ efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table_arg, if (status != EFI_SUCCESS) return status; - return rng->get_rng(rng, NULL, size, out); + return efi_call_proto(efi_rng_protocol, get_rng, rng, NULL, size, out); } /* @@ -161,15 +171,16 @@ efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg) if (status != EFI_SUCCESS) return status; - status = rng->get_rng(rng, &rng_algo_raw, EFI_RANDOM_SEED_SIZE, - seed->bits); + status = efi_call_proto(efi_rng_protocol, get_rng, rng, &rng_algo_raw, + EFI_RANDOM_SEED_SIZE, seed->bits); + if (status == EFI_UNSUPPORTED) /* * Use whatever algorithm we have available if the raw algorithm * is not implemented. */ - status = rng->get_rng(rng, NULL, EFI_RANDOM_SEED_SIZE, - seed->bits); + status = efi_call_proto(efi_rng_protocol, get_rng, rng, NULL, + EFI_RANDOM_SEED_SIZE, seed->bits); if (status != EFI_SUCCESS) goto err_freepool; -- 2.24.0