From patchwork Thu Sep 27 08:50:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147685 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726208lji; Thu, 27 Sep 2018 01:51:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/2lPXqp7dyRCpGHOQprzha/LjPwZwFxyTDLmpx029nzFDabj0g1stwxWhxn8/iXl3AQEY X-Received: by 2002:a62:4299:: with SMTP id h25-v6mr10196640pfd.73.1538038262810; Thu, 27 Sep 2018 01:51:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038262; cv=none; d=google.com; s=arc-20160816; b=dX52tokOORODC6eo0ibwK/Ct3MeKGB21gdvCDSyINXJAEjmTDB0BXSczakdfLL4END ZAmGuzgRT9f43olboTuhRUA/XkdnOO5mg1zB4vQeSifbBstsRmxumO0iIo6bPWms2Xuc VAdw0MOHyw95/AcR4xvuL9aTWD1J2exeOL+JS9jENLkzv/OpuTeKUC2jMT6VrXQGjgMp rRy05u1OnD6GcyZPSRCNRMSJx1JLIapuLsmS4zY9NUUxY4HDE5SVxAw3HgXK2E98NiwF uZUCNfc3SGPOkoPJh1YLOrtD0j02G6FhNRgneS/9xl2dvbJYFbhNxPS/gf5Sfp7D9ivP CTfA== 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; bh=pliM0wAhEQbP7B2f//HIg7uUcfNbBN60CgcLvrL/TbY=; b=X0WLEB0emrXsLqD9H2G0USmQJUR51IjdqrdM5+BwAOFcEk6Sz9e6uJmrl6r1Y8oJG4 eVvDn97lTzusKT0VMmAJ8XMxLUY+2QuNaxJHSFvVxBH9qpWpUnCOTXze1biGX2oE5rej rz92p161VszarlhTsHcgDxw8UTt0ATDJofzscSw6U24ie+v19fRiafcubtr3D3FtTJSP NQoUqR4tC0+34ktRSM6UnYCoHSCz1LAHQh+AkY5SGLITrZhk0QPycLAkcaMVenFNRoPn WhDYB8900j+IfSyLSx+hC6XcBarAt5ve55f3znrw1TYnSNmLISePaJYwpXJRahlJ/FLc BXJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ji+Retyv; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 z9-v6si1608734pfg.46.2018.09.27.01.51.02; Thu, 27 Sep 2018 01:51:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=Ji+Retyv; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727285AbeI0PIK (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:10 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39028 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726948AbeI0PIJ (ORCPT ); Thu, 27 Sep 2018 11:08:09 -0400 Received: by mail-wr1-f65.google.com with SMTP id s14-v6so1657217wrw.6 for ; Thu, 27 Sep 2018 01:50:59 -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=pliM0wAhEQbP7B2f//HIg7uUcfNbBN60CgcLvrL/TbY=; b=Ji+RetyvGrM4kppR1BHBn9jBPUwbfAU9gkrn7EX19XHyKQlRz6DO6xiwEGj8pMihfV ouVzVT4iEDQmICj+j0fDYb3BrF0KxfpM0Nd+LlDgCMfLDtgccC1Az25bz088U6nsF1t4 OJZc9pz4892orsoD1Xirg/GDdwX89C9KKc7rA= 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=pliM0wAhEQbP7B2f//HIg7uUcfNbBN60CgcLvrL/TbY=; b=cwddkXGr9A0RfbbwOyoQYLK8Iu4Yt0PbCN4vDfhx8g8A7cTraqeV8gAhBqf2cGS5xc uTxznktW1qj2evFh4vu5cnU/N9McfBJBmVeAT2n1JfQihVOR1dVyghf4QDXi3URH2SRM bLnDT2ZjeyujeIVvOMUn2WoNuE7lt08BHdt5XS9zk6gbrJ4m36CoN1ZaZJP7GSnU4JwF GU6ynyvXiyWxxvxosdgp6yowMw0utOhHtUJA3rV/nEhr84fLfzzYWJtEZ0k7oI+lTkQ9 dH9RBldba0fs/8g545Rnp3Kj5jquYSjeST9WHNWNqsxzR2wyIhdGFhClu2ISkygzIhFN UNWA== X-Gm-Message-State: ABuFfohD1MuS1biRj/8LZ024Zjj42QLb0meDvav5FTQWowRJZF9xokJE bSue6t4AKnE+ne3QGg9MN4cDDg== X-Received: by 2002:adf:a185:: with SMTP id u5-v6mr8316031wru.50.1538038258916; Thu, 27 Sep 2018 01:50:58 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.50.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:50:58 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 02/11] efi/arm: libstub: add a root memreserve config table Date: Thu, 27 Sep 2018 10:50:29 +0200 Message-Id: <20180927085039.8391-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Installing UEFI configuration tables can only be done before calling ExitBootServices(), so if we want to use the new MEMRESRVE config table from the kernel proper, we need to install a dummy entry from the stub. Tested-by: Jeremy Linton Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm-stub.c | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.18.0 diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 6920033de6d4..30ac0c975f8a 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -69,6 +69,31 @@ static struct screen_info *setup_graphics(efi_system_table_t *sys_table_arg) return si; } +void install_memreserve_table(efi_system_table_t *sys_table_arg) +{ + struct linux_efi_memreserve *rsv; + efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID; + efi_status_t status; + + status = efi_call_early(allocate_pool, EFI_LOADER_DATA, sizeof(*rsv), + (void **)&rsv); + if (status != EFI_SUCCESS) { + pr_efi_err(sys_table_arg, "Failed to allocate memreserve entry!\n"); + return; + } + + rsv->next = 0; + rsv->base = 0; + rsv->size = 0; + + status = efi_call_early(install_configuration_table, + &memreserve_table_guid, + rsv); + if (status != EFI_SUCCESS) + pr_efi_err(sys_table_arg, "Failed to install memreserve config table!\n"); +} + + /* * This function handles the architcture specific differences between arm and * arm64 regarding where the kernel image must be loaded and any memory that @@ -235,6 +260,8 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, } } + install_memreserve_table(sys_table); + new_fdt_addr = fdt_addr; status = allocate_new_fdt_and_exit_boot(sys_table, handle, &new_fdt_addr, efi_get_max_fdt_addr(dram_base), From patchwork Thu Sep 27 08:50:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147686 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726253lji; Thu, 27 Sep 2018 01:51:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV62VLRHZmWJk6xIsJkoXgmSAbqJeIkrP+7bhh98AtmKuZFOgXRwl5lvo1EOQmoyDHau8768O X-Received: by 2002:a17:902:28a4:: with SMTP id f33-v6mr9812700plb.297.1538038265410; Thu, 27 Sep 2018 01:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038265; cv=none; d=google.com; s=arc-20160816; b=0uftYjvRmPhfIFVpNWiKC/FjanWRfg89emFa+kMgkp49YwRcLXPUh8ViORdKKBiStT ulF7AInIFF+pqrGNjDAKIq+zYmxyzoLAemlQNf2X1f/3Q660E6LOUGMTjH8WGCFtokmL YBWZlGKnaT4lObd++nQctAMUECyMugeavgJWgKxxirryZFJWcQyilLJRsYzgn5AGOACQ oQqbitEiu9I1oEMzBd37E0xEdacvFVR04GUvMUPD2+Pe1EzZgtvKomALz7UF0nSlt5eR 6QSQPU/EnlCzFmJG05cJ9oHJ4isKKXzyL2JIoxlc+nGc1vaqXEm+li3QqlhdNGs9vII7 Y66w== 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; bh=VxRTYSwbB2m9KxrX9xxpY79O1ZkMCQToVtuc67/7tNk=; b=KJj9WZRgiyAID9OHb5W8gISHkgvcDQEAkOmKZFscwIqL9NsXRui6oCe2LVJ3UJDhs9 SwT/8qFKY8cUQvMCiftZd30GqGHT1H4TWws1XjaFfEM9txU5jwrYAmI5p+tY3RELZGY1 kKYOE1juoGvCXY4KYzTUbCeK1gpUGsOd69wCawpVuQmoJp/lr1v/8FNqWvknAt0gTMTt oo44ElFpZ43ki0BuK39DLnVTpFREAeOg+mUVHBiRVjvQ1vDpq5YK9bswQW3wTxMlaHR3 qUN31PtTtW7fA3NQFRrGzQWA7WAuE1krFpWObHhbAx9seqnbjhq+HoVGTT/00d9jcpDM myew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MvJ+Bt0I; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 z9-v6si1608734pfg.46.2018.09.27.01.51.05; Thu, 27 Sep 2018 01:51:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=MvJ+Bt0I; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727343AbeI0PIN (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:13 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52007 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727255AbeI0PIM (ORCPT ); Thu, 27 Sep 2018 11:08:12 -0400 Received: by mail-wm1-f66.google.com with SMTP id y25-v6so5009664wmi.1 for ; Thu, 27 Sep 2018 01:51:02 -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=VxRTYSwbB2m9KxrX9xxpY79O1ZkMCQToVtuc67/7tNk=; b=MvJ+Bt0IuUYpPBLf2pOUOmlZ0MQuENxD1uRruMePcdsJmL8hGYmL6UneFZ/CsBNYVh NYde3rKDpTTKsXN0rDQwX77izbJfu87TsLs0/bivhuzH+Ob5J3hJRRGw3Mh6nLKfeVxp YtW7B/XsTPc/BGZ7Xey9v5ZvZgSawN3GWVH/4= 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=VxRTYSwbB2m9KxrX9xxpY79O1ZkMCQToVtuc67/7tNk=; b=D/7Ts5JZ5lxrScTRU3v3JnDOND7MGiOkdB4TEAWHDHuOh5Jzjnntt+lakdK4U4QYDW ZTelylld/a7hpC+NLQSPqoHJb5KGJAYG5dYpnZFdBawC29A+5yksiBCa4cwrfoFZQWOf cNdPaQw3jsHSWT7KZ86Sm2BcU1Yj5LgjWFbYKS70KkxUjur+rSeKZqNDYYAvTNtKnein ecSZT78pYfh5UGt3EZzg5ZJ6vHfw1AdGMuPvp9fAPxfW+bTwvA2GJonl+pnzI/qAxilE 3xRcz1dllO0zqcH3h0Yq/CauCDrJWygEtwJBRyIBer20RZj6bVGkNleokK1/yZ1umDmP 5Mxw== X-Gm-Message-State: ABuFfojVBnIvO3H4StPA59+1FujtVlsr8chXRHzpBdWwBEQogYewZkkM VSGRfYB0rjDRy+qAAMzsQ8mZ4Q== X-Received: by 2002:a1c:5505:: with SMTP id j5-v6mr1031824wmb.146.1538038261852; Thu, 27 Sep 2018 01:51:01 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:01 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 04/11] efi/libstub: arm: support building with clang Date: Thu, 27 Sep 2018 10:50:31 +0200 Message-Id: <20180927085039.8391-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Alistair Strachan When building with CONFIG_EFI and CONFIG_EFI_STUB on ARM, the libstub Makefile would use -mno-single-pic-base without checking it was supported by the compiler. As the ARM (32-bit) clang backend does not support this flag, the build would fail. This changes the Makefile to check the compiler's support for -mno-single-pic-base before using it, similar to c1c386681bd7 ("ARM: 8767/1: add support for building ARM kernel with clang"). Signed-off-by: Alistair Strachan Reviewed-by: Stefan Agner Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.18.0 diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 14c40a7750d1..c51627660dbb 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -16,7 +16,8 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -O2 \ cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) -fpie \ $(DISABLE_STACKLEAK_PLUGIN) cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ - -fno-builtin -fpic -mno-single-pic-base + -fno-builtin -fpic \ + $(call cc-option,-mno-single-pic-base) cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt From patchwork Thu Sep 27 08:50:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147689 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726326lji; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV63V64mP70f+GT7JniRwA/ivLV9LQ+tjwwBmM/qtPiGXHzsRZo5QUOinphwy+6G85ExUrkOR X-Received: by 2002:a63:9612:: with SMTP id c18-v6mr8975223pge.21.1538038269119; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038269; cv=none; d=google.com; s=arc-20160816; b=dcUKzlyCN6FRssbcBtPgDgrXvAik2DPH7w6DvB93Ohb1W+49MeRNnDmhrKw4Vuk5fT i7hoIc0Y43BoT6x2IQurvTSHWyfhceN2OX3tJ1j0B6R3Km62ebwwE1T6D6srlTzuv1CM cocOH9S4iOBMtdyi5YRiFVboSJKyAvPFyOkC+QHyQk1UXeTlTbNxPZHDVNrK41fpZ5VK d2MLII9hXZis3YqxuzBTrLilI4yVClfrAGiZ69AAve+j2fYLSJRacVQcTyS+GqJ3xVkB MrlAeGcoCJ/8woI68bOIvKZ245vyEQ7cLHjdRzAcR9SreMPw4vpvog3IoFV1o2fVdtYs mrUA== 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; bh=8qG3i7EOfW75+1ul/qMJed+W8vBlnWG4DFjga9+cTRI=; b=hrNQiQ3g91s/NOmu+fW1oMsahpZSpjoyaY2bfCUDDHngjJ9mxCXgtiRZWBuFH9vs82 jwMoDROk8Z7aCAl3kSZ7vyFngHZxuAdg+elNeh1YuOxNvZ9ykw2fsE5ZZeJ9TJE5CSR9 OKshgyltUufzhe69u8+KAgTCZbYShttHeGb1WmjJvkJeP49q2KeJMnF50uFMEBj3SvtC qLzzpnYaG2z+lJsWMDtl4bXPy92wW4VSD3NEuUyHrEWgCZLZEJehJMdXEtjtk9I9VApA edW8+JXg+raxNjj+HL6UJ228eiQNs5G8H4flwrSI/pYSovzUHikqbwNUEBeqxXVKlhSv lzqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CTudQxlz; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 l15-v6si1430170pgh.593.2018.09.27.01.51.08; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=CTudQxlz; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727027AbeI0PIP (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:15 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41815 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727315AbeI0PIP (ORCPT ); Thu, 27 Sep 2018 11:08:15 -0400 Received: by mail-wr1-f65.google.com with SMTP id j15-v6so1647955wrt.8 for ; Thu, 27 Sep 2018 01:51:05 -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=8qG3i7EOfW75+1ul/qMJed+W8vBlnWG4DFjga9+cTRI=; b=CTudQxlzyl1XsS+Y4b5DeSKYBr5h0qMtnEAEWbqW3aHZsDDutmDbVGk0frhXrwe1Ia zQJEgZvV7TL7KSq/VgT14zQFbM8tni0q3Ku3OI9UkL/bkiNtWpdDyfptBlFFVMHn+W26 VwtF2/bUqNkonFF2yk7reykD+QR+JdIDlqXjo= 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=8qG3i7EOfW75+1ul/qMJed+W8vBlnWG4DFjga9+cTRI=; b=bm1iKMjR13H0BiKSS+Dnru0Bc/A44FK8eUiYH6/z7tRTbuwNhB1Iz5P0rchedyb5Yy VS/PBwD0EezrMX/F0xeH44VQXADFgaMBrpJcgI6GpnOCq4j/gTauq0zMBwyN5LbmSJjL RiM3lu87WkOq7xJu87Zqrh8WnwFT4YBlzVKhUT3DKdjDNpT+JEYEI/14zzSTq3gOPOOG DBPrLgVeexm0GKtm3BBkjjM1kOmHqf7x8Pg/b4MgBHh62FVPd+c3qmrCBa/yBCt6+6Yy 3LVibVY9jQgIcGnWY8T2Ds5frdco2nBY6b/5nmXSTewps8zNIqW33Sa+vk5kB5Nsg+WD 5vSg== X-Gm-Message-State: ABuFfohhmkjsI0zqlUqzo7Xvr/bYUE3tjr4u0IpwnGiT0vJqS/yMbuM7 H9i6VfqOcWTTXlUyHQ9FAGFSfA== X-Received: by 2002:adf:fb0e:: with SMTP id c14-v6mr7970479wrr.117.1538038264841; Thu, 27 Sep 2018 01:51:04 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:04 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 06/11] efi: Make efi_rts_work accessible to efi page fault handler Date: Thu, 27 Sep 2018 10:50:33 +0200 Message-Id: <20180927085039.8391-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Sai Praneeth After the kernel has booted, if any accesses by firmware causes a page fault, the efi page fault handler would freeze efi_rts_wq and schedules a new process. To do this, the efi page fault handler needs efi_rts_work. Hence, make it accessible. There will be no race conditions in accessing this structure, because all the calls to efi runtime services are already serialized. Tested-by: Bhupesh Sharma Suggested-by: Matt Fleming Based-on-code-from: Ricardo Neri Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/runtime-wrappers.c | 53 +++++-------------------- include/linux/efi.h | 36 +++++++++++++++++ 2 files changed, 45 insertions(+), 44 deletions(-) -- 2.18.0 diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c index aa66cbf23512..b18b2d864c2c 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -45,39 +45,7 @@ #define __efi_call_virt(f, args...) \ __efi_call_virt_pointer(efi.systab->runtime, f, args) -/* efi_runtime_service() function identifiers */ -enum efi_rts_ids { - GET_TIME, - SET_TIME, - GET_WAKEUP_TIME, - SET_WAKEUP_TIME, - GET_VARIABLE, - GET_NEXT_VARIABLE, - SET_VARIABLE, - QUERY_VARIABLE_INFO, - GET_NEXT_HIGH_MONO_COUNT, - UPDATE_CAPSULE, - QUERY_CAPSULE_CAPS, -}; - -/* - * efi_runtime_work: Details of EFI Runtime Service work - * @arg<1-5>: EFI Runtime Service function arguments - * @status: Status of executing EFI Runtime Service - * @efi_rts_id: EFI Runtime Service function identifier - * @efi_rts_comp: Struct used for handling completions - */ -struct efi_runtime_work { - void *arg1; - void *arg2; - void *arg3; - void *arg4; - void *arg5; - efi_status_t status; - struct work_struct work; - enum efi_rts_ids efi_rts_id; - struct completion efi_rts_comp; -}; +struct efi_runtime_work efi_rts_work; /* * efi_queue_work: Queue efi_runtime_service() and wait until it's done @@ -91,7 +59,6 @@ struct efi_runtime_work { */ #define efi_queue_work(_rts, _arg1, _arg2, _arg3, _arg4, _arg5) \ ({ \ - struct efi_runtime_work efi_rts_work; \ efi_rts_work.status = EFI_ABORTED; \ \ init_completion(&efi_rts_work.efi_rts_comp); \ @@ -184,18 +151,16 @@ static DEFINE_SEMAPHORE(efi_runtime_lock); */ static void efi_call_rts(struct work_struct *work) { - struct efi_runtime_work *efi_rts_work; void *arg1, *arg2, *arg3, *arg4, *arg5; efi_status_t status = EFI_NOT_FOUND; - efi_rts_work = container_of(work, struct efi_runtime_work, work); - arg1 = efi_rts_work->arg1; - arg2 = efi_rts_work->arg2; - arg3 = efi_rts_work->arg3; - arg4 = efi_rts_work->arg4; - arg5 = efi_rts_work->arg5; + arg1 = efi_rts_work.arg1; + arg2 = efi_rts_work.arg2; + arg3 = efi_rts_work.arg3; + arg4 = efi_rts_work.arg4; + arg5 = efi_rts_work.arg5; - switch (efi_rts_work->efi_rts_id) { + switch (efi_rts_work.efi_rts_id) { case GET_TIME: status = efi_call_virt(get_time, (efi_time_t *)arg1, (efi_time_cap_t *)arg2); @@ -253,8 +218,8 @@ static void efi_call_rts(struct work_struct *work) */ pr_err("Requested executing invalid EFI Runtime Service.\n"); } - efi_rts_work->status = status; - complete(&efi_rts_work->efi_rts_comp); + efi_rts_work.status = status; + complete(&efi_rts_work.efi_rts_comp); } static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) diff --git a/include/linux/efi.h b/include/linux/efi.h index 22e4de9d3700..a929d2bf41fa 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1662,6 +1662,42 @@ struct linux_efi_tpm_eventlog { extern int efi_tpm_eventlog_init(void); +/* efi_runtime_service() function identifiers */ +enum efi_rts_ids { + GET_TIME, + SET_TIME, + GET_WAKEUP_TIME, + SET_WAKEUP_TIME, + GET_VARIABLE, + GET_NEXT_VARIABLE, + SET_VARIABLE, + QUERY_VARIABLE_INFO, + GET_NEXT_HIGH_MONO_COUNT, + UPDATE_CAPSULE, + QUERY_CAPSULE_CAPS, +}; + +/* + * efi_runtime_work: Details of EFI Runtime Service work + * @arg<1-5>: EFI Runtime Service function arguments + * @status: Status of executing EFI Runtime Service + * @efi_rts_id: EFI Runtime Service function identifier + * @efi_rts_comp: Struct used for handling completions + */ +struct efi_runtime_work { + void *arg1; + void *arg2; + void *arg3; + void *arg4; + void *arg5; + efi_status_t status; + struct work_struct work; + enum efi_rts_ids efi_rts_id; + struct completion efi_rts_comp; +}; + +extern struct efi_runtime_work efi_rts_work; + /* Workqueue to queue EFI Runtime Services */ extern struct workqueue_struct *efi_rts_wq; From patchwork Thu Sep 27 08:50:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147690 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726338lji; Thu, 27 Sep 2018 01:51:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV62zaKRQ5HMOnP5Qn2+RxPGcznFr3sMYIyrAGt55qz8JwtlMIBUiLj/EiBKiZMkF33qcCpYW X-Received: by 2002:a63:5b14:: with SMTP id p20-v6mr9169886pgb.56.1538038269982; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038269; cv=none; d=google.com; s=arc-20160816; b=ZrVCMeadNGhdXOJFq05geE5a4gZ/w1WcEr4EYiCzQCT7OnebRSoOvZAiJ+1h7vxirO 6qqWWkFy2d328DTksZ+pXBxIJRuDK0BngwAY0mniMza2IE4k3bdRMn9pMy/MOpid/B3O doxbW7cYdSYbtw/gFJDn6ir28cYfLV+18WU9PHLBT79MA7GzKoBZlh5qBn/xDyB1izLp D22QZDedFwJeONbY5lcWcNWgbn5Hn03N1LnDyf6zPffA/pZu6A4H7zIeOMSPDpm8q+ZK UahAknbSgh8rR6zOTTc6HvekL1Qhta8UP8eSAb2ZfDwbs9t/36AGpEofTanTHWu1H1Bc RJ8Q== 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; bh=2Hst4Xmssk5t5MSzJ6l4LGDPoTA7TiBmRxnOh47JqGw=; b=mt7IqrpbYtR4mtuhGOMAhOZbmiOk1Iu6fm5VKXE86KjBI5JitI59CPtw6efYzc95BY F+9LdGNymf0k1wdnaBuzcUBlgJQc7EDjQC67FMLlwwOiJKdlc54Advja6OMFs36PbrWP 48njBcHl3q+7wINCbp3tWaHPlO9h5PkOn4OiuW+ZYefmoQZoiEZ8mGMIVbfx2qR3Cqio ZLSoGnYO53aiv4PEIO39owljhpHYsRimq9hwgMfm56DfdR2dU67cDIN48PY/nk61PSEY edKr0FBVkwScB0BH8bF3iBRp7ZFw5GrYIXb70xOmXAzCNVRYM9g0NgRooM0aWHbTIKx9 qjPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=esLzEebS; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 l15-v6si1430170pgh.593.2018.09.27.01.51.09; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=esLzEebS; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727417AbeI0PIS (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:18 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39040 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727315AbeI0PIR (ORCPT ); Thu, 27 Sep 2018 11:08:17 -0400 Received: by mail-wr1-f67.google.com with SMTP id s14-v6so1657609wrw.6 for ; Thu, 27 Sep 2018 01:51:07 -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=2Hst4Xmssk5t5MSzJ6l4LGDPoTA7TiBmRxnOh47JqGw=; b=esLzEebS9YFaA1LjD25exnWeIGHrQzAhSd5WDcGGNtOerRfxPjzd5KqG1uGLqVWrUH 1XqPRqAg66LTCEcivcHFxTyqJ986X8GeJFiImJ0lGGMcNHHZQpPHOZsPijuyZndoph0T 0RwgecSmHBAwkf+1qlweJjgCFt9gfSi5U/QPc= 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=2Hst4Xmssk5t5MSzJ6l4LGDPoTA7TiBmRxnOh47JqGw=; b=hTfeSRXvlEHhwOsza0JfG7XHK6XlyzKNAO9rXk4OseQJM5qt2w2GKyf0elFwG8z6gm GAvrKfe9lSlxominmVVEi+5hSsin+ekVEI4GPegtDEb3mPS1G/7wbxLe8mkCm9EKgWLi Dpg0QpQNLlksc6KmTXQcoLW66iFJ9jm4ZDwzUsR+8e6QiD2srbQGQzw9TT/uhlYTkQZ+ phecCQTng7L2fq3PDmn9gzv+htH6S70nqpgtsu4sZvo2QPme7ufT1eZ//SyN2u9OvPwv ZHi5gyRS+zoxhEyaZpYyu09qWTi9CD9TkN5taJPzBspDGT6lEvqnvQClpSQcCdpyY+Zc P5SQ== X-Gm-Message-State: ABuFfoin4ugwWGpDoAuIdHTHRaNOZYbM+jnRtwAiB646QN/pOn3Sgj5y PSTyMa26wfHmRrziXJ4iaNSAuA== X-Received: by 2002:adf:b2d7:: with SMTP id g81-v6mr7829116wrd.48.1538038266464; Thu, 27 Sep 2018 01:51:06 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:05 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 07/11] efi/x86: Handle page faults occurring while running EFI runtime services Date: Thu, 27 Sep 2018 10:50:34 +0200 Message-Id: <20180927085039.8391-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Sai Praneeth Memory accesses performed by UEFI runtime services should be limited to: - reading/executing from EFI_RUNTIME_SERVICES_CODE memory regions - reading/writing from/to EFI_RUNTIME_SERVICES_DATA memory regions - reading/writing by-ref arguments - reading/writing from/to the stack. Accesses outside these regions may cause the kernel to hang because the memory region requested by the firmware isn't mapped in efi_pgd, which causes a page fault in ring 0 and the kernel fails to handle it, leading to die(). To save kernel from hanging, add an EFI specific page fault handler which recovers from such faults by 1. If the efi runtime service is efi_reset_system(), reboot the machine through BIOS. 2. If the efi runtime service is _not_ efi_reset_system(), then freeze efi_rts_wq and schedule a new process. The EFI page fault handler offers us two advantages: 1. Avoid potential hangs caused by buggy firmware. 2. Shout loud that the firmware is buggy and hence is not a kernel bug. Tested-by: Bhupesh Sharma Suggested-by: Matt Fleming Based-on-code-from: Ricardo Neri Signed-off-by: Sai Praneeth Prakhya Reviewed-by: Thomas Gleixner [ardb: clarify commit log] Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 1 + arch/x86/mm/fault.c | 9 +++ arch/x86/platform/efi/quirks.c | 78 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 8 +++ include/linux/efi.h | 8 ++- 5 files changed, 103 insertions(+), 1 deletion(-) -- 2.18.0 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index cec5fae23eb3..eea40d52ca78 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -140,6 +140,7 @@ 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); +extern void efi_recover_from_page_fault(unsigned long phys_addr); struct efi_setup_data { u64 fw_vendor; diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 47bebfe6efa7..a5b9ddb0f1fe 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -16,6 +16,7 @@ #include /* prefetchw */ #include /* exception_enter(), ... */ #include /* faulthandler_disabled() */ +#include /* efi_recover_from_page_fault()*/ #include #include /* boot_cpu_has, ... */ @@ -25,6 +26,7 @@ #include /* emulate_vsyscall */ #include /* struct vm86 */ #include /* vma_pkey() */ +#include /* efi_recover_from_page_fault()*/ #define CREATE_TRACE_POINTS #include @@ -788,6 +790,13 @@ no_context(struct pt_regs *regs, unsigned long error_code, if (is_errata93(regs, address)) return; + /* + * Buggy firmware could access regions which might page fault, try to + * recover from such faults. + */ + if (IS_ENABLED(CONFIG_EFI)) + efi_recover_from_page_fault(address); + /* * Oops. The kernel tried to access some bad page. We'll have to * terminate things with extreme prejudice: diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 844d31cb8a0c..669babcaf245 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -16,6 +16,7 @@ #include #include #include +#include #define EFI_MIN_RESERVE 5120 @@ -654,3 +655,80 @@ int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, } #endif + +/* + * If any access by any efi runtime service causes a page fault, then, + * 1. If it's efi_reset_system(), reboot through BIOS. + * 2. If any other efi runtime service, then + * a. Return error status to the efi caller process. + * b. Disable EFI Runtime Services forever and + * c. Freeze efi_rts_wq and schedule new process. + * + * @return: Returns, if the page fault is not handled. This function + * will never return if the page fault is handled successfully. + */ +void efi_recover_from_page_fault(unsigned long phys_addr) +{ + if (!IS_ENABLED(CONFIG_X86_64)) + return; + + /* + * Make sure that an efi runtime service caused the page fault. + * "efi_mm" cannot be used to check if the page fault had occurred + * in the firmware context because efi=old_map doesn't use efi_pgd. + */ + if (efi_rts_work.efi_rts_id == NONE) + return; + + /* + * Address range 0x0000 - 0x0fff is always mapped in the efi_pgd, so + * page faulting on these addresses isn't expected. + */ + if (phys_addr >= 0x0000 && phys_addr <= 0x0fff) + return; + + /* + * Print stack trace as it might be useful to know which EFI Runtime + * Service is buggy. + */ + WARN(1, FW_BUG "Page fault caused by firmware at PA: 0x%lx\n", + phys_addr); + + /* + * Buggy efi_reset_system() is handled differently from other EFI + * Runtime Services as it doesn't use efi_rts_wq. Although, + * native_machine_emergency_restart() says that machine_real_restart() + * could fail, it's better not to compilcate this fault handler + * because this case occurs *very* rarely and hence could be improved + * on a need by basis. + */ + if (efi_rts_work.efi_rts_id == RESET_SYSTEM) { + pr_info("efi_reset_system() buggy! Reboot through BIOS\n"); + machine_real_restart(MRR_BIOS); + return; + } + + /* + * Before calling EFI Runtime Service, the kernel has switched the + * calling process to efi_mm. Hence, switch back to task_mm. + */ + arch_efi_call_virt_teardown(); + + /* Signal error status to the efi caller process */ + efi_rts_work.status = EFI_ABORTED; + complete(&efi_rts_work.efi_rts_comp); + + clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); + pr_info("Froze efi_rts_wq and disabled EFI Runtime Services\n"); + + /* + * Call schedule() in an infinite loop, so that any spurious wake ups + * will never run efi_rts_wq again. + */ + for (;;) { + set_current_state(TASK_IDLE); + schedule(); + } + + return; +} diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c index b18b2d864c2c..a19d845bdb06 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -61,6 +61,11 @@ struct efi_runtime_work efi_rts_work; ({ \ efi_rts_work.status = EFI_ABORTED; \ \ + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { \ + pr_warn_once("EFI Runtime Services are disabled!\n"); \ + goto exit; \ + } \ + \ init_completion(&efi_rts_work.efi_rts_comp); \ INIT_WORK_ONSTACK(&efi_rts_work.work, efi_call_rts); \ efi_rts_work.arg1 = _arg1; \ @@ -79,6 +84,8 @@ struct efi_runtime_work efi_rts_work; else \ pr_err("Failed to queue work to efi_rts_wq.\n"); \ \ +exit: \ + efi_rts_work.efi_rts_id = NONE; \ efi_rts_work.status; \ }) @@ -393,6 +400,7 @@ static void virt_efi_reset_system(int reset_type, "could not get exclusive access to the firmware\n"); return; } + efi_rts_work.efi_rts_id = RESET_SYSTEM; __efi_call_virt(reset_system, reset_type, status, data_size, data); up(&efi_runtime_lock); } diff --git a/include/linux/efi.h b/include/linux/efi.h index a929d2bf41fa..845174e113ce 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1662,8 +1662,13 @@ struct linux_efi_tpm_eventlog { extern int efi_tpm_eventlog_init(void); -/* efi_runtime_service() function identifiers */ +/* + * efi_runtime_service() function identifiers. + * "NONE" is used by efi_recover_from_page_fault() to check if the page + * fault happened while executing an efi runtime service. + */ enum efi_rts_ids { + NONE, GET_TIME, SET_TIME, GET_WAKEUP_TIME, @@ -1673,6 +1678,7 @@ enum efi_rts_ids { SET_VARIABLE, QUERY_VARIABLE_INFO, GET_NEXT_HIGH_MONO_COUNT, + RESET_SYSTEM, UPDATE_CAPSULE, QUERY_CAPSULE_CAPS, }; From patchwork Thu Sep 27 08:50:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147691 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726377lji; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV63yB6GVaaQN3qf+W+/S/v8Ac2Ss1AxuHzHy6kdQodK68xwvO72H02gIurAdnlgVT+E831JU X-Received: by 2002:a17:902:aa02:: with SMTP id be2-v6mr9861092plb.294.1538038272774; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038272; cv=none; d=google.com; s=arc-20160816; b=izCFFe2VTaAyOYKe9silRCJ1Qz9oqbHgZQE3Z80I7kWSKecKpgkdSd9NjeSXqqh3jz ceHv0rBxwio7tjHFralp1fjmSvHE9LyXC14SjmwQnBD4YjPpYJOfnB+SkzfiIBJDkEza ESAhrTzeVNVUGfaAIWiZJ2rA19WTz9Z5IgZvtz0X6ETtk7nTv7PF96yE5oer5NbrXJS5 Sf8qg7VhoA8xjUlsEJznTW73V318B7ThVK2Bg5IfX40L66ILZdvVYo/gyPtdgSK7otpJ GIFmpZRh9b3D1ArwS4alm18Ooofnc7rszI5Yi+7dbDZcsZfVqFVIBSP34YBTFq7Fehzq lPZA== 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; bh=iV7F4d1AYaAve1kQcC/87SijzJzQIBKlPBUcmLRWBv0=; b=GgJbSnzNkwUFmiV8K5CByzeGv2M2A3Ae/7dLwB4zHSo88QVudNksFHe1E6YNOFZjYj 2zvyxxWOk2zo/Y8b4TuRUZA0nb+nFLNDYQ9vijwpk5rmaQUDFSJNYKxI1zek5CGOyJ9K +/rBHH6m/snmLMyu9uZy+RzXHMU/KBSpiHhTbMrd8ojX+LCe9N3BUiz3zzC+9ktJ4RZP Bkf1GfQX+CTBHx/JA4sxGBp5KAdeGIWQG+zzzhku11cO+msz0kDzY8rRIFiSY1yrfqcb LA+eDwOX0jDKAYlY0HNilTjSy52uWy9/BjuERmuR0RDZNa5MHTxXJpDlC6h69ZasitkT X56w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TkZmmJdB; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 y14-v6si1513151plp.458.2018.09.27.01.51.12; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=TkZmmJdB; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727415AbeI0PIT (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:19 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37796 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbeI0PIT (ORCPT ); Thu, 27 Sep 2018 11:08:19 -0400 Received: by mail-wm1-f67.google.com with SMTP id y26-v6so4490124wma.2 for ; Thu, 27 Sep 2018 01:51:08 -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=iV7F4d1AYaAve1kQcC/87SijzJzQIBKlPBUcmLRWBv0=; b=TkZmmJdBo/SUvBqPKL+IcIanULSh9vtUwZ5eAdAWdba7syillbGVRCXzXNAyovEjhx h2S6gEAG/tX9CkTqagjlyppkJboAiR4CryMJID7lv2wLQwboMOyNG52rWbZxH0umVy3V MG8h/p/0E1462SFuOvI2Jg4mLzQjLYjD1h+gk= 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=iV7F4d1AYaAve1kQcC/87SijzJzQIBKlPBUcmLRWBv0=; b=gSYMJwXlyzgwOCg1/yjy0q1Ljh5USDttNnUCr4rqtm5KWTL2zbyVC3L+x8lTEZpr/C tbN9sUkre8C4/YjgWIZP8rHqdQnuoKm50KkeiipJ9cIjwpE6Q9YP3VelLI7zPT922q2v q67Cn6Jq1wpGNGBJrQmp7mBaHtdQI5sET8h3J7Q/FozQZnzHVG4kckFyGq/5QMSA87/Y SPeWCrNJFNNffjKKah5vI7fYvDa6uCNUIKHnJRJEv+lQLdS7wscEVqC47cAL6Ahc08gH n4ogDKYQmeBojDpyx5AR94TWtzWATZl9HxWEtZXFACqOp32F4mIMnQIL/iqQEcsL8o5b B0aA== X-Gm-Message-State: ABuFfohnj2itA3jd2+nYJ5o8g4ShbHA043ukBUglZiyQIsh0SLnLrefx g+xaGa0AvL8aKOFGRf34NsDm/A== X-Received: by 2002:a1c:e5cf:: with SMTP id c198-v6mr7058866wmh.113.1538038267937; Thu, 27 Sep 2018 01:51:07 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:07 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 08/11] efi/x86: drop task_lock() from efi_switch_mm() Date: Thu, 27 Sep 2018 10:50:35 +0200 Message-Id: <20180927085039.8391-9-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Sebastian Andrzej Siewior efi_switch_mm() is a wrapper around switch_mm() which saves current's ->active_mm, sets the requests mm as ->active_mm and invokes switch_mm(). I don't think that task_lock() is required during that procedure. It protects ->mm which isn't changed here. It needs to be mentioned that during the whole procedure (switch to EFI's mm and back) the preemption needs to be disabled. A context switch at this point would reset the cr3 value based on current->mm. Also, this function may not be invoked at the same time on a different CPU because it would overwrite the efi_scratch.prev_mm information. Remove task_lock() and also update the comment to reflect it. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi_64.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) -- 2.18.0 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index ee5d08f25ce4..e8da7f492970 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -619,18 +619,16 @@ void __init efi_dump_pagetable(void) /* * 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. + * in a kernel thread and user context. Preemption needs to remain disabled + * while the EFI-mm is borrowed. mmgrab()/mmdrop() is not used because the mm + * can not change under us. + * It should be ensured that there are no concurent calls to this function. */ 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 From patchwork Thu Sep 27 08:50:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147692 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726388lji; Thu, 27 Sep 2018 01:51:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV61f2F3qVmvZWfxAzRBAnymAUMYPPItcSgT1Ln/wZRq+qG4Sb3GyHLGSw7hHEve3UVcKi/tn X-Received: by 2002:a62:4dc1:: with SMTP id a184-v6mr10239759pfb.5.1538038273044; Thu, 27 Sep 2018 01:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038273; cv=none; d=google.com; s=arc-20160816; b=r3pLDqR/6VN2cj6CiTc7HK0aDqIhLN5Py+4G1LSQrS7Kx9zo638JUK5/2ewTEB+dIJ w96qs+rgv5kLEG3yVAnZeAAFK83yB3WHhe31Q5y4bCPYNV2rcHB0RXQ4ZcBOM9LGXNWL TlgNRm60LSpOCOeeeOyF2PgG7mCapBhZgPF6JAJkslzhXpHrfqswNIlDzVlzHU8MbcHM 5WB2XBeTiEMe4mmsIuehbEaMLvf7OsN2lXQhY2WWCia4+zn7EFueY/ele7QKP/dhpM5Z yNRS4KkoiMtD9s4wIleQsb+me0Jh1vIJs3CLqSfx6yDjcUh2qUKel7+IlZwfH9iDhuW/ fEBg== 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; bh=G7faJzsD3RoI+9ZciyV9NwH0zlHSWtEgk++NwoeQKTU=; b=choBSCj+sz/g9uxsW0c/zK8eYcFwxdpEPJ8hBeh+yW1VAztjmbAcNiIhnyF/Z41Gr/ 8zScgsMlmbGe+f3AHYRbdHwM0aMAe840Hw/SyfAcb9gviYzkIxvHuupO1DH6Us1V1sE0 c9v75KnHHL9nw5rWeRSCqoafeS7xZ6uOQ+hekx7vFx9SoXheVy1Dq1jv3z9lhQAWlG3t 6yLSlBMJMjNUHjSUYSu4T6bUas7pICEjh9P62CQuDmhRvspd9WnW6DRobKuIt1ffaD1j yaTXVLr91eJ8++mCcq6uZ1sTgBm8HUeOEwyrQ9dhKi2sTydsS1gyRP8RFKe3Co77Dpp3 3HKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g9rl4lXw; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 y14-v6si1513151plp.458.2018.09.27.01.51.12; Thu, 27 Sep 2018 01:51:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=g9rl4lXw; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727462AbeI0PIU (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:20 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37044 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727342AbeI0PIT (ORCPT ); Thu, 27 Sep 2018 11:08:19 -0400 Received: by mail-wr1-f67.google.com with SMTP id u12-v6so1665440wrr.4 for ; Thu, 27 Sep 2018 01:51:10 -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=G7faJzsD3RoI+9ZciyV9NwH0zlHSWtEgk++NwoeQKTU=; b=g9rl4lXwZQBPXY7Wwn06ohS0x+uep6V+L1wUn0QOetpxa+xO/dHJQE2UgMzsKox8YF XyWpVaSsHRea0WwNl0YZzyg8ISzJ6HOw4vag761jg88XUsMWuXPbWLNixCc8LN8AdP74 hIhJD3tdYCBU1GmA6K/hl3mIdLuvbn29NXc9w= 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=G7faJzsD3RoI+9ZciyV9NwH0zlHSWtEgk++NwoeQKTU=; b=MN17cz+qtRgSYZHmknnrRUOLpksaT/6nWeYrRneBi1p1dp+KjHrm7txcnW6Sx0fHcb nrUI620LcK3yBqQyzYUfik7dqLRagwQAh8uMTySxEbIs4WPiTTnsObpU9s1FoSrso5fc Djn9IhQ0u8yjAEKxRKaLZvtYIcsYOpNk3cPTa/TpM5ppxTBK8ix79C68VGHKVWeA+G4F j7Qm6Jx+KVIx4BMzYvmDZGiRRbLMWWCjKw1PXketzTFO9ljkjSACCySt+dVdvdmtcQUN dc+vgWC2x2OTYMqX6dDfjc38pcFBKVllQSbBfThBRkbcDDty2qHxsH/W4pALwdexc151 NUMQ== X-Gm-Message-State: ABuFfoixcTcLkxZdrmATv9sfm7XL59jdMTa8kvTQiI3LRxyhL9xuO+Nq OYsNKPPC1qu3a3elC1m5IrZ52g== X-Received: by 2002:adf:9244:: with SMTP id 62-v6mr758366wrj.130.1538038269464; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:08 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 09/11] efi/x86: earlyprintk - Add 64bit efi fb address support Date: Thu, 27 Sep 2018 10:50:36 +0200 Message-Id: <20180927085039.8391-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Aaron Ma EFI GOP uses 64-bit frame buffer address in some BIOS. Add 64bit address support in efi earlyprintk. Signed-off-by: Aaron Ma Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/early_printk.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.18.0 diff --git a/arch/x86/platform/efi/early_printk.c b/arch/x86/platform/efi/early_printk.c index 5fdacb322ceb..7476b3b097e1 100644 --- a/arch/x86/platform/efi/early_printk.c +++ b/arch/x86/platform/efi/early_printk.c @@ -26,12 +26,14 @@ static bool early_efi_keep; */ static __init int early_efi_map_fb(void) { - unsigned long base, size; + u64 base, size; if (!early_efi_keep) return 0; base = boot_params.screen_info.lfb_base; + if (boot_params.screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) + base |= (u64)boot_params.screen_info.ext_lfb_base << 32; size = boot_params.screen_info.lfb_size; efi_fb = ioremap(base, size); @@ -46,9 +48,11 @@ early_initcall(early_efi_map_fb); */ static __ref void *early_efi_map(unsigned long start, unsigned long len) { - unsigned long base; + u64 base; base = boot_params.screen_info.lfb_base; + if (boot_params.screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) + base |= (u64)boot_params.screen_info.ext_lfb_base << 32; if (efi_fb) return (efi_fb + start); From patchwork Thu Sep 27 08:50:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147694 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726496lji; Thu, 27 Sep 2018 01:51:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV6386CYTv0SXA+Pn2GqFvw0vY1qcLmqRj7gVVWb3oaWFVXhxgHIDjLrzQBSEsmedIIv7pp+f X-Received: by 2002:a63:7044:: with SMTP id a4-v6mr9182636pgn.63.1538038281591; Thu, 27 Sep 2018 01:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038281; cv=none; d=google.com; s=arc-20160816; b=h3opw35LIAPOku5jNlpK0wax3xipPYgjO+v5IwfJ2fzyB0ZvQaCP7mS54iC+zLDroM vrtEBdB4BlxNYPFxElUuKEwdcpqtWZJMuWoRf4Uchf/PSG9ln8qfVYRTolFMEA0FzOG/ fV7fTNQjFMO/6gvXrpj/n8bsIt5wF22z/M7tsUq/BiK9EQutKOd4qsbD++eWQLoa6vNK uVrCN7hqRTb3/sKafUb6bUFucfckOyqNkxlznFRPBedZWosz/8rIBJgeO9KByUfUquEu KX7YX6Ivh6hT/b1Tk+wtRo9YdQoEyQFUvH1R4XBPjHfx99xRuoSqSt3sej7OkoEeVhe8 cdEQ== 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; bh=TfIdZcBS7cb/g0U3CKumXnOhft7wKZSPUCftG/nZTIU=; b=mKn75GzZIbHT4OZyJQHNx1b9+gXU8itTJT0miyc4P2XT1X51Wu2D579ILN3Gfh/2O4 aIYbxORc/rzm6kuZHCIYcwKzMlzpHwXS/3W8JIsKZr8MscRW8VCpGN/cYdI03LrWe2G9 Vkf/XjUDTIE0DGJ+bX2ASqkErsjaIW0yi0KNAf+DQeQYOC0EGwiCSsKf3+yJXUDR4nyW fyy5aQarr1H0cXlWMVpLzBY5eOa7rSnaoM7KkHZeqDLZFn3Mgpy57uQCfm9YzYlQD/I9 rH0nAAz8fK3KNsxq7tKMI8iVNLL/xS8Hfa/db3Vd9sASVeXkTo39Kpv5MzxGlCYJwPD8 wlkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MxmXSZVp; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 n13-v6si1259522pgd.280.2018.09.27.01.51.21; Thu, 27 Sep 2018 01:51:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=MxmXSZVp; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1727362AbeI0PI3 (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:29 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42825 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbeI0PIX (ORCPT ); Thu, 27 Sep 2018 11:08:23 -0400 Received: by mail-wr1-f66.google.com with SMTP id b11-v6so1643445wru.9 for ; Thu, 27 Sep 2018 01:51:13 -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=TfIdZcBS7cb/g0U3CKumXnOhft7wKZSPUCftG/nZTIU=; b=MxmXSZVp9aZeoV7cZf9KfayGE16KbjJtimG5liLaZNVP2zRf2ka2NLhsepqy2hQH5D VL/D1UATC2OZdEDtaH9HRBuuTL/QPFCktrwVSqgaW1FLpdj1GTBrlfTBpxFBSIzwHRqc NlBi66GGIhZQeDCYg19m3yCWKfjxjyU9ajlIw= 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=TfIdZcBS7cb/g0U3CKumXnOhft7wKZSPUCftG/nZTIU=; b=VOpkg+j1zHwWnJgVabYWraf4/kp8cRJd2XzDJQUt149WPEQHMIUqupOF6qfCwFNVhE qR5n/t/hiyohNkeXZOhR/5C0xF5qZqWZRJLRR8UQR/MDsgHANLLhhPrK2KbMNXPW5xY0 VbY5Q08ypwYHbAyteb9Fj6gVtfWd/efxA9LRtMO6uB3H9QMqiAHhH/StPro4jFwKNqy3 1mTSUmCLWrpCrW6cTbIHGw0kaLLQ79CizFlHdu5glltmMTstHtBeSpZpB6V4JLBTTtT6 7knovQq173i3quD+6qfGoogSUOPfOOda0PJFoKD60gR1cKL15Sf1qQyurats5x0bJrOu tyDg== X-Gm-Message-State: ABuFfojxd/kXkF22aL5bQrflG36LWkwWp1fGas61M7INNtH6MiKpb0AB TBIqZENN9dWDK+Dm6oM2kCCzew== X-Received: by 2002:adf:ffc3:: with SMTP id x3-v6mr8154410wrs.137.1538038272552; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:11 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 11/11] x86: boot: Fix EFI stub alignment Date: Thu, 27 Sep 2018 10:50:38 +0200 Message-Id: <20180927085039.8391-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Ben Hutchings We currently align the end of the compressed image to a multiple of 16. However, the PE-COFF header included in the EFI stub says that the file alignment is 32 bytes, and when adding an EFI signature to the file it must first be padded to this alignment. sbsigntool commands warn about this: warning: file-aligned section .text extends beyond end of file warning: checksum areas are greater than image size. Invalid section table? Worse, pesign -at least when creating a detached signature- uses the hash of the unpadded file, resulting in an invalid signature if padding is required. Avoid both these problems by increasing alignment to 32 bytes when CONFIG_EFI_STUB is enabled. Signed-off-by: Ben Hutchings Signed-off-by: Ard Biesheuvel --- arch/x86/boot/tools/build.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.18.0 diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index d4e6cd4577e5..bf0e82400358 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -391,6 +391,13 @@ int main(int argc, char ** argv) die("Unable to mmap '%s': %m", argv[2]); /* Number of 16-byte paragraphs, including space for a 4-byte CRC */ sys_size = (sz + 15 + 4) / 16; +#ifdef CONFIG_EFI_STUB + /* + * COFF requires minimum 32-byte alignment of sections, and + * adding a signature is problematic without that alignment. + */ + sys_size = (sys_size + 1) & ~1; +#endif /* Patch the setup code with the appropriate size parameters */ buf[0x1f1] = setup_sectors-1;