From nobody Sun Feb 8 17:55:10 2026 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 B87512BB17 for ; Thu, 15 Jan 2026 02:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444983; cv=none; b=jIJ9+kjwnRf8zuV2E0pa7a9gJXshmF74JN0MA/MFZBIvhNPIXVZTTgV/2JFmNf1pV9ba38DbMOMtl5+BHzPhNj9ugQWn9OkaLnVhdZqJWC+wrfHGKt3wQ5NFdfrQjE+h3iVEWpx07sz62ThFAHe6cUULCMCNotNx+snV/UqdTwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444983; c=relaxed/simple; bh=fDcOEzdBe5xRENpKlXhSuHOhCSlbP++yhs6h6KsFKQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ADbrPE9OctEJK52hrp3n8bt3ai6B8eny1lMzEWjGnSiZgLCMjPWwOpcx0f5Ec5vR1FtXUOXhlWOfy/M5+oF9y+jq0Sr5Vqz/rNgdALgs/y6T56+eY700nu3rLh1kD1YDEgvO2LNNCn+kbNtqq0nizyt+U4woL9SYud699gE8MuU= 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=Us9t87d/; arc=none smtp.client-ip=209.85.160.177 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="Us9t87d/" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-5013c1850bdso4203591cf.0 for ; Wed, 14 Jan 2026 18:43:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1768444980; x=1769049780; 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=qcW/hY6JWQg4aPWEmrNXUmJDtQucQInwfAPavQZW27U=; b=Us9t87d/dhJEqXczgG1WsOAfkTeSyLmXACYX/1WdL3flk9o/yhwqBfeotEvTE9SDbN v7g4s7P1Jamensj/GW1tCYt0ZWoP84t3/hlvPDpdGxI2Obwgd/M9nBIIdMK2K16DRqrf utAll/OhHARLVpSRdHoN/WQq/3Dhq12kfNiFB/6x3+GLCFKE8Gqc2KeDsga7Lq+a8U5Z WLeMfgTnCbNyBxxub+fc2wZei8Op12Y8m13/MM1coamo6MGcl2kM3bh0pAU5vpUiQiN3 zGYOXqxXEF49tK749g+92sfXJ73JBE7WXD15srYy+35Vgz7/c3JaKIDGcz00XkV/jJMH PR6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768444980; x=1769049780; 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=qcW/hY6JWQg4aPWEmrNXUmJDtQucQInwfAPavQZW27U=; b=RJVyGqdowB0d5/Gy4uHBN6cuLi7XYHDuiofDs1n/HjU6gsDkBfgIVPOIe+P5abq3lj b0PVqH6wVm/zHLyjCS5O+K4TFRQQ3xfbTT93pmnEPGg/5iBS0JsmztH+dk+tsI6B5uaO bNgUZBdnUnRb5j4r5lDsgyvGxLN9wfLe9r35rIQsIquXjZpIAZfJI2iWlmutkweM+KRp /ek634WwnAF02MGYuJw2WN/YJaoWudqOsZmYGFU91Y3kf6LilYRNsUB1dEErmZ7rKIIm jo3nyN3Z/51AH2VPprETBD+37oLXA238/dZrtUXlrzLhm2wmzOEogmJP62aOW0smeSJc tJ6g== X-Forwarded-Encrypted: i=1; AJvYcCUZfXml/MYsTiUynGAB+KBiSqcDhLOU+x7xaxaSqGZinsrn+P8Q+FdmM8482jJ9qRH8srfXPL2NvVOZQ1g=@vger.kernel.org X-Gm-Message-State: AOJu0YxyUesVtj3AytEF4isCFanc0EQ70TdR1NSQaJtjdM81J5lYJAh8 MHDlaY538rQeDnxktkRRkprVMwAja9lImUYOFpsOn7e3SLwIm6lObiEubQ+W6qwmq0o= X-Gm-Gg: AY/fxX4ss5yR+fwaWMxuST32prEc8WIkgFge+f6BOXm+57HTQC5nOYi7UKXJDtscdjT uL85hRXqd/VvTnIl3mrQaYiQPfTFyiL0SZhOiCn/M3bxKJ5iYEMlIQekiDIO7OjVJYAd7hLoKD3 A+ADpMA8aIkZTAc9yT9wpkYBoXMJUoC/RkfyuTduSt/myoI3aEgRf72VMuqIBT1yMZIxqk1nifr u1rugSooQR0pLSQ3LH2ehq4MOGdRoCgoi4dptJny9huZ1ZPF+efTam1znCpBM5cPNnbcX9iaxGQ 3ZmlSqzX4DpJsuvdooa0qHizwVuwqMPSl4cmM3SEAwt32ckSjTSs8klDRSNYmQtUDKlCQxWgEzJ 6bjv83SVsVtUJZX1Svo1Q+P95ofAvpgZOeraaNt9Z9RbCZ+kD2TNTgwFqyoExfS0dcwUoTUKikH dAKHP4HJCI6RBpOY6/VEVOnf/3zipPpoHDq9XROJp9cu2mfpCs2XzJb7N2ZYsMaOmMY5gmEMQbL xE= X-Received: by 2002:a05:622a:1f11:b0:4ee:4a3a:bd05 with SMTP id d75a77b69052e-5014849d291mr69984841cf.74.1768444979611; Wed, 14 Jan 2026 18:42:59 -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-50148ee050esm26853761cf.30.2026.01.14.18.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 18:42:59 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, kernel-team@meta.com, dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, david@kernel.org, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, osalvador@suse.de, akpm@linux-foundation.org Subject: [PATCH] dax/kmem: add build config for protected dax memory blocks Date: Wed, 14 Jan 2026 21:42:22 -0500 Message-ID: <20260115024222.3486455-1-gourry@gourry.net> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260114235022.3437787-6-gourry@gourry.net> References: <20260114235022.3437787-6-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" Since this protection may break userspace tools, it should be an opt-in until those tools have time to update to the new daxN.M/hotplug interface instead of memory blocks. Suggested-by: Dan Williams Signed-off-by: Gregory Price --- drivers/dax/Kconfig | 18 ++++++++++++++++++ drivers/dax/kmem.c | 29 ++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig index d656e4c0eb84..cc13c22eb8f8 100644 --- a/drivers/dax/Kconfig +++ b/drivers/dax/Kconfig @@ -78,4 +78,22 @@ config DEV_DAX_KMEM =20 Say N if unsure. =20 +config DEV_DAX_KMEM_PROTECTED + bool "Protect DAX_KMEM memory blocks being changed" + depends on DEV_DAX_KMEM + default n + help + Prevents actions from outside the KMEM DAX driver from changing + DAX KMEM memory block states. For example, the memory block + sysfs functions (online, state) will return -EBUSY, and normal + calls to memory_hotplug functions from other drivers and kernel + sources will fail. + + This may break existing memory block management patterns that + depend on offlining DAX KMEM blocks from userland before unbinding + the driver. Use this only if your tools have been updated to use + the daxN.M/hotplug interface. + + Say N if unsure. + endif diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index f3562f65376c..094b8a51099e 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -184,6 +184,21 @@ static int dax_kmem_memory_notifier_cb(struct notifier= _block *nb, return NOTIFY_BAD; } =20 +static int dax_kmem_register_notifier(struct dax_kmem_data *data) +{ + if (!IS_ENABLED(DEV_DAX_KMEM_PROTECTED)) + return 0; + data->mem_nb.notifier_call =3D dax_kmem_memory_notifier_cb; + return register_memory_notifier(&data->mem_nb); +} + +static void dax_kmem_unregister_notifier(struct dax_kmem_data *data) +{ + if (!IS_ENABLED(DEV_DAX_KMEM_PROTECTED)) + return; + unregister_memory_notifier(&data->mem_nb); +} + /** * dax_kmem_do_hotplug - hotplug memory for dax kmem device * @dev_dax: the dev_dax instance @@ -563,13 +578,9 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) if (rc < 0) goto err_resources; =20 - /* Register memory notifier to block external operations */ - data->mem_nb.notifier_call =3D dax_kmem_memory_notifier_cb; - rc =3D register_memory_notifier(&data->mem_nb); - if (rc) { - dev_warn(dev, "failed to register memory notifier\n"); + rc =3D dax_kmem_register_notifier(data); + if (rc) goto err_notifier; - } =20 /* * Hotplug using the system default policy - this preserves backwards @@ -595,7 +606,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return 0; =20 err_hotplug: - unregister_memory_notifier(&data->mem_nb); + dax_kmem_unregister_notifier(data); err_notifier: dax_kmem_cleanup_resources(dev_dax, data); err_resources: @@ -619,7 +630,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax) =20 device_remove_file(dev, &dev_attr_hotplug); dax_kmem_cleanup_resources(dev_dax, data); - unregister_memory_notifier(&data->mem_nb); + dax_kmem_unregister_notifier(data); memory_group_unregister(data->mgid); kfree(data->res_name); kfree(data); @@ -640,7 +651,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax) struct dax_kmem_data *data =3D dev_get_drvdata(dev); =20 device_remove_file(dev, &dev_attr_hotplug); - unregister_memory_notifier(&data->mem_nb); + dax_kmem_unregister_notifier(data); =20 /* * Without hotremove purposely leak the request_mem_region() for the --=20 2.52.0