From patchwork Thu Sep 27 08:50:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147687 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726280lji; Thu, 27 Sep 2018 01:51:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV632eAPDuvgczTzYMXkiUvUd+9Wi5ysaXg7VOF6Im6KFHctqWRvtQ+ZBbJ6W0UmBqqIAoFYo X-Received: by 2002:a63:380d:: with SMTP id f13-v6mr9196535pga.124.1538038266711; Thu, 27 Sep 2018 01:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038266; cv=none; d=google.com; s=arc-20160816; b=avp18r3BocNEHcTocqxC4Ow+uHuXSmgIbQjWPbUGyJT51tXHJ3plTvIGDyM0QYEai1 oz3c99BQMk8sJPnzRuHqNHzkGDBbOdsJ6692OF7qPuVC068U8GyVG2coffSqmTcMsm38 ghzGgYEND873/cPrKlpmqja2v5Gvw46/FcS4sKfdiHnEI03BuLF0NtBxXsUbbPfHoprC 2M39mojKglnRQcq5LMwkEfQ1VBF+POBsv2neqPu4vp5kt3nn3Doj7smH2VDEISl3vhiq izjrnYldO+WXi3UFETdSnnSmdhIBW0VHEAFwL6hCbA3etWMyAHJKcqSepoKC3DGkNIxn t+Sw== 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=f8rCgirc+Q/Pjj+hezpx+WshLqF7c604zeE4cCjQ4cU=; b=nYKgaS+8XY5MYGe7bVz7c7aImQkrvdB0FR+SLfDeULxTHCeNjXDG7YUZpwFFexjJtC G0VQ5yLM8kvmYVYPOo4n8SmHwazX78MVJzOvHQSGJtE21Wo7+4AonFGXmTk1CYL4XtOu KJDqGvAeDAHQjVsJwWHr2Rr0mNkNLnNPjfrTFlFV7mo9/ObSoL9mhK7Tz/H93eXJV+mP gXmeIuInCuyWSXzjt4TULF82hGkrUD8bXB7A7+kPyuVi+X/wcvXlds7dvyKsIL/A96qw U95Kdp+Um86TVOvjznm4xmcSaRQmN33LBKgQCP9mTYTDdkAlRyYr6jj0sqMnfq8Gk0M0 hJfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bovG80Cm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 t65-v6si1498251pgt.248.2018.09.27.01.51.06; Thu, 27 Sep 2018 01:51:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=bovG80Cm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727340AbeI0PIL (ORCPT + 32 others); Thu, 27 Sep 2018 11:08:11 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51165 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbeI0PIL (ORCPT ); Thu, 27 Sep 2018 11:08:11 -0400 Received: by mail-wm1-f67.google.com with SMTP id s12-v6so5032584wmc.0 for ; Thu, 27 Sep 2018 01:51:01 -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=f8rCgirc+Q/Pjj+hezpx+WshLqF7c604zeE4cCjQ4cU=; b=bovG80CmbjL84b5Zsj4eHC7ELIy3ILRfjn7nny+sOwsD9OQLDif7BtAPKn1cmccbAj CD313OwFymTWeSWL4w7q/j8EPuOxM2JEzK63Mk76d/1b7GDHa3zPkBDuVJf17EC+OFX1 fFHfqSiPqdljW9o7Gi73hRRYpGRCiY3yNMjSc= 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=f8rCgirc+Q/Pjj+hezpx+WshLqF7c604zeE4cCjQ4cU=; b=XTQcimw5kNk6u5OZEtZWjL+W99Vq6h0pXcNrWc4R8On50FTTi1hHX4TizunOhplKDX UzxxOM/whaGOgqTD7raUW/5wK2noGkcWvQMw8faOljpS4mPQbRSMmSmlpE25kjy3o70y GhsULyG7f9tbvkNIaYh9xH/y1aRNvp5mCtj1tX+DsLGQW6wA95BkghEyT+UUYVIzSooW 4MVK4ZADJPKK3DgkS3JeK7cPsTKnnnhPn7ILChGLxXQj3DSBHwMOJJMuyWPprJgMsAzX hPMp1ra9oi7mo2H0NV53IYugUWYBemCpgihtvyQTRLBoDy1ZE8maYB3CH/drExkH0ogF cP3g== X-Gm-Message-State: ABuFfoipX+e/XYTl5AcZROtsphrv783+0mwfP4+7zzM1Z8HW73CeC07o eDUZ/laSjCAgJ8sYjjktHh7WujUPk9g= X-Received: by 2002:a1c:8a55:: with SMTP id m82-v6mr6884527wmd.70.1538038260353; Thu, 27 Sep 2018 01:51:00 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:50:59 -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 03/11] efi: add API to reserve memory persistently across kexec reboot Date: Thu, 27 Sep 2018 10:50:30 +0200 Message-Id: <20180927085039.8391-4-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add kernel plumbing to reserve memory regions persistently on a EFI system by adding entries to the MEMRESERVE linked list. Tested-by: Jeremy Linton Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 32 ++++++++++++++++++++++++++++++++ include/linux/efi.h | 1 + 2 files changed, 33 insertions(+) -- 2.18.0 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 a5cb580472c5..22e4de9d3700 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);