From patchwork Tue Nov 6 11:37:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150257 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3775351ljp; Tue, 6 Nov 2018 03:37:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dEQWGjoxbn6dyQmI+C3z8ESo7y+iNulXKQJqqy2xkwewiy5cdoBen3Z/hFg4elR0r+c/PA X-Received: by 2002:a17:902:3103:: with SMTP id w3-v6mr26504590plb.51.1541504266821; Tue, 06 Nov 2018 03:37:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541504266; cv=none; d=google.com; s=arc-20160816; b=lWhmCMUbTDqM9t4qWwM6jbSWTikl2ehfhTOVQpnGuZBNDGPtWSB3zQP/xMTb3uQe6y 9IeZjtb5htx4XWLTab5wPzacGc3ggo2NNKf1j14SIyJIc2O7Zh/VM871jo+JJSQf2IPa s9pdNP3mx/Kmd6Lj3i3ecT34yWhvSnWq+upneAKaMzyZcZQ5qtYTWguKSJh7LbV1voQf 6aLOW3KBfsCLGzS3is+cItgGLTMZAWjVFq0vti8nt2lZ3jCSWj+AyBQsnU9xdq6MCm2F qb5YUdYJwTxtnpAP4PUu6K4GYyA/Buuk0V5hgOm8ZVGWr1AkiG2b0R+tPGBPovVykIpZ 5ipg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E9tfc28PkEiOPLpRre63HbM1KC12woQQWyYxHBbdomk=; b=Tu3tLSsa3hmVEYeaR5s9JUulnyihW/+Zdja7ib/IE/MikPoqQfTv2CocUavyzf98/y l6H+HX86kL4AZPfRcLa9PNM9N1SCp3hEwqvC0Gv1amtBUjT4XQlgXVhwoXWp76wdMfvB HtZuiAWpA1I2+UrNbksig9PXVcQIvA5eC0XBGfpjUviCn17Ig207p1whxFWvZP+uxe4V NaIEmbp3rWn0F5vQquqPt399uIIaDLRcdDd9trqvqcIBo929mYEEkhfEZvdwoDtxQWpw nZWe+7ElNiAU7AtzOrTXI5ggmE8is0BCPk+Zvx6cs19DG3zZpYZU0pm5w6xOo0i3NqQC apbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XfZFPYRS; 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 q10-v6si44073084pls.344.2018.11.06.03.37.46; Tue, 06 Nov 2018 03:37:46 -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=XfZFPYRS; 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 S1730605AbeKFVCc (ORCPT + 3 others); Tue, 6 Nov 2018 16:02:32 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38698 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729728AbeKFVCc (ORCPT ); Tue, 6 Nov 2018 16:02:32 -0500 Received: by mail-wr1-f67.google.com with SMTP id d10-v6so13097927wrs.5 for ; Tue, 06 Nov 2018 03:37:44 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=E9tfc28PkEiOPLpRre63HbM1KC12woQQWyYxHBbdomk=; b=XfZFPYRSDzBpggZ+0Oil676DIvkhi+Ybm/5GykEioe5k+w15aqu9n5wTJspx2HzuQo OyURY2Grn7dmE7g5TzDYMZFxn2N+mOHYkMDLa7P254vdkEfwps0FKgPh0eMbWW+OsnxQ jm3wKSaWtnQ2CTIpttSF+cRALQxyimeOuUgHE= 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:mime-version:content-transfer-encoding; bh=E9tfc28PkEiOPLpRre63HbM1KC12woQQWyYxHBbdomk=; b=H2AyszE7KgAQibxCQVzujo+wSH5Ww7NcR+M8Pm2cTfoHFjpablC2rKNvX56cYv7d4H uT6yE/k4hAU+9INVat8hIuzgcChcLVUyD6TH1jwh5Gz9i1moQloTjiVI7XbRt50iwznp 35A5K8Y4+06HAS8QB7sYmxyj+TO/NVViGReHqURNVZP9Ax8H8g6etKAoNMlr/vyst0+s VA5JpeZ1dC6sEyUiSX/46Lc0b82rIjyLVIY+3lkC5adY+FxvhZXwzhwlC25JAF5hjAk5 F8Dkl/C/481hYHYQgh80zkygEMozknkK0F18dWGWaMg1pO5MtHR5LDeWipBmkxM7l6yZ 9s0w== X-Gm-Message-State: AGRZ1gLGG3Wdy7gSlPxFdmjY3Qq5pvtbBzngWh5R5IOVRnGuslA2HoV9 PiUdqnXB8nfgMEryC/VnzljypA== X-Received: by 2002:a5d:48cc:: with SMTP id p12-v6mr23582923wrs.122.1541504264174; Tue, 06 Nov 2018 03:37:44 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:3117:2b29:5ef7:a9e5]) by smtp.gmail.com with ESMTPSA id t187-v6sm1431529wmt.45.2018.11.06.03.37.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 03:37:43 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, mark.rutland@arm.com, marc.zyngier@arm.com, Ard Biesheuvel Subject: [PATCH 3/4] efi: permit multiple entries in persistent memreserve data structure Date: Tue, 6 Nov 2018 12:37:31 +0100 Message-Id: <20181106113732.16351-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181106113732.16351-1-ard.biesheuvel@linaro.org> References: <20181106113732.16351-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org In preparation of updating efi_mem_reserve_persistent() to cause less fragmentation when dealing with many persistent reservations, update the struct definition and the code that handles it currently so it can describe an arbitrary number of reservations using a single linked list entry. The actual optimization will be implemented in a subsequent patch. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 30 +++++++++++++------- drivers/firmware/efi/libstub/arm-stub.c | 2 +- include/linux/efi.h | 13 +++++++-- 3 files changed, 31 insertions(+), 14 deletions(-) -- 2.19.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 55e4ea20bdc3..85d2ec532816 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -602,18 +602,25 @@ int __init efi_apply_persistent_mem_reservations(void) while (prsv) { struct linux_efi_memreserve *rsv; + u8 *p; + int i; - /* reserve the entry itself */ - memblock_reserve(prsv, sizeof(*rsv)); - - rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB); - if (rsv == NULL) { + p = memremap(ALIGN_DOWN(prsv, PAGE_SIZE), PAGE_SIZE, + MEMREMAP_WB); + if (p == NULL) { pr_err("Could not map UEFI memreserve entry!\n"); return -ENOMEM; } - if (rsv->size) - memblock_reserve(rsv->base, rsv->size); + rsv = (void *)(p + prsv % PAGE_SIZE); + + /* reserve the entry itself */ + memblock_reserve(prsv, EFI_MEMRESERVE_SIZE(rsv->size)); + + for (i = 0; i < atomic_read(&rsv->count); i++) { + memblock_reserve(rsv->entry[i].base, + rsv->entry[i].size); + } prsv = rsv->next; memunmap(rsv); @@ -971,11 +978,12 @@ 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; + int rsvsize = EFI_MEMRESERVE_SIZE(1); if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) return -ENODEV; - rsv = kmalloc(sizeof(*rsv), GFP_KERNEL); + rsv = kmalloc(rsvsize, GFP_KERNEL); if (!rsv) return -ENOMEM; @@ -985,8 +993,10 @@ int efi_mem_reserve_persistent(phys_addr_t addr, u64 size) return -ENOMEM; } - rsv->base = addr; - rsv->size = size; + rsv->size = 1; + atomic_set(&rsv->count, 1); + rsv->entry[0].base = addr; + rsv->entry[0].size = size; spin_lock(&efi_mem_reserve_persistent_lock); rsv->next = parent->next; diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 30ac0c975f8a..5bcfa08e8bb1 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -83,8 +83,8 @@ void install_memreserve_table(efi_system_table_t *sys_table_arg) } rsv->next = 0; - rsv->base = 0; rsv->size = 0; + atomic_set(&rsv->count, 0); status = efi_call_early(install_configuration_table, &memreserve_table_guid, diff --git a/include/linux/efi.h b/include/linux/efi.h index 100ce4a4aff6..dfce82b2ca8a 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1715,9 +1715,16 @@ extern struct efi_runtime_work efi_rts_work; extern struct workqueue_struct *efi_rts_wq; struct linux_efi_memreserve { - phys_addr_t next; - phys_addr_t base; - phys_addr_t size; + int size; // allocated size of the array + atomic_t count; // number of entries used + phys_addr_t next; // pa of next struct instance + struct { + phys_addr_t base; + phys_addr_t size; + } entry[0]; }; +#define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \ + (count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0])) + #endif /* _LINUX_EFI_H */