Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1013446rdb; Fri, 22 Dec 2023 11:36:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf9fgj2oGhuvjJy38tvIy2mz8vTr6JTVxI1nQN6O7gin4o3G2KSQ1rYUFuxUzdx1kVI/4A X-Received: by 2002:a05:620a:51cd:b0:77f:ad35:dc33 with SMTP id cx13-20020a05620a51cd00b0077fad35dc33mr2076690qkb.65.1703273814748; Fri, 22 Dec 2023 11:36:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703273814; cv=none; d=google.com; s=arc-20160816; b=LOCtoqA1lkbVPM8U9wshj7Y8dD7cUyPf5T4SoTgXfb4GSCVRHBUYM86MbfHcylc9JE E+2/LRr1/jC9dkUGr78FZLINRUXNB35EByRYo+Nes8/9uwySj29Wcal37IUvtghMkwm1 9v6vy6tUBBz2/MRUuIIvyETx9dPHgdJTaPDA0j6FW+/j5j28hC+4hE7rXUdpSm/9qSbP eNcVApQPKSy6f+5P55iVrgWa8GeKHhz6F0WUFboKT6OxHX10OuGIOmxHh8ZfrVkQBfVR E/HpLU6z5aLXYLQi3AD69jOKoimwzD0k59PH5TKPT3czSeD9Rhxk3Ye32+BhspxdFF5X DQKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=V6Ou6SwquM+raA1qs66DJzmcDcyVj924rceIRas5lS8=; fh=xprWcyUKTLi4rhte7gFCvduD673j12awuFkCPnYDQVY=; b=AvEUY7K9JXvqXEvyGwpS76OrivVs3374QeAvZM5kRXnmEWoSeKJN5FUagHStipcIZh 8EB1BUEccHZaTE0RkUMOB99o3uZWhXLLkJnlEGUxCPd7ih09wKNHnokB6Vt/PxGelP5f rsxRak/1o/XV4ZNp6MNxmuGPzVCLXtZmEq1Gxnt3SmeKmi88hvnKGLLMa/jYP/VnkmlX dB0l9el+bJEj3/6hQQhWFBjiKdq9UUz9onkqT8l9ySKkU18ebdQ67sV7bN/ftT9/Go2w +LqykOjGUyOnA0cW0EW4w9hN5YKxnKMRztrqhJRq++aSLVHbW7AAVqvnh/6TIW2JmheD SxcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=fK8T2oo1; spf=pass (google.com: domain of linux-kernel+bounces-10016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qr16-20020a05620a391000b0077f74ccf008si5157823qkn.478.2023.12.22.11.36.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 11:36:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=fK8T2oo1; spf=pass (google.com: domain of linux-kernel+bounces-10016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 722D81C22908 for ; Fri, 22 Dec 2023 19:36:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE9B82E82E; Fri, 22 Dec 2023 19:36:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fK8T2oo1" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3F572C84B; Fri, 22 Dec 2023 19:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1703273797; x=1734809797; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V6Ou6SwquM+raA1qs66DJzmcDcyVj924rceIRas5lS8=; b=fK8T2oo1NrusDyl9JTVbXJW76JITugWDsgjqinDOoBbi9PxWyyiMZfJ3 q5FyXj/DzwLKJUE4SDlEKW/uHZv+dFSNU/WmVl+RcBV9Oz1O/W0cFBOYX JUWMFT/XBoC8LQtAEpTJ6Hxv4YjKYOQl61OkrH+TTMRzgXVKsdoxY+P9R k=; X-IronPort-AV: E=Sophos;i="6.04,297,1695686400"; d="scan'208";a="261444389" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 19:36:34 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com (Postfix) with ESMTPS id 9FF3949A6D; Fri, 22 Dec 2023 19:36:22 +0000 (UTC) Received: from EX19MTAUWB002.ant.amazon.com [10.0.21.151:35389] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.24.220:2525] with esmtp (Farcaster) id 9ed8fb9a-78f6-45ad-a602-e555218674d3; Fri, 22 Dec 2023 19:36:21 +0000 (UTC) X-Farcaster-Flow-ID: 9ed8fb9a-78f6-45ad-a602-e555218674d3 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; Fri, 22 Dec 2023 19:36:21 +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; Fri, 22 Dec 2023 19:36:17 +0000 From: Alexander Graf To: CC: , , , , , , , Eric Biederman , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Rob Herring" , Steven Rostedt , "Andrew Morton" , Mark Rutland , "Tom Lendacky" , Ashish Kalra , James Gowans , Stanislav Kinsburskii , , , , Anthony Yznaga , Usama Arif , David Woodhouse , Benjamin Herrenschmidt Subject: [PATCH v2 02/17] memblock: Declare scratch memory as CMA Date: Fri, 22 Dec 2023 19:35:52 +0000 Message-ID: <20231222193607.15474-3-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231222193607.15474-1-graf@amazon.com> References: <20231222193607.15474-1-graf@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D035UWA004.ant.amazon.com (10.13.139.109) To EX19D020UWC004.ant.amazon.com (10.13.138.149) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- mm/memblock.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index e89e6c8f9d75..3700c2c1a96d 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -1100,10 +1101,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; } @@ -2153,6 +2150,20 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end) } } +#ifdef CONFIG_MEMBLOCK_SCRATCH +static void reserve_scratch_mem(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) { + /* Mark as CMA to prevent kernel allocations in it */ + set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_CMA); + } +} +#endif + static unsigned long __init __free_memory_core(phys_addr_t start, phys_addr_t end) { @@ -2214,6 +2225,17 @@ static unsigned long __init free_low_memory_core_early(void) memmap_init_reserved_pages(); +#ifdef 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) + reserve_scratch_mem(start, end); +#endif + /* * 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 -- 2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879