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 1AAFCA00C2; Tue, 8 Mar 2022 13:57:03 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 90D084068E; Tue, 8 Mar 2022 13:57:02 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id B3BA34068B for ; Tue, 8 Mar 2022 13:57:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646744220; x=1678280220; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=92fjfbbe16WFFGAX2VYMANckITKG1XnON/npCIsUOqQ=; b=b8GyKavUu+0cm/L3YJlPpQb8zy5lq2cb5XQBVUi99p3pVmvnIfrDu/33 Lhpv04rk+6GBdqvBAtXPTkc87bF4qUuqg6Y+xtOkd34yXbZ5116CQurU3 BQpIrapKW+HU6VRMRaH8qzCxUHF4mxoZPCP8ZCsvxD/RGO/qInGa7s23D h1/fvui5u00TU/cCvFJ7YtcBJ4Mpp+ABNIBufiJhX8ksSlWtbPrVNjW+w NJjcySj+qVg7CsGhv7mH3CXhBvCZhbirIegzg1CcQOrfoK0Zs8HNR/1CV cHwd6Nfa2DmAAd6AgKoWdNdLPZ77AH99bICSrLMk4tN4DgE8F8HjoqTPZ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10279"; a="315391007" X-IronPort-AV: E=Sophos;i="5.90,164,1643702400"; d="scan'208";a="315391007" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2022 04:56:59 -0800 X-IronPort-AV: E=Sophos;i="5.90,164,1643702400"; d="scan'208";a="510089303" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.2.229]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 08 Mar 2022 04:56:58 -0800 Date: Tue, 8 Mar 2022 12:56:55 +0000 From: Bruce Richardson To: Fidaullah Noonari Cc: stephen@networkplumber.org, dev@dpdk.org, Fidaullah Noonari Subject: Re: [PATCH] usertools: add check for IOMMU support in dpdk-devbind Message-ID: References: <20220308124901.9838-1-fidaullah.noonari@gmai.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220308124901.9838-1-fidaullah.noonari@gmai.com> 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 On Tue, Mar 08, 2022 at 05:49:01PM +0500, Fidaullah Noonari wrote: > binding with vfio driver, when IOMMU is disabled, causes program to crash. > this patch checks for IOMMU support, if it is disabled, changes vfio > into unsafe noiommu mode and prints a warning message. > > Signed-off-by: Fidaullah Noonari > --- > usertools/dpdk-devbind.py | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py > index ace4627218..f42eead0c4 100755 > --- a/usertools/dpdk-devbind.py > +++ b/usertools/dpdk-devbind.py > @@ -466,6 +466,26 @@ def unbind_all(dev_list, force=False): > unbind_one(d, force) > > > +def check_iommu(): > + """Check if IOMMU is enabled on system""" > + if len(os.listdir("/sys/class/iommu")) != 0: > + return True > + print("Warning: IOMMU support disabled") > + return False > + > + > +def enable_noiommu_mode(): > + """Enables the noiommu mode for vfio drivers""" > + filename = "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode" > + try: > + f = open(filename, "w") > + except: > + sys.exit("Error: unable to enable noiommu mode, could not open '%s'" % filename) > + f.write("1") > + f.close() > + print("Warning: enabling unsafe no IOMMU mode for vfio drivers") > + > + > def bind_all(dev_list, driver, force=False): > """Bind method, takes a list of device locations""" > global devices > @@ -492,6 +512,11 @@ def bind_all(dev_list, driver, force=False): > except ValueError as ex: > sys.exit(ex) > > + # check for IOMMU support > + if not check_iommu(): > + if driver == "vfio-pci": > + enable_noiommu_mode() > + > for d in dev_list: > bind_one(d, driver, force) > I like the idea of doing this from the script, but I would rather it not happen by default, since no-iommu reduces the security of the system. In the normal case, I think it would be best if the script printed an error message asking the user to enable iommu. We can also then add a flag to allow the user to explicitly ask for no-iommu mode and take the risk. /Bruce