From patchwork Wed Jul 24 15:34:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 57038 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 329C11C221; Wed, 24 Jul 2019 17:34:52 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 7F8E01C218 for ; Wed, 24 Jul 2019 17:34:48 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2019 08:34:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,303,1559545200"; d="scan'208";a="163880266" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.223.125]) by orsmga008.jf.intel.com with ESMTP; 24 Jul 2019 08:34:46 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: john.mcnamara@intel.com, thomas@monjalon.net Date: Wed, 24 Jul 2019 16:34:43 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/2] usertools/devbind: add error on forgetting to specify driver 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" A common user error is to forget driver to which the PCI devices should be bound to. Currently, the error message in this case looks unhelpful misleading and indecipherable to anyone but people who know how devbind works. Fix this by checking if the driver string is actually a valid device string. If it is, we assume that the user has just forgot to specify the driver, and display appropriate error. We also assume that no one will name their driver in a format that looks like a PCI address, but that seems like a reasonable assumption to make. Signed-off-by: Anatoly Burakov --- usertools/dpdk-devbind.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 542ecffcc..f7c4c6434 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -342,9 +342,8 @@ def dev_id_from_dev_name(dev_name): if dev_name in devices[d]["Interface"].split(","): return devices[d]["Slot"] # if nothing else matches - error - print("Unknown device: %s. " - "Please specify device in \"bus:slot.func\" format" % dev_name) - sys.exit(1) + raise ValueError("Unknown device: %s. " + "Please specify device in \"bus:slot.func\" format" % dev_name) def unbind_one(dev_id, force): @@ -493,7 +492,12 @@ def unbind_all(dev_list, force=False): unbind_one(devices[d]["Slot"], force) return - dev_list = map(dev_id_from_dev_name, dev_list) + try: + dev_list = map(dev_id_from_dev_name, dev_list) + except ValueError as ex: + print(ex) + sys.exit(1) + for d in dev_list: unbind_one(d, force) @@ -502,7 +506,26 @@ def bind_all(dev_list, driver, force=False): """Bind method, takes a list of device locations""" global devices - dev_list = map(dev_id_from_dev_name, dev_list) + # a common user error is to forget to specify the driver the devices need to + # be bound to. check if the driver is a valid device, and if it is, show + # a meaningful error. + try: + dev_id_from_dev_name(driver) + # if we've made it this far, this means that the "driver" was a valid + # device string, so it's probably not a valid driver name. + print("ERROR: Driver '%s' does not look like a valid driver. " + "Did you forget to specify the driver to bind devices to?" % + driver) + sys.exit(1) + except ValueError: + # driver generated error - it's not a valid device ID, so all is well + pass + + try: + dev_list = map(dev_id_from_dev_name, dev_list) + except ValueError as ex: + print(ex) + sys.exit(1) for d in dev_list: bind_one(d, driver, force) From patchwork Wed Jul 24 15:34:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 57039 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 361901C21D; Wed, 24 Jul 2019 17:34:55 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 629CF1C21D for ; Wed, 24 Jul 2019 17:34:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2019 08:34:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,303,1559545200"; d="scan'208";a="163880276" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.223.125]) by orsmga008.jf.intel.com with ESMTP; 24 Jul 2019 08:34:48 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: john.mcnamara@intel.com, thomas@monjalon.net Date: Wed, 24 Jul 2019 16:34:44 +0100 Message-Id: <1862ad94e15a61121aea75a2933dc8a44bb12623.1563982007.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/2] usertools/devbind: check if module is loaded before binding 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" Currently, if an attempt is made to bind a device to a driver that is not loaded, a confusing and misleading error message appears. Fix it so that, before binding to the driver, we actually check if it is loaded in the kernel first. Signed-off-by: Anatoly Burakov --- usertools/dpdk-devbind.py | 48 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index f7c4c6434..53112c999 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -146,6 +146,25 @@ def check_output(args, stderr=None): return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr).communicate()[0] +# check if a specific kernel module is loaded +def module_is_loaded(module): + # Get list of sysfs modules (both built-in and dynamically loaded) + sysfs_path = '/sys/module/' + + # Get the list of directories in sysfs_path + sysfs_mods = [os.path.join(sysfs_path, o) for o + in os.listdir(sysfs_path) + if os.path.isdir(os.path.join(sysfs_path, o))] + + # get module names + sysfs_mods = [os.path.basename(a) for a in sysfs_mods] + + # special case for vfio_pci (module is named vfio-pci, + # but its .ko is named vfio_pci) + sysfs_mods = [a if a != 'vfio_pci' else 'vfio-pci' for a in sysfs_mods] + + return module in sysfs_mods + def check_modules(): '''Checks that igb_uio is loaded''' @@ -155,27 +174,9 @@ def check_modules(): mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers] # first check if module is loaded - try: - # Get list of sysfs modules (both built-in and dynamically loaded) - sysfs_path = '/sys/module/' - - # Get the list of directories in sysfs_path - sysfs_mods = [os.path.join(sysfs_path, o) for o - in os.listdir(sysfs_path) - if os.path.isdir(os.path.join(sysfs_path, o))] - - # Extract the last element of '/sys/module/abc' in the array - sysfs_mods = [a.split('/')[-1] for a in sysfs_mods] - - # special case for vfio_pci (module is named vfio-pci, - # but its .ko is named vfio_pci) - sysfs_mods = [a if a != 'vfio_pci' else 'vfio-pci' for a in sysfs_mods] - - for mod in mods: - if mod["Name"] in sysfs_mods: - mod["Found"] = True - except: - pass + for mod in mods: + if module_is_loaded(mod["Name"]): + mod["Found"] = True # check if we have at least one loaded module if True not in [mod["Found"] for mod in mods] and b_flag is not None: @@ -521,6 +522,11 @@ def bind_all(dev_list, driver, force=False): # driver generated error - it's not a valid device ID, so all is well pass + # check if we're attempting to bind to a driver that isn't loaded + if not module_is_loaded(driver): + print("ERROR: Driver '%s' is not loaded." % driver) + sys.exit(1) + try: dev_list = map(dev_id_from_dev_name, dev_list) except ValueError as ex: