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);