From patchwork Wed Feb 13 13:27:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 158228 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp72353jaa; Wed, 13 Feb 2019 05:28:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IYVrNf/ocTwawMYEyut+xIHCLbUaN/rcJWpR5sMPWQ4zZLjJ3DTmd+CNAlRmgC5Ptkt8Ofj X-Received: by 2002:a17:902:9a81:: with SMTP id w1mr528405plp.19.1550064523106; Wed, 13 Feb 2019 05:28:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550064523; cv=none; d=google.com; s=arc-20160816; b=BJGJYtQ8S4PKWZ6TsJbm5DiaXwLRuA4yOqknbhXS5hlgAdYm2UU3nxvslgytM3qmUf lr2Dz98byMj6MwKGjC/CJXADW7dKlKPZZ1saAEolpSRP5yaqAO5hD3IJlpf5nx1DO5zK ZGkic+emQyLcsuRvMMG2xrEI+WtkyS4XLxHJPYt8UbdESts4j27LifDFIwvqA90csvXa RlBy3Lej8ouROMlBucHl3oA6snf1eaMVo2XIq3JtQZFko7uzw9ZJf8F3qsAsLNCt+rXO OVAZmMW9ptH1jEoZu4UzJ+Te2UMEIxxHNXtG3yqdQpYe2Rw0yQ5T5i+EtBd78IbdAoNG IYDA== 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=Pcq+KlYpunIsRMvl5N8urLfnQtGhYRhha0Fk42l8s1s=; b=QUAwhkpf3RIC/ByKLGQ7oR3CfcT6j3sSnZDEhSIBDu5w+T/a3cH5XKUtRLsDSpF/MV 8i75vd7Y/nzUg0WOmQCb7fGgRmsQMULU8ZQe3Ea+L96YpDDzCNZZvKi42bFQcHVtxWJS q2kVb+mcCPBCLr2U1/ieHrtJb3P7JZcL1cw0dxvvWQElhSyq6ruTalnMWOfYKVMKm2GL X/1RnhmFwt7dlYO6aiBCC9fQdluk5EkdsPk7TmReiCEdgXsY7jRAj9BftxVsL88pNYkf tJON5ZhfGjSQpoi0IiQ6TGRBLLEo5fVvAmdSPVmUDLQzMuVIT4cOIah6Om1nnoMipP6l j56A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XaRXIc7e; 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 g10si16074205plq.371.2019.02.13.05.28.42; Wed, 13 Feb 2019 05:28: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=XaRXIc7e; 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 S1731659AbfBMN2k (ORCPT + 3 others); Wed, 13 Feb 2019 08:28:40 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40408 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730035AbfBMN2k (ORCPT ); Wed, 13 Feb 2019 08:28:40 -0500 Received: by mail-wm1-f66.google.com with SMTP id q21so2405736wmc.5 for ; Wed, 13 Feb 2019 05:28:37 -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=Pcq+KlYpunIsRMvl5N8urLfnQtGhYRhha0Fk42l8s1s=; b=XaRXIc7epzKjHIVTj6gNKn5+cxg7Ghkp8lZNxiYHbAyxUEaVN56j4iYJwSBGp4aE5+ 3QtsoOGwtDEjEIWOIxO1KELBeSJsoPvpZMWwAUZuWkbyE4hL/iaEYYytZI7LdiWJNp4F zBvvY+Cg6ZwoATNYw5MH5Bol6+5YIWz5bpQgSbmH95qUuNmW47KjjSJBZ0yhPWl3/7yh JPpMXlDJW78MtIMTb8ofOkCuN+g+myvHgWJD1FWwJfHAHrXvU72K/0lO18i4HwWZEBWN qH2ecbpVXEo0QXCAaOEjBKcKuOPjgBjuJN9UtejMwy8ysfzsSZ0ljex08BxoljXBg7NW WNCQ== 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=Pcq+KlYpunIsRMvl5N8urLfnQtGhYRhha0Fk42l8s1s=; b=MgVWtqUnV0TSJpLBgucCpyYpoohp2iK/QhYH67RUES7yPI2IWt1Au/ftaUcL8JG6Ty EWUYZUFMk58lLFeGi9gJFpmNE0KytWD3b07UsxEUKiSqST6DowUhN3isBkM6G2Ahk2kY +ru2vtdp937isltTp8tpUGnrWaP93gWZvexpqLIpvoLjCijh15rB91oK38JY1mJFD8zc /9xGWAL5nRbalB3OiKvN5nxg6udzksU4XQIMcmdyhSsIcPExHj8bIXfE5oL9Iys3JxCq PeAitjNI6THqQtN8381rglsRFcmShQPWcq9kIw81DHubPBHejAWCECVvHYcnlReYRo+Z tRhg== X-Gm-Message-State: AHQUAuYhI1fq6u5xbgcAt2UXXkLxXRJosJulZxNCrDc6sbINryZ9949p Ua3wtIgUlRos07nGPNM4phcmm8KGZUA= X-Received: by 2002:a7b:cb4a:: with SMTP id v10mr339024wmj.1.1550064516723; Wed, 13 Feb 2019 05:28:36 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-27-200.w90-86.abo.wanadoo.fr. [90.86.252.200]) by smtp.gmail.com with ESMTPSA id x3sm22841195wrd.19.2019.02.13.05.28.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 05:28:35 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Andrew Morton , Marc Zyngier , James Morse , linux-mm@kvack.org Subject: [PATCH 1/2] arm64: account for GICv3 LPI tables in static memblock reserve table Date: Wed, 13 Feb 2019 14:27:37 +0100 Message-Id: <20190213132738.10294-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190213132738.10294-1-ard.biesheuvel@linaro.org> References: <20190213132738.10294-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 the irqchip and EFI code, we have what basically amounts to a quirk to work around a peculiarity in the GICv3 architecture, which permits the system memory address of LPI tables to be programmable only once after a CPU reset. This means kexec kernels must use the same memory as the first kernel, and thus ensure that this memory has not been given out for other purposes by the time the ITS init code runs, which is not very early for secondary CPUs. On systems with many CPUs, these reservations could overflow the memblock reservation table, and this was addressed in commit eff896288872 ("efi/arm: Defer persistent reservations until after paging_init()"). However, this turns out to have made things worse, since the allocation of page tables and heap space for the resized memblock reservation table itself may overwrite the regions we are attempting to reserve, which may cause all kinds of corruption, also considering that the ITS will still be poking bits into that memory in response to incoming MSIs. So instead, let's grow the static memblock reservation table on such systems so it can accommodate these reservations at an earlier time. This will permit us to revert the above commit in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/memory.h | 11 +++++++++++ include/linux/memblock.h | 3 --- mm/memblock.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) -- 2.20.1 Acked-by: Mike Rapoport Acked-by: Will Deacon Acked-by: Marc Zyngier diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index e1ec947e7c0c..7e2b13cdd970 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -332,6 +332,17 @@ static inline void *phys_to_virt(phys_addr_t x) #define virt_addr_valid(kaddr) \ (_virt_addr_is_linear(kaddr) && _virt_addr_valid(kaddr)) +/* + * Given that the GIC architecture permits ITS implementations that can only be + * configured with a LPI table address once, GICv3 systems with many CPUs may + * end up reserving a lot of different regions after a kexec for their LPI + * tables, as we are forced to reuse the same memory after kexec (and thus + * reserve it persistently with EFI beforehand) + */ +#if defined(CONFIG_EFI) && defined(CONFIG_ARM_GIC_V3_ITS) +#define INIT_MEMBLOCK_RESERVED_REGIONS (INIT_MEMBLOCK_REGIONS + 2 * NR_CPUS) +#endif + #include #endif diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 64c41cf45590..859b55b66db2 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -29,9 +29,6 @@ extern unsigned long max_pfn; */ extern unsigned long long max_possible_pfn; -#define INIT_MEMBLOCK_REGIONS 128 -#define INIT_PHYSMEM_REGIONS 4 - /** * enum memblock_flags - definition of memory region attributes * @MEMBLOCK_NONE: no special request diff --git a/mm/memblock.c b/mm/memblock.c index 022d4cbb3618..a526c3ab8390 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -26,6 +26,12 @@ #include "internal.h" +#define INIT_MEMBLOCK_REGIONS 128 +#define INIT_PHYSMEM_REGIONS 4 +#ifndef INIT_MEMBLOCK_RESERVED_REGIONS +#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS +#endif + /** * DOC: memblock overview * @@ -92,7 +98,7 @@ unsigned long max_pfn; unsigned long long max_possible_pfn; static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; -static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; +static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS] __initdata_memblock; #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS] __initdata_memblock; #endif @@ -105,7 +111,7 @@ struct memblock memblock __initdata_memblock = { .reserved.regions = memblock_reserved_init_regions, .reserved.cnt = 1, /* empty dummy entry */ - .reserved.max = INIT_MEMBLOCK_REGIONS, + .reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS, .reserved.name = "reserved", #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP