From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 DE77826FD9A for ; Sun, 22 Feb 2026 08:50:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771750232; cv=none; b=SP/lArTrAJGv9JkzHCk485KcXy+Ep2Cepaw6eYRTW0m3OIQ+/T7SqRw7R4DdaO9oKvC6ITcqXnxs7T98oMcXvAt6rShvLx4pHSHksXTF886pEmP098oEYXyKZN/YOg6XtX6T8yj1EJddFTJqdoRZjwlePQi1IqUXs4wPxsj1Qs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771750232; c=relaxed/simple; bh=LTHce9XCprcQ3/di/gbA4Gz5ydpF6pXfobVwEVYqdmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HiGCyUEqykFI5V7rsH7rc3920ftbHy7Pq7efrri7mi+0T1jP+Y5xy4yNAIldpTJW7yEQVwd0hU0yrp5G4VqpPd0uGPWOKkvGrP87/D3c8YqzN87YvJXO8Vu3DiJpG8ndDvo1KVkQqSGRlugmc0I8dQN++otRhVkT6WK2rvMQ50M= 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=qQzn8wGy; arc=none smtp.client-ip=209.85.160.169 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="qQzn8wGy" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-506a7bbe9d0so29137741cf.0 for ; Sun, 22 Feb 2026 00:50:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1771750230; x=1772355030; 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=kpwyVnUix8AlXytS75zE0sxhDRGKImtyt6+A2dtIhcc=; b=qQzn8wGypHBzLW4Uv+gCP4SrBkgnRwhcH8aVi6VpUz0rYGH5K5Op6ObFAZMCy/hKG4 IF2l2D+aC6DiUjYA+dXUz12bkohB6WVJ9KilXWvrudH2x63/+n5/kIjCF1rnOuS451Dl NR2NRVae0M0uRwGylEqv4n1HEPqW9alDiUxUF5PhsIP78R3gIdlR2q/ofpqnxsCBNaOV 0p7sAbVDF+51/+fLa+9/+bSbAX/4cuapT8tOLvuAlPG7Fl2fEnlbAFQ4DCXVQpzmcoCf KpqxIXfdm95BmhWji5H3lKfzj5onm0Hmezuhi9d0mCWrMEFDiRgaKjG0lIQF45G4ftpc B/sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771750230; x=1772355030; 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=kpwyVnUix8AlXytS75zE0sxhDRGKImtyt6+A2dtIhcc=; b=uzxz+w3NVlnBdEUWUnqRrIexxtOzUY5WGKIvInpgXMBqlZrIv49baa3eOSo8KwWUbV S68nxMVq9aR9PXF43Y8/c/7GNXjfE0Jntmy7fM6c4njKSxSpFAiiKCEJHIpI28r10g4F rAGUhM/zoo2cLw3tv/Yc4sKWL7E+uoosW03J2EZXb/u0hRVgNhzYMfK3BOY+ptJJ4Tbe axuGOXDFKdGKyeiaru9NkcME29/T32c/clIX1SRGp0OSxLdU03/jh7IMF6IKnrtwATb3 zAVrvCkqkydQrv+JiXY3Zh2PDusQoGlkOx/kI3/IIemd6nazfJWLQHrbWtg2a8G3xMuf iWyA== X-Forwarded-Encrypted: i=1; AJvYcCUuJnU2UX1BBOkNljhpx/TdGT5jEIIj0CWUMgQnZPLOoW5FpI46fvpOXjVMfdNT3OkSDkTKObkinaVrUqXnIEL6U7g=@vger.kernel.org X-Gm-Message-State: AOJu0YxoxxFazFtGRvi1XgRYfY+5EzdfD6Ql2/mfum6rJ6XPy0zX4lIY 29zk9WYcB2tPwIMbFNzIOsv3zhxLzSd3RatIjmHkcPLW78HUReUi7pNthBVGUq+vaiQ= X-Gm-Gg: AZuq6aJGNU6XUXjJ9P7Q64hEAYICAW+Im10H3Ks9JT+qaES6rPJ5uqPMUtKzWb71HGu tZmBJSXplL8cUVsm9X1kdwRuHHTtUOUGAbmv9xJy8C2Ej4ZDbEz51KNb4MbhLXIPD5itnag4MUj qx1IKGLSgJ9PFiI8mA2nkCoh66OpDhsLSwK4GCrv1FfGzeE1Avmkkbh0xi2dQHAjQ/caMl6DwrP jlOO/8eJHtUVFLs7M8MwPzmFCc8o6/Djti9ajsvjAC3bOrJV+FRSPXxWoWjx0xbm2Mkq1ds34FX cid54WZXsbLj+loftnDXbpEnV7BHMziO6fjD27/l3S92kOO2aPUP1UN/nLe+6TtsDUVTIYhPIo4 H+3oN2GYW/t9ldJ5HNH+oNbxVrybFm40ijSnq1e5l6z8YHmtBSsPIEgH61wtsmp4ygEMMrop85R VouwxsJ59ErwdvTLtegUI/MWCqDfwygw0cdP+wGB0gc4FQeJstJmrhybL+Fy1xfdK6TtXTlghlw rWmBE2exi0j8aI= X-Received: by 2002:ac8:7fc5:0:b0:506:6f78:e091 with SMTP id d75a77b69052e-5070bc91781mr65950941cf.60.1771750229747; Sun, 22 Feb 2026 00:50:29 -0800 (PST) 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 d75a77b69052e-5070d53f0fcsm38640631cf.9.2026.02.22.00.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Feb 2026 00:50:28 -0800 (PST) From: Gregory Price To: lsf-pc@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, damon@lists.linux.dev, kernel-team@meta.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com, longman@redhat.com, akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, osalvador@suse.de, ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, yury.norov@gmail.com, linux@rasmusvillemoes.dk, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, jackmanb@google.com, sj@kernel.org, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, muchun.song@linux.dev, xu.xin16@zte.com.cn, chengming.zhou@linux.dev, jannh@google.com, linmiaohe@huawei.com, nao.horiguchi@gmail.com, pfalcato@suse.de, rientjes@google.com, shakeel.butt@linux.dev, riel@surriel.com, harry.yoo@oracle.com, cl@gentwo.org, roman.gushchin@linux.dev, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, zhengqi.arch@bytedance.com, terry.bowman@amd.com Subject: [RFC PATCH v4 25/27] cxl/core: Add private node support to cxl_sysram Date: Sun, 22 Feb 2026 03:48:40 -0500 Message-ID: <20260222084842.1824063-26-gourry@gourry.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260222084842.1824063-1-gourry@gourry.net> References: <20260222084842.1824063-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Extend the cxl_sysram region to support N_MEMORY_PRIVATE hotplug via add_private_memory_driver_managed(). When a caller passes private=true to devm_cxl_add_sysram(), the memory is registered as a private node, isolating it from normal allocations and reclaim. Signed-off-by: Gregory Price --- drivers/cxl/core/core.h | 2 +- drivers/cxl/core/region_sysram.c | 50 +++++++++++++++++++++++++------- drivers/cxl/cxl.h | 9 ++++-- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 973bbcae43f7..8ca3d6d41fe4 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -56,7 +56,7 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); -int devm_cxl_add_sysram(struct cxl_region *cxlr, enum mmop online_type); +int devm_cxl_add_sysram(struct cxl_region *cxlr, bool private, enum mmop online_type); #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, diff --git a/drivers/cxl/core/region_sysram.c b/drivers/cxl/core/region_sysram.c index 47a415deb352..77aaa52e7332 100644 --- a/drivers/cxl/core/region_sysram.c +++ b/drivers/cxl/core/region_sysram.c @@ -85,12 +85,23 @@ static int sysram_hotplug_add(struct cxl_sysram *sysram, enum mmop online_type) /* * Ensure that future kexec'd kernels will not treat * this as RAM automatically. + * + * For private regions, use add_private_memory_driver_managed() + * to register as N_MEMORY_PRIVATE which isolates the memory from + * normal allocations and reclaim. */ - rc = __add_memory_driver_managed(sysram->mgid, - sysram->hpa_range.start, - range_len(&sysram->hpa_range), - sysram_res_name, mhp_flags, - online_type); + if (sysram->private) + rc = add_private_memory_driver_managed(sysram->mgid, + sysram->hpa_range.start, + range_len(&sysram->hpa_range), + sysram_res_name, mhp_flags, + online_type, &sysram->np); + else + rc = __add_memory_driver_managed(sysram->mgid, + sysram->hpa_range.start, + range_len(&sysram->hpa_range), + sysram_res_name, mhp_flags, + online_type); if (rc) { remove_resource(res); kfree(res); @@ -108,10 +119,23 @@ static int sysram_hotplug_remove(struct cxl_sysram *sysram) if (!sysram->res) return 0; - rc = offline_and_remove_memory(sysram->hpa_range.start, - range_len(&sysram->hpa_range)); - if (rc) - return rc; + if (sysram->private) { + rc = offline_and_remove_private_memory(sysram->numa_node, + sysram->hpa_range.start, + range_len(&sysram->hpa_range)); + /* + * -EBUSY means memory was removed but node_private_unregister() + * could not complete because other regions share the node. + * Continue to resource cleanup since the memory is gone. + */ + if (rc && rc != -EBUSY) + return rc; + } else { + rc = offline_and_remove_memory(sysram->hpa_range.start, + range_len(&sysram->hpa_range)); + if (rc) + return rc; + } if (sysram->res) { remove_resource(sysram->res); @@ -257,7 +281,8 @@ static void sysram_unregister(void *_sysram) device_unregister(&sysram->dev); } -int devm_cxl_add_sysram(struct cxl_region *cxlr, enum mmop online_type) +int devm_cxl_add_sysram(struct cxl_region *cxlr, bool private, + enum mmop online_type) { struct cxl_sysram *sysram __free(put_cxl_sysram) = NULL; struct memory_dev_type *mtype; @@ -291,6 +316,11 @@ int devm_cxl_add_sysram(struct cxl_region *cxlr, enum mmop online_type) if (online_type >= 0) sysram->online_type = online_type; + /* Set up private node registration if requested */ + sysram->private = private; + if (private) + sysram->np.owner = sysram; + dev = &sysram->dev; rc = dev_set_name(dev, "sysram_region%d", cxlr->id); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 8e8342fd4fde..54e5f9ac59dc 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -619,6 +620,8 @@ struct cxl_dax_region { * @mgid: Memory group id * @mtype: Memory tier type * @numa_node: NUMA node for this memory + * @private: true if this region uses N_MEMORY_PRIVATE hotplug + * @np: private node registration state (valid when @private is true) * * Device that directly performs memory hotplug for CXL RAM regions. */ @@ -633,6 +636,8 @@ struct cxl_sysram { int mgid; struct memory_dev_type *mtype; int numa_node; + bool private; + struct node_private np; }; /** @@ -987,7 +992,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); struct cxl_sysram *to_cxl_sysram(struct device *dev); struct device *cxl_sysram_dev(struct cxl_sysram *sysram); -int devm_cxl_add_sysram(struct cxl_region *cxlr, enum mmop online_type); +int devm_cxl_add_sysram(struct cxl_region *cxlr, bool private, enum mmop online_type); int cxl_sysram_offline_and_remove(struct cxl_sysram *sysram); u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); #else @@ -1011,7 +1016,7 @@ static inline struct cxl_sysram *to_cxl_sysram(struct device *dev) { return NULL; } -static inline int devm_cxl_add_sysram(struct cxl_region *cxlr, +static inline int devm_cxl_add_sysram(struct cxl_region *cxlr, bool private, enum mmop online_type) { return -ENXIO; -- 2.53.0