From patchwork Fri Sep 21 16:32:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147303 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1023641ljw; Fri, 21 Sep 2018 09:32:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYrZUsjB0nWai456RPsCYuP/eXpTfp0CN9AV3ftNz6ZeHMnYD/DgJfg4eBIEk/gLRegmuJA X-Received: by 2002:a63:6645:: with SMTP id a66-v6mr6083847pgc.5.1537547572310; Fri, 21 Sep 2018 09:32:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537547572; cv=none; d=google.com; s=arc-20160816; b=Ghu20NBwXEQa+gx7SqhDWLxYAelchjbywHNUAgnEebKnCB1es93/zGtNeFjy+v1qkl v3Tzo5DCU3zokIxoHPR7kEgjMq8B8KPU2JKQMurCYtKY6GLHzksUhPCrq1/Er00t5CN3 YhkSpSu7WSm07u1KOR1DXNEifngEg3/eDhkJGQb4ng3z0Hl8uFAfrQQ4hCYqarXWcWtx QlYOAqjf1PxXMUCa7fjf7oWtdTBaGjdOCRwiuORSTnUXoi9URqga5ttBGSrFRIv+BtjL PQ8kPmDQhG1O7wffKCNgOB0bAbWVqmsAiliihH6kBAveGNIoLG4tIfobqEtdTAb3yEkr iHMA== 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=KvaRcxvupptwuZNigzbHL87WXqH4RcIXUa+v8YRtv9Y=; b=oFvvkWptcghUyltP/oZ441lobBx+ilT72bf/pb13DDaZMT5EXHdHX5oK2vvfeCBShC qfK8Cl1FpMRSb1qXVZ1g2IvdZ1qzXbySlCftglEJU7cerTG9guyvqlJ6rPYCvPkAMhYZ SI09Y9Guxxky+LStouMmgxz/Wy0vPSvTE1kZvYPR4qmDgGHCu/hj5VTCq00xZBUOxDBU J5AxAJANAia9KVgf8Y1zTjoMlqFlmUiQnYHU7KZtXbxsNY2qCsOY0kj0/uleUbVQ1nEx Ziblc3ZnzGZZfApf8aELqnacbnqFR4GLiWTaZcnwRihytB9RtF6EAwF7GBkI6juiT5nP uEYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d81CUp47; 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 c31-v6si26024953pgl.126.2018.09.21.09.32.52; Fri, 21 Sep 2018 09:32:52 -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=d81CUp47; 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 S2390779AbeIUWW3 (ORCPT + 3 others); Fri, 21 Sep 2018 18:22:29 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34552 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390767AbeIUWW3 (ORCPT ); Fri, 21 Sep 2018 18:22:29 -0400 Received: by mail-pg1-f193.google.com with SMTP id d19-v6so6305184pgv.1 for ; Fri, 21 Sep 2018 09:32:50 -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=KvaRcxvupptwuZNigzbHL87WXqH4RcIXUa+v8YRtv9Y=; b=d81CUp47QsV4euBVfO3jk75S7GlkkQBl6srg5qpNgR3VgJSooZWY25gB9vvKHbUbfY A/mwSrM90lTIgpJwpSnEnvV7e+c/9e8Jx0OhVtqvXCqO09s38j0fFCTZ1SleOnzqEOJn 4iehvaltXR5ou9/eVIdQeBHz8QAe5bQ1Fvd5A= 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=KvaRcxvupptwuZNigzbHL87WXqH4RcIXUa+v8YRtv9Y=; b=bqGJ8aqLjN3bLIu1pGFSAoecF3wi0bEVKys3jbOVHXYRNZwckjwU+UenZNcVN1+HRz 92MuYDDYlut+sRRNhlmmQV4DPXIe+Z8zWI8gC1LKqR4J7DuwMjSQ1h4iuTMed3dctcBX wBxbCBJTryEj3O/8owCxUYxt2LnY59eSNr6IBibRcib5HqMyE15O4r95NlAYCVbIluiL 2tjQilHefxOF5XQoJFZu4tPqanZyfT56IpFU0LVzMbIq3LflgvpLXARZezV2UGYF4nDW KDqr4W/6+aBR2bUnj8LGhbpv2nStcdAk1u4bzbZeDqvV3VFSbuLMU/KGOjhoyYZj7m/2 5KDg== X-Gm-Message-State: APzg51AXAIgZDlnAHT/03wGQkYfbzr4ZK56QmdamGFk5WdnQmReODtiD UyNYhnxuNFYW6SrphYUtVi4q+Ea6YqU= X-Received: by 2002:a62:c805:: with SMTP id z5-v6mr47820301pff.44.1537547570082; Fri, 21 Sep 2018 09:32:50 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id y4-v6sm39313996pfn.123.2018.09.21.09.32.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 09:32:49 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Jeremy Linton , Marc Zyngier Subject: [PATCH 1/3] efi: honour memory reservations passed via a linux specific config table Date: Fri, 21 Sep 2018 09:32:44 -0700 Message-Id: <20180921163246.16632-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921163246.16632-1-ard.biesheuvel@linaro.org> References: <20180921163246.16632-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org In order to allow the OS to reserve memory persistently across a kexec, introduce a Linux-specific UEFI configuration table that points to the head of a linked list in memory, allowing each kernel to add list items describing memory regions that the next kernel should treat as reserved. This is useful, e.g., for GICv3 based ARM systems that cannot disable DMA access to the LPI tables, forcing them to reuse the same memory region again after a kexec reboot. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 27 +++++++++++++++++++- include/linux/efi.h | 8 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 2a29dd9c986d..688132ac8a0a 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -52,7 +52,8 @@ struct efi __read_mostly efi = { .properties_table = EFI_INVALID_TABLE_ADDR, .mem_attr_table = EFI_INVALID_TABLE_ADDR, .rng_seed = EFI_INVALID_TABLE_ADDR, - .tpm_log = EFI_INVALID_TABLE_ADDR + .tpm_log = EFI_INVALID_TABLE_ADDR, + .mem_reserve = EFI_INVALID_TABLE_ADDR, }; EXPORT_SYMBOL(efi); @@ -484,6 +485,7 @@ static __initdata efi_config_table_type_t common_tables[] = { {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table}, {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed}, {LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log}, + {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &efi.mem_reserve}, {NULL_GUID, NULL, NULL}, }; @@ -591,6 +593,29 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, early_memunmap(tbl, sizeof(*tbl)); } + if (efi.mem_reserve != EFI_INVALID_TABLE_ADDR) { + unsigned long prsv = efi.mem_reserve; + + while (prsv) { + struct linux_efi_memreserve *rsv; + + /* reserve the entry itself */ + memblock_reserve(prsv, sizeof(*rsv)); + + rsv = early_memremap(prsv, sizeof(*rsv)); + if (rsv == NULL) { + pr_err("Could not map UEFI memreserve entry!\n"); + return -ENOMEM; + } + + if (rsv->size) + memblock_reserve(rsv->base, rsv->size); + + prsv = rsv->next; + early_memunmap(rsv, sizeof(*rsv)); + } + } + return 0; } diff --git a/include/linux/efi.h b/include/linux/efi.h index dea9e7bb5208..c72599b8b344 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -672,6 +672,7 @@ void efi_native_runtime_setup(void); #define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f) #define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b) #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa) +#define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2) typedef struct { efi_guid_t guid; @@ -957,6 +958,7 @@ extern struct efi { unsigned long mem_attr_table; /* memory attributes table */ unsigned long rng_seed; /* UEFI firmware random seed */ unsigned long tpm_log; /* TPM2 Event Log table */ + unsigned long mem_reserve; /* Linux EFI memreserve table */ efi_get_time_t *get_time; efi_set_time_t *set_time; efi_get_wakeup_time_t *get_wakeup_time; @@ -1704,4 +1706,10 @@ extern struct workqueue_struct *efi_rts_wq; extern struct efi_runtime_work efi_rts_work; +struct linux_efi_memreserve { + phys_addr_t next; + phys_addr_t base; + phys_addr_t size; +}; + #endif /* _LINUX_EFI_H */