From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A3CD9A04DD; Tue, 26 Nov 2019 07:49:29 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BD3D72B88; Tue, 26 Nov 2019 07:49:28 +0100 (CET) Received: from APC01-PU1-obe.outbound.protection.outlook.com (mail-oln040092254014.outbound.protection.outlook.com [40.92.254.14]) by dpdk.org (Postfix) with ESMTP id B489628EE for ; Tue, 26 Nov 2019 07:49:26 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TTFOMGSsOAsn/zDcsau57l+my09nMrqdavd8NDo4f5di/TG2y3eqeuGbZgaHyTYqWm6wmCrNjcIKKoumfipzvA9XzZeKD8Kp5oQZHqe3gB31lYhYJoajmw966qxYbx9twzrQcyR/7tCe40GV+hlLdcttzgaLByNE6Vup8Cc8T3xSQ6MOr7yIps7kkPZ3UM8M61QhnI5JHzMjIGJxR3KRz0F3pScB6tQVR8y8YYdPl2OR17QctPZd3pvJsqC8y9s58RMKDE63yEEqyIuUhDu3PE7VKZNtbiIS7Yeda3rucB3I8H93ayuM20asKYJNorB97Avx4qmY8eUjbo/nzJqtCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ehHsdT/ep+WIzBvsoRISyzBRwXI5m9G9U0u9efb1mo0=; b=QdEIUSTLBybjG+vvjn8p4/C06lDV9gx6zzzBlJIyAUP2Z6JLGvZjVv1vIO67PHZsmtoTusI7F9MGMGWd/GCJAtCNYt5H14G1X5xRKNVxbKzreexhhSpelcJuNwhJ1D0J9ih2IT7hTiRPoi3lPcsrrBERzwU4X1u4i1vwXLzmUkpQT2zERV5NY/O8PHqEeueCisyVEYTdGC66hDgHV7Nou7jNxVcSsNKgtZ65t44nRc6UU24i4Zq0cqNXED5sipA3uEX0nXQ7RQto1SI5FkIoA6u/YuZdfsgZ5C8ISFCe+E2YoAHHE5TgS4PhaZl9A3IsUELaK3dRrXbmaGK3dBcMzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ehHsdT/ep+WIzBvsoRISyzBRwXI5m9G9U0u9efb1mo0=; b=N8rh9kTlbWmkLoOKNAQhCk+egzpePrVOpDUONJsWU0x5wZabTqgR2LN8zUfCviq6AGrrEQovfzU0fI6IVS4owwbo/quymgOa3b2psVm39FPb/UoeK3eLjJqd7iUKfPyigUULkeDK3FuhF+mc4YMKRYy2pBaDvepgcv4OIOw+Oq9Y0G9DZpxzXSsvEhR3Zz4svp3uNRk7vsNodEZVVLD1ci1TGJZBNLII2V4duMx3ryGZz8C4SsyIMa2f+FgdryprEzleCE8LLLJwjIVXWeul3aAU+iurcjK8KgKj+0CUZeiyYjBbdMWqgpAcLdCeZPUgoQD66b/8bDmAwoGGfcX7fQ== Received: from HK2APC01FT017.eop-APC01.prod.protection.outlook.com (10.152.248.57) by HK2APC01HT209.eop-APC01.prod.protection.outlook.com (10.152.249.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.17; Tue, 26 Nov 2019 06:49:24 +0000 Received: from HK0PR06MB2740.apcprd06.prod.outlook.com (10.152.248.56) by HK2APC01FT017.mail.protection.outlook.com (10.152.248.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.17 via Frontend Transport; Tue, 26 Nov 2019 06:49:24 +0000 Received: from HK0PR06MB2740.apcprd06.prod.outlook.com ([fe80::746d:7e8a:d390:ca1]) by HK0PR06MB2740.apcprd06.prod.outlook.com ([fe80::746d:7e8a:d390:ca1%7]) with mapi id 15.20.2474.023; Tue, 26 Nov 2019 06:49:24 +0000 From: Hui Wei To: "dev@dpdk.org" Thread-Topic: [PATCH] usertools: fix bind failed can not regression Thread-Index: AQHVpCWjz07Z0jkB2EC0OuIMIMzI2g== Date: Tue, 26 Nov 2019 06:49:24 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SGXP274CA0004.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::16) To HK0PR06MB2740.apcprd06.prod.outlook.com (2603:1096:203:56::17) x-incomingtopheadermarker: OriginalChecksum:6207F59FC93E43FAA3255679307E2A9A91DCDFBEB3677C2232B5064C7FEE40CE; UpperCasedChecksum:C1AB18558CA60160CC306F1D29782733126C68E3B4BC58C241A95E2562BE5845; SizeAsReceived:7080; Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.24.0.windows.2 x-tmn: [hQYSsngOvZTQrNULX5Tf+6mi5+7klUpN] x-microsoft-original-message-id: <20191126064830.1801-1-huiweics@hotmail.com> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 0e3b29cb-a832-4c3c-3ecb-08d7723cc5ef x-ms-traffictypediagnostic: HK2APC01HT209: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yzMUOT+PB6Toug/5Cpp02ioZ6EilCorKGt+lKONtmEnsBBMDgYxc7VM/WUIbKkVMyqu+oMfed/egXInWXZOK55/Ps3iXkj+l7TcXq6fntF2MuwYyFaZBy2xYTq1yReG0GNMcIKKwMABSK0VT2sFfACBdoGwPzG0USel45TZwO/WhylRwjp3N1jyw+Maan8Bn x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 0e3b29cb-a832-4c3c-3ecb-08d7723cc5ef X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Nov 2019 06:49:24.6296 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT209 Subject: [dpdk-dev] [PATCH] usertools: fix bind failed can not regression X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" nic bind to mlx5_core, enable sriov, nic has one pf and 8 vfs, bind pf to vfio-pci failed, can not regress to mlx5_core Signed-off-by: Wei Hui --- usertools/dpdk-devbind.py | 165 ++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 71 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 7b5cbc12c..59e3960af 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -379,6 +379,7 @@ def bind_one(dev_id, driver, force): is already bound to a different driver, it will be unbound first''' dev =3D devices[dev_id] saved_driver =3D None # used to rollback any unbind in case of failur= e + bind_success =3D False =20 # prevent disconnection of our ssh session if dev["Ssh_if"] and not force: @@ -386,16 +387,12 @@ def bind_one(dev_id, driver, force): "Not modifying" % dev_id, file=3Dsys.stderr) return =20 - # unbind any existing drivers we don't want + # does not need to do anything if has_driver(dev_id): if dev["Driver_str"] =3D=3D driver: print("Notice: %s already bound to driver %s, skipping" % (dev_id, driver), file=3Dsys.stderr) return - else: - saved_driver =3D dev["Driver_str"] - unbind_one(dev_id, force) - dev["Driver_str"] =3D "" # clear driver string =20 # For kernels >=3D 3.15 driver_override can be used to specify the dri= ver # for a device rather than relying on the driver to provide a positive @@ -403,40 +400,45 @@ def bind_one(dev_id, driver, force): # the vendor and device ID, adding them to the driver new_id, # will erroneously bind other devices too which has the additional bur= den # of unbinding those devices - if driver in dpdk_drivers: - filename =3D "/sys/bus/pci/devices/%s/driver_override" % dev_id - if os.path.exists(filename): - try: - f =3D open(filename, "w") - except: - print("Error: bind failed for %s - Cannot open %s" - % (dev_id, filename), file=3Dsys.stderr) - return - try: - f.write("%s" % driver) - f.close() - except: - print("Error: bind failed for %s - Cannot write driver %s = to " - "PCI ID " % (dev_id, driver), file=3Dsys.stderr) - return - # For kernels < 3.15 use new_id to add PCI id's to the driver - else: - filename =3D "/sys/bus/pci/drivers/%s/new_id" % driver - try: - f =3D open(filename, "w") - except: - print("Error: bind failed for %s - Cannot open %s" - % (dev_id, filename), file=3Dsys.stderr) - return - try: - # Convert Device and Vendor Id to int to write to new_id - f.write("%04x %04x" % (int(dev["Vendor"],16), - int(dev["Device"], 16))) - f.close() - except: - print("Error: bind failed for %s - Cannot write new PCI ID= to " - "driver %s" % (dev_id, driver), file=3Dsys.stderr) - return + filename =3D "/sys/bus/pci/devices/%s/driver_override" % dev_id + if os.path.exists(filename): + try: + f =3D open(filename, "w") + except: + print("Error: bind failed for %s - Cannot open %s" + % (dev_id, filename), file=3Dsys.stderr) + return + try: + f.write("%s" % driver) + f.close() + except: + print("Error: bind failed for %s - Cannot write driver %s to " + "PCI ID " % (dev_id, driver), file=3Dsys.stderr) + return + # For kernels < 3.15 use new_id to add PCI id's to the driver + else: + filename =3D "/sys/bus/pci/drivers/%s/new_id" % driver + try: + f =3D open(filename, "w") + except: + print("Error: bind failed for %s - Cannot open %s" + % (dev_id, filename), file=3Dsys.stderr) + return + try: + # Convert Device and Vendor Id to int to write to new_id + f.write("%04x %04x" % (int(dev["Vendor"],16), + int(dev["Device"], 16))) + f.close() + except: + print("Error: bind failed for %s - Cannot write new PCI ID to = " + "driver %s" % (dev_id, driver), file=3Dsys.stderr) + return + + # unbind any existing drivers we don't want + if has_driver(dev_id): + saved_driver =3D dev["Driver_str"] + unbind_one(dev_id, force) + del dev["Driver_str"] # clear driver string =20 # do the bind by writing to /sys filename =3D "/sys/bus/pci/drivers/%s/bind" % driver @@ -445,42 +447,63 @@ def bind_one(dev_id, driver, force): except: print("Error: bind failed for %s - Cannot open %s" % (dev_id, filename), file=3Dsys.stderr) - if saved_driver is not None: # restore any previous driver - bind_one(dev_id, saved_driver, force) - return - try: - f.write(dev_id) - f.close() - except: - # for some reason, closing dev_id after adding a new PCI ID to new= _id - # results in IOError. however, if the device was successfully boun= d, - # we don't care for any errors and can safely ignore IOError - tmp =3D get_pci_device_details(dev_id, True) - if "Driver_str" in tmp and tmp["Driver_str"] =3D=3D driver: - return - print("Error: bind failed for %s - Cannot bind to driver %s" - % (dev_id, driver), file=3Dsys.stderr) - if saved_driver is not None: # restore any previous driver - bind_one(dev_id, saved_driver, force) - return - - # For kernels > 3.15 driver_override is used to bind a device to a dri= ver. - # Before unbinding it, overwrite driver_override with empty string so = that - # the device can be bound to any other driver - filename =3D "/sys/bus/pci/devices/%s/driver_override" % dev_id - if os.path.exists(filename): - try: - f =3D open(filename, "w") - except: - sys.exit("Error: unbind failed for %s - Cannot open %s" - % (dev_id, filename)) + else: try: - f.write("\00") + f.write(dev_id) f.close() except: - sys.exit("Error: unbind failed for %s - Cannot open %s" - % (dev_id, filename)) + # for some reason, closing dev_id after adding a new PCI ID to= new_id + # results in IOError. however, if the device was successfully = bound, + # we don't care for any errors and can safely ignore IOError + tmp =3D get_pci_device_details(dev_id, True) + if "Driver_str" in tmp and tmp["Driver_str"] =3D=3D driver: + return + print("Error: bind failed for %s - Cannot bind to driver %s" + % (dev_id, driver), file=3Dsys.stderr) + else: + bind_success =3D True =20 + if False =3D=3D bind_success: + if saved_driver is not None: # restore any previous driver + bind_one(dev_id, saved_driver, force) + dev["Driver_str"] =3D saved_driver + else: + # At this point, pci device previous does not bind to any driv= er, or it will + # be restored it's previous driver. + # For kernels > 3.15 driver_override is used to bind a device = to a driver. + # Before unbinding it, overwrite driver_override with empty st= ring so that + # the device can be bound to any other driver + filename =3D "/sys/bus/pci/devices/%s/driver_override" % dev_i= d + if os.path.exists(filename): + try: + f =3D open(filename, "w") + except: + sys.exit("Error: restore failed for %s - Cannot open %= s" + % (dev_id, filename)) + try: + f.write("\00") + f.close() + except: + sys.exit("Error: restore failed for %s - Cannot write = %s" + % (dev_id, filename)) + # For kernels < 3.15 use remove_id to delete PCI id's from the= driver + else: + filename =3D "/sys/bus/pci/drivers/%s/remove_id" % driver + try: + f =3D open(filename, "w") + except: + print("Error: restore failed for %s - Cannot open %s" + % (dev_id, filename), file=3Dsys.stderr) + return + try: + # Convert Device and Vendor Id to int to write to remo= ve_id + f.write("%04x %04x" % (int(dev["Vendor"],16), + int(dev["Device"], 16))) + f.close() + except: + print("Error: restore failed for %s - Cannot write new= PCI ID to " + "driver %s remove_id" % (dev_id, driver), file= =3Dsys.stderr) + return =20 def unbind_all(dev_list, force=3DFalse): """Unbind method, takes a list of device locations""" --=20 2.24.0.windows.2