From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (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 807C036B041 for ; Wed, 14 Jan 2026 21:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768426538; cv=none; b=jC0zHbfNzEaFKg+dU63QnJ67E+6ZglAFwMN63UWqGIgMsEr/JeOVIo/zdrF5Y5Heu5Vg0EiTr7/PFD25dH5rtL1qj+Xb4drMhRMe+2/Ayf3ptLMzKt9RPTQf7tUhbxmNZIY9XboTNn0J9MyXWMNC8oi37qIum1mmwxcyhp1BdD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768426538; c=relaxed/simple; bh=Ifuf2L6wRVVt+3qNeBjdLicdVJ8UNwMl/Wbxz9ngJzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bgyRrnaURkHe8LejOXIFC2FCvC3nOLclxv5EyGq4HONtOh+he/p3YydVWrNdhPim6hwQgA+z5ElvpnDtKmkVnOOGRWDVGDBX8AEHopzBrLSvYaQOvxSsGQ6XiaI9IRrl/apYwKsDO8A1nIO/E2ZK5Uys9Uy1c8SmGtcDRPIcqLY= 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=nKJXNjXR; arc=none smtp.client-ip=209.85.160.41 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="nKJXNjXR" Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-40413188553so161802fac.1 for ; Wed, 14 Jan 2026 13:35:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768426530; x=1769031330; 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=TPBFShXog0UoyhMxz+wxzMnblXj48CNmW7x9zXtvk2c=; b=nKJXNjXRM8Zliu8M/KlKk+1v4a5LztVfsrmeTshpcfOHC4ohxwT2cEW7Pvdew6pRp3 dEXNgPpUsx1XuR//IznBqqrQARbPwqtfplUOfCV2DrnwzUguBGCMKTR+g/+eKr5tBcxM L392xxXOFaEQWBsCdvBcGlPzw+memAaxndcxwYaFlnpSTf3ElWsS/zOz+G3I3Fno9WJh I0H0IE1Nbc/ErD1kV/J2c6lM5mSMKJDpMTmYukzE643qXnwnwOhZ+dk9yjPQXT/v70XQ BOnUOZlr2+13spvb9+cqJFm9Z/Qx8DaFEvclYCWNxwVgY0It5MJ2nsI/cHUUQ46bkmkK oI1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768426530; x=1769031330; 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=TPBFShXog0UoyhMxz+wxzMnblXj48CNmW7x9zXtvk2c=; b=nI8RPFVoqawrTjwAzyyqP/58Ednmt8LCqNhPaJhajzBClkzaTW40GTNVKWej1vUOKx LVgWgPWrc85fVw5f0UCxzs/ie9rEyxfLpA+OB1mQTdr3SMYY+Dpm7dXkKIj0jTWRRb8t gbHkslZFFTpRT0PGWaXiUbnBD95NYoJirz5AzNsct2NH0FhrUfPpJniVqvzmdasrKfqU /XJE//Qslx35leQFObrWe6IGiBXLg/hd7sPEHxwyvt9h0YpDW41w0l1iegogIMayf+7U 1jkQgaKxMondFIfQpatOSZscihjODKo8Rl/wAOmBGEe+gjW30s3bxvuNKURz1Ab2nE9z DVkg== X-Forwarded-Encrypted: i=1; AJvYcCUOYxW/1RtfqTumKMjk2WOG8fCTSD4qLxWUk3VmcZg/TKDSM9StJxRYo9bHcAAbqBnVLVCBNw4oE2Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxPwLJrUdB/KcaYbADWKN8yXmD0y4SP92XdYEw201KP1NIiu+L+ aDyOx0JHQrN+Lcqw3+87J9kXx6DFQ3+vIDMQcAfw6cV3M5KjkLQYUH6a X-Gm-Gg: AY/fxX5gkqlT3AxKeHYTMnEX3T6Ps1IUsKPR7Iqn1BMnRNhfBREha9es085YjMyfNU8 94KGg2c7Db+oTOHu4JqViIOBRTkyWV3Ct/sugueKlNGTjteNYcpbDPtcf1KFGBexL9TioL7ScWu K5lQVRJwTFYnhxZ9JIisjtSugrTVoR8bvSV9YJ8ySBDmLvn7zx19RU8LIw2svHXUEwrgpw6TnRp Cu93EWn7nBtChxshw0u2aOin44NpwDKEm5e4S5ortR0xei0abtzoEFfgTPC7B4bkJwyN649Cfkg Lb18bY7yNhowQtyCFf4D6NaOuSGbrST02CFtdLlP55pR+uA0sjEfLfn1o9LVz3aOmcgmJF+3yfz 2P0bEaZj7nIXM4UvSRLZPrxa7u93vxa7trKcNdIg3qqSrUXOGM6YS7doGcVXoXuZDoVN35Ay6Al oj0oLkXV4BrscMmT0dm07P9CdZ7/cIFw9tmCX6Pbw4EmXo X-Received: by 2002:a05:6871:8b0b:b0:404:1da3:8005 with SMTP id 586e51a60fabf-4041da384acmr1095432fac.54.1768426530025; Wed, 14 Jan 2026 13:35:30 -0800 (PST) Received: from localhost.localdomain ([2603:8080:1500:3d89:4c85:2962:e438:72c4]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-3ffa50721a6sm17707178fac.10.2026.01.14.13.35.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 14 Jan 2026 13:35:29 -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 , 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 Subject: [PATCH V4 06/19] dax: Add dax_set_ops() for setting dax_operations at bind time Date: Wed, 14 Jan 2026 15:31:53 -0600 Message-ID: <20260114213209.29453-7-john@groves.net> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260114213209.29453-1-john@groves.net> References: <20260114153133.29420.compound@groves.net> <20260114213209.29453-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 Add a new dax_set_ops() function that allows drivers to set the dax_operations after the dax_device has been allocated. This is needed for fsdev_dax where the operations need to be set during probe and cleared during unbind. The fsdev driver uses devm_add_action_or_reset() for cleanup consistency, avoiding the complexity of mixing devm-managed resources with manual cleanup in a remove() callback. This ensures cleanup happens automatically in the correct reverse order when the device is unbound. Signed-off-by: John Groves --- drivers/dax/fsdev.c | 16 ++++++++++++++++ drivers/dax/super.c | 38 +++++++++++++++++++++++++++++++++++++- include/linux/dax.h | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/dax/fsdev.c b/drivers/dax/fsdev.c index f58c88de7a4d..d658942b7143 100644 --- a/drivers/dax/fsdev.c +++ b/drivers/dax/fsdev.c @@ -114,6 +114,13 @@ static void fsdev_kill(void *dev_dax) kill_dev_dax(dev_dax); } +static void fsdev_clear_ops(void *data) +{ + struct dev_dax *dev_dax = data; + + dax_set_ops(dev_dax->dax_dev, NULL); +} + /* * Page map operations for FS-DAX mode * Similar to fsdax_pagemap_ops in drivers/nvdimm/pmem.c @@ -296,6 +303,15 @@ 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; + + rc = devm_add_action_or_reset(dev, fsdev_clear_ops, dev_dax); + if (rc) + return rc; + run_dax(dax_dev); return devm_add_action_or_reset(dev, fsdev_kill, dev_dax); } 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 fe1315135fdd..5aaaca135737 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -247,6 +247,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.52.0