DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huisong Li <lihuisong@huawei.com>
To: <dev@dpdk.org>
Cc: <andrew.rybchenko@oktetlabs.ru>, <thomas@monjalon.net>,
	<ferruh.yigit@xilinx.com>, <huangdaode@huawei.com>,
	<liudongdong3@huawei.com>, <lihuisong@huawei.com>
Subject: [PATCH] usertools: fix bind failure from dpdk to kernel
Date: Fri, 5 Aug 2022 11:10:22 +0800	[thread overview]
Message-ID: <20220805031022.9795-1-lihuisong@huawei.com> (raw)

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


             reply	other threads:[~2022-08-05  3:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05  3:10 Huisong Li [this message]
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)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220805031022.9795-1-lihuisong@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@xilinx.com \
    --cc=huangdaode@huawei.com \
    --cc=liudongdong3@huawei.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).