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: 10670157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A92115A6 for ; Tue, 6 Nov 2018 11:38:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44ABC291DF for ; Tue, 6 Nov 2018 11:38:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33193291F0; Tue, 6 Nov 2018 11:38:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ADE2E291DF for ; Tue, 6 Nov 2018 11:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=beIzQJJj5qFKHwVEva4XJzj0gz2fSPVNrlEhTwmyTRI=; b=tk3zLO6+ymFNQv 1FnifbOTwfXPvVtK3soDlb0g0z+9vNrS8Mpklw/+110bqv841RGrDaDcXEwbqdG/f2Qcr6Karwo3+ fViblaDVZk4W5p3Evjw3uEOnZ7mUttoF3ViP3XFvWTS8gxxUkl7ArUHlPW9CFEc8E5OEOFwz5aqHp KH6+07m41wi6m+Az6xlB/K6wq8ORU4y42eJGRvcmmD1P9kcFa0KwoQA2bXl2wZmKCnB9s6eqU+7zK G5J+iDOo0GTzQjzmojwKN0AkeMboFwe02TreYTKFQNTG5i3oSjQlqoep3gUxWsMmIGs+mHjwyFeGm lhgt4WOZlg3SbisFJDCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJzge-0008Iy-Ag; Tue, 06 Nov 2018 11:38:24 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJzgC-0007bs-07 for linux-arm-kernel@lists.infradead.org; Tue, 06 Nov 2018 11:37:57 +0000 Received: by mail-wr1-x444.google.com with SMTP id o15-v6so9463772wrv.4 for ; Tue, 06 Nov 2018 03:37:45 -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=Al/RrMCV9d+W2jnHHfoPx/qch5JgDIn4G/oEGFYB2DFWiK9jnceJT/6fs8IMu9MiEr sqdQc0LWsud1WxrKXf1XruP1J8JPFqGNnx8mtcgkT1MWnd3lruyaXXZX2GdGhJaVjxs7 w6woUakiaKF53x3ZHEuZJve1+3KvvV1ESN35gqqFgkGaqKT4duJXQ9IupMxInUAZ+DKM tDOC2rudG7y8jdv6sQUIQlNswD0YgYAWJFVCWpRdhkVq/YeE0UFkCcOwhLPlrsult4di 6YKankKQ+l+zwOSGxvWAGMA/z4BFnDFPtzvv3XdbjZKOHo2cFOHcUcVC8nsu1zjJydss JceQ== X-Gm-Message-State: AGRZ1gI1tFOvuMOzmJieWRlcY27NrgTsKTueaTWHoBEipodcZQ6ZKH85 d/0wskgy7OkBuLD0Dohgtavh2yP9ByM= X-Google-Smtp-Source: AJdET5eaQasPwDjocGwWp2dVBhie9dQk0ev3IBAuQEBg8qfSK7DjF0kus0qd5EqqOTCR0EVuQc/8/Q== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181106_033756_043240_0C40ECCC X-CRM114-Status: GOOD ( 17.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, linux-efi@vger.kernel.org, Ard Biesheuvel , marc.zyngier@arm.com, bhsharma@redhat.com, will.deacon@arm.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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 */