[PATCH RESEND v2 0/2] driver core: bus: Fix issues related to bus_rescan_devices_helper()

Zijun Hu posted 2 patches 1 month ago
drivers/base/bus.c | 78 ++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 64 insertions(+), 14 deletions(-)
[PATCH RESEND v2 0/2] driver core: bus: Fix issues related to bus_rescan_devices_helper()
Posted by Zijun Hu 1 month ago
This patch series is to fix issues related to bus_rescan_devices_helper().

The function is improperly used for 2 incompatible scenarios as
explained below:

Scenario A: scan drivers for a single device user specify
 - user may care about precise synchronous scanning result, so the
   function can not collapse error codes.

Scenario B: scan drivers for all devices of a bus
 - user may need to scan drivers for a bus's devices as many as
   possible, so the function needs to ignore inconsequential error
   codes for a device in order to continue to scan for next device.

Fixed by implementing bus_rescan_single_device() for scenario A
and correcting the function for scenario B.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
Changes in v2:
- Temporarily drop the change related to bus_type's match() return value
- For this 1/2 change, transfer internal -EPROBE_DEFER to user known
  -EAGAIN, correct title, commit message, inline comments.
- For this 2/2 change, Add an extra -EBUSY to ignore, correct title
  commit message, inline comments.
- Link to v1: https://lore.kernel.org/r/20240904-bus_match_unlikely-v1-0-122318285261@quicinc.com

---
Zijun Hu (2):
      driver core: bus: Fix drivers_probe_store() giving user wrong scanning result
      driver core: bus: Correct API bus_rescan_devices() behavior

 drivers/base/bus.c | 78 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 64 insertions(+), 14 deletions(-)
---
base-commit: fea64fa04c31426eae512751e0c5342345c5741c
change-id: 20240830-bus_match_unlikely-abe9334bcfd2

Best regards,
-- 
Zijun Hu <quic_zijuhu@quicinc.com>
Re: [PATCH RESEND v2 0/2] driver core: bus: Fix issues related to bus_rescan_devices_helper()
Posted by Greg Kroah-Hartman 1 week, 6 days ago
On Tue, Oct 22, 2024 at 07:18:00PM +0800, Zijun Hu wrote:
> This patch series is to fix issues related to bus_rescan_devices_helper().
> 
> The function is improperly used for 2 incompatible scenarios as
> explained below:
> 
> Scenario A: scan drivers for a single device user specify
>  - user may care about precise synchronous scanning result, so the
>    function can not collapse error codes.

I do not understand this, what is wrong that this is fixing?

> Scenario B: scan drivers for all devices of a bus
>  - user may need to scan drivers for a bus's devices as many as
>    possible, so the function needs to ignore inconsequential error
>    codes for a device in order to continue to scan for next device.

How often is that needed?  And why can't that still work with the
existing code?

thanks,

greg k-h
Re: [PATCH RESEND v2 0/2] driver core: bus: Fix issues related to bus_rescan_devices_helper()
Posted by Zijun Hu 1 week, 5 days ago
On 2024/11/12 19:48, Greg Kroah-Hartman wrote:
> On Tue, Oct 22, 2024 at 07:18:00PM +0800, Zijun Hu wrote:
>> This patch series is to fix issues related to bus_rescan_devices_helper().
>>
>> The function is improperly used for 2 incompatible scenarios as
>> explained below:
>>
>> Scenario A: scan drivers for a single device user specify
>>  - user may care about precise synchronous scanning result, so the
>>    function can not collapse error codes.
> 
> I do not understand this, what is wrong that this is fixing?
> 

for scanning drivers for single device, it gives user wrong scanning
result(success or failure).

patch 1/2 is a concrete example.

>> Scenario B: scan drivers for all devices of a bus
>>  - user may need to scan drivers for a bus's devices as many as
>>    possible, so the function needs to ignore inconsequential error
>>    codes for a device in order to continue to scan for next device.
> 
> How often is that needed?  And why can't that still work with the
> existing code?
>

1) API bus_rescan_devices() invokes it and can't achieve its design
purpose due to error described above.

2) as shown by recent mainlined commit, usage of API
bus_rescan_devices() have been dropped due to some bugs.
Commit: 3d6ebf16438d ("cxl/port: Fix cxl_bus_rescan() vs
bus_rescan_devices()")

3) there are only 2 usages for the API now.
// does not do what the comments say
https://elixir.bootlin.com/linux/v6.11/source/drivers/pcmcia/ds.c#L725
// do multi repeated iterating, can be simplified if fix the API bugs
https://elixir.bootlin.com/linux/v6.11/source/drivers/hid/hid-core.c#L2967

4) i have more reply in below link about the API's bugs.
https://lore.kernel.org/all/20240913-bus_match_unlikely-v2-2-5c0c3bfda2f6@quicinc.com/

we may go to patch 2/2 to continue discussion.

> thanks,
> 
> greg k-h
Re: [PATCH RESEND v2 0/2] driver core: bus: Fix issues related to bus_rescan_devices_helper()
Posted by Zijun Hu 1 week, 5 days ago
On 2024/11/12 19:48, Greg Kroah-Hartman wrote:
> On Tue, Oct 22, 2024 at 07:18:00PM +0800, Zijun Hu wrote:
>> This patch series is to fix issues related to bus_rescan_devices_helper().
>>
>> The function is improperly used for 2 incompatible scenarios as
>> explained below:
>>
>> Scenario A: scan drivers for a single device user specify
>>  - user may care about precise synchronous scanning result, so the
>>    function can not collapse error codes.
> 
> I do not understand this, what is wrong that this is fixing?
> 

for scanning drivers for single device, it gives user wrong scanning
result(success or failure).

patch 1/2 is a concrete example.

>> Scenario B: scan drivers for all devices of a bus
>>  - user may need to scan drivers for a bus's devices as many as
>>    possible, so the function needs to ignore inconsequential error
>>    codes for a device in order to continue to scan for next device.
> 
> How often is that needed?  And why can't that still work with the
> existing code?
>

1) API bus_rescan_devices() invokes it and can't achieve its design
purpose due to error described above.

2) as shown by recent mainlined commit, usage of API
bus_rescan_devices() have been dropped due to some bugs.
Commit: 3d6ebf16438d ("cxl/port: Fix cxl_bus_rescan() vs
bus_rescan_devices()")

3) there are only 2 usages for the API now.
// does not do what the comments say
https://elixir.bootlin.com/linux/v6.11/source/drivers/pcmcia/ds.c#L725
// do multi repeated iterating, can be simplified if fix the API bugs
https://elixir.bootlin.com/linux/v6.11/source/drivers/hid/hid-core.c#L2967

4) i have more reply in below link about the API's bugs.
https://lore.kernel.org/all/20240913-bus_match_unlikely-v2-2-5c0c3bfda2f6@quicinc.com/

> thanks,
> 
> greg k-h