From: "zhangzekun (A)" <zhangzekun11@huawei.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: <linux-kernel@vger.kernel.org>, <rafael.j.wysocki@intel.com>,
<regressions@lists.linux.dev>, <tj@kernel.org>,
<alex.williamson@redhat.com>, <chenjun102@huawei.com>,
Greg KH <gregkh@linuxfoundation.org>
Subject: Re: Possible hungtask issue will be introduced with device_lock() in uevent_show()
Date: Mon, 27 Jan 2025 11:27:01 +0800 [thread overview]
Message-ID: <7b535c35-9aeb-4a60-ab42-438f70835137@huawei.com> (raw)
In-Reply-To: <6791a45f711e2_9b922948@dwillia2-mobl3.amr.corp.intel.com.notmuch>
> Hi Zekun,
>
> If you have some cycles to help investigate the replacement fix that
> would be much appreciated.
>
> So far I came up with this:
>
> http://lore.kernel.org/172790598832.1168608.4519484276671503678.stgit@dwillia2-xfh.jf.intel.com
>
> ...but have not had time to debug the 0day report.
>
> My worry is still that Linux has long since shipped the expectation that
> reading 'uevent' bounces the device_lock() which, among other things,
> makes sure that any in-flight driver probing has completed.
>
> The report of USB devices disappearing is consistent with a udev
> operation failing due to the driver not being done attaching, or
> something similar.
>
> So even though you have not seen any issues, I suspect small differences
> in the devices on your system and the reporter's system, or udev rule
> differences could result in a failure to trigger the regression.
>
>
Hi, Dan
The patch trys to prevent the potential dead lock by letting
device_lock() gets before kernfs_get_active(), but I think it might not
be enough to solve all the potential dead lock. The device_lock() will
be held while removing the driver in device_release_driver(), which
means will be held through driver's .remove(). If .remove() is waiting
for resources to be released by userspace process, and then the
userspace process call device_lock() in uevent_show(), we will have dead
locks here.
In the following case:
device_release_driver
device_lock() blocked by
<operation 1> ---------------------------> <operation 2>
uevent_show()
device_lock()
In [1], It is beacause that pci_stop_and_remove_bus_device() will call
device_release_driver() first and then call device_del() to remove the
uevent sysfs attributes (Sorry for mistakes made in [1],
device_release_driver() is called by pci_stop_bus_device()). So, I think
it might not be a good idea to hold the device_lock() through uevent_show().
ioctl(..,VFIO_GROUP_GET_DEVICE_FD,..)
...
vfio_device_get_from_name()
vfio_devcie->refcount -> 2
pci_stop_and_remove_bus_device()
pci_stop_bus_device()
device_release_driver()
device_lock()
device_remove()
vfio_unregister_group_dev()
vfio_device_put_registration()
vfio_devcie->refcount -> 1
wait for refcount == 0
uevent_show()
device_lock()
[1]
https://lore.kernel.org/lkml/20241231075608.84009-1-zhangzekun11@huawei.com/
Best Regards,
Zekun
prev parent reply other threads:[~2025-01-27 3:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 21:54 [PATCH v2] driver core: Fix userspace expectations of uevent_show() as a probe barrier Dan Williams
2024-10-07 9:39 ` kernel test robot
2024-10-08 0:26 ` Dan Williams
2024-10-13 15:00 ` Greg KH
2024-10-28 9:08 ` Thorsten Leemhuis
2024-10-28 22:57 ` Dan Williams
2024-10-29 0:21 ` Greg KH
2024-12-31 7:56 ` Possible hungtask issue will be introduced with device_lock() in uevent_show() Zhang Zekun
2024-12-31 8:26 ` Greg KH
2025-01-04 6:02 ` zhangzekun (A)
2025-01-04 8:14 ` Greg KH
2025-01-23 2:07 ` Dan Williams
2025-01-27 3:27 ` zhangzekun (A) [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=7b535c35-9aeb-4a60-ab42-438f70835137@huawei.com \
--to=zhangzekun11@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=chenjun102@huawei.com \
--cc=dan.j.williams@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=regressions@lists.linux.dev \
--cc=tj@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
all inboxes | Powered by JetHome®