From patchwork Wed May 29 17:12:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13679310 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 09685C25B7C for ; Wed, 29 May 2024 17:15:58 +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=7jb9WYMN1MbpS0MlXTwzvC85gPRreSQJ9g3V47LkuYo=; b=H/WZhPkVu6LonD 2CwvxgpubKwXJr3jC3gBEvVew1bR7YMo0O6EWk6sJR2T6Znu6LfgERYr19jMpQ4PZv15+5sOKGJ0a /QClqxjKack+q0xJA92ZFF1Zy+c5tPfZAYC+LJkQNtbCnZdEF+aObzjD1rhsZfKj49tIUDIoV1eso 3L+oXeEyl3MHVderyAFytY+FO/dU/vysN/qsjLy4esp1jVFV1tSWiBi5JbmRq8+UwTJTaSNZElji8 tDWua/TFs2QUejS9g29VQorhCveqAUsgk7qohsblWnqyChYFT785gK7JlSpgfOOqzkb0zoIts7Cho +5DkGtwEm+LxwINik2ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCMtu-000000052MK-1oHt; Wed, 29 May 2024 17:15:46 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCMtr-000000052LQ-0NxO for linux-arm-kernel@lists.infradead.org; Wed, 29 May 2024 17:15:45 +0000 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VqGG82hwKz6K9Hp; Thu, 30 May 2024 01:14:40 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 536541400CA; Thu, 30 May 2024 01:15:41 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 29 May 2024 18:15:40 +0100 From: Jonathan Cameron To: Dan Williams , , , Sudeep Holla CC: Andrew Morton , David Hildenbrand , Will Deacon , Jia He , Mike Rapoport , , , , Yuquan Wang , Oscar Salvador , Lorenzo Pieralisi , James Morse Subject: [RFC PATCH 6/8] arm64: mm: numa_fill_memblks() to add a memblock.reserved region if match. Date: Wed, 29 May 2024 18:12:34 +0100 Message-ID: <20240529171236.32002-7-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240529171236.32002-1-Jonathan.Cameron@huawei.com> References: <20240529171236.32002-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240529_101543_504715_EB50A4B5 X-CRM114-Status: GOOD ( 13.77 ) 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 CXL memory hotplug relies on additional NUMA nodes being created for any CXL Fixed Memory Window if there is no suitable one created by system firmware. To detect if system firmware has created one look for any normal memblock that overlaps with the Fixed Memory Window that has a NUMA node (nid) set. If one is found, add a region with the same nid to memblock.reserved so we can match it later when CXL memory is hotplugged. If not, add a region anyway because a suitable NUMA node will be set later. So for now use NUMA_NO_NODE. Signed-off-by: Jonathan Cameron --- arch/arm64/mm/init.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 6a2f21b1bb58..27941f22db1c 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -50,6 +50,32 @@ #ifdef CONFIG_NUMA +/* + * Scan existing memblocks and if this region overlaps with a region with + * a nid set, add a reserved memblock. + */ +int __init numa_fill_memblks(u64 start, u64 end) +{ + struct memblock_region *region; + + for_each_mem_region(region) { + int nid = memblock_get_region_node(region); + + if (nid == NUMA_NO_NODE) + continue; + if (!(end < region->base || start >= region->base + region->size)) { + memblock_add_reserved_node(start, end - start, nid, + MEMBLOCK_RSRV_NOINIT); + return 0; + } + } + + memblock_add_reserved_node(start, end - start, NUMA_NO_NODE, + MEMBLOCK_RSRV_NOINIT); + + return NUMA_NO_MEMBLK; +} + static int __memory_add_physaddr_to_nid(u64 addr) { unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);