Skip to contentSkip to conversation

changes to driver_override parsing broke DPDK script

REGRESSION Stephen Hemminger 6 participants 13 messages Aug 9, 2022 – Sep 1, 2022

Subsystems (3)
lore
Share & tools
lore

Stephen Hemminger

author Reviewed-by Andy Shevchenko Acked-by Bjorn Helgaas
#0 lore raw

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

The script is sending single nul character to remove override and that no longer works.

Source code to dpdk-devbind
https://github.com/DPDK/dpdk/blob/main/usertools/dpdk-devbind.py

#1 lore raw

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 29 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

The script is sending single nul character to remove override and that no longer works.

Source code to dpdk-devbind
https://github.com/DPDK/dpdk/blob/main/usertools/dpdk-devbind.py

#2 lore raw
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 19 lines
Quoted 19 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
may be cleared with an empty string (echo > driver_override)."
Documentation/ABI/testing/sysfs-bus-pci

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Best regards,
Krzysztof

#3 lore raw
Quoted 5 lines · Krzysztof Kozlowski
Quoted 4 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 9 lines
Quoted 6 lines · Stephen Hemminger
Quoted 5 lines

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

I could not find in the report (neither here) steps to reproduce it. Can you provide me some short description (what kernel options are required, what commands to run)?

I tried to run:

$ usertools/dpdk-devbind.py --status
$ usertools/dpdk-devbind.py --bind '0000:00:03.0'
Error: No devices specified.

Best regards,
Krzysztof

#4 lore raw
Quoted 20 lines · On Wed, 10 Aug 2022 09:13:40 +0300 Krzysztof Kozlowski…
Quoted 5 lines · Krzysztof Kozlowski
Quoted 4 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 9 lines
Quoted 6 lines · Stephen Hemminger
Quoted 5 lines

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

I could not find in the report (neither here) steps to reproduce it. Can you provide me some short description (what kernel options are required, what commands to run)?

Quoted 8 lines

I tried to run:

$ usertools/dpdk-devbind.py --status
$ usertools/dpdk-devbind.py --bind '0000:00:03.0'
Error: No devices specified.

Best regards,
Krzysztof

To test, you need to be willing to have one network device disappear from kernel. The bug is in the unbind step this is an example of it working with 5.17 kernel.

~/DPDK/main $ ./usertools/dpdk-devbind.py --status

Network devices using kernel driver
===================================
0000:01:00.0 'Wi-Fi 6 AX200 2723' if=wlo1 drv=iwlwifi unused= 0000:02:00.0 'RTL8125 2.5GbE Controller 8125' if=enp2s0 drv=r8169 unused= *Active*

~/DPDK/main $ sudo modprobe vfio-pci
~/DPDK/main $ sudo ./usertools/dpdk-devbind.py --bind=vfio-pci enp2s0
Warning: routing table indicates that interface 0000:02:00.0 is active. Not modifying ~/DPDK/main $ ip li set dev enp2s0 down
RTNETLINK answers: Operation not permitted
~/DPDK/main $ sudo ip li set dev enp2s0 down
~/DPDK/main $ sudo ./usertools/dpdk-devbind.py --bind=vfio-pci enp2s0 ~/DPDK/main $ ./usertools/dpdk-devbind.py --status

Network devices using DPDK-compatible driver
============================================
0000:02:00.0 'RTL8125 2.5GbE Controller 8125' drv=vfio-pci unused=r8169

Network devices using kernel driver
===================================
0000:01:00.0 'Wi-Fi 6 AX200 2723' if=wlo1 drv=iwlwifi unused=vfio-pci

~/DPDK/main $ sudo ./usertools/dpdk-devbind.py -u 0000:02:00.0 ~/DPDK/main $ ./usertools/dpdk-devbind.py --status

Network devices using kernel driver
===================================
0000:01:00.0 'Wi-Fi 6 AX200 2723' if=wlo1 drv=iwlwifi unused=vfio-pci

Other Network devices
=====================
0000:02:00.0 'RTL8125 2.5GbE Controller 8125' unused=r8169,vfio-pci

maintainer
#5 lore raw
In reply to Krzysztof Kozlowski
Quoted 41 lines · Krzysztof Kozlowski
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 19 lines
Quoted 19 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
may be cleared with an empty string (echo > driver_override)."
Documentation/ABI/testing/sysfs-bus-pci

Quoted 7 lines

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

One can argue that a string of just '\0' is an "empty string" and we should be able to properly handle this in the kernel. Heck, "\0\0\0\0\0\0" is also an "empty string", right?

I don't have an issue with fixing the kernel up here, it should be able to handle this.

thanks,

greg k-h

maintainer
#6 lore raw
Quoted 50 lines · Greg KH
Quoted 41 lines · Krzysztof Kozlowski
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 19 lines
Quoted 19 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
may be cleared with an empty string (echo > driver_override)."
Documentation/ABI/testing/sysfs-bus-pci

Quoted 7 lines

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Quoted 6 lines

