From patchwork Mon Jan 10 21:08:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 531027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D712C433F5 for ; Mon, 10 Jan 2022 21:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343748AbiAJVI7 (ORCPT ); Mon, 10 Jan 2022 16:08:59 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:44432 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343809AbiAJVI7 (ORCPT ); Mon, 10 Jan 2022 16:08:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1641848940; x=1673384940; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MXSIRuBHoh28PI4X24VkzI5Tw/8El6+B/ZMgWJ8og94=; b=g7PTGI0Q6YKJzb4LqoB2PbgMUvywG4X+9q8Y0yjfquaZGt8EbqrNwaJg Gcu/B6X4JES0xZOFIdloBY6514iUvkkryiNobVGjWw4zwbXRbqwQkI4hW fx/Uz4NAHS6g2LOIBCKaXCz+/oIQxYYQkiggK3kanR0kD4FcAvg/DAyJj Q=; X-IronPort-AV: E=Sophos;i="5.88,278,1635206400"; d="scan'208";a="169221590" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-e823fbde.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP; 10 Jan 2022 21:08:58 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1a-e823fbde.us-east-1.amazon.com (Postfix) with ESMTPS id 6C4FFC08AB; Mon, 10 Jan 2022 21:08:57 +0000 (UTC) Received: from EX13D13UWB002.ant.amazon.com (10.43.161.21) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 10 Jan 2022 21:08:27 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D13UWB002.ant.amazon.com (10.43.161.21) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 10 Jan 2022 21:08:27 +0000 Received: from dev-dsk-fllinden-2c-d7720709.us-west-2.amazon.com (172.19.206.175) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.26 via Frontend Transport; Mon, 10 Jan 2022 21:08:27 +0000 Received: by dev-dsk-fllinden-2c-d7720709.us-west-2.amazon.com (Postfix, from userid 6262777) id 7B3F9A1; Mon, 10 Jan 2022 21:08:27 +0000 (UTC) From: Frank van der Linden To: , , , , , , , , , , , CC: , Frank van der Linden Subject: [PATCH 1/3] memblock: define functions to set the usable memory range Date: Mon, 10 Jan 2022 21:08:07 +0000 Message-ID: <20220110210809.3528-2-fllinden@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220110210809.3528-1-fllinden@amazon.com> References: <20220110210809.3528-1-fllinden@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Some architectures might limit the usable memory range based on a firmware property, like "linux,usable-memory-range" for ARM crash kernels. This limit needs to be enforced after firmware memory map processing has been done, which might be e.g. FDT or EFI, or both. Define an interface for it that is firmware type agnostic. Signed-off-by: Frank van der Linden --- include/linux/memblock.h | 2 ++ mm/memblock.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 34de69b3b8ba..6128efa50d33 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -481,6 +481,8 @@ phys_addr_t memblock_reserved_size(void); phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); +void memblock_set_usable_range(phys_addr_t base, phys_addr_t size); +void memblock_enforce_usable_range(void); void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); void memblock_mem_limit_remove_map(phys_addr_t limit); bool memblock_is_memory(phys_addr_t addr); diff --git a/mm/memblock.c b/mm/memblock.c index 5096500b2647..cb961965f3ad 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -101,6 +101,7 @@ unsigned long max_low_pfn; unsigned long min_low_pfn; unsigned long max_pfn; unsigned long long max_possible_pfn; +phys_addr_t usable_start, usable_size; static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS] __initdata_memblock; @@ -1715,6 +1716,42 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) base + size, PHYS_ADDR_MAX); } +/** + * memblock_set_usable_range - set usable memory range + * @base: physical address that is the start of the range + * @size: size of the range. + * + * Used when a firmware property limits the range of usable + * memory, like for the linux,usable-memory-range property + * used by ARM crash kernels. + */ +void __init memblock_set_usable_range(phys_addr_t base, phys_addr_t size) +{ + usable_start = base; + usable_size = size; +} + +/** + * memblock_enforce_usable_range - cap memory ranges to usable range + * + * Some architectures call this during boot after firmware memory ranges + * have been scanned, to make sure they fall within the usable range + * set by memblock_set_usable_range. + * + * This may be called more than once if there are multiple firmware sources + * for memory ranges. + * + * Avoid "no memory registered" warning - the warning itself is + * useful, but we know this can be called with no registered + * memory (e.g. when the synthetic DT for the crash kernel has + * been parsed on EFI arm64 systems). + */ +void __init memblock_enforce_usable_range(void) +{ + if (memblock_memory->total_size) + memblock_cap_memory_range(usable_start, usable_size); +} + void __init memblock_mem_limit_remove_map(phys_addr_t limit) { phys_addr_t max_addr; From patchwork Mon Jan 10 21:08:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 532377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F908C433F5 for ; Mon, 10 Jan 2022 21:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343844AbiAJVJM (ORCPT ); Mon, 10 Jan 2022 16:09:12 -0500 Received: from smtp-fw-80007.amazon.com ([99.78.197.218]:17459 "EHLO smtp-fw-80007.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343830AbiAJVJD (ORCPT ); Mon, 10 Jan 2022 16:09:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1641848944; x=1673384944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3mAfbygsmalJDceTYZOaldGWaMo2oFy/FRm2NURPlA0=; b=KS8AmUNlSStP0MSt3503WDFRbsAyFiGnY08p8xL4GUhsTjrtz366prJj e3oav2KsGQMF96ZxCUjantfZmch8kQY7zcZzl+0hi+oNwO6xGTvYd2u4U T4cEd4mbjx0tqjekZ0Mib0fNBRgt6jlnDkilI24dHkvcTcrDPOpMxq5XX M=; X-IronPort-AV: E=Sophos;i="5.88,278,1635206400"; d="scan'208";a="54264531" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-b09d0114.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP; 10 Jan 2022 21:09:03 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1a-b09d0114.us-east-1.amazon.com (Postfix) with ESMTPS id 9DB4F81162; Mon, 10 Jan 2022 21:08:58 +0000 (UTC) Received: from EX13D13UWA003.ant.amazon.com (10.43.160.181) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 10 Jan 2022 21:08:29 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D13UWA003.ant.amazon.com (10.43.160.181) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 10 Jan 2022 21:08:29 +0000 Received: from dev-dsk-fllinden-2c-d7720709.us-west-2.amazon.com (172.19.206.175) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.26 via Frontend Transport; Mon, 10 Jan 2022 21:08:28 +0000 Received: by dev-dsk-fllinden-2c-d7720709.us-west-2.amazon.com (Postfix, from userid 6262777) id 91F88A1; Mon, 10 Jan 2022 21:08:28 +0000 (UTC) From: Frank van der Linden To: , , , , , , , , , , , CC: , Frank van der Linden Subject: [PATCH 2/3] of: fdt: use memblock usable range interface Date: Mon, 10 Jan 2022 21:08:08 +0000 Message-ID: <20220110210809.3528-3-fllinden@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220110210809.3528-1-fllinden@amazon.com> References: <20220110210809.3528-1-fllinden@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Use the memblock usable range interface to set and enforce the usable memory range (if any). Signed-off-by: Frank van der Linden --- drivers/of/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 4546572af24b..b3c2a4124518 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1279,7 +1279,8 @@ void __init early_init_dt_scan_nodes(void) of_scan_flat_dt(early_init_dt_scan_memory, NULL); /* Handle linux,usable-memory-range property */ - memblock_cap_memory_range(cap_mem_addr, cap_mem_size); + memblock_set_usable_range(cap_mem_addr, cap_mem_size); + memblock_enforce_usable_range(); } bool __init early_init_dt_scan(void *params) From patchwork Mon Jan 10 21:08:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 531026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8065C433FE for ; Mon, 10 Jan 2022 21:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343834AbiAJVJN (ORCPT ); Mon, 10 Jan 2022 16:09:13 -0500 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]:51403 "EHLO smtp-fw-9103.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343832AbiAJVJE (ORCPT ); Mon, 10 Jan 2022 16:09:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1641848943; x=1673384943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YIWq81r60zfkEYgTyv+1nuUbOltX8pQmAlK88kahj7U=; b=LHO7P3IoxEdgs725qfi/x6LDvcfDDc8qkxj96nOdhYlM73sJSKBjkxUH PgdD0jsaU+cv/8CwqItycOA8QGQ2fa5dm8nrNgYRhoaZYdyDoQfiQKc7l pWqeK1E3lfXW1UoPEViz1sq2gTNroz+jkeZgj4z34dH9g3LCxYOEYTUu1 Q=; X-IronPort-AV: E=Sophos;i="5.88,278,1635206400"; d="scan'208";a="983755819" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-10222bbc.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 10 Jan 2022 21:09:01 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-10222bbc.us-east-1.amazon.com (Postfix) with ESMTPS id 478641A0040; Mon, 10 Jan 2022 21:08:59 +0000 (UTC) Received: from EX13D13UWA003.ant.amazon.com (10.43.160.181) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 10 Jan 2022 21:08:30 +0000 Received: from EX13MTAUEA002.ant.amazon.com (10.43.61.77) by EX13D13UWA003.ant.amazon.com (10.43.160.181) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 10 Jan 2022 21:08:30 +0000 Received: from dev-dsk-fllinden-2c-d7720709.us-west-2.amazon.com (172.19.206.175) by mail-relay.amazon.com (10.43.61.169) with Microsoft SMTP Server id 15.0.1497.26 via Frontend Transport; Mon, 10 Jan 2022 21:08:29 +0000 Received: by dev-dsk-fllinden-2c-d7720709.us-west-2.amazon.com (Postfix, from userid 6262777) id 92312B5F; Mon, 10 Jan 2022 21:08:29 +0000 (UTC) From: Frank van der Linden To: , , , , , , , , , , , CC: , Frank van der Linden Subject: [PATCH 3/3] efi: enforce usable memory range after reserving regions Date: Mon, 10 Jan 2022 21:08:09 +0000 Message-ID: <20220110210809.3528-4-fllinden@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220110210809.3528-1-fllinden@amazon.com> References: <20220110210809.3528-1-fllinden@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The usable memory range may be restricted through parameters that did not come from EFI, like the FDT "linux,usable-memory-range" property. Enforce this range after the EFI memory map regions have been processed. Signed-off-by: Frank van der Linden --- drivers/firmware/efi/efi-init.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/firmware/efi/efi-init.c b/drivers/firmware/efi/efi-init.c index b19ce1a83f91..280e9178c7df 100644 --- a/drivers/firmware/efi/efi-init.c +++ b/drivers/firmware/efi/efi-init.c @@ -204,6 +204,13 @@ static __init void reserve_regions(void) memblock_reserve(paddr, size); } } + + /* + * Done, filter !nomap memory we just added so that the + * usable range is enforced. This is normally only set + * for crash kernels on some architectures. + */ + memblock_enforce_usable_range(); } void __init efi_init(void)