DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] usertools: fix bind failure from dpdk to kernel
@ 2022-08-05  3:10 Huisong Li
  2022-08-05 15:35 ` Stephen Hemminger
  0 siblings, 1 reply; 9+ messages in thread
From: Huisong Li @ 2022-08-05  3:10 UTC (permalink / raw)
  To: dev
  Cc: andrew.rybchenko, thomas, ferruh.yigit, huangdaode, liudongdong3,
	lihuisong

Currently, the steps for binding device from dpdk driver to kernel
driver is as follows:
echo $BDF > /sys/bus/pci/drivers/vfio-pci/unbind
echo $BDF > /sys/bus/pci/drivers/$kernel_driver/bind

This steps cannot bind device from dpdk driver to kernel driver on
platform with kernel 5.19. The 'driver_override' must be specify
kernel driver before binding device to kernel driver.

Fixes: 720b7a058260 ("usertools: fix device binding with kernel tools")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 usertools/dpdk-devbind.py | 52 ++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 33 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 4d9c1be666..0e21ab3543 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -365,6 +365,24 @@ def bind_one(dev_id, driver, force):
         unbind_one(dev_id, force)
         dev["Driver_str"] = ""  # clear driver string
 
+    # For kernels >= 5.19 driver_override must be written, or device
+    # can not be bind from dpdk driver to other specified driver.
+    filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
+    if exists(filename):
+        try:
+            f = open(filename, "w")
+        except OSError as err:
+            print("Error: bind failed for %s - Cannot open %s: %s"
+                  % (dev_id, filename, err), file=sys.stderr)
+            return
+        try:
+            f.write("%s" % driver)
+            f.close()
+        except OSError as err:
+            print("Error: bind failed for %s - Cannot write driver %s to "
+                  "PCI ID: %s" % (dev_id, driver, err), file=sys.stderr)
+            return
+
     # For kernels >= 3.15 driver_override can be used to specify the driver
     # for a device rather than relying on the driver to provide a positive
     # match of the device.  The existing process of looking up
@@ -372,23 +390,8 @@ def bind_one(dev_id, driver, force):
     # will erroneously bind other devices too which has the additional burden
     # of unbinding those devices
     if driver in dpdk_drivers:
-        filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
-        if exists(filename):
-            try:
-                f = open(filename, "w")
-            except OSError as err:
-                print("Error: bind failed for %s - Cannot open %s: %s"
-                      % (dev_id, filename, err), file=sys.stderr)
-                return
-            try:
-                f.write("%s" % driver)
-                f.close()
-            except OSError as err:
-                print("Error: bind failed for %s - Cannot write driver %s to "
-                      "PCI ID: %s" % (dev_id, driver, err), file=sys.stderr)
-                return
         # For kernels < 3.15 use new_id to add PCI id's to the driver
-        else:
+        if not exists(filename):
             filename = "/sys/bus/pci/drivers/%s/new_id" % driver
             try:
                 f = open(filename, "w")
@@ -432,23 +435,6 @@ def bind_one(dev_id, driver, force):
             bind_one(dev_id, saved_driver, force)
         return
 
-    # For kernels > 3.15 driver_override is used to bind a device to a driver.
-    # Before unbinding it, overwrite driver_override with empty string so that
-    # the device can be bound to any other driver
-    filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
-    if exists(filename):
-        try:
-            f = open(filename, "w")
-        except OSError as err:
-            sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
-                     % (dev_id, filename, err))
-        try:
-            f.write("\00")
-            f.close()
-        except OSError as err:
-            sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
-                     % (dev_id, filename, err))
-
 
 def unbind_all(dev_list, force=False):
     """Unbind method, takes a list of device locations"""
-- 
2.22.0


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

end of thread, other threads:[~2022-08-11  8:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05  3:10 [PATCH] usertools: fix bind failure from dpdk to kernel Huisong Li
2022-08-05 15:35 ` Stephen Hemminger
2022-08-09 11:44   ` lihuisong (C)
2022-08-09 17:58     ` Stephen Hemminger
2022-08-10  6:02       ` Krzysztof Kozlowski
2022-08-10 13:50         ` Stephen Hemminger
2022-08-10  5:59     ` Krzysztof Kozlowski
2022-08-10 13:49       ` Stephen Hemminger
2022-08-11  2:10         ` lihuisong (C)

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).