From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Hamza Mahfooz <hamza.mahfooz@amd.com>, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Pan, Xinhui" <Xinhui.Pan@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Mario Limonciello" <mario.limonciello@amd.com>,
"Lijo Lazar" <lijo.lazar@amd.com>,
"Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>,
"Le Ma" <le.ma@amd.com>, "André Almeida" <andrealmeid@igalia.com>,
"James Zhu" <James.Zhu@amd.com>,
"Aurabindo Pillai" <aurabindo.pillai@amd.com>,
"Joerg Roedel" <jroedel@suse.de>,
"Iwona Winiarska" <iwona.winiarska@intel.com>,
"Robin Murphy" <robin.murphy@arm.com>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH 1/3] driver core: bus: introduce can_remove()
Date: Mon, 5 Feb 2024 09:48:39 +0100 [thread overview]
Message-ID: <fe098f5a-b0b0-4698-ad8f-2d302fa37626@gmail.com> (raw)
In-Reply-To: <20240202222603.141240-1-hamza.mahfooz@amd.com>
Am 02.02.24 um 23:25 schrieb Hamza Mahfooz:
> Currently, drivers have no mechanism to block requests to unbind
> devices. However, this can cause resource leaks and leave the device in
> an inconsistent state, such that rebinding the device may cause a hang
> or otherwise prevent the device from being rebound. So, introduce
> the can_remove() callback to allow drivers to indicate if it isn't
> appropriate to remove a device at the given time.
Well that is nonsense. When you physically remove a device (e.g. unplug
it) then there is nothing in software you can do to prevent that.
Regards,
Christian.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com>
> ---
> drivers/base/bus.c | 4 ++++
> include/linux/device/bus.h | 2 ++
> 2 files changed, 6 insertions(+)
>
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index daee55c9b2d9..7c259b01ea99 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -239,6 +239,10 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
>
> dev = bus_find_device_by_name(bus, NULL, buf);
> if (dev && dev->driver == drv) {
> + if (dev->bus && dev->bus->can_remove &&
> + !dev->bus->can_remove(dev))
> + return -EBUSY;
> +
> device_driver_detach(dev);
> err = count;
> }
> diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
> index 5ef4ec1c36c3..c9d4af0ed3b8 100644
> --- a/include/linux/device/bus.h
> +++ b/include/linux/device/bus.h
> @@ -46,6 +46,7 @@ struct fwnode_handle;
> * be called at late_initcall_sync level. If the device has
> * consumers that are never bound to a driver, this function
> * will never get called until they do.
> + * @can_remove: Called before attempting to remove a device from this bus.
> * @remove: Called when a device removed from this bus.
> * @shutdown: Called at shut-down time to quiesce the device.
> *
> @@ -85,6 +86,7 @@ struct bus_type {
> int (*uevent)(const struct device *dev, struct kobj_uevent_env *env);
> int (*probe)(struct device *dev);
> void (*sync_state)(struct device *dev);
> + bool (*can_remove)(struct device *dev);
> void (*remove)(struct device *dev);
> void (*shutdown)(struct device *dev);
>
prev parent reply other threads:[~2024-02-05 8:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-02 22:25 [PATCH 1/3] driver core: bus: introduce can_remove() Hamza Mahfooz
2024-02-02 22:25 ` [PATCH 2/3] PCI: " Hamza Mahfooz
2024-02-02 23:38 ` Greg Kroah-Hartman
2024-02-02 22:25 ` [PATCH 3/3] drm/amdgpu: wire up the can_remove() callback Hamza Mahfooz
2024-02-02 22:41 ` Bjorn Helgaas
2024-02-02 23:40 ` Greg Kroah-Hartman
2024-02-06 14:29 ` Daniel Vetter
2024-02-06 18:42 ` Christian König
2024-02-09 11:00 ` Daniel Vetter
2024-02-02 23:41 ` Greg Kroah-Hartman
2024-02-02 23:38 ` [PATCH 1/3] driver core: bus: introduce can_remove() Greg Kroah-Hartman
2024-02-05 8:48 ` Christian König [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe098f5a-b0b0-4698-ad8f-2d302fa37626@gmail.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=James.Zhu@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrealmeid@igalia.com \
--cc=aurabindo.pillai@amd.com \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=hamza.mahfooz@amd.com \
--cc=iwona.winiarska@intel.com \
--cc=jroedel@suse.de \
--cc=le.ma@amd.com \
--cc=lijo.lazar@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=srinivasan.shanmugam@amd.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox