From nobody Sun Feb 8 23:42:20 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 7EAA9279903 for ; Thu, 15 Jan 2026 02:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444776; cv=none; b=RKW87TyXtB9sgna6JxnyMNfMb8wH2C2U/Xappf2WVfWl0AALBFXXzo9c7Q1CZt8u82zzlTPrINsX85zV/kH3V+kenKH1nk8/dwA/mibTBIw6ni53IPBQM16CQ+oQj5iab0JXYd/eBzvAIK+lYtgtF49rQvf5YmHwf+0bEJbSq2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444776; c=relaxed/simple; bh=fDcOEzdBe5xRENpKlXhSuHOhCSlbP++yhs6h6KsFKQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lYC3nVO5VEYJwp0QKjJbzjUctHxrRmjybftjboj0DglgOC3Vf3yHU5nUGUMpIwq8gyhP/HTobx5gYtEt0hjZhx0hIZxbTT69rnXyIn/NszWTaYPDEf+HLMtU85YPex2KA+ClhIHc3hHaj8E1Z5AoyYIGXFdfVASAWWTrz2xtwPs= 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=D4tR96jG; arc=none smtp.client-ip=209.85.222.172 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="D4tR96jG" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-8c5389c3d4cso49945885a.3 for ; Wed, 14 Jan 2026 18:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1768444773; x=1769049573; 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=D4tR96jGkAEt6CS91cRfxd9RmJ0fEgzUczJ/yYtzWhmhSzLPUMn9RY/jcWjH64S57u AmbNiYlrZoE8PWCcqTBvxzrFNdnP1oLXD+Wfz7NN8xvUVzGjrG07MsSU6AJq0Y7qdj+m 7FLAPuIr4McuQHkzvyK2xaqXU6kIP3AnlLzB2St24xfOfalNlAG453fmOtlIvPAg+hj4 95PSsQXbtthVIToKIZU1KwrMUk32Dq7pPuFf0tNaYJ2Lktrqw5mosNQ3sTXeahkRZpP2 BlyR3dvrWRf/b/f7mq6Cacg14PIHraK00s1fd+MJFD1qLI5KZ5E1SCcLPt5O7JgG/RGX umAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768444773; x=1769049573; 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=UxV60ptmWNMktb3L3VT5xOjyi9hJQrkr8KdOFR5Sm9AO0HR7mgH2g9ctGTkLxfb1Ll 8y6zwpW39bJhpgPGSQvhBwH7RpxghK/8J8sld+Cq5wNuiwxjZWN4bdMbFH6QpyO2SVb1 mQyU6Bsk+bnAv+re531ouvzKmcKhOCA+g6skhQ6ntdLeYILs4ivoV1Mz518SdNiL1AhO 7HlfnVb6jKsbw9VM4RwE5+PminorHdWNPfc5FHMj+83+wX43hro9whXqKXa7D/dDWb4H UFiAh1Qt4pLl/phohgtqlVTQtZoNCGoEwPWz4fQMpREWHtWDtOufBwWZeAHUSjvW6Bzu WStg== X-Forwarded-Encrypted: i=1; AJvYcCWu48cisI56pHoP9qRkn1X+3ooIQB7Y5YJDbbpPegv8ws/BEHDB6UueWw3rTUTQxj7SPF8Aql03CeOo5pI=@vger.kernel.org X-Gm-Message-State: AOJu0YwXhiVa8IKS16GfAL+iTYWkM/vm2iRncb7SUZqVdKldYszTP1DM jPH3zDGneZXvHCByMxhYRP0C/O7DLbmadzZ09z2I3mWht4a9Q7XTYY9ArktPD+i76I894ABFzgy w1im/yOo= X-Gm-Gg: AY/fxX5lbq6v6U1w9/6ZYK9fFdhKpBYnSMWk9lLA1AMr3qDe6ZppRSEOF6g53AqBxGP U6SckLmqk6YGuQwnYiKSv/gk41syxoDjL0fAQsdTvak2b9oBBTeE07Hki+XlefjFynj+Uml6rxE g3FFLmlXW+1L0nYq9CZj+I8vDQnCvZVbX6TtKhk3mpk6JY8VJBjBmZLCyLNBdxq92PgF7TPFSfZ K06PSR3aSI95SSNxxvTeeKBpzzS8Ox0FyfVK71eJPt3fU1FCPqjvFh8AvPwWkKo1WzhHHgZOJ1Q 83Oba8QU6a4zij3t1h87CYVEqISBXDPGug7Ny/J4ria8zk5uK7ZpRfhkfaXXFE2oXz5dTGPMJkF q/0jkW/nLV9p02k0v/dy0RAj6C/HQkfzkaxfUTt4VDp4oQ7J1SUNeElV3e7ZpIYQncuOs7x0TKZ gxXf6uXuUXZW3WZjI5l3E7HFj/b+0EDDV7Ssf/zjOL055x+2LEW5mnwuQb5O3/YaNOKOUqsR+fs 7Q= X-Received: by 2002:a05:622a:400b:b0:4ee:1f22:3613 with SMTP id d75a77b69052e-5014a96778amr49477661cf.62.1768444773152; Wed, 14 Jan 2026 18:39:33 -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-50148ee050esm26777371cf.30.2026.01.14.18.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 18:39:32 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: kernel-team@meta.com, linux-kernel@vger.kernel.org, Dan Williams Subject: [PATCH] dax/kmem: add build config for protected dax memory blocks Date: Wed, 14 Jan 2026 21:38:54 -0500 Message-ID: <20260115023854.3484175-1-gourry@gourry.net> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251113145815.2926823-1-gourry@gourry.net> References: <20251113145815.2926823-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" 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