From patchwork Wed Feb 20 09:32:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 1045226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 444C7q71BCz9s70; Wed, 20 Feb 2019 20:32:55 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gwOFG-0000zn-OF; Wed, 20 Feb 2019 09:32:50 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gwOFF-0000zO-85 for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:49 +0000 Received: from mail-wr1-f70.google.com ([209.85.221.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gwOFE-0000zH-Up for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:48 +0000 Received: by mail-wr1-f70.google.com with SMTP id z4so10375093wrq.1 for ; Wed, 20 Feb 2019 01:32:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vUG80BUqfgMkGp7EBkGV5wvVDYYwy7fVKyBZlW+nt1w=; b=f345FplzaaRhXGgzHie6n+4n/n07hst5nPqmSgAhHfRq/9JCE4I8EM0wbtxRWFIqUo Hd1BMN9s4/VM+UbiIiEJ0m+pMeI9BO2yhvnl+P15weiI9E9Pddybyes5ZxShvQxE+/nV Ih4wrwa/WLkKt3L8qQk9gDdygyzzyvRuaGy+qGsAR3Za2/vuSRRkT6Zj9m6m/+8smnuC cqpfatbnw4wqnyLwL2UeCB3UAudJEeuNvgNVcEiqJZvzP/VjFoB7aHZcUYfR4V7l3CNc 5kHdyoT5kJ9J9TNY+4Sdy/GltWBi6XKGwfQl4p1Rx33GFpkMM+fdfvxGXrAvxTfIEBbB qZ0Q== X-Gm-Message-State: AHQUAubXBYms3jrecLTRDxSxaxsIPMixoRPX1V8bhC5oOMyexMMqex48 JsrDBurRt888KjwIfpULAX/SEjg0nzvPdChulEScIeUecsDWwQY3DwIgPt2+7ZXqIC1mYZjcVxr i/HjAcPQdNsPzR0Vky8YJDo7xFqVHoTk0eJmGSJ+YIA== X-Received: by 2002:adf:a382:: with SMTP id l2mr20006931wrb.79.1550655168272; Wed, 20 Feb 2019 01:32:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IZrpZmhPZGt8GJ4/SPc49spfqG6wTTiwsh2smmBkup9oizXDQxXNDKtCZpuk4TyZR4WQIxdwA== X-Received: by 2002:adf:a382:: with SMTP id l2mr20006908wrb.79.1550655167883; Wed, 20 Feb 2019 01:32:47 -0800 (PST) Received: from xps13.canonical.com ([194.204.107.10]) by smtp.gmail.com with ESMTPSA id a184sm5291340wmh.37.2019.02.20.01.32.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 01:32:47 -0800 (PST) From: dann frazier To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/4][Disco] arm64, mm, efi: Account for GICv3 LPI tables in static memblock reserve table Date: Wed, 20 Feb 2019 10:32:33 +0100 Message-Id: <20190220093236.30296-2-dann.frazier@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190220093236.30296-1-dann.frazier@canonical.com> References: <20190220093236.30296-1-dann.frazier@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ard Biesheuvel BugLink: https://bugs.launchpad.net/bugs/1816425 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. [ mingo: Minor cleanups. ] Signed-off-by: Ard Biesheuvel Acked-by: Mike Rapoport Acked-by: Will Deacon Acked-by: Marc Zyngier Cc: Andrew Morton Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190215123333.21209-2-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar (cherry picked from commit 8a5b403d71affa098009cc3dff1b2c45113021ad) Signed-off-by: dann frazier --- arch/arm64/include/asm/memory.h | 11 +++++++++++ include/linux/memblock.h | 3 --- mm/memblock.c | 11 +++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 56562ff01076d..c966ffd0ee91e 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -312,6 +312,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 (one per CPU), 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 + NR_CPUS + 1) +#endif + #include #endif diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 5169205493782..4f45444ea8b07 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -17,9 +17,6 @@ #include #include -#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 237944479d25a..51e340845a1de 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -27,6 +27,13 @@ #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 * @@ -83,7 +90,7 @@ */ 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 @@ -96,7 +103,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 From patchwork Wed Feb 20 09:32:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 1045227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 444C7t5btFz9s5R; Wed, 20 Feb 2019 20:32:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gwOFJ-00011M-Uz; Wed, 20 Feb 2019 09:32:53 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gwOFH-00010N-Ln for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:51 +0000 Received: from mail-wr1-f70.google.com ([209.85.221.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gwOFH-0000zT-7z for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:51 +0000 Received: by mail-wr1-f70.google.com with SMTP id f4so10504059wrg.9 for ; Wed, 20 Feb 2019 01:32:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ut5zPJrgt5rObmIKo82ZQlGhlUYK8OWqcLo9AnU+nkM=; b=KIBIt6u9fD/4bu5sVu24lcA8xuLSJC5sa6pDy86GcVca5GUQU9ZpheBorriXX4Ambh zsm/tGOFJrFkZuQ5iRHjojYuTx5oBBS3D9qfM4aL89bEdPtjvEiGqzzLu7A33qHI6EmW B/YOBo3BvX3/DwGXoflYs/tQ1P58+x4wfe4AO37JoHe33+GMj83EubJB3QzOu1f8xSVg 31pybc9WW71OYN5s0LowHSpJYm/KF1r1ZspG28cZZ28rC+aiYYAcPyaf7iYnbc8NVD5Q Dy772Ek1bGQsmdEbdLZqU6OQKRlj9BTOsezkbOUKSHY6U2wXfoNveoNbP2r552FIw42t pLfQ== X-Gm-Message-State: AHQUAubL6bTdbktSeHw58RTxJxex5gMMzoy5mP8cV5/UvBsZuYDQM/oy LtetBIgv2UEPs0qgDREJLys+UIcHxHbkvwzyMPpzBAuK8d4mxLb23wQGMLVHYsNuoa1gIOvzVYl YD7wOCCz6+0IMSy5ZqZEoT+ZxliICNCsXAYyx00kECg== X-Received: by 2002:adf:e5cc:: with SMTP id a12mr25787909wrn.130.1550655170690; Wed, 20 Feb 2019 01:32:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IZZ4yAm2RzK4AKJjggUEC6zYStvVmZ+69KXoKrl9HzFzZLXJSAaNlD3rqse5ZMVcE51J4bgvg== X-Received: by 2002:adf:e5cc:: with SMTP id a12mr25787886wrn.130.1550655170347; Wed, 20 Feb 2019 01:32:50 -0800 (PST) Received: from xps13.canonical.com ([194.204.107.10]) by smtp.gmail.com with ESMTPSA id t2sm2927151wmi.37.2019.02.20.01.32.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 01:32:49 -0800 (PST) From: dann frazier To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/4][Disco] efi/arm: Revert "Defer persistent reservations until after paging_init()" Date: Wed, 20 Feb 2019 10:32:34 +0100 Message-Id: <20190220093236.30296-3-dann.frazier@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190220093236.30296-1-dann.frazier@canonical.com> References: <20190220093236.30296-1-dann.frazier@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ard Biesheuvel BugLink: https://bugs.launchpad.net/bugs/1816425 This reverts commit eff896288872d687d9662000ec9ae11b6d61766f, which deferred the processing of persistent memory reservations to a point where the memory may have already been allocated and overwritten, defeating the purpose. Signed-off-by: Ard Biesheuvel Acked-by: Will Deacon Cc: Linus Torvalds Cc: Marc Zyngier Cc: Mike Rapoport Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190215123333.21209-3-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar (backported from commit 582a32e708823e5957fd73ccd78dc4a9e49d21ea) [dannf: Minor offset adjustments in efi.h] Signed-off-by: dann frazier --- arch/arm64/kernel/setup.c | 1 - drivers/firmware/efi/efi.c | 4 ---- drivers/firmware/efi/libstub/arm-stub.c | 3 --- include/linux/efi.h | 7 ------- 4 files changed, 15 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index ceceb7529f370..b3354ff94e798 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -313,7 +313,6 @@ 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 8a1696f46f38b..663ae770bc605 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -593,11 +593,7 @@ 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/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 3d36142cf8120..30ac0c975f8a1 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -75,9 +75,6 @@ void install_memreserve_table(efi_system_table_t *sys_table_arg) efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID; efi_status_t status; - if (IS_ENABLED(CONFIG_ARM)) - return; - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, sizeof(*rsv), (void **)&rsv); if (status != EFI_SUCCESS) { diff --git a/include/linux/efi.h b/include/linux/efi.h index e044522db183e..5ef44bb15dcb3 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1212,8 +1212,6 @@ extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused); extern bool efi_is_table_address(unsigned long phys_addr); extern void __init efi_set_secure_boot(enum efi_secureboot_mode mode); - -extern int efi_apply_persistent_mem_reservations(void); #else static inline bool efi_enabled(int feature) { @@ -1233,11 +1231,6 @@ static inline bool efi_is_table_address(unsigned long phys_addr) return false; } static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {} - -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 Feb 20 09:32:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 1045228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 444C7x2BS5z9s5R; Wed, 20 Feb 2019 20:33:01 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gwOFM-00012g-5g; Wed, 20 Feb 2019 09:32:56 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gwOFK-00011L-3S for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:54 +0000 Received: from mail-wm1-f70.google.com ([209.85.128.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gwOFJ-0000zd-Mn for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:53 +0000 Received: by mail-wm1-f70.google.com with SMTP id v7so887437wme.9 for ; Wed, 20 Feb 2019 01:32:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V3AZny+JPJYFLeswXRlSA8BzSE+s5iuxgXKy4AHB8Zw=; b=I1/Pygo+ygPMuNnIZexqegXlO3bhkA3bHeczhufMGXK5FcazYBkXqXLdpl70ntCDnH EqSz8wUwGcLKoLmeOyLZl85Zbn5hktX01oigIsp54ojLpUcnanPVJmzh62Zgu8UPIQuD LAVcIvI6ZWfyXUos8M/P4qbCYrnRCyoHpr8z445lD7IQ2ongg9bE0NB8zinQf/54J9Br a++slAHHlLahMw+sStF649Pc/qfUVDwHbDre+ZYWwnL5JY37qMJgWlIyJxTZpfp0eQdS Ip35uUy4M0zkyFqZ2BBB37CMvGQjKA5OxqbxRV21KpfHok1Zhgo0npCYrt2/MnDCSfXs 6CPA== X-Gm-Message-State: AHQUAuYqliSi0bSnvCa+ryzvNRxG11n9aD+gLibAnT7sC0VBtWHJbpgI 6AHq8IX755GCOqx0Qg+i/wwh1HAZ5EX6UbRgEUVg/4GCIxG5H7j/cwf1ksAtXKxSRMvN68djTFN nfrokIjHEEdYfEoVYQav40GaCjcm0QHDgpj+2wwJm9w== X-Received: by 2002:adf:afce:: with SMTP id y14mr22868903wrd.219.1550655173045; Wed, 20 Feb 2019 01:32:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IbZpZYYcdRFv1yQR2XEgz5nHFGS1bqBsEXpYz4pxlS4ySif7iSf2tTbzLf8ZiUHJp03eQu8Tw== X-Received: by 2002:adf:afce:: with SMTP id y14mr22868882wrd.219.1550655172668; Wed, 20 Feb 2019 01:32:52 -0800 (PST) Received: from xps13.canonical.com ([194.204.107.10]) by smtp.gmail.com with ESMTPSA id y20sm33570654wra.51.2019.02.20.01.32.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 01:32:51 -0800 (PST) From: dann frazier To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/4][SRU Cosmic] arm64, mm, efi: Account for GICv3 LPI tables in static memblock reserve table Date: Wed, 20 Feb 2019 10:32:35 +0100 Message-Id: <20190220093236.30296-4-dann.frazier@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190220093236.30296-1-dann.frazier@canonical.com> References: <20190220093236.30296-1-dann.frazier@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ard Biesheuvel BugLink: https://bugs.launchpad.net/bugs/1816425 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. [ mingo: Minor cleanups. ] Signed-off-by: Ard Biesheuvel Acked-by: Mike Rapoport Acked-by: Will Deacon Acked-by: Marc Zyngier Cc: Andrew Morton Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190215123333.21209-2-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar (backported from commit 8a5b403d71affa098009cc3dff1b2c45113021ad) [dannf: Trivial offset fixes in memblock.h, memblock.c] Signed-off-by: dann frazier --- arch/arm64/include/asm/memory.h | 11 +++++++++++ include/linux/memblock.h | 3 --- mm/memblock.c | 11 +++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 49d99214f43c5..156d9d2ce9f47 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -300,6 +300,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 (one per CPU), 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 + NR_CPUS + 1) +#endif + #include #endif diff --git a/include/linux/memblock.h b/include/linux/memblock.h index ca59883c83645..f3c6296285e4a 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -17,9 +17,6 @@ #include #include -#define INIT_MEMBLOCK_REGIONS 128 -#define INIT_PHYSMEM_REGIONS 4 - /* Definition of memblock flags. */ enum { MEMBLOCK_NONE = 0x0, /* No special request */ diff --git a/mm/memblock.c b/mm/memblock.c index 4b5d245fafc17..f4eb4639afce9 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -27,8 +27,15 @@ #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 + 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 @@ -41,7 +48,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 From patchwork Wed Feb 20 09:32:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 1045229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 444C801xMdz9s5R; Wed, 20 Feb 2019 20:33:04 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gwOFP-00014z-J2; Wed, 20 Feb 2019 09:32:59 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gwOFM-00012h-DA for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:56 +0000 Received: from mail-wr1-f69.google.com ([209.85.221.69]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gwOFL-0000zr-VR for kernel-team@lists.ubuntu.com; Wed, 20 Feb 2019 09:32:56 +0000 Received: by mail-wr1-f69.google.com with SMTP id e14so10191588wrt.12 for ; Wed, 20 Feb 2019 01:32:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GMrsDSUbsPveB8lnfw9+jo/weEyuBDDcaC/1uPDjAJ8=; b=OSiysumRHBTg0w2/B+10VGsCEkhZP4CIoOgEHnMVD0kNpX4r8m28pR5A/KHinRYRaA QszHxsOXeNGC0Zd3Fmwgq7GIQGJQf6IgM3XhEzy7xLPj/ZUBjKmOjcFomXaMAk5yHmIQ fKRGwZ4/zZxdxD6j18hElxQlltXtfDrGN1nlGtR/Pa0T+WhUedsrhnCUw+41f7wP5fTU ukZkMQVxAd25+CvsXvxLKCHETXkC7LCDjH/P7AuUgDOjzWCVNbk93cgS9PqPAyW1RzUu 3Bh+pBQcz8DjMTBO9OknJt433T6TPeb30TWa/bivqdC2QOjO1f80VJV1jn7bTk9oulGs w0gg== X-Gm-Message-State: AHQUAuaucYo5oWMjF81qkjeI7dIXysjPXG/rgcOuKga0pJb3lNxGuuUH YnIi3t64kJo5IlZrXUp+lXLAdR7jBPnpOeRrTYYXoR2/iFOMKYVmCqM69XiH7onmG6U4AtMT262 gCPmCiy2clfjkq2qGsreUoUChta6pkdQeAQfpV66eBA== X-Received: by 2002:adf:edca:: with SMTP id v10mr22845275wro.313.1550655175309; Wed, 20 Feb 2019 01:32:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IaoEMLTEwdr4M8xzdXSBdRKQmN14aATxppNrHtHBbWlmNY+K7XKK1Fv9eDRCY6eBhAmWJwPdw== X-Received: by 2002:adf:edca:: with SMTP id v10mr22845263wro.313.1550655174953; Wed, 20 Feb 2019 01:32:54 -0800 (PST) Received: from xps13.canonical.com ([194.204.107.10]) by smtp.gmail.com with ESMTPSA id h13sm26400196wrs.42.2019.02.20.01.32.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 01:32:54 -0800 (PST) From: dann frazier To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/4][SRU Cosmic] efi/arm: Revert "Defer persistent reservations until after paging_init()" Date: Wed, 20 Feb 2019 10:32:36 +0100 Message-Id: <20190220093236.30296-5-dann.frazier@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190220093236.30296-1-dann.frazier@canonical.com> References: <20190220093236.30296-1-dann.frazier@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ard Biesheuvel BugLink: https://bugs.launchpad.net/bugs/1816425 This reverts commit eff896288872d687d9662000ec9ae11b6d61766f, which deferred the processing of persistent memory reservations to a point where the memory may have already been allocated and overwritten, defeating the purpose. Signed-off-by: Ard Biesheuvel Acked-by: Will Deacon Cc: Linus Torvalds Cc: Marc Zyngier Cc: Mike Rapoport Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190215123333.21209-3-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar (backported from commit 582a32e708823e5957fd73ccd78dc4a9e49d21ea) [dannf: Minor offset adjustments in efi.h] Signed-off-by: dann frazier --- arch/arm64/kernel/setup.c | 1 - drivers/firmware/efi/efi.c | 4 ---- drivers/firmware/efi/libstub/arm-stub.c | 3 --- include/linux/efi.h | 7 ------- 4 files changed, 15 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index ca32a884bc7d4..952c2b1268822 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -327,7 +327,6 @@ 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 4ee1e5c13029e..989e8a208dfb6 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -584,11 +584,7 @@ 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/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index e30c26f572c25..60f202e57a607 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -100,9 +100,6 @@ void install_memreserve_table(efi_system_table_t *sys_table_arg) efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID; efi_status_t status; - if (IS_ENABLED(CONFIG_ARM)) - return; - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, sizeof(*rsv), (void **)&rsv); if (status != EFI_SUCCESS) { diff --git a/include/linux/efi.h b/include/linux/efi.h index 2290aa9380c56..ae2a65ea6017f 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1204,8 +1204,6 @@ extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused); extern bool efi_is_table_address(unsigned long phys_addr); extern void __init efi_set_secure_boot(enum efi_secureboot_mode mode); - -extern int efi_apply_persistent_mem_reservations(void); #else static inline bool efi_enabled(int feature) { @@ -1225,11 +1223,6 @@ static inline bool efi_is_table_address(unsigned long phys_addr) return false; } static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {} - -static inline int efi_apply_persistent_mem_reservations(void) -{ - return 0; -} #endif extern int efi_status_to_err(efi_status_t status);