From: Jon Hunter <jonathanh@nvidia.com>
To: Saravana Kannan <saravanak@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Michael Walle <michael@walle.cc>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Guenter Roeck <linux@roeck-us.net>, <kernel-team@android.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 2/3] driver core: Update device link status properly for device_bind_driver()
Date: Fri, 12 Mar 2021 16:59:45 +0000 [thread overview]
Message-ID: <b0171cd5-0145-eecd-5849-a4867704a0d9@nvidia.com> (raw)
In-Reply-To: <20210302211133.2244281-3-saravanak@google.com>
On 02/03/2021 21:11, Saravana Kannan wrote:
> Device link status was not getting updated correctly when
> device_bind_driver() is called on a device. This causes a warning[1].
> Fix this by updating device links that can be updated and dropping
> device links that can't be updated to a sensible state.
>
> [1] - https://lore.kernel.org/lkml/56f7d032-ba5a-a8c7-23de-2969d98c527e@nvidia.com/
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> ---
> drivers/base/base.h | 1 +
> drivers/base/core.c | 35 +++++++++++++++++++++++++++++++++++
> drivers/base/dd.c | 4 +++-
> 3 files changed, 39 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/base.h b/drivers/base/base.h
> index 52b3d7b75c27..1b44ed588f66 100644
> --- a/drivers/base/base.h
> +++ b/drivers/base/base.h
> @@ -185,6 +185,7 @@ extern int device_links_read_lock(void);
> extern void device_links_read_unlock(int idx);
> extern int device_links_read_lock_held(void);
> extern int device_links_check_suppliers(struct device *dev);
> +extern void device_links_force_bind(struct device *dev);
> extern void device_links_driver_bound(struct device *dev);
> extern void device_links_driver_cleanup(struct device *dev);
> extern void device_links_no_driver(struct device *dev);
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index f29839382f81..45c75cc96fdc 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1153,6 +1153,41 @@ static ssize_t waiting_for_supplier_show(struct device *dev,
> }
> static DEVICE_ATTR_RO(waiting_for_supplier);
>
> +/**
> + * device_links_force_bind - Prepares device to be force bound
> + * @dev: Consumer device.
> + *
> + * device_bind_driver() force binds a device to a driver without calling any
> + * driver probe functions. So the consumer really isn't going to wait for any
> + * supplier before it's bound to the driver. We still want the device link
> + * states to be sensible when this happens.
> + *
> + * In preparation for device_bind_driver(), this function goes through each
> + * supplier device links and checks if the supplier is bound. If it is, then
> + * the device link status is set to CONSUMER_PROBE. Otherwise, the device link
> + * is dropped. Links without the DL_FLAG_MANAGED flag set are ignored.
> + */
> +void device_links_force_bind(struct device *dev)
> +{
> + struct device_link *link, *ln;
> +
> + device_links_write_lock();
> +
> + list_for_each_entry_safe(link, ln, &dev->links.suppliers, c_node) {
> + if (!(link->flags & DL_FLAG_MANAGED))
> + continue;
> +
> + if (link->status != DL_STATE_AVAILABLE) {
> + device_link_drop_managed(link);
> + continue;
> + }
> + WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE);
> + }
> + dev->links.status = DL_DEV_PROBING;
> +
> + device_links_write_unlock();
> +}
> +
> /**
> * device_links_driver_bound - Update device links after probing its driver.
> * @dev: Device to update the links for.
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index f18963f42e21..eb201c6d5a6a 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -460,8 +460,10 @@ int device_bind_driver(struct device *dev)
> int ret;
>
> ret = driver_sysfs_add(dev);
> - if (!ret)
> + if (!ret) {
> + device_links_force_bind(dev);
> driver_bound(dev);
> + }
> else if (dev->bus)
> blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
> BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
>
Thanks, this fixes the problem I had observed.
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Cheers!
Jon
--
nvpublic
next prev parent reply other threads:[~2021-03-12 17:00 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 21:11 [PATCH v1 0/3] driver core: Set fw_devlink=on take II Saravana Kannan
2021-03-02 21:11 ` [PATCH v1 1/3] driver core: Avoid pointless deferred probe attempts Saravana Kannan
2021-03-09 23:26 ` Saravana Kannan
2021-03-23 13:58 ` Greg Kroah-Hartman
2021-03-02 21:11 ` [PATCH v1 2/3] driver core: Update device link status properly for device_bind_driver() Saravana Kannan
2021-03-12 16:59 ` Jon Hunter [this message]
2021-03-02 21:11 ` [PATCH v1 3/3] Revert "Revert "driver core: Set fw_devlink=on by default"" Saravana Kannan
[not found] ` <161670714806.3012082.14889556041667946511@swboyd.mtv.corp.google.com>
2021-03-25 21:59 ` Saravana Kannan
2021-04-26 20:51 ` Florian Fainelli
2021-04-26 21:33 ` Saravana Kannan
2021-04-26 21:47 ` Florian Fainelli
2021-04-27 7:05 ` Geert Uytterhoeven
2021-04-27 7:48 ` Cristian Marussi
[not found] ` <CA+-6iNz_kL0DnbRb0A=WSSLK0mnqw35S47TDXq5rhwXL_VWdPg@mail.gmail.com>
2021-04-27 14:11 ` Cristian Marussi
2021-04-27 15:10 ` Sudeep Holla
2021-04-27 16:24 ` Saravana Kannan
2021-04-27 16:47 ` Florian Fainelli
2021-04-27 21:05 ` Saravana Kannan
2021-04-28 8:40 ` Sudeep Holla
2021-04-27 16:24 ` Florian Fainelli
2021-04-27 16:28 ` Saravana Kannan
2021-04-27 16:42 ` Sudeep Holla
2021-04-27 16:39 ` Sudeep Holla
2021-04-27 16:50 ` Florian Fainelli
2021-04-27 17:10 ` Geert Uytterhoeven
2021-03-02 22:24 ` [PATCH v1 0/3] driver core: Set fw_devlink=on take II Michael Walle
2021-03-02 22:42 ` Saravana Kannan
2021-03-02 22:47 ` Saravana Kannan
2021-03-03 8:59 ` Michael Walle
2021-03-03 9:28 ` Saravana Kannan
2021-03-03 10:21 ` Michael Walle
2021-03-05 3:25 ` Saravana Kannan
2021-03-03 9:22 ` Geert Uytterhoeven
2021-03-03 9:24 ` Saravana Kannan
2021-03-03 10:02 ` Geert Uytterhoeven
2021-03-03 16:55 ` Saravana Kannan
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=b0171cd5-0145-eecd-5849-a4867704a0d9@nvidia.com \
--to=jonathanh@nvidia.com \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=m.szyprowski@samsung.com \
--cc=michael@walle.cc \
--cc=rafael@kernel.org \
--cc=saravanak@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.