From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 778E9A00C4; Fri, 5 Aug 2022 05:11:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1E8B94067C; Fri, 5 Aug 2022 05:11:23 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 49000400D5 for ; Fri, 5 Aug 2022 05:11:20 +0200 (CEST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LzVvW0C8kzTgZy; Fri, 5 Aug 2022 11:09:59 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 5 Aug 2022 11:11:18 +0800 Received: from localhost.localdomain (10.28.79.22) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 5 Aug 2022 11:11:17 +0800 From: Huisong Li To: CC: , , , , , Subject: [PATCH] usertools: fix bind failure from dpdk to kernel Date: Fri, 5 Aug 2022 11:10:22 +0800 Message-ID: <20220805031022.9795-1-lihuisong@huawei.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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