linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used
@ 2020-06-16 20:37 Matthias Kaehlcke
  2020-06-17  5:35 ` Bjorn Andersson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Matthias Kaehlcke @ 2020-06-16 20:37 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, Andy Gross
  Cc: linux-arm-msm, Manu Gautam, linux-usb, linux-kernel,
	Sandeep Maheswaram, Doug Anderson, Stephen Boyd,
	Matthias Kaehlcke, Bjorn Andersson

dwc3_qcom_of_register_core() uses of_platform_populate() to add
the dwc3 core device. The driver core will try to probe the device,
however this might fail (e.g. due to deferred probing) and
of_platform_populate() would still return 0 if the device was
successully added to the platform bus. Verify that the core device
is actually bound to its driver before using it, defer probing of the
dwc3_qcom device if the core device isn't ready (yet).

Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver").
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
depends on:
  https://lore.kernel.org/patchwork/patch/1251661/ ("driver core:Export
    the symbol device_is_bound")

 drivers/usb/dwc3/dwc3-qcom.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 1dfd024cd06b..5a9036b050c6 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -537,6 +537,16 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	/*
+	 * A successful return from of_platform_populate() only guarantees that
+	 * the core device was added to the platform bus, however it might not
+	 * be bound to its driver (e.g. due to deferred probing). This driver
+	 * requires the core device to be fully initialized, so defer probing
+	 * if it isn't ready (yet).
+	 */
+	if (!device_is_bound(&qcom->dwc3->dev))
+		return -EPROBE_DEFER;
+
 	return 0;
 }
 
-- 
2.27.0.290.gba653c62da-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used
  2020-06-16 20:37 [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used Matthias Kaehlcke
@ 2020-06-17  5:35 ` Bjorn Andersson
  2020-06-17 19:49 ` Stephen Boyd
  2020-06-21  5:50 ` kernel test robot
  2 siblings, 0 replies; 5+ messages in thread
From: Bjorn Andersson @ 2020-06-17  5:35 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Felipe Balbi, Greg Kroah-Hartman, Andy Gross, linux-arm-msm,
	Manu Gautam, linux-usb, linux-kernel, Sandeep Maheswaram,
	Doug Anderson, Stephen Boyd

On Tue 16 Jun 13:37 PDT 2020, Matthias Kaehlcke wrote:

> dwc3_qcom_of_register_core() uses of_platform_populate() to add
> the dwc3 core device. The driver core will try to probe the device,
> however this might fail (e.g. due to deferred probing) and
> of_platform_populate() would still return 0 if the device was
> successully added to the platform bus. Verify that the core device
> is actually bound to its driver before using it, defer probing of the
> dwc3_qcom device if the core device isn't ready (yet).
> 
> Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver").
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

I wish there was a better way than to unregistering the dwc3 device when
this happens. E.g. if dwc3 fails for some other reason we still would
keep probe deferring the qcom part and each time attempt to reprobe dwc3.

But with the way the device model is used here I don't have any better
suggestions, and until a better solution appears this does improve the
situation...

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
> depends on:
>   https://lore.kernel.org/patchwork/patch/1251661/ ("driver core:Export
>     the symbol device_is_bound")
> 
>  drivers/usb/dwc3/dwc3-qcom.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 1dfd024cd06b..5a9036b050c6 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -537,6 +537,16 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> +	/*
> +	 * A successful return from of_platform_populate() only guarantees that
> +	 * the core device was added to the platform bus, however it might not
> +	 * be bound to its driver (e.g. due to deferred probing). This driver
> +	 * requires the core device to be fully initialized, so defer probing
> +	 * if it isn't ready (yet).
> +	 */
> +	if (!device_is_bound(&qcom->dwc3->dev))
> +		return -EPROBE_DEFER;
> +
>  	return 0;
>  }
>  
> -- 
> 2.27.0.290.gba653c62da-goog
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used
  2020-06-16 20:37 [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used Matthias Kaehlcke
  2020-06-17  5:35 ` Bjorn Andersson
@ 2020-06-17 19:49 ` Stephen Boyd
  2020-06-17 21:24   ` Matthias Kaehlcke
  2020-06-21  5:50 ` kernel test robot
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Boyd @ 2020-06-17 19:49 UTC (permalink / raw)
  To: Andy Gross, Felipe Balbi, Greg Kroah-Hartman, Matthias Kaehlcke
  Cc: linux-arm-msm, Manu Gautam, linux-usb, linux-kernel,
	Sandeep Maheswaram, Doug Anderson, Matthias Kaehlcke,
	Bjorn Andersson

Quoting Matthias Kaehlcke (2020-06-16 13:37:37)
> dwc3_qcom_of_register_core() uses of_platform_populate() to add
> the dwc3 core device. The driver core will try to probe the device,
> however this might fail (e.g. due to deferred probing) and
> of_platform_populate() would still return 0 if the device was
> successully added to the platform bus. Verify that the core device
> is actually bound to its driver before using it, defer probing of the
> dwc3_qcom device if the core device isn't ready (yet).
> 
> Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver").
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> depends on:
>   https://lore.kernel.org/patchwork/patch/1251661/ ("driver core:Export
>     the symbol device_is_bound")
> 
>  drivers/usb/dwc3/dwc3-qcom.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 1dfd024cd06b..5a9036b050c6 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -537,6 +537,16 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
>                 return -ENODEV;
>         }
>  
> +       /*
> +        * A successful return from of_platform_populate() only guarantees that
> +        * the core device was added to the platform bus, however it might not
> +        * be bound to its driver (e.g. due to deferred probing). This driver
> +        * requires the core device to be fully initialized, so defer probing
> +        * if it isn't ready (yet).
> +        */
> +       if (!device_is_bound(&qcom->dwc3->dev))
> +               return -EPROBE_DEFER;

