From patchwork Mon Mar 12 08:44:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131373 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp477417ljb; Mon, 12 Mar 2018 01:45:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELsF7K7ou4p3Q4Va62FwP4gi/wdMyGELCIwhhKVDGq+bSETSR7r3tYnswLS/9NQxRbEJh8QI X-Received: by 10.99.137.65 with SMTP id v62mr5970824pgd.90.1520844344652; Mon, 12 Mar 2018 01:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520844344; cv=none; d=google.com; s=arc-20160816; b=tTyhNyjztR1M67qgHtdjtL3M9eBxfa5xbOt5j3dTrvPcjJZ76JK2JAMlbK8c1frbud oXGCGF+HieYaM4rrTy7z0lEGMxZi7Ql5+KYtbNN2273DoI5tSZO8bbc0/RCIQpdx92fa QIrrgU8oZyPA0DHLa7h+VKg94ma82RjMYKiJN9uVQUCPnFp2X/LuYRCySoWTlVaDBFx7 oQtGGH6XYowkraL9w0DjZdj+j+OVkm0miZaV11tERrWPLd94lA8Z3BTA/gd7nSbrJjmJ VRtOk5qEBKaqhlk40zzYgFzX4Xndd2bjIPwDmf+9KtKyEnMqrdAJXJHoKsbUs7mGkt+A eOMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=p5jjkCO9QcXGzG+Iy5/VqD/giTUNaJPTbSz5nwGqEfM=; b=hHcRC+I5Hkb7I+3v9J9LlworBalXEG+MH4KwmA46HADK4pdFvSrzjQEgpELVgQbeCg TMNkb281zqLhKDwK8mFoZz7IJC7TOVz2l1BA59aBN0f+38i8ZPJZrAupU01fxIJSJXSr IkirQuez0epnQHg6VXtfvF2v+xbOkKWR7cKTPWEA67gTs2xNVLu1NjoOCElAbLXIHtYo ZRemoipPUqj0d7zvyO+hNmUy2Su+pzni9erX4Rw1CyHJeBnq6BbknRkB7zQPQIRuibiJ h5jE1vq5M4pHgHVZZZ+nehAFXaEQpWFNsnXpG1uC5Jqf0UALin94Of5q6UHvLYSw9epp nSnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OGI5Xabf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si1657339pgn.230.2018.03.12.01.45.44; Mon, 12 Mar 2018 01:45:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OGI5Xabf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539AbeCLIpk (ORCPT + 28 others); Mon, 12 Mar 2018 04:45:40 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37841 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751849AbeCLIpa (ORCPT ); Mon, 12 Mar 2018 04:45:30 -0400 Received: by mail-wr0-f193.google.com with SMTP id z12so14757248wrg.4 for ; Mon, 12 Mar 2018 01:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p5jjkCO9QcXGzG+Iy5/VqD/giTUNaJPTbSz5nwGqEfM=; b=OGI5XabfXISXvDdlmu46gWqyV18IjR3naKQB+OVt8npzpwjt04aTEDPg+vTKYO1Z0Q MEKJEuK8PMIJoUrQOEmzbpwfb255O0OpK1VDS7+kqaj3R4cq62YkQBaO/GR4qRReIHt+ uS62TJtPZaGzHgUkC+2jg68atChZr8oGiKUK0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p5jjkCO9QcXGzG+Iy5/VqD/giTUNaJPTbSz5nwGqEfM=; b=qHCRlU5kPoAveESOepk6R85MxqAqGiAPgyxh8fKnjDweESZ/agQ+iSeQjR9BVr3nSa cm20kyG7ysBGPO2Y6rb0WHb5hpN61cEPTqccxI5SOy/4z7LGIjLJq+fiM9gv6P2Bmbvu 66ua8Sz2N++UniuBxyGWItEXZ6tAFXcEewCEEPkPoENgM9vb9b0MoquVRp1gOzMQNo3k N7FxPM2LRxO0Jd85JODR9H9UPB51A20/jfECpgtk5zXDtGMiqilj4Fz/I5l4nPNJrdtF DkRv8f9HPbIQue5FrqdHO9ugeZk/FqndDdUWxj+R0SmRAS9zVs0vVeJAsdYVIIxKT3ao V1jw== X-Gm-Message-State: AElRT7HCHBJeHDbxk5gpRs05Fomo7kUq1pvP/dUm/QbBLLU9TOsrxGXd +jZFlT3ad1Ka42mha4BwVUHdIA== X-Received: by 10.223.176.77 with SMTP id g13mr5861889wra.21.1520844329173; Mon, 12 Mar 2018 01:45:29 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id c1sm6544788wre.27.2018.03.12.01.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 01:45:28 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Borislav Petkov , Tony Luck , Andy Lutomirski , "Michael S . Tsirkin" , Ricardo Neri , Ravi Shankar Subject: [PATCH 1/5] efi: Use efi_mm in x86 as well as ARM Date: Mon, 12 Mar 2018 08:44:56 +0000 Message-Id: <20180312084500.10764-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180312084500.10764-1-ard.biesheuvel@linaro.org> References: <20180312084500.10764-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Presently, only ARM uses mm_struct to manage efi page tables and efi runtime region mappings. As this is the preferred approach, let's make this data structure common across architectures. Specially, for x86, using this data structure improves code maintainability and readability. Signed-off-by: Sai Praneeth Prakhya Cc: "Lee, Chun-Yi" Cc: Borislav Petkov Cc: Tony Luck Cc: Andy Lutomirski Cc: Michael S. Tsirkin Cc: Ricardo Neri Cc: Ravi Shankar Tested-by: Bhupesh Sharma Reviewed-by: Matt Fleming [ardb: don't #include the world to get a declaration of struct mm_struct] Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 1 + arch/x86/platform/efi/efi_64.c | 3 +++ drivers/firmware/efi/arm-runtime.c | 9 --------- drivers/firmware/efi/efi.c | 9 +++++++++ include/linux/efi.h | 2 ++ 5 files changed, 15 insertions(+), 9 deletions(-) -- 2.15.1 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index a399c1ebf6f0..c62443fa7d0a 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -7,6 +7,7 @@ #include #include #include +#include /* * We map the EFI regions needed for runtime services non-contiguously, diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index c310a8284358..0045efe9947b 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -231,6 +231,9 @@ int __init efi_alloc_page_tables(void) return -ENOMEM; } + mm_init_cpumask(&efi_mm); + init_new_context(NULL, &efi_mm); + return 0; } diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 13561aeb7396..5889cbea60b8 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -31,15 +31,6 @@ extern u64 efi_system_table; -static struct mm_struct efi_mm = { - .mm_rb = RB_ROOT, - .mm_users = ATOMIC_INIT(2), - .mm_count = ATOMIC_INIT(1), - .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), - .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), - .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), -}; - #ifdef CONFIG_ARM64_PTDUMP_DEBUGFS #include diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 92b9e79e5da9..232f4915223b 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -75,6 +75,15 @@ static unsigned long *efi_tables[] = { &efi.mem_attr_table, }; +struct mm_struct efi_mm = { + .mm_rb = RB_ROOT, + .mm_users = ATOMIC_INIT(2), + .mm_count = ATOMIC_INIT(1), + .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), + .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), + .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), +}; + static bool disable_runtime; static int __init setup_noefi(char *arg) { diff --git a/include/linux/efi.h b/include/linux/efi.h index f5083aa72eae..f1b7d68ac460 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -966,6 +966,8 @@ extern struct efi { unsigned long flags; } efi; +extern struct mm_struct efi_mm; + static inline int efi_guidcmp (efi_guid_t left, efi_guid_t right) { From patchwork Mon Mar 12 08:44:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131376 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp478025ljb; Mon, 12 Mar 2018 01:46:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELtbsDOuzrsHS4CQECksI+Cz89bma7sfLHZyqdpb2GnTyQ7H0DdcQlbvT/QWfRDWvcXp2dKo X-Received: by 2002:a17:902:6e0f:: with SMTP id u15-v6mr7408388plk.78.1520844395350; Mon, 12 Mar 2018 01:46:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520844395; cv=none; d=google.com; s=arc-20160816; b=WdJZ+Rs3AkEpaTTDi7wwmUVXstQICvUdbegomoYw7leXhBTpAEcmUHGubAC50jYR42 r3HBN0pBAXk7JaRrgliP5nRiUIeA8FMKm5mxbr57zLBhQiHvJ+NarwOSMnjjcQ8MckI5 lZT/OSq4Zyp8/S8MV2SZUHWesgg1Skiq8Tkps6V+eirQ9i6PD5YkcJjz38x6/Wee8TVk 57Zy5UrArAlPrbhJKWHEoHGu+EuT+FcWfoNsgwxCKhVycwYJA4ZYyqvBJ+lgshQns/wx zt57OCr0KrjqvG9fBvPWxzywca0jK/5CaKT8EenMOhah0iop9dTr4zqYIiBpUoZn/Wfa 6ZjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qa5AutG4QCRbyp1jPz/06C3tNLkJdxW216XmUztKtsQ=; b=on/fAr6u5+IPPgi/P6K33ra34414fEnLWQDjJa3SfQvH8DYnjMxx44ItARzzsHinAS ZHa7bU+yj3IlRxXWj1jU5nsgDsZjaYPGmd0NLhH73y6FzbJRzqghOcs7FHQl/Y/ZQOS+ JiCp8iSDylmAB4OQHbpYmpUeW5jPdpF+JRjd3tu2f2v2G+xejDzY3qhcxCMpWXYAwQAQ IM7458Ho24om4rm1NUAJcMLlXoU77ABY4ZJaV8lqOsVHGtfNbL4zjUoHE6EjyI0uBLDN eaRWhqyQbSl6wuYz0RtzqhkK8Gvw2cc9G+AC+VYw18P7opkztCi/sPwvfFvI1hEXz5vY yFIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QKXuvTUx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37-v6si5613988plb.231.2018.03.12.01.46.35; Mon, 12 Mar 2018 01:46:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QKXuvTUx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752489AbeCLIqb (ORCPT + 28 others); Mon, 12 Mar 2018 04:46:31 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37853 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752516AbeCLIpf (ORCPT ); Mon, 12 Mar 2018 04:45:35 -0400 Received: by mail-wr0-f196.google.com with SMTP id z12so14757512wrg.4 for ; Mon, 12 Mar 2018 01:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qa5AutG4QCRbyp1jPz/06C3tNLkJdxW216XmUztKtsQ=; b=QKXuvTUxOj2kO56WWj/rT2AlNWYhetZSYwZC2i8xMfJLzNN8W3J1cSK7DYZwjV14wo p8w63NMRW74onL8/Be0XCkMRDnPH/l4ePtL5J+by+cu39luXJklbH9fI7g4TrmhTChH/ T6d0SEWW+aJrRjyYNTdvgkEomr140gyf6Whyg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qa5AutG4QCRbyp1jPz/06C3tNLkJdxW216XmUztKtsQ=; b=cDi57l7zCz1Rm4nyOwDRMPykngj7jjOlIRdW69qEZiLSC+jXOS7h8vYfPybD00bG9x q/hUedo/lLwr/DRlmpI4/KztAjo4SDV0yBDFP4umrIBafPHOzhGj6TC49v9rVlcRLgbw 3CVKiW8MGRv79d1tS1WTarKD/r3tSy1uq/m1lqWQ5q2c2nVfjNx9AJT12sodr9aIb72K 767zH3fQYviAAQ/9MegANrpnMSlUC/AKYLG0Lc6JVKxRzw/9bNJD+ogfJEIq/oMLa4UT FENQlFGXsP14HRbTSh96uuHJg9pkYQz0d0KDO91zpxpD/lLkYbLXeAR9EVGj+rI3R3Tk XomA== X-Gm-Message-State: AElRT7H29zvifz0ttFj7QzgFmfQ+86GNs/TyJsOGeZlTtF/9IpuoM3kq o3Talg7qaCo8Kw6Mwz/JQ0uoxQ== X-Received: by 10.223.153.215 with SMTP id y81mr5449948wrb.144.1520844334274; Mon, 12 Mar 2018 01:45:34 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id c1sm6544788wre.27.2018.03.12.01.45.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 01:45:33 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Borislav Petkov , Tony Luck , Andy Lutomirski , "Michael S . Tsirkin" , Bhupesh Sharma , Ricardo Neri , Ravi Shankar Subject: [PATCH 3/5] x86/efi: Use efi_switch_mm() rather than manually twiddling with %cr3 Date: Mon, 12 Mar 2018 08:44:58 +0000 Message-Id: <20180312084500.10764-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180312084500.10764-1-ard.biesheuvel@linaro.org> References: <20180312084500.10764-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Use helper function efi_switch_mm() to switch to/from efi_mm when invoking any UEFI runtime services. Likewise, we need to switch back to previous mm (mm context stolen by efi_mm) after the above calls return successfully. We can use efi_switch_mm() helper function only with x86_64 kernel and "efi=old_map" disabled because, x86_32 and efi=old_map do not use efi_pgd, rather they use swapper_pg_dir. Signed-off-by: Sai Praneeth Prakhya Cc: "Lee, Chun-Yi" Cc: Borislav Petkov Cc: Tony Luck Cc: Andy Lutomirski Cc: Michael S. Tsirkin Cc: Bhupesh Sharma Cc: Ricardo Neri Cc: Ravi Shankar Tested-by: Bhupesh Sharma Reviewed-by: Matt Fleming [ardb: add #include of sched/task.h for task_lock/_unlock] Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 25 +++++++++------------- arch/x86/platform/efi/efi_64.c | 41 +++++++++++++++++++----------------- arch/x86/platform/efi/efi_thunk_64.S | 2 +- 3 files changed, 33 insertions(+), 35 deletions(-) -- 2.15.1 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index c62443fa7d0a..cec5fae23eb3 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -70,14 +70,13 @@ extern asmlinkage u64 efi_call(void *fp, ...); #define efi_call_phys(f, args...) efi_call((f), args) /* - * Scratch space used for switching the pagetable in the EFI stub + * struct efi_scratch - Scratch space used while switching to/from efi_mm + * @phys_stack: stack used during EFI Mixed Mode + * @prev_mm: store/restore stolen mm_struct while switching to/from efi_mm */ struct efi_scratch { - u64 r15; - u64 prev_cr3; - pgd_t *efi_pgt; - bool use_pgd; - u64 phys_stack; + u64 phys_stack; + struct mm_struct *prev_mm; } __packed; #define arch_efi_call_virt_setup() \ @@ -87,11 +86,8 @@ struct efi_scratch { __kernel_fpu_begin(); \ firmware_restrict_branch_speculation_start(); \ \ - if (efi_scratch.use_pgd) { \ - efi_scratch.prev_cr3 = __read_cr3(); \ - write_cr3((unsigned long)efi_scratch.efi_pgt); \ - __flush_tlb_all(); \ - } \ + if (!efi_enabled(EFI_OLD_MEMMAP)) \ + efi_switch_mm(&efi_mm); \ }) #define arch_efi_call_virt(p, f, args...) \ @@ -99,10 +95,8 @@ struct efi_scratch { #define arch_efi_call_virt_teardown() \ ({ \ - if (efi_scratch.use_pgd) { \ - write_cr3(efi_scratch.prev_cr3); \ - __flush_tlb_all(); \ - } \ + if (!efi_enabled(EFI_OLD_MEMMAP)) \ + efi_switch_mm(efi_scratch.prev_mm); \ \ firmware_restrict_branch_speculation_end(); \ __kernel_fpu_end(); \ @@ -145,6 +139,7 @@ extern void __init efi_dump_pagetable(void); extern void __init efi_apply_memmap_quirks(void); extern int __init efi_reuse_config(u64 tables, int nr_tables); extern void efi_delete_dummy_variable(void); +extern void efi_switch_mm(struct mm_struct *mm); struct efi_setup_data { u64 fw_vendor; diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index 8881e601c32d..229af5bbecb8 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -81,9 +82,8 @@ pgd_t * __init efi_call_phys_prolog(void) int n_pgds, i, j; if (!efi_enabled(EFI_OLD_MEMMAP)) { - save_pgd = (pgd_t *)__read_cr3(); - write_cr3((unsigned long)efi_scratch.efi_pgt); - goto out; + efi_switch_mm(&efi_mm); + return NULL; } early_code_mapping_set_exec(1); @@ -155,8 +155,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd) pud_t *pud; if (!efi_enabled(EFI_OLD_MEMMAP)) { - write_cr3((unsigned long)save_pgd); - __flush_tlb_all(); + efi_switch_mm(efi_scratch.prev_mm); return; } @@ -344,13 +343,6 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) if (efi_enabled(EFI_OLD_MEMMAP)) return 0; - /* - * Since the PGD is encrypted, set the encryption mask so that when - * this value is loaded into cr3 the PGD will be decrypted during - * the pagetable walk. - */ - efi_scratch.efi_pgt = (pgd_t *)__sme_pa(pgd); - /* * It can happen that the physical address of new_memmap lands in memory * which is not mapped in the EFI page table. Therefore we need to go @@ -364,8 +356,6 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) return 1; } - efi_scratch.use_pgd = true; - /* * Certain firmware versions are way too sentimential and still believe * they are exclusive and unquestionable owners of the first physical page, @@ -624,6 +614,22 @@ void __init efi_dump_pagetable(void) #endif } +/* + * Makes the calling thread switch to/from efi_mm context. Can be used + * for SetVirtualAddressMap() i.e. current->active_mm == init_mm as well + * as during efi runtime calls i.e current->active_mm == current_mm. + * We are not mm_dropping()/mm_grabbing() any mm, because we are not + * losing/creating any references. + */ +void efi_switch_mm(struct mm_struct *mm) +{ + task_lock(current); + efi_scratch.prev_mm = current->active_mm; + current->active_mm = mm; + switch_mm(efi_scratch.prev_mm, mm, NULL); + task_unlock(current); +} + #ifdef CONFIG_EFI_MIXED extern efi_status_t efi64_thunk(u32, ...); @@ -677,16 +683,13 @@ efi_status_t efi_thunk_set_virtual_address_map( efi_sync_low_kernel_mappings(); local_irq_save(flags); - efi_scratch.prev_cr3 = __read_cr3(); - write_cr3((unsigned long)efi_scratch.efi_pgt); - __flush_tlb_all(); + efi_switch_mm(&efi_mm); func = (u32)(unsigned long)phys_set_virtual_address_map; status = efi64_thunk(func, memory_map_size, descriptor_size, descriptor_version, virtual_map); - write_cr3(efi_scratch.prev_cr3); - __flush_tlb_all(); + efi_switch_mm(efi_scratch.prev_mm); local_irq_restore(flags); return status; diff --git a/arch/x86/platform/efi/efi_thunk_64.S b/arch/x86/platform/efi/efi_thunk_64.S index 189b218da87c..46c58b08739c 100644 --- a/arch/x86/platform/efi/efi_thunk_64.S +++ b/arch/x86/platform/efi/efi_thunk_64.S @@ -33,7 +33,7 @@ ENTRY(efi64_thunk) * Switch to 1:1 mapped 32-bit stack pointer. */ movq %rsp, efi_saved_sp(%rip) - movq efi_scratch+25(%rip), %rsp + movq efi_scratch(%rip), %rsp /* * Calculate the physical address of the kernel text. From patchwork Mon Mar 12 08:44:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131375 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp477797ljb; Mon, 12 Mar 2018 01:46:17 -0700 (PDT) X-Google-Smtp-Source: AG47ELufH2/y2teT7jPE62vV0dgBb31XTmMjvv0fokPPIJeNlA40M1gHxGKNRSnJ9LOhWupX9bQb X-Received: by 10.99.62.193 with SMTP id l184mr2643292pga.87.1520844377832; Mon, 12 Mar 2018 01:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520844377; cv=none; d=google.com; s=arc-20160816; b=Qx9t26wTxwFRLruHq+q6Nc7Oz/mo3mrDaHgeQHJDf2nelfV+UpdEZWgAfTovf3kIXz f5rFfdpPOwPgn7H18LIzYCXBfs/ECjBwU9OWa0FVdEe4yDlX2BgrVxoNa4jWSWPpGo24 ZCYeBkslEqt2c9ekziIFVswBcTWUSuVtWuC6rIk/qW/3vze61i5QXM4kM/2iPdDslv4U 5oifhWhUsza48UCb0UqS+5/5zhM6AdPqNLOahzqohytZS1Ri9jB+EI+8OYpXZkICySnt w0tpvNhsNOdQGo1IF5f60+AkjacfIAH0Ygtjz9iBFXBBBXS4Vl0l68fUXtS7b6i2HXiu m28w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qP3u6As7DueGEFQiyk696bVhrQjfVU2zrFvqrN7hcoQ=; b=rOqnJBkd6i8OB/w70yeLdr2sbOe3G0ZGSd5QzPXfS2KvBoYxESKYDlDgZkNb6FU1vB +KrLsYxKW2AwfMeHTyOhb1Yhx7DH+Pf8YyI9wyqK+EX7t8JBQCvHggHi82b1rMOx1WxA uCne9FzHXMVjEV9SRHKQFpZaUHFR8UPZJXB8bUD3kAkyorEJtvYWupDqDaK+9f63J09M ADxPMQQShNipUNea+DJuXdjHXFXqmjhbqAtIqrBDhCXDZDf88evx4mGQnN1Mj1MZPC+8 HnIE0JWPF9o90G7tU52qrFmXl+4/2h++c6wXExanYQVnWZuqUrCAoDbMmKhpXXheQuHv IF6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UJe/yOab; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y18si5524483pfa.9.2018.03.12.01.46.17; Mon, 12 Mar 2018 01:46:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UJe/yOab; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752475AbeCLIqP (ORCPT + 28 others); Mon, 12 Mar 2018 04:46:15 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37854 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751911AbeCLIph (ORCPT ); Mon, 12 Mar 2018 04:45:37 -0400 Received: by mail-wr0-f195.google.com with SMTP id z12so14757596wrg.4 for ; Mon, 12 Mar 2018 01:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qP3u6As7DueGEFQiyk696bVhrQjfVU2zrFvqrN7hcoQ=; b=UJe/yOaboJ0dA6K5oi2g8gCxSmMb0KNFWONLAOtu2W1V53z3lMkFDKLDy0MHlxEhAP PnKOlFX9xDzBF/ZCRpKJ4ypAa8CRtUPjn3sXgqIDEWCTJL104SRpg/m/TC3Bb+c+2vpS PitCKikyR1HOGLOMjWMybojZcU96GjyDPwoYA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qP3u6As7DueGEFQiyk696bVhrQjfVU2zrFvqrN7hcoQ=; b=Q/yx/TT+wuosNpwZTAnxwhfOuxgj96cu6gOu/D/wDrc4EU+4m+eTIghOmRRuOeono1 BFCNvICpqGi4p2TPVqbOWq/RGzWgkMTGc5u6n4F2zZ+TxmlhePtUB4YIR9KIzD207gPc PrY/BEEIglE1bFwNxRH2bew+QJJn/45f4NUcmsCnV/wS5kt6KxckHCrsBYn1muq6Zywv T6i81XxCF69lkKTO+Czd32FUqbFBFy8GCUq03z+kj/e97myUWNqCrMmKWG6S3gF1MPKt ayVpUdncElF9+F+DB2SozmhOSf4q0gSLWFeUgeXf7BD2NO6vH4cwef5K4yKIRioE5BxQ 7Oxg== X-Gm-Message-State: AElRT7GBw6jiE9YuG6czNi+biCUdUwNqfvF9y3FiTR6/EAYNEUcqP5hC EC/vKo7JaBkhA/s12amqCmALlQ== X-Received: by 10.223.176.36 with SMTP id f33mr284464wra.75.1520844335992; Mon, 12 Mar 2018 01:45:35 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id c1sm6544788wre.27.2018.03.12.01.45.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 01:45:35 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Peter Jones Subject: [PATCH 4/5] efi/esrt: fix handling of early ESRT table mapping Date: Mon, 12 Mar 2018 08:44:59 +0000 Message-Id: <20180312084500.10764-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180312084500.10764-1-ard.biesheuvel@linaro.org> References: <20180312084500.10764-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As reported by Tyler, efi_esrt_init() will return without releasing the ESRT table header mapping if it encounters a table with an unexpected version. Replacing the 'return' with 'goto err_memunmap' would fix this particular occurrence, but, as it turns out, the code is rather peculiar to begin with: - it never uses the header mapping after memcpy()'ing out its contents, - it maps and unmaps the entire table without ever looking at the contents. So let's refactor this code to unmap the table header right after the memcpy() so we can get rid of the error handling path altogether, and drop the second mapping entirely. Cc: Peter Jones Reported-by: Tyler Baicar Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/esrt.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) -- 2.15.1 diff --git a/drivers/firmware/efi/esrt.c b/drivers/firmware/efi/esrt.c index c47e0c6ec00f..1ab80e06e7c5 100644 --- a/drivers/firmware/efi/esrt.c +++ b/drivers/firmware/efi/esrt.c @@ -279,6 +279,7 @@ void __init efi_esrt_init(void) } memcpy(&tmpesrt, va, sizeof(tmpesrt)); + early_memunmap(va, size); if (tmpesrt.fw_resource_version == 1) { entry_size = sizeof (*v1_entries); @@ -291,7 +292,7 @@ void __init efi_esrt_init(void) if (tmpesrt.fw_resource_count > 0 && max - size < entry_size) { pr_err("ESRT memory map entry can only hold the header. (max: %zu size: %zu)\n", max - size, entry_size); - goto err_memunmap; + return; } /* @@ -304,7 +305,7 @@ void __init efi_esrt_init(void) if (tmpesrt.fw_resource_count > 128) { pr_err("ESRT says fw_resource_count has very large value %d.\n", tmpesrt.fw_resource_count); - goto err_memunmap; + return; } /* @@ -315,18 +316,10 @@ void __init efi_esrt_init(void) if (max < size + entries_size) { pr_err("ESRT does not fit on single memory map entry (size: %zu max: %zu)\n", size, max); - goto err_memunmap; + return; } - /* remap it with our (plausible) new pages */ - early_memunmap(va, size); size += entries_size; - va = early_memremap(efi.esrt, size); - if (!va) { - pr_err("early_memremap(%p, %zu) failed.\n", (void *)efi.esrt, - size); - return; - } esrt_data = (phys_addr_t)efi.esrt; esrt_data_size = size; @@ -336,8 +329,6 @@ void __init efi_esrt_init(void) efi_mem_reserve(esrt_data, esrt_data_size); pr_debug("esrt-init: loaded.\n"); -err_memunmap: - early_memunmap(va, size); } static int __init register_entries(void) From patchwork Mon Mar 12 08:45:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131374 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp477470ljb; Mon, 12 Mar 2018 01:45:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELv4Zjpo4sK0QeNAnG9BK+9dbKSkyuO0CBQXgefhERPEwlzOBM/GaRWAbBNzfI8nVqVOIZYH X-Received: by 2002:a17:902:968c:: with SMTP id n12-v6mr7414516plp.371.1520844349106; Mon, 12 Mar 2018 01:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520844349; cv=none; d=google.com; s=arc-20160816; b=C3gtTkhZE7e6crKI4gr7Tq0jAZX2xU9Q0DyNuDJakaJyMz5Yjg11CDrUUEvnSddN0p v5IUm2Y1uNpAF0Slk+51loscU9FaxC+2RGeqiUsfJzEJrdSn7uaBlEgZ+5cgrYJIXXP4 5B7WKaoe6ELNYH+amWYNfwy90GiST/7qXJPjob8QfGd3XSV7bJrHV9ySwyKl8oo51rdi C7gOK63M2FUCUxsaDJXgQZ9U+9LqrztDt7FLweMwpaCd0WjK35p4kw1jRUm+Te++Pvyt 55TwecW7QDGwLPTQvHW6fIgEIipceS+puX113ZkmXGSCpFmSBTBjywgZFzWLa7EjuV5y 0O1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=DqSRY6qaHYNeHVfVmuk8ymM1hb+EfbmcJFX+ARqnYQk=; b=JyUXdp1WBBR9CyE9hqDEcaLbevO/u6vDCAoedmJQMSxZ1utyklyje3G6Bhgc8hsRUw g2Ug0BgRwAfr8G7avlslc26qUhPQzu8XPLzldxg9wu5Xn0YtYro1xFLO+KdtMFasgAyT QSLLBbWg17E5IXBn5uLVqCjwyAywPolOV4hZ27Wa0YIT6dkbG0yuA5EWNFSAdhgDR+/V jABhmt8o3rsgqotfEDovkN7EJj8AcmgXEB5NQmuKj+PfERTmkVSqlXPPj/roq6CwBtrg B2w3Fs/JEsyG6QbvCmic/s4sdZpoTZY67n7pcQq9xtCfW4nIB6vGuFpnJx/eogjchurX B5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OYv/5GrN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si5689312plr.622.2018.03.12.01.45.48; Mon, 12 Mar 2018 01:45:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OYv/5GrN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752555AbeCLIpq (ORCPT + 28 others); Mon, 12 Mar 2018 04:45:46 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:52651 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752522AbeCLIpk (ORCPT ); Mon, 12 Mar 2018 04:45:40 -0400 Received: by mail-wm0-f67.google.com with SMTP id t3so14699531wmc.2 for ; Mon, 12 Mar 2018 01:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DqSRY6qaHYNeHVfVmuk8ymM1hb+EfbmcJFX+ARqnYQk=; b=OYv/5GrNV4yVFIO/XZyhnT7ICiVARn/EXVYhZ7XfsG7M8DRKV4KZdW4azBHobjXQQX yMpYfEWjaLkKm9isTYSKPFvJ1CpX8OLT1Y6Ri3SZE+Drp0bKTx/KKDFRkQx8oWcgtKqr uhEKuvwE9wkxK+V6kxEYtoqt/FWQAeccGGsU8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DqSRY6qaHYNeHVfVmuk8ymM1hb+EfbmcJFX+ARqnYQk=; b=eUvupGrq1AUja0Q06w2X89ZqCGj/WzWPJXo6Jvpp7xAoFkpUAizGUxneMLps551VIB 4T4P2hHlxfPnVD6MEXEQnlPlEk611wCj3EA94s8cRXz5hcWv9CBOl94wayNYqHndafrU QnpkYCoFFQZJL954VnPGbKvryldVa+mFNiICC1/FH+WNHe9QfJSaLnNszjswsz2fLlfa lsMSYjmDlTgmeK66Ok30aQ1ZIuXPL+2Eid7nRQIiYOG3hyFUIfIrvyLJeYnUIWqvlgee UmIRKTDnrLVtG1IdfkuMtDAga+j9mpfwYoF3JD14+2mPSw09E9Is1lB3L+i65yVcWnZm tefg== X-Gm-Message-State: AElRT7HPq/L1QVhhfxyMraSLk/bPvZv4xC4YVTM+RiE3eEKHtpNyi/Qz YW1uQW3i6DZtNvfGtm89pRmbrQ== X-Received: by 10.28.52.9 with SMTP id b9mr5311681wma.134.1520844339072; Mon, 12 Mar 2018 01:45:39 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id c1sm6544788wre.27.2018.03.12.01.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 01:45:37 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arnd Bergmann , Lukas Wunner Subject: [PATCH 5/5] efi: use string literals for efi_char16_t variable initializers Date: Mon, 12 Mar 2018 08:45:00 +0000 Message-Id: <20180312084500.10764-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180312084500.10764-1-ard.biesheuvel@linaro.org> References: <20180312084500.10764-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we unambiguously build the entire kernel with -fshort-wchar, it is no longer necessary to open code efi_char16_t[] initializers as arrays of characters, and we can move to the L"xxx" notation instead. Cc: Arnd Bergmann Cc: Lukas Wunner Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 3 ++- arch/x86/platform/efi/quirks.c | 8 +++++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/firmware/efi/libstub/secureboot.c | 12 +++--------- drivers/firmware/efi/libstub/tpm.c | 7 ++----- 5 files changed, 13 insertions(+), 19 deletions(-) -- 2.15.1 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index f2251c1c9853..47d3efff6805 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -421,9 +421,10 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params) } } +static const efi_char16_t apple[] = L"Apple"; + static void setup_quirks(struct boot_params *boot_params) { - static efi_char16_t const apple[] = { 'A', 'p', 'p', 'l', 'e', 0 }; efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long) efi_table_attr(efi_system_table, fw_vendor, sys_table); diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 1ef11c26f79b..36c1f8b9f7e0 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -75,7 +75,7 @@ struct quark_security_header { u32 rsvd[2]; }; -static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; +static const efi_char16_t efi_dummy_name[] = L"DUMMY"; static bool efi_no_storage_paranoia; @@ -105,7 +105,8 @@ early_param("efi_no_storage_paranoia", setup_storage_paranoia); */ void efi_delete_dummy_variable(void) { - efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, + efi.set_variable((efi_char16_t *)efi_dummy_name, + &EFI_DUMMY_GUID, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, @@ -182,7 +183,8 @@ efi_status_t efi_query_variable_store(u32 attributes, unsigned long size, if (!dummy) return EFI_OUT_OF_RESOURCES; - status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, + status = efi.set_variable((efi_char16_t *)efi_dummy_name, + &EFI_DUMMY_GUID, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 7b3ba40f0745..a34e9290a699 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -9,7 +9,7 @@ cflags-$(CONFIG_X86_32) := -march=i386 cflags-$(CONFIG_X86_64) := -mcmodel=small cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -O2 \ -fPIC -fno-strict-aliasing -mno-red-zone \ - -mno-mmx -mno-sse + -mno-mmx -mno-sse -fshort-wchar cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) -fpie cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c index 959777ec8a77..8f07eb414c00 100644 --- a/drivers/firmware/efi/libstub/secureboot.c +++ b/drivers/firmware/efi/libstub/secureboot.c @@ -16,18 +16,12 @@ /* BIOS variables */ static const efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID; -static const efi_char16_t efi_SecureBoot_name[] = { - 'S', 'e', 'c', 'u', 'r', 'e', 'B', 'o', 'o', 't', 0 -}; -static const efi_char16_t efi_SetupMode_name[] = { - 'S', 'e', 't', 'u', 'p', 'M', 'o', 'd', 'e', 0 -}; +static const efi_char16_t efi_SecureBoot_name[] = L"SecureBoot"; +static const efi_char16_t efi_SetupMode_name[] = L"SetupMode"; /* SHIM variables */ static const efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID; -static efi_char16_t const shim_MokSBState_name[] = { - 'M', 'o', 'k', 'S', 'B', 'S', 't', 'a', 't', 'e', 0 -}; +static const efi_char16_t shim_MokSBState_name[] = L"MokSBState"; #define get_efi_var(name, vendor, ...) \ efi_call_runtime(get_variable, \ diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c index da661bf8cb96..2298560cea72 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -16,11 +16,8 @@ #include "efistub.h" #ifdef CONFIG_RESET_ATTACK_MITIGATION -static const efi_char16_t efi_MemoryOverWriteRequest_name[] = { - 'M', 'e', 'm', 'o', 'r', 'y', 'O', 'v', 'e', 'r', 'w', 'r', 'i', 't', - 'e', 'R', 'e', 'q', 'u', 'e', 's', 't', 'C', 'o', 'n', 't', 'r', 'o', - 'l', 0 -}; +static const efi_char16_t efi_MemoryOverWriteRequest_name[] = + L"MemoryOverwriteRequestControl"; #define MEMORY_ONLY_RESET_CONTROL_GUID \ EFI_GUID(0xe20939be, 0x32d4, 0x41be, 0xa1, 0x50, 0x89, 0x7f, 0x85, 0xd4, 0x98, 0x29)