From patchwork Wed Nov 7 14:16:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150395 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5221104ljp; Wed, 7 Nov 2018 06:16:33 -0800 (PST) X-Google-Smtp-Source: AJdET5fgMqvfTbzUeMoGk0EC6hqsGctb+TIAA0KdZpcszMyOE+bhfsh3+w09evTg0NSMEUWc2zYJ X-Received: by 2002:a65:530c:: with SMTP id m12mr329884pgq.224.1541600193548; Wed, 07 Nov 2018 06:16:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541600193; cv=none; d=google.com; s=arc-20160816; b=GMYfHb4dSKF+1CJ6JPq0zSI1DcomwkSlBfjVsmnEPLHUVC/P/6PBeriBMHZBoewj/E eEb565MOujrdKUj0rOfc72qmXT0RbSLZfzkSjeXMMpzqIEbPJdNfGGuWBV3Kbaf6s1j4 CYHGcMOamUPqcMdCq1jyKVQvpPptscyVgu2qTqgmCUfm2eD6N4vmTgWPV+3PI6DkwkzD aWRKYwa4FmyQA1ek6L5zMiDUpLDZU/LEneOnH7JAomz01SmiLHBvYe1m0ma0V/akEpyh 1pk12dD9dIS857qocsEJ+ohnDmTPW0CzJCHy1Yfsdp5B5X2WuWQR7YLp4DSf1YDf4hUI ehHA== 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=3joajA68nNoNDkmszGfR6qLascJ0zzFoHlsaWpC1BKQ=; b=FBRK1+EIiYMxVm7X/xcvUUEcPtv6tUfPCUjKe96RY6rSAfJcYxRgeE18HAH/eBM+Pp GwBkAOB8lsktu0uChaX8Z9REvuWMZK5YQgOAFXrqqxM9Vuf61gTotQ6P8SiCDP5s4vGD iX2HvCI3IswMxFgCuWiizRqFo5VD9iMs3/D9yXWyjZ3JKpRJJEPYSxZMNE7BtttnfGxT gwpUAhPGThqKhtBwAWvDoyNjJyfMLG3XW02+z+diFuCbYkcxbtEByDuySQhQ5+nzHvaU AF2pgluVmlxpoZEudtEdJIKwxF1EiJPrhmfwYLrbytCusiF/TaWXt+yYQrRWC0/E10/h 1ceA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fL12Jner; 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 r3-v6si703022pgn.313.2018.11.07.06.16.33; Wed, 07 Nov 2018 06:16:33 -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=fL12Jner; 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 S1730805AbeKGXrG (ORCPT + 3 others); Wed, 7 Nov 2018 18:47:06 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38797 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbeKGXrG (ORCPT ); Wed, 7 Nov 2018 18:47:06 -0500 Received: by mail-wr1-f68.google.com with SMTP id d10-v6so17583622wrs.5 for ; Wed, 07 Nov 2018 06:16:31 -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=3joajA68nNoNDkmszGfR6qLascJ0zzFoHlsaWpC1BKQ=; b=fL12JnerTLWnp1sm3qbh0kbRkHkQJrLji0qB4s7mT1VidyBcN27M90rCRXYPCDSwOk xuBa6zSyWW4I1YIIZKFUDhQFupmrx5ubxrweLf0b37FhkYV/R8ykeCXftcjXohT6+WEv fKqoNaT0xMzNRWnmySQryQlf0GKsFRw2dHbNE= 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=3joajA68nNoNDkmszGfR6qLascJ0zzFoHlsaWpC1BKQ=; b=tueWoz8lwnyO0T6DkvnJypxmNOEV68a0CwZlbgf0gPtszgCHq8H27ud+UGGMQFEj9f SuQjZ/gh3X2quuxTOkt5X3Wy2cT7JVVEpKVEiKteWyc3d+2+u44Ey9lARm5md9BWnghq e1oWtu9hHvsQZgfGaCoHzWkHa+7jD9vqIpJ/QeYfBW7qUr7RflFJVSirWFFr/G6MLKrz vs8RtG1nrPw60tYtGS7sbtC6iM2+IOAXTlX+olxTS1MLwqb1feT/PRKq/7nGCAx7seAa KC9f6yGGTvqd94gNJnVCVUq+MTvnMHnNFza1/e7A64Tg+/sF11sfERz5xjNJBXb9i9Ea yWrg== X-Gm-Message-State: AGRZ1gKc2aV+cRP2UcruRdwTbaCSUKXaRTsGLs0hcjbSoM5w1oNWabW2 Juno7pvR/+eDBwpk+nB0ylw18A== X-Received: by 2002:adf:8281:: with SMTP id 1-v6mr406290wrc.252.1541600191035; Wed, 07 Nov 2018 06:16:31 -0800 (PST) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id q2sm948447wrx.77.2018.11.07.06.16.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 06:16:29 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: marc.zyngier@arm.com, will.deacon@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, Ard Biesheuvel Subject: [PATCH v2 5/6] efi: permit multiple entries in persistent memreserve data structure Date: Wed, 7 Nov 2018 15:16:10 +0100 Message-Id: <20181107141611.12076-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181107141611.12076-1-ard.biesheuvel@linaro.org> References: <20181107141611.12076-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. Tested-by: Marc Zyngier Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 32 +++++++++++++------- drivers/firmware/efi/libstub/arm-stub.c | 2 +- include/linux/efi.h | 13 ++++++-- 3 files changed, 32 insertions(+), 15 deletions(-) -- 2.19.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 72a4da76d274..59f8ac93c759 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -602,21 +602,28 @@ 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 = early_memremap(prsv, sizeof(*rsv)); - if (rsv == NULL) { + p = early_memremap(ALIGN_DOWN(prsv, PAGE_SIZE), + PAGE_SIZE); + 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; - early_memunmap(rsv, sizeof(*rsv)); + early_memunmap(p, PAGE_SIZE); } } @@ -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 */