From patchwork Wed Nov 7 14:16:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150391 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5220963ljp; Wed, 7 Nov 2018 06:16:25 -0800 (PST) X-Google-Smtp-Source: AJdET5c69GUYG+USFSC82Ad6tvM7In05a0bzo2LuoEl8pb1MnyyPoNv4yRXDsKdqR0iZYZ23ddC5 X-Received: by 2002:a63:be4d:: with SMTP id g13mr329844pgo.378.1541600185747; Wed, 07 Nov 2018 06:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541600185; cv=none; d=google.com; s=arc-20160816; b=y7Ae6p6r49gGAF2PRAyq77xZ6YOf0vDmmIekUhvGKHSoPHCQIEXpfwjTXKmnzXWeSu nOMwXZxcJy+8cg+yDJYueGacQghMiaN1/kSKQb4zaRwKDgafoBbPizRI1Sk1qATnzApV nHMIdhCt9G9DtF2GHTK6gtJdys/Cs9I5YhVMfAF480oYqhGXsX1Ftp3rfFM4zsQ2FD5t soezNGkweI7pgRnXztJdJO+uohuHOPIayR3/w+aZbzdubYZmxu1V89iiue1PAR4fpZB+ w98vY6C1oNNGOsOP007oJynT5sp1KNgtznGhU0XoRtKtp9C9MuOilHP5IVdHS20OItr6 TC0Q== 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=8Adw24IB3R0fxokSO7y06jI60Vj0FlFjArtGGAaVO9w=; b=YiGg+Rgd4fEegC0GwIuXmNpHJNjOSO5G/46W6ur0j883iMWoAEqLozypSlpyXqGlDL s1ppo5OurwEKdbVFxt5Y2dPtoJsSt+LHucoJypTcnzUAz8HOTUTdTY4lPo25bNOuHfbo KZy7zg0Rf0jArqgoxYWJ1V3BQgmPDPCt6f8618ktz+nvj2o7XQkCU05svg2i51ee1TV0 EQHSVXOrqOOTW3IWVGrT7fb0X4xWh4ATO8moq8oukqoNx6QFcMvy0jKQIvPBd1LXPYIJ 4Nih/u2hUcbc+m66Uydvor0xKsUFryBZaJXLG8tQHnN50c56l5V5OAqRjcwxteu4Ljqu eDQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cJDPPAHl; 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.25; Wed, 07 Nov 2018 06:16:25 -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=cJDPPAHl; 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 S1727781AbeKGXq6 (ORCPT + 3 others); Wed, 7 Nov 2018 18:46:58 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45203 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbeKGXq6 (ORCPT ); Wed, 7 Nov 2018 18:46:58 -0500 Received: by mail-wr1-f68.google.com with SMTP id k15-v6so14594290wre.12 for ; Wed, 07 Nov 2018 06:16:24 -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=8Adw24IB3R0fxokSO7y06jI60Vj0FlFjArtGGAaVO9w=; b=cJDPPAHl6mQsFU+Nvg0K6+vY9w/85ZJQzLRx9qWBDQWz/vRdeqF5uGgfR1zX9kgKPA 0SXEj7FspPmkOY1IGx2wc9Zk6nVC0tqibzSpfhEeKvHALmtuf60IJ22p8MwyXN2/Pd1O 7LlQYQrktWtObqnCcy9z58fS24sTupnEapkwg= 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=8Adw24IB3R0fxokSO7y06jI60Vj0FlFjArtGGAaVO9w=; b=ii8A70Lcn7UvIL8jPmALf0cpPX8Q5a5e6PwuGPj+e2Ofay41hJ/BdZizSKIYZHqw8a eyoolsf8D0+JylPkPmfKHE+F/qRNx3yuHvgJVtgIpsoh+0xU6DZTEGv3vlcuIRFAgq4g E+BNjQMudoUUa44Ek9oBgebYKip6X6XDEgSnnDN1b8RYyuSjO726k4wKX1NoO0YkGfW5 TW5/REDc+hz8VZovUUCII0VuL8m5nGDqwNtNCfQ2HNWf0cqZWPRlvGdRPDCj9jbkCoMs VYsBj1+RU3oCqFXtrbwD5O0A1X3dcT25KBbX2XCUAVbL92WHsCmrEDnZc/GPMQJu3kIB yhVQ== X-Gm-Message-State: AGRZ1gJEBBoGWnHf3asuq4OOAQM2r58NPzeQAe0B/OfmBEKpGorXzS+u eun9YvvG7f4u3Hz5NOeEgpIFjw== X-Received: by 2002:adf:df82:: with SMTP id z2-v6mr384571wrl.118.1541600183576; Wed, 07 Nov 2018 06:16:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 06:16:22 -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 1/6] arm64: memblock: don't permit memblock resizing until linear mapping is up Date: Wed, 7 Nov 2018 15:16:06 +0100 Message-Id: <20181107141611.12076-2-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 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 Acked-by: Will Deacon Tested-by: Marc Zyngier 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 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 d6d05c8c5c52..e1b2d58a311a 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -671,6 +671,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 Wed Nov 7 14:16:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150392 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5221016ljp; Wed, 7 Nov 2018 06:16:28 -0800 (PST) X-Google-Smtp-Source: AJdET5dE0hUTVD51JPeM5yhtaYjdkaYobCUvIUFuXNUovsc9q/rHHS5rReEvig9KimQy6e90eigk X-Received: by 2002:a17:902:be0f:: with SMTP id r15-v6mr400678pls.170.1541600188212; Wed, 07 Nov 2018 06:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541600188; cv=none; d=google.com; s=arc-20160816; b=JeRIyg6GEeoicBTEzp3w+b5NwDZtS9HRAdqc1+91+ozUnZzPXi70AqU50PJEu8JyPS YRXQd0S4bo5zMk72gs+kfL4Emte5XKwoL0qkN4BMs/V4PqHmZnx/tZPKZ7un4ArcvCGa NTruoRXjURGIARkgrWgMU/T9/cOsb6cGxeNKiw6Au+LA/Lrwj9wnM4N4DPN36iCNS1GN ILnSp2vMZdsFo5PjP6aT0gRuqHxOPsGB3c178mRrRC1Tn3Q4foYubsgTLxZ6Lq4sr/r3 F4YRqdk8NKHUWTxEBBL5X58a4BGK9ZuMMoDtZZSSBmEANc8TQMcfyElmNmrhnpHshxEF SKwQ== 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=xibZMrmFRctwfUHc2hleZblnVgrd6pCGef3nafzcBOw=; b=X15FAE14R8aPguLVhpXgoFeFuDd1CHl9ui/s1nw7XEt9tUsVkX8ouaEz45MpUhODIR lbXBSsloEGqQiHman7xaUnLGfc1hu7yAKbuL6cd8Ijc6L04uaRtnsT9csHUJbaZpJR+w kYs3eXgWPOjgPjAKbdQrE1Q40u1M244jNkpzYLxvHJ6zBPNQBCAlVjxQQUNFM29uHXGp bw+ejjliT21HIaKsjua4qKDSVp5AgQ2gExxj8baWEBW3Ky3fvGaXZSk/iFtlDJNuZvTO 7VVQDpPSSIpkmUJ0rqxcq5iMxD/pXWotV1p/Nhm2sHn/L4nRYZ17ykVUSO31nlLAa30r wtTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ca3ikalc; 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.28; Wed, 07 Nov 2018 06:16:28 -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=Ca3ikalc; 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 S1727802AbeKGXrA (ORCPT + 3 others); Wed, 7 Nov 2018 18:47:00 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33676 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727698AbeKGXrA (ORCPT ); Wed, 7 Nov 2018 18:47:00 -0500 Received: by mail-wr1-f67.google.com with SMTP id u9-v6so7233497wrr.0 for ; Wed, 07 Nov 2018 06:16:26 -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=xibZMrmFRctwfUHc2hleZblnVgrd6pCGef3nafzcBOw=; b=Ca3ikalcJ4PFfl/YWKML3wH7An+aRYGvHom/p22TX+Ge6UCG3MUlQVdsLqTEawTNVX agxul/mMLTBcVxFtkB5QVgNfocTePvKivQwPcLembY+1hRLs5FQBBP7qDyt1CXWQ1wYM rLNeemsh6blTxpgl3YAloDvRJfPyl3FX2vHMc= 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=xibZMrmFRctwfUHc2hleZblnVgrd6pCGef3nafzcBOw=; b=pJJTboRmGE1qWU7S9Xp8pWdzWMl8Zqew6UBeSUXdZDT6l/VQ7wkxa77OUskUCHtUiJ 8AnNWJfnoQHLjVK38NEJTz2rl4n8awyEObFuJjFXRmGcNZCqCMswc9mYaGxd0VCN/wNe FdP8YfFzLvb9zDraMOc5KMX8RAL6GINjyzmysISAcDefCGVPZUP3oEi1BLePfuXd/qrN Sr4CzI1QH1ROh23OP2D4Je2kTzOYEoH3OH1SOpwZk0SPLD2QOLVQsdsYm7z0XXrIzTwQ eP5Gq0LzHGVG9s3d2Kc27sBMLSKSmRw3o2DFjhHMbFyfjgV0E0NSz17TvsPO/gUZgGOj Ao2Q== X-Gm-Message-State: AGRZ1gKZ832BXQNjWHZK8Bcgsi7B7WUpaiANyPIlbNiKsWexJEtF6uZB Xeior7Cq7dexPdxdXOY03QTTwg== X-Received: by 2002:adf:fa04:: with SMTP id m4-v6mr368859wrr.155.1541600185560; Wed, 07 Nov 2018 06:16:25 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 06:16:24 -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 2/6] ARM: mm: permit memblock resizing right after mapping the linear region Date: Wed, 7 Nov 2018 15:16:07 +0100 Message-Id: <20181107141611.12076-3-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 The memblock arrays can be resized dynamically if needed, but this is only done after memblock_allow_resize() is called, since it is up to the architecture to decide at which point doing so is possible (i.e., when all the memory that memblock describes is actually mapped) ARM grants this permission in bootmem_init(), but in order for the EFI persistent memory reservation code (which may create memblock reservations that trigger such a dynamic resize) to be able to be called before shutting down early fixmap (upon which the EFI code depends due to its use of early_memremap()), we need to do this earlier. So let's move the call to memblock_allow_resize() to right after the point where low memory is mapped and declared as the memory limit for memblock allocation. Signed-off-by: Ard Biesheuvel --- arch/arm/mm/init.c | 1 - arch/arm/mm/mmu.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) -- 2.19.1 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 32e4845af2b6..797fad2b16ee 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -304,7 +304,6 @@ void __init bootmem_init(void) { unsigned long min, max_low, max_high; - memblock_allow_resize(); max_low = max_high = 0; find_limits(&min, &max_low, &max_high); diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index f5cc1ccfea3d..f6bf6686559d 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1626,6 +1626,7 @@ void __init paging_init(const struct machine_desc *mdesc) prepare_page_table(); map_lowmem(); memblock_set_current_limit(arm_lowmem_limit); + memblock_allow_resize(); dma_contiguous_remap(); early_fixmap_shutdown(); devicemaps_init(mdesc); From patchwork Wed Nov 7 14:16:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150393 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5221046ljp; Wed, 7 Nov 2018 06:16:29 -0800 (PST) X-Google-Smtp-Source: AJdET5ebb01wYdplvKGr51qqEpD/dQOl0nAiwCRN9QoCwPWgMd8wqz6rWpsx5Ys7VTSnUXOAiDP/ X-Received: by 2002:a63:495b:: with SMTP id y27mr345248pgk.32.1541600189485; Wed, 07 Nov 2018 06:16:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541600189; cv=none; d=google.com; s=arc-20160816; b=spGfMBv+B+Ch5U+/p9/awVVxiFjLtEPMc8H/+JmqAC9dQZ0aBbNpodb8l5Zuuz0nDF mOM+IBox9etsPmskGWV8w3lV8WmBwuCWGzueu7sqhggQJFmPqoJCIQSroNolJZ0luMdX RE25dFF/onYuqXCLCye8mWCKqhHirSrzmc53mzVMFlgcI25Bt1XwW3oi2JYNtcFFlxnv iIZRU81dFz3q7y5A/AM+ZbK3igeK8SLFHW4EvDT5ccwu0pSkabjzJby4Ak7xJc6Er/GG uUJgpRePsWTnUnhIvgFUV3D6JCnRD9yqVAZCkHZr5FwmlaiNC/frspwKtDOGK7wfnrDq DR6g== 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=gqMRihPHK965nddLZ6a9LJLXSPUIfcMqa5LZd74Yi+o=; b=qmtVgviVWyrECQc+mOL/zgflVwhiIi+d5wMm6nKkZ/fccQOsDqFz6qGJ3Wld/mQzzE 5LUbbJbroByVIW6sgiVhKUwzPXZKkOCtXNUFp9tG+x4eJ7WRq4SaKly5VWl9LgMDgohm lGvXS8Xqv47FUgII0FaYGHjadyZDGF/PMIyko3TY+82/q7VTH8bWfIvQ9fv+wO5n+GuJ 4KaWggtVmcTstdDDdEWEn+V2LV1sdsuluTi7mlSpJ7xo70kJi6MEpfnUWPfwKqLTV2wB DDMr1uNZtVPVpERhxQHZcAcBP4aidRAZwOEf9e1qOdoie7VGgDYvjDGKPySlacOyzM2S HpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f6mwQuDr; 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.28; Wed, 07 Nov 2018 06:16:29 -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=f6mwQuDr; 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 S1727613AbeKGXrB (ORCPT + 3 others); Wed, 7 Nov 2018 18:47:01 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35944 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbeKGXrB (ORCPT ); Wed, 7 Nov 2018 18:47:01 -0500 Received: by mail-wm1-f66.google.com with SMTP id a8-v6so15852355wmf.1 for ; Wed, 07 Nov 2018 06:16:27 -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=gqMRihPHK965nddLZ6a9LJLXSPUIfcMqa5LZd74Yi+o=; b=f6mwQuDrhw76aHoxcdRQKpNTPIxa3gMSlsX+Ub+r1utkY3AwJhFbRvwRwIT9d+hl6e DN5OlkzKiXRM2IxKt4AROPuXo+9b84ztcHAUXNA9o9iQ66Qhp4JA8sr1vewGvISJdAmh g0shBJqfZbVafUgiUM4g7PkbvKt3EdxjcTbzU= 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=gqMRihPHK965nddLZ6a9LJLXSPUIfcMqa5LZd74Yi+o=; b=dL7B+mOggBgmjfZTw2wyaQba1gr5gitWNI3o57Jhm3Hoc8ah+pmTsGkQFUAPtKlUuL 87DaKEVymJN9ikPhbBQwhQ+IL9yqt+mj3scslnfygEb9hfnhAiZvbAdPXly7gmpAQTkP nRiws3b1yD3cRGpc8J084pUZPyYGI8B/tiCu1YeHcjdcR7Ff2O3heJea5612LgWhMU+V LBCUsLRl7FetaorQQLUFLF6te7JeiGkkzBO1YG/KXSx4WaxMnNDt9Qt7fW0Xyy/8FLJ4 k4oHg5XPph522vopLtF8vzGyhykpCEE7nO7PzdziOVgNrGajOOiA5mL5oBF0aFO/2Qcp /wRQ== X-Gm-Message-State: AGRZ1gIFS9lkKSfR7WVyOc9phn610GJ3632v4f/j7LR/WeXU5aD0hGwo rNExA9eN31lbUkLM3fQ0n0M+2w== X-Received: by 2002:a1c:9947:: with SMTP id b68-v6mr355156wme.22.1541600186903; Wed, 07 Nov 2018 06:16:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 06:16:25 -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 3/6] ARM: mm: permit early_memremap() to be used in paging_init() Date: Wed, 7 Nov 2018 15:16:08 +0100 Message-Id: <20181107141611.12076-4-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 early_memremap() and early_ioremap() rely on early fixmap support, which shares its virtual address space with kmap(), and so it is taken down in paging_init(). In order to permit the EFI persistent memory reservation code to use early_memremap() when called from paging_init(), move the call to early_ioremap_reset() into paging_init(), right before the call to early_fixmap_shutdown(), creating a window where we can add the call to efi_apply_persistent_mem_reservations() in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/arm/kernel/setup.c | 2 -- arch/arm/mm/mmu.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.19.1 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index ac7e08886863..2f85cce38333 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1114,8 +1114,6 @@ void __init setup_arch(char **cmdline_p) /* Memory may have been removed so recalculate the bounds. */ adjust_lowmem_bounds(); - early_ioremap_reset(); - paging_init(mdesc); request_standard_resources(mdesc); diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index f6bf6686559d..078f82f89fe5 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1628,6 +1629,7 @@ void __init paging_init(const struct machine_desc *mdesc) memblock_set_current_limit(arm_lowmem_limit); memblock_allow_resize(); dma_contiguous_remap(); + early_ioremap_reset(); early_fixmap_shutdown(); devicemaps_init(mdesc); kmap_init(); From patchwork Wed Nov 7 14:16:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150394 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5221071ljp; Wed, 7 Nov 2018 06:16:31 -0800 (PST) X-Google-Smtp-Source: AJdET5cEqE6w6SnZcutGKd6haFTPTFZMf7fBzsRLblzn2ooghv94Yecb/4CS0feLmpgKT7NdJ/AA X-Received: by 2002:a17:902:3e3:: with SMTP id d90-v6mr411957pld.118.1541600191123; Wed, 07 Nov 2018 06:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541600191; cv=none; d=google.com; s=arc-20160816; b=zs7XoXrk0WOHFtQ/PDtVYnH6OYFcuEy3o6feJCtzvkwuLX/LfwfsfcBm25l0zxhPUw pkiQzxy/YzKOqgnWJbjIW/j+aVmGQBqmTW9V/Dwg1y4CplilJ9R6g6olcH7JeRsCIjNS MrgA1T0ySlMZ7YUjoId2X8mdCAcr7uGm72XJWXcPFjixkJjqy/a1sF0aenk9DCutOOMl csJYmtTha7xgDlLHlsSK6z/b42AQD4yaPxqP0LHH/Uyn4Ey6DqQV3oFCklxjk4TTuu00 xFtJvBv9rSze3MikLkT0mZw9pAjlrPRsZNpNLdrgKAX/zxvgPLE4PUIBB1WO0aGbJOuf 5Ahw== 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=Tr8foXw6aq0MQflYxCLzmVJC0ciVK12b4fFVOOhpxSY=; b=RXUII7GdeORyuIjJxilzT928Tirv5bGzGETfk/apD/NKuip514a417WjT8Bo5+e48I 1/Ti+G4pV4qr63I8ffIhgMj0cXrhEioz//HuTaf7wa5l+AY6hOYZ7XXlssWFuptbxTUI uasJqK8Qq+4hNY9jmjZfd5Oz+BxeibuiI6kMVe96dF4vqY9bRrJ/Kthj4dAhUfbdUqs4 zsAgrjvbxvldCXP2X1b4pSZZRHVumdDaDQVZXKmgRVE1xkGHQHlWSUUnEG9GTInEiQxX aI9vQhjsVfN0Pd0Vws80zGCuLkcZ+IxJE5Sud8Ga7zOZaL6pOu0RESwqSS5GWq9r8TzJ IVvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MF8ico6P; 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.30; Wed, 07 Nov 2018 06:16:31 -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=MF8ico6P; 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 S1727698AbeKGXrD (ORCPT + 3 others); Wed, 7 Nov 2018 18:47:03 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45208 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbeKGXrD (ORCPT ); Wed, 7 Nov 2018 18:47:03 -0500 Received: by mail-wr1-f65.google.com with SMTP id k15-v6so14594595wre.12 for ; Wed, 07 Nov 2018 06:16:29 -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=Tr8foXw6aq0MQflYxCLzmVJC0ciVK12b4fFVOOhpxSY=; b=MF8ico6PXrA2BhPxBQFFbW8jAGJMJ/k7IUknMbUPu1cM/oB2GUV5WrFhyVtL7OBmwR NVo10MF3EdpoPJzxuDTeechLP0Pu/gqbGlukZ38s3v+tiFoyH71+0LbQQxohvnW+KPvR pkMiceInWTKziMUfXGrrXZnI9sjZ5jvnvNC24= 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=Tr8foXw6aq0MQflYxCLzmVJC0ciVK12b4fFVOOhpxSY=; b=Ta7/in2dM3m2/kYhK5AW0kruY64mcutAadXbUrgbqNAUrnYMRqw9Nd24XmU+YkMXb2 RgY25trS2trelwbvkXJSBjGRomCE46EC53AbL1t/nPCYCDLciqWZdek4t6MYsXFJ6iCd NT+OLZ6ALOCg0ufW10egVhuuPJqmjM9sTo7WtCcaBu2bKn2BsCxfEbw1+pRhiKIpaB8c EYQt9+8cMNHWnrUQtiDxs9Qn518FYbViabo9bQJxEetcic808VdlaSL0lTUMe0y5Dtio kjQX+jDQlme6Mrd8mnlnrJoZ28Cv+o7MVF6C/QS9H/5XggPnaOUj/WVq2iang5ME6/ht Ssgw== X-Gm-Message-State: AGRZ1gI1Sw+CJPG+HEAWiZn+Mp6SvmBnupwyB7KrWHtluOssSWTaLKov 1OAqiIr1r5JKR/opwR/U89ICx3McCsk= X-Received: by 2002:adf:f68e:: with SMTP id v14-v6mr330447wrp.261.1541600188603; Wed, 07 Nov 2018 06:16:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 06:16:27 -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 4/6] efi/arm: defer persistent reservations until after paging_init() Date: Wed, 7 Nov 2018 15:16:09 +0100 Message-Id: <20181107141611.12076-5-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 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 arm64, and from paging_init() on ARM, after memblock resizing has been enabled but before the early memremap support that we rely on has been taken down. Tested-by: Marc Zyngier Signed-off-by: Ard Biesheuvel --- arch/arm/mm/mmu.c | 2 ++ arch/arm64/kernel/setup.c | 1 + drivers/firmware/efi/efi.c | 4 ++++ include/linux/efi.h | 7 +++++++ 4 files changed, 14 insertions(+) -- 2.19.1 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 078f82f89fe5..8ecffb8c0c0b 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -9,6 +9,7 @@ */ #include #include +#include #include #include #include @@ -1629,6 +1630,7 @@ void __init paging_init(const struct machine_desc *mdesc) memblock_set_current_limit(arm_lowmem_limit); memblock_allow_resize(); dma_contiguous_remap(); + efi_apply_persistent_mem_reservations(); early_ioremap_reset(); early_fixmap_shutdown(); devicemaps_init(mdesc); 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..72a4da76d274 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; 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 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 */ From patchwork Wed Nov 7 14:16:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150396 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5221122ljp; Wed, 7 Nov 2018 06:16:34 -0800 (PST) X-Google-Smtp-Source: AJdET5e32i9QcZFTvw3bY+oKKA38P6ESL187H3CAhkEKpFYrYE4EVA6t+ktgHWtUY4XfzPR89O3L X-Received: by 2002:a63:441e:: with SMTP id r30mr343765pga.128.1541600194508; Wed, 07 Nov 2018 06:16:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541600194; cv=none; d=google.com; s=arc-20160816; b=LVqjzb9kG+IzWDFbwf7SzV3empprIk97qYhw5K9xkkW3booLpuEs82Op4urrUCzLxN yBVxzkq0JAy3mTHaFMuW1Tw1wBfY0eUzgA3AgQyQm/1XA1WDMSEZHc+hVeasp8huV9Im Gfr3mBUlzRr3nc8cjEHkycFkUm/OxVsDcUiVglu4g5oWuuOX5lGJFSUeJrS+MHETgA7v m6pVWjLOEDACI4Zs4g9pEbvWYZTG2Nc1+R14VAJIvLaly6vY8MWsxCt4Jwuh8AruYxoW Qm7XuV8iy7c/VXyQbHYKJ9MCQpTZxhPxNsiyzDWmO5bMEB9uTyZjXEusdOi1vZnMuHU2 cBzQ== 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=VJyGFvkW+sds6Swb6NM29U54YL8cp7noX7x5ydcenvM=; b=WVVRX/53ealKoldeWfMEQviEofPhfFqtFsfC+Pa0uNjPFFSa70QWbCe8097cniOe9b h2pQZ1oRUYreq3D9Fbyn/Pqr6vnxHhAB1UIiaAsssjpOjLX2C3RIvJqXO4+JrZW8I7o9 n2zfQt3aYVHmrH2gr9tad1oFix8C2pkvlaycmo32+IRLjEeOESnxDeth8vgmZQCsVjyf qnTkkWEl4fHjBKzXLooKdw3GBOtFwGUlKMQ4jmxGFB+8cVjMUxJXzo+mE8t3ocqiu3Po ZAYpi90tXd/T4e58BjodyrrlNYQ0Hk91Ho07g7RL5r2QoXzcjRrfKApIxVA5J/IvgcHJ iYtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VNXHGdwH; 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.34; Wed, 07 Nov 2018 06:16:34 -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=VNXHGdwH; 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 S1726825AbeKGXrH (ORCPT + 3 others); Wed, 7 Nov 2018 18:47:07 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38453 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730783AbeKGXrH (ORCPT ); Wed, 7 Nov 2018 18:47:07 -0500 Received: by mail-wm1-f65.google.com with SMTP id f2-v6so2257471wme.3 for ; Wed, 07 Nov 2018 06:16:33 -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=VJyGFvkW+sds6Swb6NM29U54YL8cp7noX7x5ydcenvM=; b=VNXHGdwHMksHbAThvdqD0wkk958QjAz/AkS3mbC+6WlTAJUrBev8wZr+aPuYO520LI hlBogISgm2Q+hoZ/D7yXL2PryPAI8vKKBxcdzHmBpaRs5oV5Cdv52ydivYRbpqmPey79 rCgYg0FE4tuJKBxBkc2BiFl/b6ZwQAEfmA9ZI= 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=VJyGFvkW+sds6Swb6NM29U54YL8cp7noX7x5ydcenvM=; b=Xr6JbalSVyKHC/j4Qk/J94cIfZnL7WMF6MJS6FZnpic5Kn7dPxu7AL1MOFCH69ZfuN oHHTa3ye9yEhtmFD7LQNwSbIGZSFn/1R0r/MV0ZnV6JjpKtTagrtisdT4exQ8Iy4o8jM EQJGSSpmPG4DaDJi1w7Pal8zOhBQUWYWMOSanVziYcz/gZaVZiCPRX/t2RnWel714voU NB0rrPQ1sjnViji9M9eHNqJOhXwcfIiJTp555hudYLzpotfBten+SJXR5OKIHaWOYjgp ThqGnyujBfCCuFmfoFNlZxlsm6O3Evn8eWPHxrXsXqOkyZeGeJgU83sWvEO4JffEHqxl DBYw== X-Gm-Message-State: AGRZ1gJbxMpp7rmNIH3NLPxv+K+nO9iTwPk7mBztK+dohON0/ojs3bT6 jbx6lxS2ZPiYJzCquJtUIQVGjA== X-Received: by 2002:a1c:1b91:: with SMTP id b139-v6mr337952wmb.37.1541600192368; Wed, 07 Nov 2018 06:16:32 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 06:16:31 -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 6/6] efi: reduce the amount of memblock reservations for persistent allocations Date: Wed, 7 Nov 2018 15:16:11 +0100 Message-Id: <20181107141611.12076-7-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 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. Tested-by: Marc Zyngier 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 59f8ac93c759..347028cb392f 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 */