From patchwork Sat Jan 26 10:22:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 156676 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1359885jaa; Sat, 26 Jan 2019 02:22:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IbQmcZRm+pl9fxmCFteIPjMd+iw8GwL4SU6X0T1azlpf/1pRId0eEec1UxCIWddXQns90dV X-Received: by 2002:a62:5007:: with SMTP id e7mr2147091pfb.92.1548498143072; Sat, 26 Jan 2019 02:22:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548498143; cv=none; d=google.com; s=arc-20160816; b=JgeNspiyWc01m6vWJxAkHQelE7RhinEGjdlPCVQcpzmOTQzlitIZ+Whnv0v6rte7pI NbdzB+TDVmdW2MuJi/Svp52hIYcaJFQwUvzTNIIMZ/LZWRynUQJ0YA9f0oVsc8WtfQ17 +GCx4Hbou247VBW8pBpmHD4cuL2UpZfRQPwHcNLyh9+5aTS0ZilCf0qJG1Q3XiOK5HLX JY0+EVWK+PCbJMN8AslvGEnDGb2Wphw3aYy7DcENUd55RiYRNMhEsoxydOb1BxbSYnpT WOZsmuLH6Ia95We0/OwNYKqKpzCcORllNaDH16BzmaHfIPjLKr2QCEcoidARdT7Xc92m EBRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=LPSux1Ow7b5gv5r9U7Upb1rNzKAqe3fdivFt3Ax38Nw=; b=wiY/TKRgTqTSLigutxcR62bHkDogIfgCawjXh3Hewpvl/fClB6pANU0nosm19phaZT GRsPZas1vgTHTq0csm7hp72oeGU9wydGHEfSXPLkGr3r/mXrSdVG6zp+ey49DC8VzMYY BGBdhWjyHblrRMf/hd7SHYrSa4CLNsKrh3OINBfdaSqqWlMUEtvJICx4sk47oaRBg0+J p/1ttHvpdaGWn6b6EEIj2KgQQErQAmUkM5/yaGj94Ng4RZpcfFcKssAsqCHZQvIkuFGy +tqQmoS5sy9cHv/bqRu4LmuE7Ykz8IjXF+q5fj0K5wTAa7zzGjjYotgRFdwIi3vFDdpa opeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=US6bfJ3F; 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 h85si28105329pfd.27.2019.01.26.02.22.22; Sat, 26 Jan 2019 02:22:23 -0800 (PST) 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=US6bfJ3F; 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 S1726234AbfAZKWW (ORCPT + 3 others); Sat, 26 Jan 2019 05:22:22 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41611 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbfAZKWW (ORCPT ); Sat, 26 Jan 2019 05:22:22 -0500 Received: by mail-wr1-f65.google.com with SMTP id x10so12748287wrs.8 for ; Sat, 26 Jan 2019 02:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=LPSux1Ow7b5gv5r9U7Upb1rNzKAqe3fdivFt3Ax38Nw=; b=US6bfJ3FgUYwtZaqDsFdnMuuDjEaWPGvIpwj+SZqXnhiAW1nUAQuI0ba0S/eKztZ6p wLQZ1sDKy/ZmJj4G0WFUxNy/bcpATq3euGOKGmqwXfEn9ha9/l/FxY5PRWemWG+vz4Oz 75d5Nj9cr68+mZ6mfAEs0EQ55EXjWIvImWIik= 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; bh=LPSux1Ow7b5gv5r9U7Upb1rNzKAqe3fdivFt3Ax38Nw=; b=sYqWwX1IJ4mXA5IUgiVuhzYDOa4tAvgxF5wK4vGeHUoMAGUGMkVrLQ5GNiqbiATRFc /74S0yAmyik+WtmMiABjYdpD4o9YqDjFQqbozIg6XZ6IMk+SuXp/o+0E+ZGgl8p12Vn4 eA+zDtZ8hX07QkW/DPfJ6cXIRFX0a9F4PcRFTE2t+N6pufxMRo5Yg8WZfp6cRBAJ0AyY eiQcK9rucV3vWg4gp924D9/WXVEs6DRK1QVfNWyzpxRrzknil5yyeaRKI70QwmLrwnKC dKuiWqmVEuit+cEAy3wIlCG8EPVwMLeMd+h2IeMNpIrc3R5RTfrF572RYo8Rc0229Og5 e5ng== X-Gm-Message-State: AJcUukeoeLM022RklaWtg7RV9HVj7UkapZR8p3QBJytZtHxXUWoPRDrQ 6SjHCRDJCCi2QjBNn5A5+rpq6lbnReLC1A== X-Received: by 2002:adf:dec4:: with SMTP id i4mr14210708wrn.307.1548498139302; Sat, 26 Jan 2019 02:22:19 -0800 (PST) Received: from dogfood.home ([2a01:cb1d:112:6f00:ccd2:d408:6bac:4700]) by smtp.gmail.com with ESMTPSA id 60sm192265924wrb.81.2019.01.26.02.22.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 02:22:18 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, mark.rutland@arm.com, james.morse@arm.com, Ard Biesheuvel , Alexander Graf , Heinrich Schuchardt , AKASHI Takahiro , Leif Lindholm Subject: [PATCH] efi: arm/arm64: allow SetVirtualAddressMap() to be omitted Date: Sat, 26 Jan 2019 11:22:07 +0100 Message-Id: <20190126102207.29488-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The UEFI spec revision 2.7 errata A section 8.4 has the following to say about the virtual memory runtime services: "This section contains function definitions for the virtual memory support that may be optionally used by an operating system at runtime. If an operating system chooses to make EFI runtime service calls in a virtual addressing mode instead of the flat physical mode, then the operating system must use the services in this section to switch the EFI runtime services from flat physical addressing to virtual addressing." So it is pretty clear that calling SetVirtualAddressMap() is entirely optional, and so there is no point in doing so unless it achieves anything useful for us. This is not the case for 64-bit ARM. The native mapping used by the OS is arbitrarily converted into another permutation of userland addresses (i.e., bits [63:48] cleared), and the runtime code could easily deal with the original layout in exactly the same way as it deals with the converted layout. However, due to constraints related to page size differences if the OS is not running with 4k pages, and related to systems that may expose the individual sections of PE/COFF runtime modules as different memory regions, creating the virtual layout is a bit fiddly, and requires us to sort the memory map and reason about adjacent regions with identical memory types etc etc. So the obvious fix is to stop calling SetVirtualAddressMap() altogether on arm64 systems. However, to avoid surprises, which are notoriously hard to diagnose when it comes to OS<->firmware interactions, let's start by making it an opt-out feature, and implement support for the 'efi=novamap' kernel command line parameter on ARM and arm64 systems. (Note that 32-bit ARM generally does require SetVirtualAddressMap() to be used, given that the physical memory map and the kernel virtual address map are not guaranteed to be non-overlapping like on arm64. However, having support for efi=novamap,noruntime on 32-bit ARM, combined with the recently proposed support for earlycon=efi, is likely to be useful to diagnose boot issues on such systems if they have no accessible serial port) Cc: Alexander Graf Cc: Heinrich Schuchardt Cc: AKASHI Takahiro Cc: Leif Lindholm Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm-stub.c | 5 +++++ drivers/firmware/efi/libstub/efi-stub-helper.c | 10 ++++++++++ drivers/firmware/efi/libstub/efistub.h | 1 + drivers/firmware/efi/libstub/fdt.c | 3 +++ 4 files changed, 19 insertions(+) -- 2.17.1 Tested-by: Jeffrey Hugo Tested-by: Bjorn Andersson Tested-by: Lee Jones diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index eee42d5e25ee..626ec4b4a664 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -370,6 +370,11 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size, paddr = in->phys_addr; size = in->num_pages * EFI_PAGE_SIZE; + if (novamap()) { + in->virt_addr = in->phys_addr; + continue; + } + /* * Make the mapping compatible with 64k pages: this allows * a 4k page size kernel to kexec a 64k page size kernel and diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index e94975f4655b..442f51c2a53d 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -34,6 +34,7 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; static int __section(.data) __nokaslr; static int __section(.data) __quiet; +static int __section(.data) __novamap; int __pure nokaslr(void) { @@ -43,6 +44,10 @@ int __pure is_quiet(void) { return __quiet; } +int __pure novamap(void) +{ + return __novamap; +} #define EFI_MMAP_NR_SLACK_SLOTS 8 @@ -482,6 +487,11 @@ efi_status_t efi_parse_options(char const *cmdline) __chunk_size = -1UL; } + if (!strncmp(str, "novamap", 7)) { + str += strlen("novamap"); + __novamap = 1; + } + /* Group words together, delimited by "," */ while (*str && *str != ' ' && *str != ',') str++; diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 32799cf039ef..337b52c4702c 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -27,6 +27,7 @@ extern int __pure nokaslr(void); extern int __pure is_quiet(void); +extern int __pure novamap(void); #define pr_efi(sys_table, msg) do { \ if (!is_quiet()) efi_printk(sys_table, "EFI stub: "msg); \ diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index 0dc7b4987cc2..f8f89f995e9d 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -327,6 +327,9 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, if (status == EFI_SUCCESS) { efi_set_virtual_address_map_t *svam; + if (novamap()) + return EFI_SUCCESS; + /* Install the new virtual address map */ svam = sys_table->runtime->set_virtual_address_map; status = svam(runtime_entry_count * desc_size, desc_size,