From patchwork Tue Nov 6 11:37:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150255 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3775307ljp; Tue, 6 Nov 2018 03:37:44 -0800 (PST) X-Google-Smtp-Source: AJdET5dYClKBqH0SUYqkCJ6qZ8wM1DmJrEJPbzoSTmLyQxkreA3jgtxptWhngKa4y1hmPGe3oSjM X-Received: by 2002:a63:5442:: with SMTP id e2-v6mr23662437pgm.316.1541504263922; Tue, 06 Nov 2018 03:37:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541504263; cv=none; d=google.com; s=arc-20160816; b=bCRdfNfVVnkIW5/RYPg95ZChlSTgdKWQkEZLGRol0ZstWLcuWpjCnDuwjgpRaewSUX AhX5RGhA6YhmwAKdFehXjvTWN7UZdTj1p2KwlCaYhef2n4iq/yWrJ0CMf4/j+0e/3Sv/ DiFVvQMxVb4HTsLfqnshN8LsXWU/0y5ZmdeMJ5Xc6rRYAHZPFMy8/YXOAGqfCD5iXgeo ICWy4TYsvsr7fg0+1O0kPmsoZTERzsHsXaA0d/oC6/NomBXD5BB06cg07sdyq0EYl58m FuSJQCbRzK988z0wNe5KdckD8nLIaxbFSsc5vM7sa1V0+VmCdKkXCGhV4fU8oqH9mIjF E9Kg== 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=ZGPqz/MYWANycuG9Tb+ISa8UHJfaVM9dxj3YR/jxCQc=; b=UwKZH6prj4GYGdAqW46zZyOcZWQC4tJv/QBeNm8iJglQQwZFS9/TSd25k74jUAy3eQ 4ebf1awAitWUOb/oOOVKZAJ7S5G01KQ8U1gy8UCMreUy4aHrbLyWW79SPi4MAiIPbgVW Dd2MUGKVZjz6vWd/J8Bt+qjU7SYgp/W884j+0/Opv6fKewwQirEuYMGsC5LK6GN4T9DW ht6xpCM7TAeC4IwWV2DpxszIHbykhntT1NtAv8e59WIwk1KnrB+tgqcV3lzS763o8pqu IKOrtzdZDcRgvBS6z63xem2sLLhTEcULmgeHkBw2YYIWE7kNLWz5aCDac768iJjVQpjt x6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="iXexW/bi"; 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.43; Tue, 06 Nov 2018 03:37:43 -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="iXexW/bi"; 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 S1730335AbeKFVC3 (ORCPT + 3 others); Tue, 6 Nov 2018 16:02:29 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43197 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729728AbeKFVC3 (ORCPT ); Tue, 6 Nov 2018 16:02:29 -0500 Received: by mail-wr1-f65.google.com with SMTP id y3-v6so12784676wrh.10 for ; Tue, 06 Nov 2018 03:37:42 -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=ZGPqz/MYWANycuG9Tb+ISa8UHJfaVM9dxj3YR/jxCQc=; b=iXexW/biYTNUhWdmJoVHrYaLBUxS9dw8I/G3tucCH+p95OGNX6ijjWO59gjeD2n/2U RnsyiQbZYJgQ3PkIgAL8/IYxhU6McBwd/IKXMhIghu/XQmf5H/+gX6PA/0LVj0mIKY+E m+UcNC0MIescacXAFTK7Go1h1P/7YxFNSJnhI= 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=ZGPqz/MYWANycuG9Tb+ISa8UHJfaVM9dxj3YR/jxCQc=; b=Gt/PWCkZCLbgoy5kRTpqf8u8oo9kYSjU9shy77IsqSDO76lS5BU0qkr188aV9N37cI BQ7FyVQAm5h++tn6vOXu0X3LVA+pquhdAg9+F2bG+66NBtftknU/DVclNOVuu/BQw7Q2 QyPL+/UFkOvyg2IyLlkVOv9m1WjlipGxJIFlcaccw6qOnrV6Dn+6PjJDZDZ+jVCWHGFF M983PvAatihl5EXZc0SR4HUQTtkhsbRJHa2XWpeJtdfOrG0EErJjGN/pX/AhLJ5JrOgH OWzUe+SLu2Ug2COBuHgffS4JBqujMh/X0QjajR2EkY7cW2QFxWbQDvZ8+mNeSCLJWEMo 5WPw== X-Gm-Message-State: AGRZ1gIhxUCOBzbOxR87g60+8N0Y9b7KC0dy+q8/UIydQVxxsDsNPR9s axUgcs7j45vt/UpbyCp8t0oup6N7Rek= X-Received: by 2002:adf:c550:: with SMTP id s16-v6mr22802200wrf.264.1541504261269; Tue, 06 Nov 2018 03:37:41 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 03:37:40 -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 1/4] arm64: memblock: don't permit memblock resizing until linear mapping is up Date: Tue, 6 Nov 2018 12:37:29 +0100 Message-Id: <20181106113732.16351-2-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 Bhupesh reports that having numerous memblock reservations at early boot may result in the following crash: Unable to handle kernel paging request at virtual address ffff80003ffe0000 ... Call trace: __memcpy+0x110/0x180 memblock_add_range+0x134/0x2e8 memblock_reserve+0x70/0xb8 memblock_alloc_base_nid+0x6c/0x88 __memblock_alloc_base+0x3c/0x4c memblock_alloc_base+0x28/0x4c memblock_alloc+0x2c/0x38 early_pgtable_alloc+0x20/0xb0 paging_init+0x28/0x7f8 This is caused by the fact that we permit memblock resizing before the linear mapping is up, and so the memblock_reserved() array is moved into memory that is not mapped yet. So let's ensure that this crash can no longer occur, by deferring to call to memblock_allow_resize() to after the linear mapping has been created. Reported-by: Bhupesh Sharma Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/init.c | 2 -- arch/arm64/mm/mmu.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.19.1 Acked-by: Will Deacon diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 9d9582cac6c4..9b432d9fcada 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -483,8 +483,6 @@ void __init arm64_memblock_init(void) high_memory = __va(memblock_end_of_DRAM() - 1) + 1; dma_contiguous_reserve(arm64_dma_phys_limit); - - memblock_allow_resize(); } void __init bootmem_init(void) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 394b8d554def..d1d6601b385d 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -659,6 +659,8 @@ void __init paging_init(void) memblock_free(__pa_symbol(init_pg_dir), __pa_symbol(init_pg_end) - __pa_symbol(init_pg_dir)); + + memblock_allow_resize(); } /* From patchwork Tue Nov 6 11:37: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: 150256 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3775331ljp; Tue, 6 Nov 2018 03:37:45 -0800 (PST) X-Google-Smtp-Source: AJdET5ck3zSz0SXT22ZgD04o5G5DrIGjvrwV/v4S4LBNYtFVv5TTKcz+KYxyLW6VP9b9o5fYH3Ae X-Received: by 2002:a63:3d03:: with SMTP id k3mr17914868pga.191.1541504265659; Tue, 06 Nov 2018 03:37:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541504265; cv=none; d=google.com; s=arc-20160816; b=AN+YnZy1a/kNaNCrgNO/7Q2CyL9EPPLthd2a6id+Vf6Vm/moEHGVbj8fYDq+K2UexC EDYykTFFwGJXT4ToOcXj6KOHij+/5OUaBvNhGZJfOlgQevNY6D7Uu6sCxXN1AHksdkRI 4zlqzQZzOdLcERXb7kxRjJiv2IrmLAcEzW0AiiCpdt6ewb77E7kuFjbUEq98XfKijWbO 48MRzvmOicYZiCbuOszRLfcjoY1XLVyYExMoMXaHC4Ri409sDqInd0eDLt4OcIzaNtzE P77zcaG/bt7wI2109S+uuyZdJbaul3Fw37QKit/wW/iH1trgFbye8sMJL4nPXDu0Yeiw j0og== 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=JxerrVzSB3nQMNgEEqnbh4b0SvNJgKQEb0pTSsx3VlE=; b=BYZI/ipMe/GBOUcMcCim0XygXKa2XhxKNBKhYbXx0DL+4FcllY24yIIVAer0OBRpfQ KdV5sWaN8/muCuLhvDIUBeW6keN8uBBbwGoC4YSbf9Q+VxE6tor3C6vaIQigbwQqj1df cZkc10EdduA8HELsCIwKiNDhh8cfQqFBEX6sJVjKjyxHbkPChOFrhHQ073oZAIHLjNbI Jgacf5ARCZZywl8mKkqv1Q8+uuodCGMM8eKxKgRsW2CqhSNFTym6Kvz+yMoGOacmBM9g V/gdIhSPuYVw20E/tXty9un0hbgXJXpBZlB2bWSaAadUZEvdRmo5fBh5sQtKhsVKs5ht BlRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LEkis6Ib; 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.45; Tue, 06 Nov 2018 03:37:45 -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=LEkis6Ib; 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 S1730444AbeKFVCb (ORCPT + 3 others); Tue, 6 Nov 2018 16:02:31 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40392 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730358AbeKFVCb (ORCPT ); Tue, 6 Nov 2018 16:02:31 -0500 Received: by mail-wm1-f66.google.com with SMTP id b203-v6so11381249wme.5 for ; Tue, 06 Nov 2018 03:37:43 -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=JxerrVzSB3nQMNgEEqnbh4b0SvNJgKQEb0pTSsx3VlE=; b=LEkis6IbqL13P9CYwk0pSb3DMuyibP8zOWT0xJQkjqheSP+YuIxivZH9wFPPr30nA3 n1FEhjV6SlrxNUHB8pXZ/eqtGjL+trEycYiTubzOAfLM/ZCQDl37uHszNLM+2qSo5Jr2 +1/F9gnVTqlrTJ/AY1AKCbRvpp8zcEOWcaYN0= 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=JxerrVzSB3nQMNgEEqnbh4b0SvNJgKQEb0pTSsx3VlE=; b=oGGgJoq5JsSSio7Pd5alQpX4FdnysJTj7qQCnQei4k41gFhLYIzojHBbduPVNka/e9 0O3RUVKLi8dYnHOR3qeU1lPnYofJmAjUAPLRnwNNgjWbTpGf1hWY36dPQrQA+0DsJKxh V+GX7gJBqXGFYTHSq+osF4KwuXITPO2hzGARWEBSg7ECQfnyySscEfVLc7Nj/O65utaT zwmMR4H3iDFMjnFOsjbAI5KUHRKneQobDFBDZ0n+ie/6/bmhKcV09sfHF5jqkFI65UqT UA4lT2DF6gb5jj5yPTe1/wtexlpSUcBD8NY7vOi0lVsyxh31lTmOFTGhOj3tgwmXkhOW nTRg== X-Gm-Message-State: AGRZ1gJHlfKl2apb0hUp5AZtPOrp9csb5vgHvu/H3rVkF6bgcvojdn+K UvlOvXnLlHreGN3YyCSbM6BKYQ== X-Received: by 2002:a1c:187:: with SMTP id 129-v6mr1635260wmb.55.1541504262987; Tue, 06 Nov 2018 03:37:42 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 03:37:42 -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 , Russell King Subject: [PATCH 2/4] efi/arm: defer persistent reservations until after paging_init() Date: Tue, 6 Nov 2018 12:37:30 +0100 Message-Id: <20181106113732.16351-3-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 The new memory EFI reservation feature we introduced to allow memory reservations to persist across kexec may trigger an unbounded number of calls to memblock_reserve(). The memblock subsystem can deal with this fine, but not before memblock resizing is enabled, which we can only do after paging_init(), when the memory we reallocate the array into is actually mapped. So break out the memreserve table processing into a separate function and call if after paging_init() on both arm64 and ARM. Cc: Russell King Signed-off-by: Ard Biesheuvel --- arch/arm/kernel/setup.c | 1 + arch/arm64/kernel/setup.c | 1 + drivers/firmware/efi/efi.c | 8 ++++++-- include/linux/efi.h | 7 +++++++ 4 files changed, 15 insertions(+), 2 deletions(-) -- 2.19.1 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index ac7e08886863..e99f12eaf390 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1117,6 +1117,7 @@ void __init setup_arch(char **cmdline_p) early_ioremap_reset(); paging_init(mdesc); + efi_apply_persistent_mem_reservations(); request_standard_resources(mdesc); if (mdesc->restart) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 953e316521fc..f4fc1e0544b7 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -313,6 +313,7 @@ void __init setup_arch(char **cmdline_p) arm64_memblock_init(); paging_init(); + efi_apply_persistent_mem_reservations(); acpi_table_upgrade(); diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 249eb70691b0..55e4ea20bdc3 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -592,7 +592,11 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, early_memunmap(tbl, sizeof(*tbl)); } + return 0; +} +int __init efi_apply_persistent_mem_reservations(void) +{ if (efi.mem_reserve != EFI_INVALID_TABLE_ADDR) { unsigned long prsv = efi.mem_reserve; @@ -602,7 +606,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, /* reserve the entry itself */ memblock_reserve(prsv, sizeof(*rsv)); - rsv = early_memremap(prsv, sizeof(*rsv)); + rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB); if (rsv == NULL) { pr_err("Could not map UEFI memreserve entry!\n"); return -ENOMEM; @@ -612,7 +616,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, memblock_reserve(rsv->base, rsv->size); prsv = rsv->next; - early_memunmap(rsv, sizeof(*rsv)); + memunmap(rsv); } } diff --git a/include/linux/efi.h b/include/linux/efi.h index 845174e113ce..100ce4a4aff6 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1167,6 +1167,8 @@ static inline bool efi_enabled(int feature) extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused); extern bool efi_is_table_address(unsigned long phys_addr); + +extern int efi_apply_persistent_mem_reservations(void); #else static inline bool efi_enabled(int feature) { @@ -1185,6 +1187,11 @@ static inline bool efi_is_table_address(unsigned long phys_addr) { return false; } + +static inline int efi_apply_persistent_mem_reservations(void) +{ + return 0; +} #endif extern int efi_status_to_err(efi_status_t status); 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 */ From patchwork Tue Nov 6 11:37:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150258 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3775375ljp; Tue, 6 Nov 2018 03:37:48 -0800 (PST) X-Google-Smtp-Source: AJdET5czfJ4eHhGcA0eebDGpt2/bnGqI+Y9dOap+5PxBPy6F8vC5vrTNXcEUJchwz+EwJUkKijEs X-Received: by 2002:a17:902:8c86:: with SMTP id t6-v6mr26352334plo.55.1541504268250; Tue, 06 Nov 2018 03:37:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541504268; cv=none; d=google.com; s=arc-20160816; b=D8pVl1crHmQXmiVYaXRHXrb1clkODDiTVSWYZruQaA8yeyIMvhO2V6hLc25X359SA/ L+gl6nZCAj9ZSvbiIqBW8yd12hiWsXDh9ZIcdeub9U7zWPfHbtaKoQHBN5bMf5TQ4Kd7 qVjqAGaCt3oPWEkMb74j2J440vYBk5WZCdVmMhgPjmwBcGYMXMwxqixXG8SnuUX9CAeU ZdSqKwzkP2KrkopYvyBIiONHnDZGxfix0iOxNIjxIsc/lC9czXHXcMWg4aeTyQrlYmbo LvyKR9sr8P/UtPTuEP4VzvBk0gKNk5WHE0drxIKE87DdR8j3x8Ka27pgYOG1x9474g7B 0dSQ== 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=+krWoVZRI0iFhA51rBwg9mzqq8rHQsi9J/F6ndnPhTE=; b=i1vYH848/rqJ34a5RSC9fUgjuB8zfAkKjZGGI6TXa/SGo21LcIkpaAyPd8g34H8Sdb RmsY4ddS/zCwC83LqXpu0aMkyNGBuaeHJWaLXSKyUpxgyD7omeOccsnom+kquaeWC/NC g5vQfFNd70Tw6GO04aZMspSVMGQsC3se5z42v3GJK0nhgmWpRfod/G7owYm3SAGESw+w 5OG1sluXBXd7OQ1ZUU0LsHdKWsMWZMuQ2ENYEnN29SLqndkY4q76rymu+Ry6h+X6EnCH 5KVJwITm+wC2iaGOYNE99ce1RsLKZ3gntHbPj2hVkVLbwO5vwnxntGfD6EcegzQuPYkb Q7lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LY32axis; 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.48; Tue, 06 Nov 2018 03:37:48 -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=LY32axis; 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 S1729728AbeKFVCe (ORCPT + 3 others); Tue, 6 Nov 2018 16:02:34 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51478 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730358AbeKFVCe (ORCPT ); Tue, 6 Nov 2018 16:02:34 -0500 Received: by mail-wm1-f66.google.com with SMTP id w7-v6so11062887wmc.1 for ; Tue, 06 Nov 2018 03:37:46 -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=+krWoVZRI0iFhA51rBwg9mzqq8rHQsi9J/F6ndnPhTE=; b=LY32axisnVrJ52ft8GtQ1HXEOK3HG5+SaYH34pZO7VoGsrPQWsn+L5GYi+7q4U7biC PwLkfQDamH54JYt19X6KAhkOR5/ddpkLgy3Dz3uBf7SRzdjxGr8omludHJaYHN33zN59 YEeZiCBNOSIIJ0a08OyVMs8dOwl9kdKjSpSDE= 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=+krWoVZRI0iFhA51rBwg9mzqq8rHQsi9J/F6ndnPhTE=; b=N14igJO7nwdBSBOj0xvidfKkrlQA5zEhcf77+u1XOvSSZa90xptQnybYxKDKyt6WL9 IOHL2IZIgm6FQ9wbYS9vRWbPUHM65d6+y7gKYm0JlA4MaQyN21F8A5tG5C4QVLdelV2n 2I66m/YXSLUzB+XAzIGeyKf0WjZHRbpet7GKgFWHYKtgde2AG0ZSxmy3yCvAsXg+2SP0 8UUgB8OOx0vS1U0giOpXpXv0TdxpqYJvYJoUn4kPRoJ3p88iOkls12cUZqmcyHDgM3We KNdPu2O6iTgQVFLNc+mISrVg0cSmROGlVoEFJY0FJLI7G3ZZRNwrNPIcYhFA+USJ4A6A sWDQ== X-Gm-Message-State: AGRZ1gLac22jwavwOFyq9RIPVnPR73fii/Qn36TbjS1npMw5fDaotVjU jOxGasM5bSIb3DxG/pFI76xIUQ== X-Received: by 2002:a1c:8a11:: with SMTP id m17-v6mr1635656wmd.15.1541504265543; Tue, 06 Nov 2018 03:37:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 03:37:44 -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 4/4] efi: reduce the amount of memblock reservations for persistent allocations Date: Tue, 6 Nov 2018 12:37:32 +0100 Message-Id: <20181106113732.16351-5-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 The current implementation of efi_mem_reserve_persistent() is rather naive, in the sense that for each invocation, it creates a separate linked list entry to describe the reservation. Since the linked list entries themselves need to persist across subsequent kexec reboots, every reservation created this way results in two memblock_reserve() calls at the next boot. On arm64 systems with 100s of CPUs, this may result in a excessive number of memblock reservations, and needless fragmentation. So instead, make use of the newly updated struct linux_efi_memreserve layout to put multiple reservations into a single linked list entry. This should get rid of the numerous tiny memblock reservations, and effectively cut the total number of reservations in half on arm64 systems with many CPUs. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 29 ++++++++++++++------ include/linux/efi.h | 3 ++ 2 files changed, 24 insertions(+), 8 deletions(-) -- 2.19.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 85d2ec532816..2ca5a59f7568 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -978,22 +978,35 @@ 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); + unsigned long prsv; + int index; if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) return -ENODEV; - rsv = kmalloc(rsvsize, GFP_KERNEL); - if (!rsv) - return -ENOMEM; - parent = memremap(efi.mem_reserve, sizeof(*rsv), MEMREMAP_WB); - if (!parent) { - kfree(rsv); + if (!parent) return -ENOMEM; + + /* first try to find a slot in an existing linked list entry */ + for (prsv = parent->next; prsv; prsv = rsv->next) { + rsv = __va(prsv); + index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size); + if (index < rsv->size) { + rsv->entry[index].base = addr; + rsv->entry[index].size = size; + + memunmap(parent); + return 0; + } } - rsv->size = 1; + /* no slot found - allocate a new linked list entry */ + rsv = (struct linux_efi_memreserve *)__get_free_page(GFP_KERNEL); + if (!rsv) + return -ENOMEM; + + rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE); atomic_set(&rsv->count, 1); rsv->entry[0].base = addr; rsv->entry[0].size = size; diff --git a/include/linux/efi.h b/include/linux/efi.h index dfce82b2ca8a..1a1a081f7244 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1727,4 +1727,7 @@ struct linux_efi_memreserve { #define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \ (count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0])) +#define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \ + / sizeof(((struct linux_efi_memreserve *)0)->entry[0])) + #endif /* _LINUX_EFI_H */