From patchwork Wed Jan 17 14:46:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 13521839 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50A66C47DA2 for ; Wed, 17 Jan 2024 14:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=87ixnfD5i9fmEFtgHWE0+X8POIb53jrx1pAXROMNeMI=; b=AeDEZ6qZemNp0Y 5AGjG56HqpSlKisWcMNOO1mPxIw5f0WQQegJ6/+rvfEnJSIuKGL9fbP9lfntuW7NbF7FmFVLBaTnH cCtK7Hbjchnqz6bZLmXuPuvv5K4xNx89MeTrHUpvKHVxTBsZsf8niZo9ug413U8zEjLFu/vgLfKwf 7AkCTHp7tdw2C9ucQWmr+ntOlCEKh1GkyciWEuNPlmFQTWuBGeZlEPpthJ7iz/3aYweoQ48ZKXlWP PLdvi7eHWnuMq8khMkLl3Iq4y0DY/q4w1r7oqTrSGDz1BYQfD+jQJWqgxENTLZ6OgCx94Zsm46xIE tcGhKxU7LkdtfNIpXl1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rQ7Cg-00HHMg-25; Wed, 17 Jan 2024 14:47:42 +0000 Received: from smtp-fw-9105.amazon.com ([207.171.188.204]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rQ7Cc-00HHHQ-11; Wed, 17 Jan 2024 14:47:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705502859; x=1737038859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jf05Sl5lvM0QZsncorT5lB2H0a51ZRNMVxi6LqgXCm8=; b=XR7LS9CU+yhQ//XYXxReq1+xHmiJg3r3smti0clb609LMTNMXxi78ZVB oOJaiIgsX8LIxYbm0U/+jmHzr+c1x3dAcpdwmxVzm16OQXFUBjdMxO/+p fLhH5R2NjnU4ftRCZq2ZAhSyI1bRqpZkm6i+6HxPW/6d4bfm+qX57p5YJ w=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="698395732" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-153b24bc.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9105.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2024 14:47:29 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-153b24bc.us-east-1.amazon.com (Postfix) with ESMTPS id 733C7C15BD; Wed, 17 Jan 2024 14:47:19 +0000 (UTC) Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:23414] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.14.60:2525] with esmtp (Farcaster) id 39c2bda5-5806-43df-98c0-f0c689dbdf36; Wed, 17 Jan 2024 14:47:18 +0000 (UTC) X-Farcaster-Flow-ID: 39c2bda5-5806-43df-98c0-f0c689dbdf36 Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 17 Jan 2024 14:47:18 +0000 Received: from dev-dsk-graf-1a-5ce218e4.eu-west-1.amazon.com (10.253.83.51) by EX19D020UWC004.ant.amazon.com (10.13.138.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 17 Jan 2024 14:47:14 +0000 From: Alexander Graf To: CC: , , , , , , , Eric Biederman , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Steven Rostedt , Andrew Morton , Mark Rutland , "Tom Lendacky" , Ashish Kalra , James Gowans , Stanislav Kinsburskii , , , , Anthony Yznaga , Usama Arif , David Woodhouse , Benjamin Herrenschmidt , Rob Herring , Krzysztof Kozlowski Subject: [PATCH v3 02/17] memblock: Declare scratch memory as CMA Date: Wed, 17 Jan 2024 14:46:49 +0000 Message-ID: <20240117144704.602-3-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240117144704.602-1-graf@amazon.com> References: <20240117144704.602-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.253.83.51] X-ClientProxiedBy: EX19D046UWA001.ant.amazon.com (10.13.139.112) To EX19D020UWC004.ant.amazon.com (10.13.138.149) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240117_064738_397013_10D6677D X-CRM114-Status: GOOD ( 17.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When we finish populating our memory, we don't want to lose the scratch region as memory we can use for useful data. Do do that, we mark it as CMA memory. That means that any allocation within it only happens with movable memory which we can then happily discard for the next kexec. That way we don't lose the scratch region's memory anymore for allocations after boot. Signed-off-by: Alexander Graf --- v1 -> v2: - test bot warning fix v2 -> v3: - s/reserve_scratch_mem/mark_phys_as_cma/ - Declare scratch memory as CMA: Remove ifdeffery - Declare scratch memory as CMA: Remove superfluous comment --- mm/memblock.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index fbb98981a202..56530d0469a8 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -1134,10 +1135,6 @@ static bool should_skip_region(struct memblock_type *type, if ((flags & MEMBLOCK_SCRATCH) && !memblock_is_scratch(m)) return true; - /* Leave scratch memory alone after scratch-only phase */ - if (!(flags & MEMBLOCK_SCRATCH) && memblock_is_scratch(m)) - return true; - return false; } @@ -2188,6 +2185,16 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end) } } +static void mark_phys_as_cma(phys_addr_t start, phys_addr_t end) +{ + ulong start_pfn = pageblock_start_pfn(PFN_DOWN(start)); + ulong end_pfn = pageblock_align(PFN_UP(end)); + ulong pfn; + + for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) + set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_CMA); +} + static unsigned long __init __free_memory_core(phys_addr_t start, phys_addr_t end) { @@ -2249,6 +2256,17 @@ static unsigned long __init free_low_memory_core_early(void) memmap_init_reserved_pages(); + if (IS_ENABLED(CONFIG_MEMBLOCK_SCRATCH)) { + /* + * Mark scratch mem as CMA before we return it. That way we + * ensure that no kernel allocations happen on it. That means + * we can reuse it as scratch memory again later. + */ + __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_SCRATCH, &start, &end, NULL) + mark_phys_as_cma(start, end); + } + /* * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id * because in some case like Node0 doesn't have RAM installed