From mboxrd@z Thu Jan 1 00:00:00 1970 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 A55833B8D57 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=1767800039; cv=none; b=EK3VLRCNcg+P0UsNu1kLdb2xf4OXgaVRgkQtkmtYNigV0hGTCsyh1B0WcvY9L1el11rG6JRt8V077Zd/VCysiwHxa6vCoO9P6IKiYG2i8NcHREv9x0zEt1UC26zbcggsTeHWr/Erh7OLZBZ8bbfJuKb3585coMMDAONzShXnMs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767800039; c=relaxed/simple; bh=Z9XPB5cChIo/t/9LU2WCPFfPnMA+oTk5cMf0x2oZ3bQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WPa1jFLGnSOvyMKh3SQpI39zo/+nzVKf458TXUVZoIPmY/3i2nLMhNl8QA5EpzKEyrQ9b7+GsUV0BnLRcftQMLRgmUvvnQMRbqPv2DHHnuRUzX/Bi7auX7BQEhGoc5eVr2Gl/72VimGi+0b40OrAnnB8A6ZPO+TvHY4DRv4YgKM= 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-450c65f3510so1426904b6e.2 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=jfpdC85U19KSFWYwyVXa9FiFSvtk33Ccuktx8V/Isp8VtU7NHZvGqlF+puKdDPXEZU bl8vFTfJn89TtIaqpYEV3OnJnSaamm6Ks4WsN5oF9b99QCGAu7ZqNugiWWlMxknGL7aG gEBFOW4kbZdegnX3sdzOyrdsw9uMepICTS+J62v/oKZP/RmjKCVR/Dk6d7rOiE2gBjAk m0lvBHo328kR3/UnD5i2YJfzZfU/+p3b8qJxBpq16ORq1pyUkqufHEpiKa7uRNPkxTZv EciRZk8T8+Chfmenuxsudj4TACMwXcw96aZIMftJHm8JFy2UH4Rg0YsfvR6erjWWvduy lp9g== X-Forwarded-Encrypted: i=1; AJvYcCVYdp4oCL9VHl8WYK1KjHCJEAjgAjGcySsXLcCO/gUPV60Qw+p30wdBsNujA3cLp/fqH69UN+vLT+Q=@vger.kernel.org X-Gm-Message-State: AOJu0YztRatOH+rmHPSgEUp9kKgSMnGL79PZ7clT+F+lOLv8nY8euc+r 4OQltcRN2QZhiJct+DOqpC4DuXgujDq2qFA4sF8L2wIpF7sH57CITfjz X-Gm-Gg: AY/fxX5PKPiOVCS0U19KwlpfWNX9nLLfonBpxzrWWFF/rFqzsCXUmxUYaAboeMuX1Ff ddt55pbPe6BVOPItofyP8gWKUa49FdrkhI8WdgdVQUY9BvfEzAlcVZasFSlPbdmTRirtHbgrZFu 9hrIdk7s+nSs4N2cqTaqZGIyJrhx4ZqvNtKNjkf4KHya97A0oWxr6bNmg6r8Q9XG6W1OI5o6esW isal6Jmo4i6jLzNXdUqFolCkuC8gt0ZpQr5h5re0Q+pz0EZ1NjXFZm5+95SwNmWxZtqpcZMk61h cX8Z6sl9NkFhtLnkQNotAR303nC4Zg2Oswkz6FsXNbJKfDbPXyBOh9c1GVd3UfMSTl15u7KC25q h5CxBa2RHVcdEiG/olGDi4P5OLur91B3Yg4wfAJwNdemO4Pf3r4um2tKlpnw1bTQjKO1t6dOvkS ejpaoW7CroVk7OoS3KhKw8naEblv2BGYg8P8MTduu7B83h 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-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; + /* Set the dax operations for fs-dax access path */ + rc = 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); } +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 = { .probe = fsdev_dax_probe, + .remove = fsdev_dax_remove, .type = DAXDRV_FSDEV_TYPE, }; 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, pgoff_t pgoff, long nr_pages, if (!dax_alive(dax_dev)) return -ENXIO; + if (!dax_dev->ops) + return -EOPNOTSUPP; + if (nr_pages < 0) return -EINVAL; @@ -207,6 +210,10 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, 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); +/** + * 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 *ops) +{ + if (ops) { + /* Setting ops: fail if already set */ + if (cmpxchg(&dax_dev->ops, NULL, ops) != NULL) + return -EBUSY; + } else { + /* Clearing ops: always allowed */ + dax_dev->ops = 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) 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 *ops); 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, -- 2.49.0