From nobody Mon Feb 9 10:28:24 2026 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 456CE318EFC for ; Wed, 7 Jan 2026 15:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767800045; cv=none; b=KdUifTUOEbZlaZAxPeQlWrtz9RTaDtSy+M8meEM8cUV+80Ze3CHQMnR1i3KRBO102zlyWxUaWpbmqpTmsA/2lN2Bl5/l+M9nXWl6wRjMVD0XWymFfY0mF4DoyK8NZZIj0nVZ3ARXb0o54fF39IzanJqCrKPkNU1OnJFcyoUtVbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767800045; c=relaxed/simple; bh=PyiR4akbn2AeaAQOQjDM80GGb6TmVA/W+ehpX5bfLv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t5bX1kUwsk1NCocQgLvDhDGctHkYRDdVOWmyi8tfc3asT3v++G6JHSxMXf3qSrlaMvM9tczzGHRydlwsGYJ+wuAeClx3ojEAcXj97VZ0bLGzowS3PhJqxeaIapo/kcV2ND2xOu4SFYvawpY4D7oLbRwVggI1RXrh2tEz0Y50R+Q= 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=ZJhZzofs; arc=none smtp.client-ip=209.85.167.169 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="ZJhZzofs" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-455a461ab6eso929648b6e.2 for ; Wed, 07 Jan 2026 07:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767800042; x=1768404842; 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=rU7mq0TXsreClp5X76nq6lsunavYv2TLFlf9O5dybH4=; b=ZJhZzofsdnRTqpnyYlsDKwYBdEOS0/pCw8mia1ef9vH+uS06XmJlIPH9JpZQgCs3Kt ihKbx8+lT3CenybuDOeJD6Az1nsGSSNadf0WQcFok1FPFTjl+nRXr+gWYtJzOPJ3s/KT UmryE8hYvgNMo0q8LYR7SHGOcadrOPeWAo6JPJ5DKJlsvw5oXzP+GF/Zf+htc9TDn0sg LFvzrDGg2mfzMm0TyQxJnfv9Wnw2/J0qVg/A9b4v9LH6w708jzN5EzZLxbEUTnkqg3bs pncLMUaGjHDH9o8bqsMWs/mKZL0e+9hjzRn2l0UmWQbM7jbwSI8rtapRTsKqfSBrdb9L h42w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767800042; x=1768404842; 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=rU7mq0TXsreClp5X76nq6lsunavYv2TLFlf9O5dybH4=; b=GnmcL0X+EokBq1BupgEHudUZKczbId/VsNJpKCrik5IqEhU/zuQP3gOBEFdga/xLTQ mzK1cfMrBM+QngSxeVCaeS6OW06W0RXuuTETLI6PuHSPaQmObr7pSfrLnD5Xr1aQ/qjG iICPaoSmDxIHwKmapLXn0GYaZlG6E2DVq+rxl5+7cdMIWzuFF6QrxbzX+Fb9GDWjHuxJ A3m/BqSR7nAjqzEMHKK9XzTjsM++/wK+tGqim9x4SehMsG5/Tvhe1meS0HHRI4I2dZQi y+oFKwg++S8hUsqBcyQZXH8O+9VqACM8ZQokPBxjtHlk7YIuBCnHrMoZkhzR7kXpsHhi 3Pzw== X-Forwarded-Encrypted: i=1; AJvYcCVSHWdAxHmdh3U8geN6aXDLjb8QyPOsJhdDj+LUHoSgjIs8cZ/MQ6GMLox0dTefAag4L98nI9UY7cXCckg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3gsGZ5YPzfMG0G4oP9y4PuKpY/nutMzYMqqtPlondnRup5ZFL T1NZCiwlxR+PyQxkclZpuURvpzVpX0g7tl6X0HuX5Aqhb9rNjdMm3B3G X-Gm-Gg: AY/fxX4OIfgekPSoK6HcB2if/vKdCa/9vdKkCjzJAV+n/ei+Iwdu3Cm5lm1BGdy5FUz WXg+MHrMIOJ/X0+CejGCKVITmm/CRB+TG4AhjpwfRnydFIRYMvHozWEati8/EwvQmXpCrfsAiKE ip83jp97tzUVazy0QIg8NaHo/RXO4HIHNt7jdjAogttUPngELHN04VnkuWROIvI2Sk/2gZkdMSZ n/zmxR8YN5bWb6Gql+Sc+9DlE2kRJumMIaKaZKl04NXq5Fi7D5E2/HJZO2YzeHiNnT7c9x9pQsI tHHkADxqVJQRXjQVeiGfpdWTBq5m/LAy1WBVkknf4z0Bbqv9XGQbKCZd1ExGBEaW/D34JaJPhVX eCsjAkJixnmpNtOxLUBYphCDLwvNAYC0xENv2zQkowHCQM3zK/AI9CeYX+fF852tO+zS7nzolkK v3bqRhn2H61WgGH65t+LN2TKahV6+ypyDEWn3LTnWda5FczAAJnmrtPLY= X-Google-Smtp-Source: AGHT+IGGuPhuNMGxMH3hMywT/xZMd9I63HO5XzGofyUeNCfHY8A9ec2ffaSkWkYNbPyHpjuffbFtfA== X-Received: by 2002:a05:6808:1188:b0:455:7da6:44d5 with SMTP id 5614622812f47-45a6bdaf691mr1055246b6e.27.1767800041948; Wed, 07 Jan 2026 07:34:01 -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.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 07 Jan 2026 07:34:01 -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 07/21] dax: prevent driver unbind while filesystem holds device Date: Wed, 7 Jan 2026 09:33:16 -0600 Message-ID: <20260107153332.64727-8-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 Add custom bind/unbind sysfs attributes for the dax bus that check whether a filesystem has registered as a holder (via fs_dax_get()) before allowing driver unbind. When a filesystem like famfs mounts on a dax device, it registers itself as the holder via dax_holder_ops. Previously, there was no mechanism to prevent driver unbind while the filesystem was mounted, which could cause some havoc. The new unbind_store() checks dax_holder() and returns -EBUSY if a holder is registered, giving userspace proper feedback that the device is in use. To use our custom bind/unbind handlers instead of the default ones, set suppress_bind_attrs=3Dtrue on all dax drivers during registration. Signed-off-by: John Groves --- drivers/dax/bus.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6e0e28116edc..ed453442739d 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -151,9 +151,61 @@ static ssize_t remove_id_store(struct device_driver *d= rv, const char *buf, } static DRIVER_ATTR_WO(remove_id); =20 +static const struct bus_type dax_bus_type; + +/* + * Custom bind/unbind handlers for dax bus. + * The unbind handler checks if a filesystem holds the dax device and + * returns -EBUSY if so, preventing driver unbind while in use. + */ +static ssize_t unbind_store(struct device_driver *drv, const char *buf, + size_t count) +{ + struct device *dev; + int rc =3D -ENODEV; + + dev =3D bus_find_device_by_name(&dax_bus_type, NULL, buf); + if (dev && dev->driver =3D=3D drv) { + struct dev_dax *dev_dax =3D to_dev_dax(dev); + + if (dax_holder(dev_dax->dax_dev)) { + dev_dbg(dev, + "%s: blocking unbind due to active holder\n", + __func__); + rc =3D -EBUSY; + goto out; + } + device_release_driver(dev); + rc =3D count; + } +out: + put_device(dev); + return rc; +} +static DRIVER_ATTR_WO(unbind); + +static ssize_t bind_store(struct device_driver *drv, const char *buf, + size_t count) +{ + struct device *dev; + int rc =3D -ENODEV; + + dev =3D bus_find_device_by_name(&dax_bus_type, NULL, buf); + if (dev) { + rc =3D device_driver_attach(drv, dev); + if (!rc) + rc =3D count; + } + put_device(dev); + return rc; +} +static DRIVER_ATTR_WO(bind); + static struct attribute *dax_drv_attrs[] =3D { &driver_attr_new_id.attr, &driver_attr_remove_id.attr, + &driver_attr_bind.attr, + &driver_attr_unbind.attr, NULL, }; ATTRIBUTE_GROUPS(dax_drv); @@ -1591,6 +1643,7 @@ int __dax_driver_register(struct dax_device_driver *d= ax_drv, drv->name =3D mod_name; drv->mod_name =3D mod_name; drv->bus =3D &dax_bus_type; + drv->suppress_bind_attrs =3D true; =20 return driver_register(drv); } --=20 2.49.0