From nobody Mon Feb 9 14:32:35 2026 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.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 A560B3B8D58 for ; Wed, 7 Jan 2026 15:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767800040; cv=none; b=GqJs4oJp2qbbtP+VcrobFpOjns8hJgB6XDdxaxAzcsSdxDtK39H5U3cN5MXBOmFDu/WH+W6EE7vpQ/7V0Wa4zrBOxiwEqwd6/AnGfJqAG2WKmT16kxQm9RF1qElJaJSD5x11CbJZintUYzh/a71KmY7ko58BTtZ8QuXgxJ6KjRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767800040; c=relaxed/simple; bh=Z9XPB5cChIo/t/9LU2WCPFfPnMA+oTk5cMf0x2oZ3bQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QMPFfovgymNrXwmcyTKxSU1NUU7tLGnTuKwnFGxxx/E4Lf0NLMI7JRqrJSfA58rgBkxBQVBT/ZGcHRVrA04j7xBDff/E5W4/gZEAYpVlpqMR+J32tiaj+fl7PvZKAfkjHGRSU5DqDKW0j5Re84WX10AHXgMW3vuN+jKKLr6PSXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=Groves.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jYZfh877; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=Groves.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jYZfh877" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-450b3f60c31so1049240b6e.3 for ; Wed, 07 Jan 2026 07:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767800036; x=1768404836; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=OlFXJUauQcVO7MpBSFt3XLVu48darYU11J/SZXzaKDg=; b=jYZfh877RReMmfFRD6GWP3bQzt1ANjBRZGVIUOLvyUfx9OnJZG/H1IeyRu+MhrLzRQ 23u/9qutVr5C00CfshrsMxHls3MQCfG1ReI2Gst4aqyPyo9sQ7Um/VmitCMnFh+QXkR3 FfY+GEqtWmwwLT8/zv/57whvbIV4yGUyJ60GtUA0//hbmft6k4TzTWzOxboL/aT2u18f +jc9RgK9PyGsaygo3mSg61TGLX1gvq/mTe5UhBk3cK4HcBWCYOjhS9CQ7ccWC5rR3tKH KPGAI3jaBPT14jjTxP8bwsB6RQwX/3Y9Ont8y49DbY1RD0VA5BGNqnLzgDzT08BNWTPx 2oNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767800036; x=1768404836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OlFXJUauQcVO7MpBSFt3XLVu48darYU11J/SZXzaKDg=; b=mczOpHU8Yy+YO6j1Fo7KfO+VZvBqng9TnNUMyAJK8pEvNe0cQ5u49JXkBNXGOtedEx jjbknD2jEgD/eKsnABTwPmPbwZ4at/LYKc27sKvSmk6nqzpKCwbEbLJKO8gLuftJWYpg QvDYPUp1t27KDaxReHkNTxOqs/GqUoq3gF1PL0hd9Jomp27Q0KuSKBdrPrOjXq5oPxMd THa3m1I0RlBhthSZ2A00UM2xONd1LvIGz9ag6gTvaXBz5Tl/0YoKRNAewZOqoQx2ONq4 10Xb+hZLBowvB+fYjZc89ZulNVgNXVEs1BBotH0u4ZB37WDwmWxiXUc6Xxn+KK1nPGwm Bgjg== X-Forwarded-Encrypted: i=1; AJvYcCU9iaL6EBX5h8Y7r7SlN1NisH+iCPk+DAjaCA1/GKJCDCPEJhqmtRMhuc5LkiJQ6JphsCkOebIPXqqi2BE=@vger.kernel.org X-Gm-Message-State: AOJu0YyGBbUSFVOvzVh0raqAmlk7+xFMbuoE0yYzlv6cz4Cx5avVOZ2O 9Y4iGJAvFkg5WwVtdEZyMj79Gy88x7DXd1b8napmEOvlIRZjxdEmAHmA X-Gm-Gg: AY/fxX6v7sytF03i8IZ4GhrtQ8pRYj4+xozcvrWsAXn8CtEb+mjBvLKfwYdCyzMGZ/T r7oU8gUgE2A+uhnKb+Df/djzgwS4gAkG64soBXcPqg8m2i65PwdfyUkP9UO8vtcB8BmTcVJAWpl Rd4gKbfN4gy7axmbulpNznoBXB8EBFk9Zpk5AC5eo2OS/+X+XQNdMcAalPCMMDPuSUwS54TymCv iIqgn/1TvxTawXsYQM0ODdOzVut0LCkwzHNI0Ku8D5WU2rzEePMYG5ceSg7BtQLj6kJ7EHhq7rN bVyfoSdmZqUDL56uF+tdHX0TTTS0To5JzVSMwIsep565C3XTfHIc+j19mYs/1lm+cdA2KRjoUtq YWeO9rwZhmyq4x+1lybj6YIp5Z4EAUYC+jMDlx3GMCjUyQL3Wi2QqGFeW6/Z/3WX91j9aF7ziiq fnnNZ9J51y13Ben/MPK1rIA4jUbfJi9zpBDr+R5RbrL2HS X-Google-Smtp-Source: AGHT+IGZ+SYDHTTG5p48tl+QB5iPnahkcLty5U9a8Qi/hJOxw+cPuomkuu2gZKHVriePbcQqcWrLVA== X-Received: by 2002:a05:6808:221e:b0:43f:7287:a5de with SMTP id 5614622812f47-45a6bdfb427mr1080778b6e.41.1767800036459; Wed, 07 Jan 2026 07:33:56 -0800 (PST) Received: from localhost.localdomain ([2603:8080:1500:3d89:a917:5124:7300:7cef]) by smtp.gmail.com with ESMTPSA id 5614622812f47-45a5e2f1de5sm2398106b6e.22.2026.01.07.07.33.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 07 Jan 2026 07:33:56 -0800 (PST) Sender: John Groves From: John Groves X-Google-Original-From: John Groves To: John Groves , Miklos Szeredi , Dan Williams , Bernd Schubert , Alison Schofield Cc: John Groves , Jonathan Corbet , Vishal Verma , Dave Jiang , Matthew Wilcox , Jan Kara , Alexander Viro , David Hildenbrand , Christian Brauner , "Darrick J . Wong" , Randy Dunlap , Jeff Layton , Amir Goldstein , Jonathan Cameron , Stefan Hajnoczi , Joanne Koong , Josef Bacik , Bagas Sanjaya , Chen Linxuan , James Morse , Fuad Tabba , Sean Christopherson , Shivank Garg , Ackerley Tng , Gregory Price , Aravind Ramesh , Ajay Joshi , venkataravis@micron.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, John Groves Subject: [PATCH V3 05/21] dax: Add dax_set_ops() for setting dax_operations at bind time Date: Wed, 7 Jan 2026 09:33:14 -0600 Message-ID: <20260107153332.64727-6-john@groves.net> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260107153332.64727-1-john@groves.net> References: <20260107153244.64703-1-john@groves.net> <20260107153332.64727-1-john@groves.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" From: John Groves The dax_device is created (in the non-pmem case) at hmem probe time via devm_create_dev_dax(), before we know which driver (device_dax, fsdev_dax, or kmem) will bind - by calling alloc_dax() with NULL ops, drivers (i.e. fsdev_dax) that need specific dax_operations must set them later. Add dax_set_ops() exported function so fsdev_dax can set its ops at probe time and clear them on remove. device_dax doesn't need ops since it uses the mmap fault path directly. Use cmpxchg() to atomically set ops only if currently NULL, returning -EBUSY if ops are already set. This prevents accidental double-binding. Clearing ops (NULL) always succeeds. Signed-off-by: John Groves --- drivers/dax/fsdev.c | 12 ++++++++++++ drivers/dax/super.c | 38 +++++++++++++++++++++++++++++++++++++- include/linux/dax.h | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/dax/fsdev.c b/drivers/dax/fsdev.c index 9e2f83aa2584..3f4f593896e3 100644 --- a/drivers/dax/fsdev.c +++ b/drivers/dax/fsdev.c @@ -330,12 +330,24 @@ static int fsdev_dax_probe(struct dev_dax *dev_dax) if (rc) return rc; =20 + /* Set the dax operations for fs-dax access path */ + rc =3D dax_set_ops(dax_dev, &dev_dax_ops); + if (rc) + return rc; + run_dax(dax_dev); return devm_add_action_or_reset(dev, fsdev_kill, dev_dax); } =20 +static void fsdev_dax_remove(struct dev_dax *dev_dax) +{ + /* Clear ops on unbind so they aren't used with a different driver */ + dax_set_ops(dev_dax->dax_dev, NULL); +} + static struct dax_device_driver fsdev_dax_driver =3D { .probe =3D fsdev_dax_probe, + .remove =3D fsdev_dax_remove, .type =3D DAXDRV_FSDEV_TYPE, }; =20 diff --git a/drivers/dax/super.c b/drivers/dax/super.c index c00b9dff4a06..ba0b4cd18a77 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -157,6 +157,9 @@ long dax_direct_access(struct dax_device *dax_dev, pgof= f_t pgoff, long nr_pages, if (!dax_alive(dax_dev)) return -ENXIO; =20 + if (!dax_dev->ops) + return -EOPNOTSUPP; + if (nr_pages < 0) return -EINVAL; =20 @@ -207,6 +210,10 @@ int dax_zero_page_range(struct dax_device *dax_dev, pg= off_t pgoff, =20 if (!dax_alive(dax_dev)) return -ENXIO; + + if (!dax_dev->ops) + return -EOPNOTSUPP; + /* * There are no callers that want to zero more than one page as of now. * Once users are there, this check can be removed after the @@ -223,7 +230,7 @@ EXPORT_SYMBOL_GPL(dax_zero_page_range); size_t dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *iter) { - if (!dax_dev->ops->recovery_write) + if (!dax_dev->ops || !dax_dev->ops->recovery_write) return 0; return dax_dev->ops->recovery_write(dax_dev, pgoff, addr, bytes, iter); } @@ -307,6 +314,35 @@ void set_dax_nomc(struct dax_device *dax_dev) } EXPORT_SYMBOL_GPL(set_dax_nomc); =20 +/** + * dax_set_ops - set the dax_operations for a dax_device + * @dax_dev: the dax_device to configure + * @ops: the operations to set (may be NULL to clear) + * + * This allows drivers to set the dax_operations after the dax_device + * has been allocated. This is needed when the device is created before + * the driver that needs specific ops is bound (e.g., fsdev_dax binding + * to a dev_dax created by hmem). + * + * When setting non-NULL ops, fails if ops are already set (returns -EBUSY= ). + * When clearing ops (NULL), always succeeds. + * + * Return: 0 on success, -EBUSY if ops already set + */ +int dax_set_ops(struct dax_device *dax_dev, const struct dax_operations *o= ps) +{ + if (ops) { + /* Setting ops: fail if already set */ + if (cmpxchg(&dax_dev->ops, NULL, ops) !=3D NULL) + return -EBUSY; + } else { + /* Clearing ops: always allowed */ + dax_dev->ops =3D NULL; + } + return 0; +} +EXPORT_SYMBOL_GPL(dax_set_ops); + bool dax_alive(struct dax_device *dax_dev) { lockdep_assert_held(&dax_srcu); diff --git a/include/linux/dax.h b/include/linux/dax.h index 74e098010016..3fcd8562b72b 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -246,6 +246,7 @@ static inline void dax_break_layout_final(struct inode = *inode) =20 bool dax_alive(struct dax_device *dax_dev); void *dax_get_private(struct dax_device *dax_dev); +int dax_set_ops(struct dax_device *dax_dev, const struct dax_operations *o= ps); long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_= pages, enum dax_access_mode mode, void **kaddr, unsigned long *pfn); size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void = *addr, --=20 2.49.0