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 D56CDA04DD; Thu, 19 Nov 2020 13:18:38 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7B4ECDED; Thu, 19 Nov 2020 13:18:36 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 587A823D for ; Thu, 19 Nov 2020 13:18:34 +0100 (CET) IronPort-SDR: kB4oqO7mpTIUhNzzEzJTcOsfJhPzv5J8S7QkfAKT34dDgDLTgkDHMvR0G0lPCtiHosAdvsA3ed L32ZyumKzXGw== X-IronPort-AV: E=McAfee;i="6000,8403,9809"; a="171376642" X-IronPort-AV: E=Sophos;i="5.77,490,1596524400"; d="scan'208";a="171376642" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2020 04:18:33 -0800 IronPort-SDR: 9+EOcqzPV4B1gYFg3gGf4idDZQtNg4T1YEzdfIXbK1HfVWw8nnOcv4KtLGHRupuE8DGVyvv31V YkPPzuNK4Oow== X-IronPort-AV: E=Sophos;i="5.77,490,1596524400"; d="scan'208";a="359956283" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.194.37]) ([10.213.194.37]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2020 04:18:32 -0800 To: Yongxin Liu , dev@dpdk.org, thomas@monjalon.net References: <20201118025854.13455-1-yongxin.liu@windriver.com> <20201119071646.10052-1-yongxin.liu@windriver.com> From: "Burakov, Anatoly" Message-ID: Date: Thu, 19 Nov 2020 12:18:30 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201119071646.10052-1-yongxin.liu@windriver.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v3] usertools/devbind: fix binding for built-in kernel drivers 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" On 19-Nov-20 7:16 AM, Yongxin Liu wrote: > A driver can be loaded as a dynamic module or a built-in module. > In commit 681a67288655 ("usertools: check if module is loaded > before binding"), script only checks modules in /sys/module/. > > However, for built-in kernel driver, it only shows up in /sys/module/, > if it has a version or at least one parameter. So add check for > modules in /lib/modules/$(uname -r)/modules.builtin. > > Thanks for Anatoly Burakov's advice. > > Signed-off-by: Yongxin Liu > --- > > v3: > - Add built-in module list in loaded_modules for checking > instead of removing error check. > > v2: > - fix git commit description style in commit log > - fix typo spelling > > --- > usertools/dpdk-devbind.py | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py > index 99112b7ab..5b34ccd2a 100755 > --- a/usertools/dpdk-devbind.py > +++ b/usertools/dpdk-devbind.py > @@ -181,7 +181,13 @@ def module_is_loaded(module): > > loaded_modules = sysfs_mods > > - return module in sysfs_mods > + # add built-in modules as loaded > + builtin_mods = subprocess.check_output(["cat /lib/modules/$(uname -r)/modules.builtin"], shell=True).splitlines() I'd rather not call shell directly, it's bad practice and is potentially unsafe. The $(uname -r) can be replaced with: import platform release = platform.uname().release # equivalent to $(uname -r) The rest can follow: filename = os.path.join("/lib/modules/", release, "modules.builtin") # read the file contents, split lines, etc. Also, please check if file exists to ensure we don't crash the script. > + for mod in builtin_mods: > + mod_name = os.path.basename(mod.decode("utf8")).split(".ko", 1) os.path.splitext(os.path.basename(...))? > + loaded_modules.append(mod_name[0]) > + > + return module in loaded_modules > > > def check_modules(): > -- Thanks, Anatoly