From patchwork Thu Dec 14 07:37:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 178548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8376587dys; Wed, 13 Dec 2023 23:38:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqLOOUItYjgmE89IMpu5383whFpG3JT6pmcWDLVtCl3YFijWy7+50+RyUstqOv/EBMYBAI X-Received: by 2002:a17:902:6bc2:b0:1d0:6ffd:e2ea with SMTP id m2-20020a1709026bc200b001d06ffde2eamr8744227plt.132.1702539520018; Wed, 13 Dec 2023 23:38:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702539520; cv=none; d=google.com; s=arc-20160816; b=daqwFDurztZ+Rw7qcZtIbJANrGEdKWOS3NeYoVMoDks0G4vKmwCQbfElpshYpPyTSD hEnod6kBwLUlobbwLPmoC8/uHsVdzkHLk9wWsqFrumNPNovIB4e+tJgoX+2SarKY/hOj oh3vV7kM1Cltipbb1iEACuR8+3w654VgiEbawL0MtVveiUW5MVc6HzLcH03qbcr/S6dh YBiIHo23ugO94BizndR4ehMbcOIxoX+jkHKIPehquXVuXfBgw9AZUJHeoq2xjvdffiC/ fjw03LZrPl2VZuupoCI5xl9G+O7C1CYDWVsMXM0vDplM1YwsiZP7aKIqC4WxQPOGdMi/ y15g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=fh20T2gB/B6w0dTGtnuH7g/9myiyWlxtGzmDSKX8rWg=; fh=sl/ePOXhMBHViO3TWdUhfhoSGyyi7lxtVvoNUwzQSs4=; b=zRDKD0vKmWAiAKm4N8SgW81BFq9YYbvyf/fXgJ0enj95G9syFMOhLbm75e+MBOzvrr iKXrucoX+bowNi9U/znd6cUOvV4Ql7i8iGG+6RfNqE8zj3GGwOdJxuR+5TvKLdRsBJHi 0jxB9RsiclpTffkOFKghfJ93HZH32HExtYzufcHKjHL144kwoi0fuDDPzCqg4jvDbSND Dmq9uQeKajPklCZte2kO5f546fg9RNQeSpm/bODOmvAEeSEE9aq3BcP1G/MoYYGvK9oD viZhLeT9MYPLLW7w+5IgvTlOxOcnG4bedmvENOQBKV5EUEa9S5P3e5ZQPyupVUJGSs1V xGrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NR65oHmK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id p4-20020a170902b08400b001d35084ea00si2324293plr.395.2023.12.13.23.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 23:38:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NR65oHmK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6EFC4801B6F5; Wed, 13 Dec 2023 23:38:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443393AbjLNHiQ (ORCPT + 99 others); Thu, 14 Dec 2023 02:38:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235496AbjLNHiI (ORCPT ); Thu, 14 Dec 2023 02:38:08 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 103E810C; Wed, 13 Dec 2023 23:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702539495; x=1734075495; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=VTyAcMOb3p9TMnLFpPQVGZqQ3IoF/IW/eEzVelz5aSE=; b=NR65oHmKWkxWVng0q57WPxqK++qQv3W7WInG1m4wQPtZKAwlRsPpgKpI r3jONdZiEnbI7VW1BsLK522unvj8r3d92XzYEPxA/E5asvTTQdkaRSjYR Y4ZXZH7qgn6qn8LBzGAzhDjqW8PJhyxVKx7O0bLkQNqFz+1JiZfWGQBkC ordgTx7LsRmGV+wh3j+MBu6DVYLAHPmGtEYWd1NpNHNWE+R/Ci9ntXZOz kvdqGcb3Xj+aYk8gLHvWDKyJTMfm/O3EqebonNkTcnNZXARbT8Qrz09+w hjcs0zxPoMTD7vl2BrxLkHj2+0/8xvskBV3pvbKnqLtg0bhuD6lUKUj/l w==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="481275530" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="481275530" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="723972068" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="723972068" Received: from llblake-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.213.191.124]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 23:38:13 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 00:37:56 -0700 Subject: [PATCH v5 3/4] mm/memory_hotplug: export mhp_supports_memmap_on_memory() MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v5-3-3f7b006960b4@intel.com> References: <20231214-vv-dax_abi-v5-0-3f7b006960b4@intel.com> In-Reply-To: <20231214-vv-dax_abi-v5-0-3f7b006960b4@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Oscar Salvador Cc: linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , linux-mm@kvack.org, Michal Hocko X-Mailer: b4 0.13-dev-433a8 X-Developer-Signature: v=1; a=openpgp-sha256; l=4625; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=VTyAcMOb3p9TMnLFpPQVGZqQ3IoF/IW/eEzVelz5aSE=; b=owGbwMvMwCXGf25diOft7jLG02pJDKlVGx4pb98Uu1/qmbru9H/PH6bM1J0/7UV3iMK//UUCo ZtfqC/k7ihlYRDjYpAVU2T5u+cj4zG57fk8gQmOMHNYmUCGMHBxCsBEUiMYGVbuX/Wr9FcXs9aM oDlX6jRyr1fI/1s065G+YX6fQ+ehP6sYGV4/iDWrnHaq9Xa2THW3oGnTxgemL7ds3qmhVXMi5Nu BHB4A X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 23:38:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785242079665138101 X-GMAIL-MSGID: 1785242079665138101 In preparation for adding sysfs ABI to toggle memmap_on_memory semantics for drivers adding memory, export the mhp_supports_memmap_on_memory() helper. This allows drivers to check if memmap_on_memory support is available before trying to request it, and display an appropriate message if it isn't available. As part of this, remove the size argument to this - with recent updates to allow memmap_on_memory for larger ranges, and the internal splitting of altmaps into respective memory blocks, the size argument is meaningless. Cc: Andrew Morton Cc: David Hildenbrand Cc: Michal Hocko Cc: Oscar Salvador Cc: Dan Williams Cc: Dave Jiang Cc: Dave Hansen Cc: Huang Ying Suggested-by: David Hildenbrand Signed-off-by: Vishal Verma Acked-by: David Hildenbrand --- include/linux/memory_hotplug.h | 6 ++++++ mm/memory_hotplug.c | 17 ++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 7d2076583494..ebc9d528f00c 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -121,6 +121,7 @@ struct mhp_params { bool mhp_range_allowed(u64 start, u64 size, bool need_mapping); struct range mhp_get_pluggable_range(bool need_mapping); +bool mhp_supports_memmap_on_memory(void); /* * Zone resizing functions @@ -262,6 +263,11 @@ static inline bool movable_node_is_enabled(void) return false; } +static bool mhp_supports_memmap_on_memory(void) +{ + return false; +} + static inline void pgdat_kswapd_lock(pg_data_t *pgdat) {} static inline void pgdat_kswapd_unlock(pg_data_t *pgdat) {} static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {} diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 926e1cfb10e9..751664c519f7 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1325,7 +1325,7 @@ static inline bool arch_supports_memmap_on_memory(unsigned long vmemmap_size) } #endif -static bool mhp_supports_memmap_on_memory(unsigned long size) +bool mhp_supports_memmap_on_memory(void) { unsigned long vmemmap_size = memory_block_memmap_size(); unsigned long memmap_pages = memory_block_memmap_on_memory_pages(); @@ -1334,17 +1334,11 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) * Besides having arch support and the feature enabled at runtime, we * need a few more assumptions to hold true: * - * a) We span a single memory block: memory onlining/offlinin;g happens - * in memory block granularity. We don't want the vmemmap of online - * memory blocks to reside on offline memory blocks. In the future, - * we might want to support variable-sized memory blocks to make the - * feature more versatile. - * - * b) The vmemmap pages span complete PMDs: We don't want vmemmap code + * a) The vmemmap pages span complete PMDs: We don't want vmemmap code * to populate memory from the altmap for unrelated parts (i.e., * other memory blocks) * - * c) The vmemmap pages (and thereby the pages that will be exposed to + * b) The vmemmap pages (and thereby the pages that will be exposed to * the buddy) have to cover full pageblocks: memory onlining/offlining * code requires applicable ranges to be page-aligned, for example, to * set the migratetypes properly. @@ -1356,7 +1350,7 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) * altmap as an alternative source of memory, and we do not exactly * populate a single PMD. */ - if (!mhp_memmap_on_memory() || size != memory_block_size_bytes()) + if (!mhp_memmap_on_memory()) return false; /* @@ -1379,6 +1373,7 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) return arch_supports_memmap_on_memory(vmemmap_size); } +EXPORT_SYMBOL_GPL(mhp_supports_memmap_on_memory); static void __ref remove_memory_blocks_and_altmaps(u64 start, u64 size) { @@ -1512,7 +1507,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) * Self hosted memmap array */ if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) && - mhp_supports_memmap_on_memory(memory_block_size_bytes())) { + mhp_supports_memmap_on_memory()) { ret = create_altmaps_and_memory_blocks(nid, group, start, size); if (ret) goto error;