Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3544775imu; Fri, 30 Nov 2018 02:02:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9DVewoteFKzj2C2Z7pL59ZGkbDB+fTXSpiOGZaWz4DhSnAQEd8J+7uZvbwp7Si5vXKNvm X-Received: by 2002:a63:4745:: with SMTP id w5mr4375600pgk.377.1543572128996; Fri, 30 Nov 2018 02:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543572128; cv=none; d=google.com; s=arc-20160816; b=bSLdXCnQ3ayic8tCLXUZ9Cu8RMpM2qyx6oB+PCxjF/II/D9Z7Qrusxjp8oGFS5ifaB qXlen9oyrdn/f6APz+2/GS+xL75rrhUpj3dl27gaSemgLA6hSPjcg+Cx5oEVhVEe2mk9 uoysHNrgxl2Pulw6XQ/r56SzE5y4lEEaXRT1dWDcm4xv2EbmlvZ5lL2/oByHQRT0XD6c DUBLusAXYy0lMfWzv0x2qB2J33xlQEXsL109E5SOfJHIVoz1bKvRlsUb02K7VjPjlklA 4wajwjWx4rvsF0fYX0FVX3/Ww2n3NzsAmJi2ksVJiAbkQVklEGphR0ddjJjIc3gS+iVA OJ+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=SvLPFOAtf+oBWK/O6xzTrD/Pkfd4oI8V180CZ+1wL0I=; b=ha9eC4Qka3O2x45xT9Wta5JqRCvUGZx/0zZI5v0uc8At4QIVSOAioMqSzRZ0JVW0/k TrCtcUs7gQTGDBlitbvdy6vq+XITHuWCdB5HkwZPsaC9bxvCABrEw2UJXz6fPp1lWYBF 83ogx9a7pX7fI+EDReomzsIHL3aduk0NJlb0X+tCZOnTJ13iBolOE5w1XvykDlF/PAQt Y13lnhtf7TD1gedxZQ5le7bzgNNLOeTxn7TIJzNACzCHetQ+QEUfjOJFGNg2rBjulUGD eknfxKclRePoyHdQ9BL7WYJejVRP19mPHhms2gBwjQDsSmjqYsWoPlsN4Nf7Jzbh13SJ nX7w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m64si5161086pfb.224.2018.11.30.02.01.54; Fri, 30 Nov 2018 02:02:08 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726717AbeK3VKA (ORCPT + 99 others); Fri, 30 Nov 2018 16:10:00 -0500 Received: from terminus.zytor.com ([198.137.202.136]:56351 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbeK3VKA (ORCPT ); Fri, 30 Nov 2018 16:10:00 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wAUA0NgA3262398 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 30 Nov 2018 02:00:23 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wAUA0Mc03262395; Fri, 30 Nov 2018 02:00:22 -0800 Date: Fri, 30 Nov 2018 02:00:22 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Ard Biesheuvel Message-ID: Cc: natechancellor@gmail.com, arend.vanspriel@broadcom.com, hdegoede@redhat.com, marc.zyngier@arm.com, matt@codeblueprint.co.uk, sedat.dilek@gmail.com, sai.praneeth.prakhya@intel.com, peterz@infradead.org, julien.thierry@arm.com, zhuyifei1999@gmail.com, luto@kernel.org, ard.biesheuvel@linaro.org, jonathanh@nvidia.com, bp@alien8.de, dave.hansen@intel.com, linux-kernel@vger.kernel.org, joe@perches.com, tglx@linutronix.de, bhsharma@redhat.com, eric.snowberg@oracle.com, torvalds@linux-foundation.org, mingo@kernel.org, hpa@zytor.com Reply-To: jonathanh@nvidia.com, ard.biesheuvel@linaro.org, luto@kernel.org, dave.hansen@intel.com, tglx@linutronix.de, joe@perches.com, linux-kernel@vger.kernel.org, bp@alien8.de, eric.snowberg@oracle.com, bhsharma@redhat.com, mingo@kernel.org, hpa@zytor.com, torvalds@linux-foundation.org, natechancellor@gmail.com, hdegoede@redhat.com, arend.vanspriel@broadcom.com, matt@codeblueprint.co.uk, marc.zyngier@arm.com, sedat.dilek@gmail.com, julien.thierry@arm.com, peterz@infradead.org, zhuyifei1999@gmail.com, sai.praneeth.prakhya@intel.com In-Reply-To: <20181129171230.18699-10-ard.biesheuvel@linaro.org> References: <20181129171230.18699-10-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/core] efi: Permit multiple entries in persistent memreserve data structure Git-Commit-ID: 5f0b0ecf043a5319e729c11a53bc8294df12dab3 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=1.6 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_48_96,FREEMAIL_FORGED_REPLYTO, FREEMAIL_REPLYTO_END_DIGIT autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5f0b0ecf043a5319e729c11a53bc8294df12dab3 Gitweb: https://git.kernel.org/tip/5f0b0ecf043a5319e729c11a53bc8294df12dab3 Author: Ard Biesheuvel AuthorDate: Thu, 29 Nov 2018 18:12:28 +0100 Committer: Ingo Molnar CommitDate: Fri, 30 Nov 2018 09:10:31 +0100 efi: Permit multiple entries in persistent memreserve data structure 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 Cc: Andy Lutomirski Cc: Arend van Spriel Cc: Bhupesh Sharma Cc: Borislav Petkov Cc: Dave Hansen Cc: Eric Snowberg Cc: Hans de Goede Cc: Joe Perches Cc: Jon Hunter Cc: Julien Thierry Cc: Linus Torvalds Cc: Matt Fleming Cc: Nathan Chancellor Cc: Peter Zijlstra Cc: Sai Praneeth Prakhya Cc: Sedat Dilek Cc: Thomas Gleixner Cc: YiFei Zhu Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20181129171230.18699-10-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/efi.c | 39 +++++++++++++++++++++++---------- drivers/firmware/efi/libstub/arm-stub.c | 2 +- include/linux/efi.h | 13 ++++++++--- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 415849bab233..80b11521627a 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -602,21 +602,33 @@ int __init efi_apply_persistent_mem_reservations(void) 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) { + u8 *p; + int i; + + /* + * Just map a full page: that is what we will get + * anyway, and it permits us to map the entire entry + * before knowing its size. + */ + 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); } } @@ -985,6 +997,7 @@ static int __init efi_memreserve_map_root(void) int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) { struct linux_efi_memreserve *rsv; + int rsvsize = EFI_MEMRESERVE_SIZE(1); int rc; if (efi_memreserve_root == (void *)ULONG_MAX) @@ -996,12 +1009,14 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) return rc; } - rsv = kmalloc(sizeof(*rsv), GFP_ATOMIC); + rsv = kmalloc(rsvsize, GFP_ATOMIC); if (!rsv) 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 = efi_memreserve_root->next; diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 3d36142cf812..9e20159ea5f5 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -86,8 +86,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 2b3b33c83b05..4f27640fdcdc 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1712,9 +1712,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 */