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 */ From patchwork Fri Sep 21 16:32:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147304 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1023651ljw; Fri, 21 Sep 2018 09:32:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYWcAgzGoAiWMJHtnbWxo3YCJxRQY86q4DayXZUQAemld5rkRvQWydwCWL9uvo3xUQUiJPS X-Received: by 2002:a62:1544:: with SMTP id 65-v6mr46921703pfv.178.1537547572779; 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=AFWKMGUD03CLiFgIyWBhjphgWZEq1+ta2qe+eMyaN5JFOaIa2RzrNdBw1i7b4SVqCO e5O9D3skpSt1hxXuNEnJvH5P0kJWluAtnsVZqf1oYw81qrfaqjxMx1h+3EB7vxxjQDOo yetzadVYOgDqacaedTVrWLqBFKwszyrlDZAn2XR6ojBuM7dWL7tAWuQ6GSchiP1/XB2R 226fx/+DgpgsxSWpy1vTZyogvOl/j+4c5exCe/MOlWiHgUVf6wvva/uX+16+XANtRS7x 1tmFTMTiliZezkfetSHooDvIHi0HamiNDkSNJ2N0+z0UoOLhx0oi8trv5Cd1pIQjuduQ JMrA== 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=+xTBG6e1Ietga+Fy3ANr2FAmeF/SEH9hQqVSCRf7Tp8=; b=IV2ztrKd70Ln3r2t2kUanX0OphSVKsOa4bd1v3DJ9RU6D0KHhNRI6D5XDslqxlULKg gopsnHo4S/cpYDVe2VUP8o51FJE9xQVrsv4Fwj1YORWAATlnKt4HpEvkErxAA8AmuWck KcMoWIx7n7x76PTmfA8/vDz5XiII/xSZajIlBXj2EXxdW9ReR65KypTydmG6sJWC1WgW 6l4FwlyqoEdVaChCCOxUiQ+LLQwGk0zB2CArsNwHxSo3fDsSV+a6hy8qGfT6rEKpxwtr N7KQCYAZpzB+RSyrHKPAwInc7u2lzxUcMYzkzZzUgEOt5YOtzAYCLAC2N4kgtOzJzuGi r+rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="g/ucUVqC"; 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="g/ucUVqC"; 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 S2390811AbeIUWWa (ORCPT + 3 others); Fri, 21 Sep 2018 18:22:30 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46309 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390767AbeIUWWa (ORCPT ); Fri, 21 Sep 2018 18:22:30 -0400 Received: by mail-pg1-f194.google.com with SMTP id b129-v6so6276815pga.13 for ; Fri, 21 Sep 2018 09:32:51 -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=+xTBG6e1Ietga+Fy3ANr2FAmeF/SEH9hQqVSCRf7Tp8=; b=g/ucUVqCXGkD64hgIgRPvSYHnUWxn/ry6Ips6NVg/mZPv4wAsjQG61PG3T/fRP9XZ+ 81NVUQ/M3PdpseGDxkUihLXGT70osVq6P2qm4SewYU96/0SGPZnvGmf3XYm2WDIb7MpN jOTvSURmUPxiammve4W9LXFqfGOgGnFF/MwmA= 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=+xTBG6e1Ietga+Fy3ANr2FAmeF/SEH9hQqVSCRf7Tp8=; b=CsTQJ6ON/z167l3vNnJ9K4EYogMvzJ083fX4t8GfOeqrRzM1iC3N9Mq8EyJySB8kp+ C331pi9FuTJwt8yncsV4wVKiXrhTj5+tcyuy8Z1rmj23sQyDNq3Xe2SnjMptFVS80lc8 olhMXjeESvPrfvwuNpP/egXuFPrXmV13G4QdyYjxUeE8DadH7bp5liI7ePXtta724SC4 IJov/Y6hX+cWi7wBK/gOw5AlaRPqujLWxGDSH13U4pY1azBYLFfDQUIfqYsEFZVSpGOs p18KPo7/MLJxaFKiBFl/ztXsACsOeW+MLdrjXp5LZ+NvUegV717mDtnelIPsfsRqrSlF 0/mw== X-Gm-Message-State: APzg51Dhc4XNqVuMfBze83RyAVVjSg8mdAG/uvZllvKvJIEHW0ktYCVJ 5L8vkfvr+xmZXagE3KkzG8v5Wx5cDH4= X-Received: by 2002:a63:4107:: with SMTP id o7-v6mr11234292pga.256.1537547571184; Fri, 21 Sep 2018 09:32:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 09:32:50 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Jeremy Linton , Marc Zyngier Subject: [PATCH 2/3] efi/arm: libstub: add a root memreserve config table Date: Fri, 21 Sep 2018 09:32:45 -0700 Message-Id: <20180921163246.16632-3-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 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. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm-stub.c | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.17.1 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 Fri Sep 21 16:32:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147305 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1023675ljw; Fri, 21 Sep 2018 09:32:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZZ499UdPuR+tF0XCUoa3GRkIUUP04bx7Ftz0n9ILr0xgFBh6XFDsej7G81XsbHm6IDCRv/ X-Received: by 2002:a17:902:bc8b:: with SMTP id bb11-v6mr44486165plb.112.1537547574055; Fri, 21 Sep 2018 09:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537547574; cv=none; d=google.com; s=arc-20160816; b=fn9seGGpfDiE1BuyI7rXUoNRwuTq+CDQz71/Hxy6vI41IRCiGtIsQDr+jvamtyAFeP TRsx2IAiXeK8B1+MfnqFelUsqFvx0W6qafcLUQ3Y41Njc0j9Tc5ywZ0ypum77LN7T0sW 5blDGqemAHn5RQKBAKC7E58OBsev+/OzcGubFMA6QYWemiVUIqPgEhFQIGgbSCEQsC1M /13TGPzG2QWvfYAS3AVukLyL1lGMAt+SwA8Ul/t1T2/LFI+C5lpQIhuWi1g1Sh4bwoHs YI5AExXTc0s11KO/OBWn6W3cPFPjA7PK8a786I4jRY664d4DfyC+uoMbIVcq5cgX1RUL IYBQ== 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=ZhvAxlxQo8nQwYA/q6rVKaATGS5FYnIIRguK861yt+c=; b=yYRDqCe0d2Yh5wUErRIPlB924NWLDWapT/pNqoU+6WzFa93zVxKRqMIHf20F5tvwhA /cVOq4dRimVP3hyZ0pWFPcJRtGWDbISu6m8ZFoqnZp46pna/j1OJh1Fcr1Dj60KgySFN jeTuZJ379vuwvJMNGTerAmst3MsC8uNRI/VuGm2Q0macuO3fUQTvaJI7sfHFKRGGU6uO wGd5y13p0oCi5la8tIMJB3qF47LYBoj5DtScpg1ydrPadbLTs2K94iqZ7kEakt2LBjgr onblLHhBgN/C4PyvO5/nLJscM7Fg9QVlkPqbMrirxM+TWK9zRx6dnFKvpN4eM/1LzuAq HVAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AYGdXKek; 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.53; Fri, 21 Sep 2018 09:32:54 -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=AYGdXKek; 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 S2390833AbeIUWWc (ORCPT + 3 others); Fri, 21 Sep 2018 18:22:32 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34558 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390767AbeIUWWb (ORCPT ); Fri, 21 Sep 2018 18:22:31 -0400 Received: by mail-pg1-f194.google.com with SMTP id d19-v6so6305236pgv.1 for ; Fri, 21 Sep 2018 09:32:53 -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=ZhvAxlxQo8nQwYA/q6rVKaATGS5FYnIIRguK861yt+c=; b=AYGdXKek7RGh7OL6QInGCqElb6KM/MTc80LN/73dl77wr3Lr09WzMxlnso1agzcMwd fhzqBKx+YyNEWaLSL7g6ePjep1zMiUAzrz0yThx6bCQWI9qpT75P0j9LRXWk6gYYqqxF /UD+Qv9DsqgnyNgjf6gvhXUNEh+lr6V7Et+uk= 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=ZhvAxlxQo8nQwYA/q6rVKaATGS5FYnIIRguK861yt+c=; b=D6zam48/YZo+jXRW3U3iIZKTGAcLu6QQoqssScYK+dR7+hepoPMIy/i8GRvI7irZUS 5QCrXXCvDDjyqapjuT+aYZ2kAbrrllO/ZVsyxWWMmOPun1+Qc7KymvyllaAjd7giatHq vvqNL7mYROzxoHHSd5ZRM0g3X2Yi/BRPNDI6bM+qHE46lpDkRdZfkbhdID2zi3otYANP S7x7IlBWBW8xcYq0wA1/FBR2eIbOc4NVC59kmKLj+9nNgF+4BeJADlY0K4Kh0rR9z+MM AUErIy/npbvz5GbZGghlWUj3+RQzcrwVLCbtRsYHLJslUZGWYyJcXq0DPoFxkZ9Gvwqf Ooyg== X-Gm-Message-State: APzg51CRhwNj4DH7LLE9B3XgMxtW8AlQERNPD/yN89fY23BOZovnLGhL Y5lRMgVawm7/OraLL3Ii3Dk3/Q4Jj1U= X-Received: by 2002:a62:c182:: with SMTP id i124-v6mr47052801pfg.248.1537547572321; Fri, 21 Sep 2018 09:32:52 -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.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 09:32:51 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Jeremy Linton , Marc Zyngier Subject: [PATCH 3/3] efi: add API to reserve memory persistently across kexec reboot Date: Fri, 21 Sep 2018 09:32:46 -0700 Message-Id: <20180921163246.16632-4-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 Add kernel plumbing to reserve memory regions persistently on a EFI system by adding entries to the MEMRESERVE linked list. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 32 ++++++++++++++++++++ include/linux/efi.h | 1 + 2 files changed, 33 insertions(+) -- 2.17.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 688132ac8a0a..249eb70691b0 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -962,6 +962,38 @@ bool efi_is_table_address(unsigned long phys_addr) return false; } +static DEFINE_SPINLOCK(efi_mem_reserve_persistent_lock); + +int efi_mem_reserve_persistent(phys_addr_t addr, u64 size) +{ + struct linux_efi_memreserve *rsv, *parent; + + if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) + return -ENODEV; + + rsv = kmalloc(sizeof(*rsv), GFP_KERNEL); + if (!rsv) + return -ENOMEM; + + parent = memremap(efi.mem_reserve, sizeof(*rsv), MEMREMAP_WB); + if (!parent) { + kfree(rsv); + return -ENOMEM; + } + + rsv->base = addr; + rsv->size = size; + + spin_lock(&efi_mem_reserve_persistent_lock); + rsv->next = parent->next; + parent->next = __pa(rsv); + spin_unlock(&efi_mem_reserve_persistent_lock); + + memunmap(parent); + + return 0; +} + #ifdef CONFIG_KEXEC static int update_efi_random_seed(struct notifier_block *nb, unsigned long code, void *unused) diff --git a/include/linux/efi.h b/include/linux/efi.h index c72599b8b344..c753d8530da6 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1043,6 +1043,7 @@ extern int __init efi_uart_console_only (void); extern u64 efi_mem_desc_end(efi_memory_desc_t *md); extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md); extern void efi_mem_reserve(phys_addr_t addr, u64 size); +extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size); extern void efi_initialize_iomem_resources(struct resource *code_resource, struct resource *data_resource, struct resource *bss_resource); extern void efi_reserve_boot_services(void);