Re: [PATCH v2] usbip: tools: Add usbip host driver availability check

Zongmin Zhou
2026-03-27T08:39:18Z

On 2026/3/27 02:43, Shuah Khan wrote:
> On 3/26/26 02:43, Greg KH wrote:
>> On Thu, Mar 26, 2026 at 11:10:02AM +0800, Zongmin Zhou wrote:
>>>
>>> On 2026/3/25 16:58, Greg KH wrote:
>>>> On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
>>>>> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>>>
>>>>> Currently, usbip_generic_driver_open() doesn't verify that the
>>>>> required
>>>>> kernel module (usbip-host or usbip-vudc) is actually loaded.
>>>>> The function returns success even when no driver is present,
>>>>> leading to usbipd daemon run success without driver loaded.
>>>>>
>>>>> So add a check function to ensure usbip host driver has been loaded.
>>>>>
>>>>> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
>>>>> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>>> ---
>>>>> Changes in v2:
>>>>> - Use system calls directly instead of checking sysfs dir.
>>>>>
>>>>>    tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
>>>>>    tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
>>>>>    2 files changed, 11 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> b/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> index 927a151fa9aa..45ab647ef241 100644
>>>>> --- a/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> @@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct
>>>>> usbip_host_driver *hdriver)
>>>>>        hdriver->ndevs = 0;
>>>>>        INIT_LIST_HEAD(&hdriver->edev_list);
>>>>> -    ret = usbip_generic_driver_open(hdriver);
>>>>> -    if (ret)
>>>>> +    if (system("/sbin/lsmod | grep -q usbip_vudc")){
>>>> What happens if the module is built into the kernel?
>>>>
>>>>>            err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>>>>                USBIP_DEVICE_DRV_NAME ".ko!");
>>>>> +        return -1;
>>>>> +    }
>>>>> +
>>>>> +    ret = usbip_generic_driver_open(hdriver);
>>>>>        return ret;
>>>>>    }
>>>>> diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> b/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> index 573e73ec36bd..f0ac941d4f6e 100644
>>>>> --- a/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> @@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct
>>>>> usbip_host_driver *hdriver)
>>>>>        hdriver->ndevs = 0;
>>>>>        INIT_LIST_HEAD(&hdriver->edev_list);
>>>>> -    ret = usbip_generic_driver_open(hdriver);
>>>>> -    if (ret)
>>>>> +    if (system("/sbin/lsmod | grep -q usbip_host")){
>>>> Same here, what happens if it is built in?
>>> Thank you for pointing this out.
>>> I apologize for not considering the built-in module case.
>>>
>>> You are right that using lsmod | grep would incorrectly fail when
>>> usbip_host
>>> is built into the kernel (CONFIG_USBIP_HOST=y).
>>> Usbip has always been built as a loadable module (.ko) by default,
>>> which led
>>> to this oversight.
>>>
>>> To address this issue, would the following approach be acceptable?
>>
>> Wait, what "issue" are you trying to fix here?  Why can't you just check
>> for opening the correct device node when the host opens the file and if
>> that fails, report an error?  Doesn't that happen today already?
>>
>
> The problem Zongmin is trying fix ish when usbipd starts, it looks for
> exported if any - if it doesn't find any it assumes there aren't any
> exported and doesn't detect that usbip_host driver isn't loaded.
>
> refresh_exported_devices() doesn't have the logic and it shouldn't
> include that logic because this hook is called periodically to
> refresh the list of exported devices. Starting usbipd and loading
> the driver are distinct steps and without any dependencies.
>
> This patch he is trying to add that detection so a message can be printed
> to say "load the driver".
>
> A message can be added easily to cover two cases:
>
> 1. usbip_host driver isn't loaded
> 2. There are no exported devices.
>
> refresh_exported_devices() will not find any devices in both
> of the above scenarios. It isn't an error if it can't find
> any exported devices.
>
> An informational message when refresh_exported_devices()
> when it doesn't find any devices could help users.
>
> Zongmin,
>
> Would adding a message that says
> "Check if usbip_host driver is loaded or export devices"
> solve the problem of hard to debug problem you are addressing here?
>
Shuah,

Your suggestion makes sense.
Adding an informational message when no devices are found would be a simple
and clean solution that helps users debug without being intrusive.

However, I plan to add the info() message in usbip_generic_driver_open()
instead of
refresh_exported_devices(), because:
- usbip_generic_driver_open() is called only once at initialization.
- refresh_exported_devices() is called periodically to refresh the
exported device list.
- When the server has no exported devices, having zero devices
is normal and not worth frequent info messages.

Theoretically, we only need to prompt once at startup. Is my
understanding correct?

I'll also remove the existing error messages like below,
since they cannot accurately determine whether the driver is loaded:

if (ret)
err("please load " USBIP_CORE_MOD_NAME ".ko and "
USBIP_HOST_DRV_NAME ".ko!");

Does this approach look acceptable?

Best regards,
--Zongmin Zhou
> thanks,
> -- Shuah