One can argue that a string of just '\0' is an "empty string" and we should be able to properly handle this in the kernel. Heck, "\0\0\0\0\0\0" is also an "empty string", right?

I don't have an issue with fixing the kernel up here, it should be able to handle this.

Stephen, does the patch below fix this for you?

thanks,

greg k-h

-----------------

drivers/base/driver.c +6 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override,
 	if (len >= (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	/*
+	 * Compute the real length of the string in case userspace sends us a
+	 * bunch of \0 characters like python likes to do.
+	 */
+	len = strlen(s);
+
 	if (!len) {
 		/* Empty string passed - clear override */
 		device_lock(dev);
#7 lore raw

cc Huisong who found the issue.

Quoted 83 lines · Greg KH
Quoted 50 lines · Greg KH
Quoted 41 lines · Krzysztof Kozlowski
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 19 lines
Quoted 19 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
may be cleared with an empty string (echo > driver_override)."
Documentation/ABI/testing/sysfs-bus-pci

Quoted 7 lines

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Quoted 6 lines

One can argue that a string of just '\0' is an "empty string" and we should be able to properly handle this in the kernel. Heck, "\0\0\0\0\0\0" is also an "empty string", right?

I don't have an issue with fixing the kernel up here, it should be able to handle this.

Stephen, does the patch below fix this for you?

thanks,

greg k-h

-----------------

drivers/base/driver.c +6 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override,
 	if (len >= (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	/*
+	 * Compute the real length of the string in case userspace sends us a
+	 * bunch of \0 characters like python likes to do.
+	 */
+	len = strlen(s);
+
 	if (!len) {
 		/* Empty string passed - clear override */
 		device_lock(dev);
Quoted 2 lines

.

This patch looks good, @huisong, please help to test the patch.

Thanks,
Dongdong

Tested-by
#8 lore raw
Quoted 92 lines · Dongdong Liu

cc Huisong who found the issue.

Quoted 78 lines · Greg KH
Quoted 50 lines · Greg KH
Quoted 41 lines · Krzysztof Kozlowski
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 19 lines
Quoted 19 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800
Author: Krzysztof Kozlowski <[email protected]> Date:   Tue Apr 19 13:34:28 2022 +0200

    PCI: Use driver_set_override() instead of open-coding

    Use a helper to set driver_override to the reduce amount of duplicated code.  Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
 may be cleared with an empty string (echo > driver_override)." Documentation/ABI/testing/sysfs-bus-pci

Quoted 7 lines

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Quoted 6 lines

One can argue that a string of just '\0' is an "empty string" and we should be able to properly handle this in the kernel.  Heck, "\0\0\0\0\0\0" is also an "empty string", right?

I don't have an issue with fixing the kernel up here, it should be able to handle this.

Stephen, does the patch below fix this for you?

thanks,

greg k-h

-----------------

drivers/base/driver.c +2 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const 
 char **override,
      if (len >= (PAGE_SIZE - 1))
          return -EINVAL;
 
+    /*
+     * Compute the real length of the string in case userspace sends 

us a

Quoted 9 lines

+     * bunch of \0 characters like python likes to do. +     */
+    len = strlen(s);
+
     if (!len) {
         /* Empty string passed - clear override */ device_lock(dev);
.

This patch looks good,  @huisong, please help to test the patch.

Quoted 3 lines

Thanks,
Dongdong
.

maintainer
#9 lore raw
Quoted 98 lines · lihuisong (C)
Quoted 96 lines · Dongdong Liu

cc Huisong who found the issue.

Quoted 82 lines · Greg KH
Quoted 54 lines · Greg KH
Quoted 44 lines · Krzysztof Kozlowski
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 22 lines
Quoted 22 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800
Author: Krzysztof Kozlowski <[email protected]> Date:   Tue Apr 19 13:34:28 2022 +0200

    PCI: Use driver_set_override() instead of open-coding

    Use a helper to set driver_override to the reduce amount of duplicated
    code.  Make the driver_override field const char, because it is not
    modified by the core and it matches other subsystems.

Signed-off-by Krzysztof Kozlowski

<[email protected]>

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
 may be cleared with an empty string (echo > driver_override)." Documentation/ABI/testing/sysfs-bus-pci

Quoted 8 lines

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which
user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Quoted 6 lines

One can argue that a string of just '\0' is an "empty string" and we should be able to properly handle this in the kernel.  Heck, "\0\0\0\0\0\0" is also an "empty string", right?

I don't have an issue with fixing the kernel up here, it should be able to handle this.

Stephen, does the patch below fix this for you?

thanks,

greg k-h

-----------------

drivers/base/driver.c +2 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const
 char **override,
      if (len >= (PAGE_SIZE - 1))
          return -EINVAL;
 
+    /*
+     * Compute the real length of the string in case userspace

sends us a

Quoted 9 lines

+     * bunch of \0 characters like python likes to do. +     */
+    len = strlen(s);
+
     if (!len) {
         /* Empty string passed - clear override */ device_lock(dev);
.

This patch looks good,  @huisong, please help to test the patch.

Quoted 4 lines
Quoted 3 lines

Thanks,
Dongdong
.

Wonderful, thanks! I'll queue this up to send to Linus after -rc1 is out.

greg k-h

maintainer
#10 lore raw
Quoted 99 lines · Greg KH
Quoted 98 lines · lihuisong (C)
Quoted 96 lines · Dongdong Liu

cc Huisong who found the issue.

Quoted 82 lines · Greg KH
Quoted 54 lines · Greg KH
Quoted 44 lines · Krzysztof Kozlowski
Quoted 10 lines · Bjorn Helgaas

[+cc regressions list]

23d99baf9d72 appeared in v5.19-rc1.

Quoted 5 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

Thanks for the report. I'll take a look.

Quoted 22 lines
Quoted 22 lines

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800
Author: Krzysztof Kozlowski <[email protected]> Date:   Tue Apr 19 13:34:28 2022 +0200

    PCI: Use driver_set_override() instead of open-coding

    Use a helper to set driver_override to the reduce amount of duplicated
    code.  Make the driver_override field const char, because it is not
    modified by the core and it matches other subsystems.

Signed-off-by Krzysztof Kozlowski

<[email protected]>

Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
 may be cleared with an empty string (echo > driver_override)." Documentation/ABI/testing/sysfs-bus-pci

Quoted 8 lines

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which
user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Quoted 6 lines

One can argue that a string of just '\0' is an "empty string" and we should be able to properly handle this in the kernel.  Heck, "\0\0\0\0\0\0" is also an "empty string", right?

I don't have an issue with fixing the kernel up here, it should be able to handle this.

Stephen, does the patch below fix this for you?

thanks,

greg k-h

-----------------

drivers/base/driver.c +2 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const
 char **override,
      if (len >= (PAGE_SIZE - 1))
          return -EINVAL;
 
+    /*
+     * Compute the real length of the string in case userspace

sends us a

Quoted 9 lines

+     * bunch of \0 characters like python likes to do. +     */
+    len = strlen(s);
+
     if (!len) {
         /* Empty string passed - clear override */ device_lock(dev);
.

This patch looks good,  @huisong, please help to test the patch.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

Thanks,
Dongdong
.

Wonderful, thanks! I'll queue this up to send to Linus after -rc1 is out.

Sorry for the delay, now sent to lkml:

	https://lore.kernel.org/r/[email protected]
#11 lore raw
In reply to Krzysztof Kozlowski
Quoted 13 lines · On Wed, 10 Aug 2022 08:54:36 +0300 Krzysztof Kozlowski…
Quoted 2 lines
Quoted 2 lines

The script is sending single nul character to remove override and that no longer works.

The sysfs API clearly states:
"and
may be cleared with an empty string (echo > driver_override)."
Documentation/ABI/testing/sysfs-bus-pci

Sending other data and expecting the same result is not conforming to API. Therefore we have usual example of some undocumented behavior which user-space started relying on and instead using API, user-space expect that undocumented behavior to be back.

Quoted 5 lines

Yay! I wonder what is the point to even describe the ABI if user-space can simply ignore it?

Best regards,
Krzysztof

The code that does this in the python script is relatively old. The writing of null was introduced back in 2017 by:

commit 720b7a058260dfd6ae0fcce956bfe44c18681499

Author: Guduri Prathyusha <[email protected]>
Date:   Wed Apr 26 19:22:19 2017 +0530

usertools: fix device binding with kernel tools

The following sequence of operation gives error in binding devices
1) Bind a device using dpdk-devbind.py
2) Unbind the device using kernel tools(/sys/bus/pci/device/driver/unbind)
3) Bind the device using kernel tools(/sys/bus/pci/driver/new_id and /sys/bus/pci/driver/bind)

The bind failure was due to cached driver name in 'driver_override'. Fix it by writing 'null' to driver_override just after binding a device so that any method of binding/unbinding can be used.

Fixes 2fc350293570 ("usertools: use optimized driver override scheme to bind")
maintainer
#12 lore raw
In reply to Stephen Hemminger
Quoted 24 lines · Stephen Hemminger

This commit broke the driver override script in DPDK. This is an API/ABI breakage, please revert or fix the commit.

Report of problem:
http://mails.dpdk.org/archives/dev/2022-August/247794.html

commit 23d99baf9d729ca30b2fb6798a7b403a37bfb800

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Apr 19 13:34:28 2022 +0200

PCI: Use driver_set_override() instead of open-coding

Use a helper to set driver_override to the reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems.

Quoted 5 lines

The script is sending single nul character to remove override and that no longer works.

Source code to dpdk-devbind
https://github.com/DPDK/dpdk/blob/main/usertools/dpdk-devbind.py

Ah, that's messy. I'll try to fix up driver_override() to handle a \0 being sent as the string, we should treat that as an empty write. Let me think about that later today...

thanks,

greg k-h