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: 10672423 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 77C4114E2 for ; Wed, 7 Nov 2018 14:16:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 651922BF68 for ; Wed, 7 Nov 2018 14:16:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5956E2C089; Wed, 7 Nov 2018 14:16:54 +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 D38EE2BF68 for ; Wed, 7 Nov 2018 14:16:53 +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=dJ0sMzWGn0C2k4XR21k+doUD4tnt31i0PExxhpjf3M4=; b=j/NokDY7uBDu7h 5zkfEyWIIdLPpC25jwCXHkL2pMRORxRacxxq6eo/oMQhkeQPibzKTFBftLspizPnMO+Kv5KqAWOXM Y915WMTbc46stGGJi8waRl77ATYvn9b+mfua8QoSVvNfGQQ3XQhWVePZDBvCZ+8EjxlwK8SNEK81Y wCz/W23h//J+hLUTLxFiKlpr/Gi3nnTmSBliQ8uhSNsfFB8O7cEunP8exXcuw4T88Xs6deqotI12P uxBm+fyJHBxGV8ItfKJleW09L6xw9ETd7TYe6r+NFFbPttzLvsLFPrK4NjU4KWN6APb3ZZV1epFIh PU9qHSwKzTeLsi97URbw==; 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 1gKOdS-0004B5-5Z; Wed, 07 Nov 2018 14:16:46 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKOdH-00040W-Pc for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 14:16:37 +0000 Received: by mail-wr1-x443.google.com with SMTP id 74-v6so17554294wrb.13 for ; Wed, 07 Nov 2018 06:16:25 -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=PB3RGbWBkvPHvGBsS07kz/GIptPmQsfXY0v6oHzhTERqjMYN5/s6vlVNzVBWjzMEe8 7PbHUKxaHKk9zQ7o1xZqyu0qngmcQ8mtd6S2I6pTZFaBmYQkbUteY1pOWqrtRvHJ377f sS+vh34jZvvg+LB+XNLWNwCuSgsebXM5eI5wT5+r2LIrYvlyiGv/0nqPnvo4QHzt05Wi D0TG5KsCwqmixBwb3CRczQaqBLeEWaR3n7hX9EZKiBbXs5O+f6EaTeMBE/b6oCxlhqMs NfBMolHq46gH2OzvdmMCB6kkcwRlJdPsa9Ki5o2ZiyPLXuYQt5f/IddLrbbHEBAHX3Jg pAgg== X-Gm-Message-State: AGRZ1gJPIkJiFOP6/34DuV0PSRSjWmqiJqyCl3aU+m2VjybCJMnQ1c42 hXFrHv7THBht5uJMkbad35A2sFH6uKI= X-Google-Smtp-Source: AJdET5cy5HThvU19UXEBUTjQer9IzrzcL0OVtcZUoo3ZOYrfx8O1A9USF70aNbYyRnuDYP+0L/DjcQ== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_061635_828144_FFAA5D77 X-CRM114-Status: GOOD ( 13.17 ) 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: marc.zyngier@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, Ard Biesheuvel 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 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(-) 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: 10672429 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 634C914E2 for ; Wed, 7 Nov 2018 14:17:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 514ED2C0AA for ; Wed, 7 Nov 2018 14:17:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45D0D2C0B1; Wed, 7 Nov 2018 14:17:31 +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 D12572C0AA for ; Wed, 7 Nov 2018 14:17:30 +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=X+7WnoOfrA/4i0a0IQjAWkhxqFYlQ0CZ9Lzovb+gjcc=; b=rB+7xo5+2NupLs jDui4yPqAnpQF3GHrSWNABlUCYnWfSmvA2AFAM40u3UBJBUFeBpMpq3FZj1yFuyeM54Sd3WSPOD8V hqcaL2eR6JwREw1FmAzWW6e/yzO47HzGsh11UVw6h4aaI1MSq4Z6s83Wk+lgXC4dTQ0V2di/bGEd2 AE3+3DP+/FHU4pj1M8fe2bzNl3l1YOcrOFcQUwEJVwrDFUrAss15WwlMpL9/eX+fpTGfXiNLVNuHL VhS0SIUw2oWbrdv4DyTtjh+V7Q/b4LZUPSphQfroDAUZ8JI18+Nopl3t2mx5oAqrXEparSd/8JBik jy7C12nWAE3tUDvdFSxw==; 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 1gKOe8-00051h-LK; Wed, 07 Nov 2018 14:17:28 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKOdJ-00040t-HX for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 14:16:39 +0000 Received: by mail-wr1-x442.google.com with SMTP id z13-v6so15201214wrs.3 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=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=UcW8aj7Uj9WbjuvZuSsB6MDx+BySeqg8I+7gSKL3YhpkKOOCzHOyKvqC+kzZ0W8JCY 7PPGs4g2TiFDfhSzEuNBxoRt5KHHNdOmsT1CV6qL9QmIacUe0cHUegUDds9h2W6kFrWe ClI2YP28Ycmi2ln9genEsA7jehxUxN4R92FTEUHz9MDHqT8Z2gjiuFMsDJbxtVPAcyAP HKqkUOaCuwn4NXNWC9kvoho38S6Xmd5P5y92ZbchoYSWJOgiPtyyfJPo3OLE7PePm1Xo e4JmBmLUKI1XjTDg8zQaMj2byvj+Yrm2mN0+2g6V1p1gh+mk0vElirobk+lRXB82s7jh AuSg== X-Gm-Message-State: AGRZ1gLx4GmpSq1pQOGsK06wL2YD0Io6iQpO/MuH9W5QFjKfh0fM09xH vliu2qJA7JFmZ5C2qlP+iPSi3RFjjPo= X-Google-Smtp-Source: AJdET5fNXXv5Tq3BC9w0tfBUtEOplurjKfl2hDV6CUPLEW9KbGAfpz4q9HMzstrIKGPZIVj3gIKFBQ== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_061637_581003_FEC5F160 X-CRM114-Status: GOOD ( 16.91 ) 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: marc.zyngier@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, Ard Biesheuvel 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 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(-) 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: 10672431 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 0D77C14D6 for ; Wed, 7 Nov 2018 14:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF3942C0AA for ; Wed, 7 Nov 2018 14:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2AFB2C0BD; Wed, 7 Nov 2018 14:18:11 +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 17F462C0AA for ; Wed, 7 Nov 2018 14:18:11 +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=WK1x2hC271J32hoMD/t3oZqM8an10wllSrFP7jTjymk=; b=ZN/heNUg0LIrEn 9gSCHZDbKvMmzJ+CUGNufWPc8ITxd/yR8bILQOkP7z2+/YImU7Xg2xa0UogOkfogj2bDt+jBCHKVp D7ldE1T9hZOIKzPCaEi3vKIEBRjxXOCc7W+vLXnkbqR8lUcyXSfIRGHgKm+mMT9hXPmd1F/pqtyqo bDXTsC/cBZ/iek6GYoJAXnGB/WAhsbLyQJEZvkvb1RNxBwa4RmNnMGtjNIR2xQjf6JwV4tcGlcO3D 2uuKYwVnaQy0qlOVIRWS+8Qtcmkf8WmldKABJilVAJkC7K4k9l/TEpBTZVYleSbMQWdlsj+rBFEjT ci+BkHTSyILOnF/x4vKg==; 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 1gKOed-0005Tq-ME; Wed, 07 Nov 2018 14:17:59 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKOdK-00040v-UF for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 14:16:40 +0000 Received: by mail-wm1-x342.google.com with SMTP id 124-v6so9301935wmw.0 for ; Wed, 07 Nov 2018 06:16:28 -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=gfdFstXoZUvqQENxRFWOHbL82qU3Jfmlgz+HcIlbs5HlftwYI3G//r70hGpHUTRTYz S5bzNEh+4xVhfylb6JRiHS8BHiMuN2eCe4rtbrCGirYmCyZXLWiR1i9blG+Ok3YAXsvy c/PVaGSCWKYopd5N0bR463VhFds3KrYa/BcD48gtQG8DIHwH4+EHDRSv4uB03TZmwPy6 n/GiDPpEhsejgB150ytgba1r2+s6UDj8cQMwQ09WIVgvBoTDCXH8U5nNSCYzSRZNTT5m Y1xH0uj/PkdZWtCz7oKVbTnWa+PLo0AfIjPYl7x7Ys8vOk7x+TJqCeXrUvhdmaLmPT/8 3r8Q== X-Gm-Message-State: AGRZ1gIxQ6+nxSAenJxqeMSF4pohDk3yBv28TI1p2d+4+GXnONVHDlce BcY/jtYi//orDST6bP6v0eeYbRxOtH0= X-Google-Smtp-Source: AJdET5f27gmzVOW8rpiE+a1I401phFrtRhI5b34oEZznL8rD1MoHgSu0nqZfLyltV7dXZd7pQ8k2iw== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_061639_001257_49D19F9E X-CRM114-Status: GOOD ( 14.07 ) 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: marc.zyngier@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, Ard Biesheuvel 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 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(-) 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: 10672425 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 0308914E2 for ; Wed, 7 Nov 2018 14:17:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4C6E2BF68 for ; Wed, 7 Nov 2018 14:16:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8CB92C089; Wed, 7 Nov 2018 14:16:59 +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 60E292BF68 for ; Wed, 7 Nov 2018 14:16:59 +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=rlm70q6QKI131OeHGk3+4cFVRYbZYZsBH1A9045qkc0=; b=KtRWQvmdpzM1xx 8LbhBXTgq6Upv2wrlTB1xHpvgJ4/wURtWC8lKINJmmheyPnZKLBj0OR4t6abeOkfpWunQ5+lt5bzT KhCNAv6MWJszKwKglUu/DtOr55fCWTXbVZWnOrlKIJQ37waZ1ULUniBqX8vIePqejvvBhcuF6khTb v9lWhBB50Ino1CFr8+BlPwOvwKm5CN+3P6wtSMRyLbVRJrqfpMCNhkw1v5fU8K2BqvH4s9PXCwCGj XjMJR79Dd6jraXs8hOXIm4xDmdiSbfMD3pRN2/qGNKo2ZJHzjM4mCTmis+wpjyXMB8mialh4TgrpL zgQPlTJ4OZkm/zgiE3pg==; 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 1gKOdc-0004PW-K0; Wed, 07 Nov 2018 14:16:56 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKOdH-00040w-Pd for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 14:16:37 +0000 Received: by mail-wr1-x443.google.com with SMTP id z13-v6so15201416wrs.3 for ; Wed, 07 Nov 2018 06:16:30 -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=tm+M1JYIoAF5xiOXEb1dqXoBo0lmyy5P/NWRP2P5rsJO/0l+h0jZFGQ4TUnppCiliZ JdUAihV65dQoob6Q6IycadUpiDNo6dKFGgzTU/5K5W7NSp52EAnZpCKMsvrNB3R7ajDz oZ5DomDlCyZdG2AsnYvIoutlkB9STPsv8nGGy4LFAcuvpDyzmsbt4FwrHkB1RV9SejJM bp07peL4WH4KKTdYqtn/PN6H6dDgmHVnI/WtNRwk9hg9WEPgquGI33BA+rJ0IGHz1fgq JqciJsQ12NdwheRANl6ojX3ukiUdhUfTQ7FVVrIShuxOzlQyMvLXlbUW4pgy23GKprbs MuHg== X-Gm-Message-State: AGRZ1gJOG+y86yqvq+URIiZ8u3Wfz3rh5EKr1E8vdq2+L1UNy4VHZNEJ XPkVfoZoDY1NwYqS9EBPGW3Iy+KSYbg= X-Google-Smtp-Source: AJdET5c0mnEXM1VmMMG1v6PCi9+C/0KAeEoVZNmCihl0qHkRaEsENlwTjvVErKRTwx9ywnhHYxeqoQ== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_061635_828968_0F37D46F X-CRM114-Status: GOOD ( 14.37 ) 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: marc.zyngier@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, Ard Biesheuvel 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 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(+) 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: 10672427 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 C385014D6 for ; Wed, 7 Nov 2018 14:17:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B10B82BFA6 for ; Wed, 7 Nov 2018 14:17:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A57472C095; Wed, 7 Nov 2018 14:17:21 +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 2C9C42BFA6 for ; Wed, 7 Nov 2018 14:17:21 +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=rHwxrpvqrj9yJ6V++eDCBVAONr60D3nsfF+D1tq2qcM=; b=oba4B2Ko18sh55 JwU3Qco5KKAhU7gnkMe6QSfuGvSGjHxBnzK1n137qbUjaRYqMTYAiy1k+v3kMZ8XrbvDql94V3Ybi RVpfiiozWoQUbffmyUKhB+UA95Yf9eS6adTNc1vfQkIZJB8LgFMc+Sk4Y4P2YfcBofiJr5RSl8GGJ m/i/viyMR1HhnYGXYQiyznREp4VggPVlYfD7Ph+9C47I1s4FtQ7JMxDTK3VrX7YeFCQ6hDGGWAd8P 5GspmGqJbC49inTM8tQr/nNAC80EeyRCOmfgpjg/HIEunZdIAJhFbZbyndO3Ak0Zehp9tVpyp+FHy ISoeNm6GfBpxdW1pigtw==; 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 1gKOdq-0004go-2V; Wed, 07 Nov 2018 14:17:10 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKOdH-00040x-Pf for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 14:16:37 +0000 Received: by mail-wr1-x443.google.com with SMTP id j26-v6so17598186wre.1 for ; Wed, 07 Nov 2018 06:16:32 -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=SeeXvOqObnUB8l6g6+Orhgo2hrB2meMR12MTPKcz2XiOiS4tBvKIT0oGt+rI/XyQNY SkXVIzJuhAJs8Qzxoy4ybLhi5gS/8dlTrOx/HroADcfwlFuwECUO6HkSrfIxoMa6z22V 9xBsiSgUj0jDVoCQtPNYPioWQHx0AMgNerEFkG6aq53IXb+huytMZz8oTsBqwMNp9Kz9 Obgq2T20bjgWc2fCj9mymS9H4SmmvEWdC4ODwE9RtNFUR/u+sjsM91VrZcCXR+xb0FB0 F7fjxNLrGYGBoaiffkqz0AzMOC0KROF1/IpVKwUYkT8jsqLT8jc3skT3gLjkyKo3W0oh J04w== X-Gm-Message-State: AGRZ1gLgb44KxpNwDquUgYge1KC9Gm+ncIFdN54tf0BzVHThRRk83dOH 04iAPVzCCku8l+rMLhGU2yNBD05pvTk= X-Google-Smtp-Source: AJdET5etvi8hCSvMdJKsAENGaWum7Qbyk1tk4nsiK78yLoBu1GfqBqc8WixNz2ulL/M8NkmW8UPxwg== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_061635_835849_3E42FAFA X-CRM114-Status: GOOD ( 17.48 ) 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: marc.zyngier@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, Ard Biesheuvel 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. 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(-) 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: 10672433 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 1517714D6 for ; Wed, 7 Nov 2018 14:21:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0432F2C0B3 for ; Wed, 7 Nov 2018 14:21:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECB262C0CD; Wed, 7 Nov 2018 14:21:01 +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 892272C0B3 for ; Wed, 7 Nov 2018 14:21:01 +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=Gkk9ZIYlk128crJcFwhfIiPEVrk+2Pp4mg1TspDY0bw=; b=RnEdWiIie2laP5 9xvZR+80eS2Jcm3XzEh9apNA7ZS96pE4MJKvOahcIxb7dmUGLQEcEt4PRNhx/cxHKEukb4MTGNZ3b VOSQnw9IsCRwX8R6KrVSkbg2DzcQk+D5MUP+uFhxXiNTIIHFcD7DBT+ZIYLgy+neTXgfviXGo6GmX /Wh8WSw2b27DWZST+iBJmqOSFFAhPt0WHHnkcnLZHwB2OSdqlsMLvEx0+3L410S5KfyluqSsSWPe+ 2SeomT61ONdOqj8W3NZ+rjC6mXwx4cqFB20IVhLmNwXqM84unVNd781JjH5cjvN1h91jE24/74OaN Jfijilg0m2V4KSrDQqYA==; 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 1gKOhY-0007AD-GD; Wed, 07 Nov 2018 14:21:00 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKOdK-00040y-UB for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2018 14:16:40 +0000 Received: by mail-wm1-x342.google.com with SMTP id p2-v6so15830401wmc.2 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=uh+Vad328/fwNpUWfAdhMCcD6RAE+uDOvzp28AgSFFcFqoPISQXSerVincobgHnzfY b8m6lgqYzsECjT0YW+ckxthpam9ozf1ZsbnTVSmTHYV4Jd0hjZ8Obd/kWAevkrmOG3Ll bpmxjlVBQ/vDFaYUL6k/8D5HkmZEqxvexkrZ3761xbFYhQIeP5jTAGwHdjU2sXJd7n84 SV+sjLFbOo8lFUivyZcs3eJzZVRpaeD2OrxOzO5GH2WwukUFuGqjJXT6U82tLmO3754X LOS6R8zuF70K9t4rPnERZvoUa1KgtB3rknSwCHp37seKs8xf/Zh3Il5T+aq9JrJrb7s1 1t9Q== X-Gm-Message-State: AGRZ1gLQKHNnpnJS22NUGJI2wUN06ukaFOCWh6uDgk2rDZv2G/VdUMGd XnL/Zv4li/qY3u1A1DKrVbL7qrpsIfw= X-Google-Smtp-Source: AJdET5eWopr7wyqy/iYDf3Bh4lI6cE8PBnpV563ZoYfJnilosiFXWWqCmfzEj7v4qUdvBrKuLcXytg== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181107_061638_997874_517D9E8D X-CRM114-Status: GOOD ( 17.06 ) 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: marc.zyngier@arm.com, bhsharma@redhat.com, linux-efi@vger.kernel.org, will.deacon@arm.com, Ard Biesheuvel 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 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(-) 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 */