Isn't this still broken? i.e. the dwc3 core driver may bind much later
and then device_is_bound() will return an error here and then we'll
return to the caller, dwc3_qcom_probe(), and that will depopulate the
device with of_platform_depopulate(). It seems like we need to run some
sort of wait for driver to be bound function instead of a one-shot check
for the driver being bound.

> +
>         return 0;

Also, what about acpi? That has the same problem but it isn't covered by
the dwc3_qcom_of_register_core() function.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used
  2020-06-17 19:49 ` Stephen Boyd
@ 2020-06-17 21:24   ` Matthias Kaehlcke
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Kaehlcke @ 2020-06-17 21:24 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andy Gross, Felipe Balbi, Greg Kroah-Hartman, linux-arm-msm,
	Manu Gautam, linux-usb, linux-kernel, Sandeep Maheswaram,
	Doug Anderson, Bjorn Andersson

Hi Stephen,

On Wed, Jun 17, 2020 at 12:49:13PM -0700, Stephen Boyd wrote:
> Quoting Matthias Kaehlcke (2020-06-16 13:37:37)
> > dwc3_qcom_of_register_core() uses of_platform_populate() to add
> > the dwc3 core device. The driver core will try to probe the device,
> > however this might fail (e.g. due to deferred probing) and
> > of_platform_populate() would still return 0 if the device was
> > successully added to the platform bus. Verify that the core device
> > is actually bound to its driver before using it, defer probing of the
> > dwc3_qcom device if the core device isn't ready (yet).
> > 
> > Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver").
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > ---
> > depends on:
> >   https://lore.kernel.org/patchwork/patch/1251661/ ("driver core:Export
> >     the symbol device_is_bound")
> > 
> >  drivers/usb/dwc3/dwc3-qcom.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> > index 1dfd024cd06b..5a9036b050c6 100644
> > --- a/drivers/usb/dwc3/dwc3-qcom.c
> > +++ b/drivers/usb/dwc3/dwc3-qcom.c
> > @@ -537,6 +537,16 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
> >                 return -ENODEV;
> >         }
> >  
> > +       /*
> > +        * A successful return from of_platform_populate() only guarantees that
> > +        * the core device was added to the platform bus, however it might not
> > +        * be bound to its driver (e.g. due to deferred probing). This driver
> > +        * requires the core device to be fully initialized, so defer probing
> > +        * if it isn't ready (yet).
> > +        */
> > +       if (!device_is_bound(&qcom->dwc3->dev))
> > +               return -EPROBE_DEFER;
> 
> Isn't this still broken? i.e. the dwc3 core driver may bind much later
> and then device_is_bound() will return an error here and then we'll
> return to the caller, dwc3_qcom_probe(), and that will depopulate the
> device with of_platform_depopulate(). It seems like we need to run some
> sort of wait for driver to be bound function instead of a one-shot check
> for the driver being bound.

My understanding is that the probing is done synchronously and either done,
failed or deferred when returning from of_platform_populate(). Ideally we
would be able to differentiate between a failure and deferral, and not defer
probing in case of an error, however I'm not aware of a way to do this with
the current driver framework.

The call flow is:

  of_platform_populate
    of_platform_bus_create
      of_platform_device_create_pdata
        of_device_add
	  device_add
	    bus_probe_device
	      device_initial_probe
	        __device_attach
	          __device_attach_driver
	            driver_probe_device
                      really_probe
                        ->probe()


> Also, what about acpi? That has the same problem but it isn't covered by
> the dwc3_qcom_of_register_core() function.

I wouldn't be surprised if it had the same problem. I'm not familiar with ACPI
though and don't have a device for testing, hence I limited the patch to the
platform device.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used
  2020-06-16 20:37 [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used Matthias Kaehlcke
  2020-06-17  5:35 ` Bjorn Andersson
  2020-06-17 19:49 ` Stephen Boyd
@ 2020-06-21  5:50 ` kernel test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2020-06-21  5:50 UTC (permalink / raw)
  To: Matthias Kaehlcke, Felipe Balbi, Greg Kroah-Hartman, Andy Gross
  Cc: kbuild-all, linux-arm-msm, Manu Gautam, linux-usb, linux-kernel,
	Sandeep Maheswaram, Doug Anderson, Stephen Boyd

[-- Attachment #1: Type: text/plain, Size: 1349 bytes --]

Hi Matthias,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on balbi-usb/testing/next]
[cannot apply to agross-msm/qcom/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use  as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthias-Kaehlcke/usb-dwc3-qcom-Make-sure-core-device-is-fully-initialized-before-it-is-used/20200617-043856
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next
config: riscv-allmodconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "device_is_bound" [drivers/usb/dwc3/dwc3-qcom.ko] undefined!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 63841 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-21  5:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-16 20:37 [PATCH] usb: dwc3: qcom: Make sure core device is fully initialized before it is used Matthias Kaehlcke
2020-06-17  5:35 ` Bjorn Andersson
2020-06-17 19:49 ` Stephen Boyd
2020-06-17 21:24   ` Matthias Kaehlcke
2020-06-21  5:50 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).