From nobody Mon Apr 6 10:44:15 2026 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B717C391E63 for ; Sat, 21 Mar 2026 15:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774105465; cv=none; b=GrQELkKiTpFFENHwZc/fTxqL5fzpXlik9R2c/HNnOXEFl3iESi364ENwojbEkjRh6LYAERDEsnKbLD3rzJuXEujqttQm+xhYKJ/MXuhk39py5AtXKtKWJREzxZpirqpbrxeyLAiG4JGyw1sk+WOIxLN8z/RKASu8aGOp6zU4BNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774105465; c=relaxed/simple; bh=rF+DX+JfgUHRP6PxAjzMWPOUKYEy9HGwrNkxn2i6BO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KmtKL3mI5gdxuhoqUKquGGFyITgLorf5QzcGrAo9YRfHWDS4bIpDEZE2vLldUvZszUSggb4BRS60t9k2oIhI8JmYpzNzmC8rOiq9SlZt+Wk0qoF8PeczwbOi3QrsE/71wE9XcxEa8NIZE7uL99zKwcAa9ixsTuZTtVY6NLAwyFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=qWNQs8ox; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="qWNQs8ox" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8cfbbdbaf3cso280479785a.0 for ; Sat, 21 Mar 2026 08:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1774105458; x=1774710258; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9vvnYDBDYSd91JS5VlgcZ1pjC7MUK2Lw1jakydB3PHI=; b=qWNQs8oxsOzKWa5EarGQo2j3wjBilO/R0/OFgHYAIpgz/2ZAgARYiLfJx1587OCLm9 XSOf8SiejkbndGbn8ArkHqtFSYE85O4/sZ9ikG88Mt30e9g/jJ3gAHYZn1nwpfcMD4h8 7FNyqyR4vT8va25+nq92GvCnn99WuMB61DRcWpx8CX4rQj9IE4OidBrOg3kapWX61xpW GOyswXcdtR6EjaE2V1fzmdDzNQ291LGkRFo5MmG7wHcW2dVBR2Twsd/XCFpF6H1dbCCO 1owcX7Oq5aRzWJ9N6Y67x5Rocu1ATQoefJzqUaQjpd9h8IFvnwkfyH3REK5ez0tpIIDU u+gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774105458; x=1774710258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9vvnYDBDYSd91JS5VlgcZ1pjC7MUK2Lw1jakydB3PHI=; b=hziN0l+ndeQSz9LrwbuGAl2SHYZBBQ5l9wjXMUKTAtGexzXNfTEx53xahLaM/Uqm1u g/5aCrg26x+4WH4NDM3B2X5uLXttWuUHErdc4z15kUtLH4eihNept85sxWDiBu9h9Bdu 1juK5fXw18OJ/iThf3ftEyU2m+Ar8fVm01Q0CQQB0NHU6iaRWIvfInOx0T5l04Ou1xcq 43bDC8V/90tWmcjegKw5A+zizJL+epSHRLopTc+T4zwSkfjKey+QRlcYWzz4oJ0lJQCi 4fwg9r7QNYsMxTTmhpaDnd40vNVnIs4F7RPsurw1bydBoJn7KP3QJWj4ieXT0MfyDSJw O3eQ== X-Forwarded-Encrypted: i=1; AJvYcCWa+VKGHJ+FNIxjxIxmb4cdefuDFNGo0Q6mUP3ZldsXyIZQQT89nr3Wv54jgyWDbD/E4J+agh2NyC7c8Mk=@vger.kernel.org X-Gm-Message-State: AOJu0YzgpNP7DFVIJ5+4YdFaI6wRmxq7o1l4dHUV5ibPjqpP6vHi09PT +PzMzOdfDucXOaktZNpj2lft0oS9KxfZaudYvcEoUCmxdLcs4Ig7ZhdXgMGsK3DU49w= X-Gm-Gg: ATEYQzzyhDj1T5fveWO7rzN1l6ZT9M4oAjfDdfpSmFRC36N0HdIeVyTY9ieWUFyzjRC F1K7xp8Ghk6N02R3UeS+HT4TpsBGcGxQ74LsVEJSQ9vWkWOsPeZ2IkHsMAmSz6I87/w5SmJWnkN 6dbCE5tY2CMHEjN9dT0zXarin4zi7d6GfAJRfuaaoDamSSZC3Ug02wbAUpKDiq4FNfNxTyP1VFO vWfOeEr7OELX3nZhjaqm+UJYLmmaSxYAJ8Ccixwr6vTLfW9u7IlP901zKnd30pXQOJanvhUYrVA 2rvoH/7fR4MRj5FLlixUODVvKl1qm7w38iQHlmJIh1WNTQHr39SS2Rh5gH6mvxTnYuWqvQxcTPe o9/hHObtcdpYQiPnolvGddiIHINNCfceRXOZgxWE6Pxz47banNVcoumd0uaK9Vux4y50A1VTIzP 5tHuYZfi3GTDbTp/kjd8MR7j88U+PjiIBJ0dgLgceelOfW208TGO/bjZ/N7wtcOMhBL0zdkze7M LrXluZtXI2tciATy5kL+HbBaQ== X-Received: by 2002:a05:620a:410c:b0:8a6:92d1:2dae with SMTP id af79cd13be357-8cfc795a1famr877339485a.5.1774105457588; Sat, 21 Mar 2026 08:04:17 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-96-255-20-138.washdc.ftas.verizon.net. [96.255.20.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cfc90ba89fsm391979885a.40.2026.03.21.08.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 08:04:17 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, david@kernel.org, osalvador@suse.de Cc: dan.j.williams@intel.com, ljs@kernel.org, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 5/8] mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg Date: Sat, 21 Mar 2026 11:04:01 -0400 Message-ID: <20260321150404.3288786-6-gourry@gourry.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260321150404.3288786-1-gourry@gourry.net> References: <20260321150404.3288786-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Existing callers of add_memory_driver_managed cannot select the preferred online type (ZONE_NORMAL vs ZONE_MOVABLE), requiring it to hot-add memory as offline blocks, and then follow up by onlining each memory block individually. Most drivers prefer the system default, but the CXL driver wants to plumb a preferred policy through the dax kmem driver. Refactor APIs to add a new interface which allows the dax kmem and cxl_core modules to select a preferred policy. Only expose this interface to those modules to avoid confusion among existing API users and to limit usage in out-of-tree modules. Refactor add_memory_driver_managed, extract __add_memory_driver_managed - Add proper kernel-doc for add_memory_driver_managed while refactoring - New helper accepts an explicit online_type. - New help validates online_type is between OFFLINE and ONLINE_MOVABLE Refactor: add_memory_resource, extract __add_memory_resource - new helper accepts an explicit online_type Original APIs now explicitly pass the system-default to new helpers. No functional change for existing users. Cc: David Hildenbrand Cc: Oscar Salvador Cc: Andrew Morton Signed-off-by: Gregory Price --- include/linux/memory_hotplug.h | 3 ++ mm/memory_hotplug.c | 60 +++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index a8bcb36f93b8..1f19f08552ea 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -320,6 +320,9 @@ extern int __add_memory(int nid, u64 start, u64 size, m= hp_t mhp_flags); extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); extern int add_memory_resource(int nid, struct resource *resource, mhp_t mhp_flags); +int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags, + enum mmop online_type); extern int add_memory_driver_managed(int nid, u64 start, u64 size, const char *resource_name, mhp_t mhp_flags); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index af9a6cb5a2f9..9081aad5078f 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1492,10 +1492,10 @@ static int create_altmaps_and_memory_blocks(int nid= , struct memory_group *group, * * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) +static int __add_memory_resource(int nid, struct resource *res, mhp_t mhp_= flags, + enum mmop online_type) { struct mhp_params params =3D { .pgprot =3D pgprot_mhp(PAGE_KERNEL) }; - enum mmop online_type =3D mhp_get_default_online_type(); enum memblock_flags memblock_flags =3D MEMBLOCK_NONE; struct memory_group *group =3D NULL; u64 start, size; @@ -1583,7 +1583,7 @@ int add_memory_resource(int nid, struct resource *res= , mhp_t mhp_flags) merge_system_ram_resource(res); =20 /* online pages if requested */ - if (mhp_get_default_online_type() !=3D MMOP_OFFLINE) + if (online_type !=3D MMOP_OFFLINE) walk_memory_blocks(start, size, &online_type, online_memory_block); =20 @@ -1601,7 +1601,13 @@ int add_memory_resource(int nid, struct resource *re= s, mhp_t mhp_flags) return ret; } =20 -/* requires device_hotplug_lock, see add_memory_resource() */ +int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) +{ + return __add_memory_resource(nid, res, mhp_flags, + mhp_get_default_online_type()); +} + +/* requires device_hotplug_lock, see __add_memory_resource() */ int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) { struct resource *res; @@ -1629,7 +1635,15 @@ int add_memory(int nid, u64 start, u64 size, mhp_t m= hp_flags) } EXPORT_SYMBOL_GPL(add_memory); =20 -/* +/** + * __add_memory_driver_managed - add driver-managed memory with explicit o= nline_type + * @nid: NUMA node ID where the memory will be added + * @start: Start physical address of the memory range + * @size: Size of the memory range in bytes + * @resource_name: Resource name in format "System RAM ($DRIVER)" + * @mhp_flags: Memory hotplug flags + * @online_type: Auto-Online behavior (offline, online, kernel, movable) + * * Add special, driver-managed memory to the system as system RAM. Such * memory is not exposed via the raw firmware-provided memmap as system * RAM, instead, it is detected and added by a driver - during cold boot, @@ -1649,9 +1663,12 @@ EXPORT_SYMBOL_GPL(add_memory); * * The resource_name (visible via /proc/iomem) has to have the format * "System RAM ($DRIVER)". + * + * Return: 0 on success, negative error code on failure. */ -int add_memory_driver_managed(int nid, u64 start, u64 size, - const char *resource_name, mhp_t mhp_flags) +int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags, + enum mmop online_type) { struct resource *res; int rc; @@ -1661,6 +1678,9 @@ int add_memory_driver_managed(int nid, u64 start, u64= size, resource_name[strlen(resource_name) - 1] !=3D ')') return -EINVAL; =20 + if (online_type < MMOP_OFFLINE || online_type > MMOP_ONLINE_MOVABLE) + return -EINVAL; + lock_device_hotplug(); =20 res =3D register_memory_resource(start, size, resource_name); @@ -1669,7 +1689,7 @@ int add_memory_driver_managed(int nid, u64 start, u64= size, goto out_unlock; } =20 - rc =3D add_memory_resource(nid, res, mhp_flags); + rc =3D __add_memory_resource(nid, res, mhp_flags, online_type); if (rc < 0) release_memory_resource(res); =20 @@ -1677,6 +1697,30 @@ int add_memory_driver_managed(int nid, u64 start, u6= 4 size, unlock_device_hotplug(); return rc; } +EXPORT_SYMBOL_FOR_MODULES(__add_memory_driver_managed, "kmem,cxl_core"); + +/** + * add_memory_driver_managed - add driver-managed memory + * @nid: NUMA node ID where the memory will be added + * @start: Start physical address of the memory range + * @size: Size of the memory range in bytes + * @resource_name: Resource name in format "System RAM ($DRIVER)" + * @mhp_flags: Memory hotplug flags + * + * Add driver-managed memory with the system default online type set by + * build config or kernel boot parameter. + * + * See __add_memory_driver_managed for more details. + * + * Return: 0 on success, negative error code on failure. + */ +int add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags) +{ + return __add_memory_driver_managed(nid, start, size, resource_name, + mhp_flags, + mhp_get_default_online_type()); +} EXPORT_SYMBOL_GPL(add_memory_driver_managed); =20 /* --=20 2.53.0