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 E0EE2A0093; Thu, 10 Mar 2022 05:08:52 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7B501410FC; Thu, 10 Mar 2022 05:08:52 +0100 (CET) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mails.dpdk.org (Postfix) with ESMTP id 256B1410DD for ; Thu, 10 Mar 2022 05:08:51 +0100 (CET) Received: by mail-wr1-f46.google.com with SMTP id e24so5980706wrc.10 for ; Wed, 09 Mar 2022 20:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NhJsXmfo/e0K+h9E9V0gylkXNIbj01QHjr+LSZV2Zbc=; b=lAzMEKbpoYIQo+8fHIw820EfZnY/8yS2aVxFXVm2Ph+/cMc6foDh4CsbXafMDUOP+m jpSMVFtW58FliKSI22wUOJTCWY4abvvgMDjke61aQbSb9SJRbZvyL1y/2LARRzn9QhXZ bTfzH9tYtrAxy8mQUaGcgixGZL4hLbodY9eJOK2iOkBhZupk4/ifiXBLEq8KItlkqCWn sTIDd7t1ogNYJTVRFPShugi/0aZSu3zhaRBtCwb4Zq7FMMzy2ufjyGSWB0AcgbVePOE/ TYJ2vmpe4Uz3h4hAKEIqRzCqbLiT7C16eI0wsBcCr3WaBolyMY+K4eJFXr+rkSqrNiWy Qm4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NhJsXmfo/e0K+h9E9V0gylkXNIbj01QHjr+LSZV2Zbc=; b=Y4mH1N8xI6DuHVOPZi5cBSDbOqgJMkyjrk67RMi/xMaA01j65HDFanc8TNGyJVwlCS Tn0uci7zu12MTsGvELxsPxt3QS8PbblunbeFnIMUwbogRmOuUjzaBhH9IHXT0VMq3QIq tt0CwcmaXqE3fHaUa2c4fx0EeJpZRtRRHMDrPAODFMT41RIbScBwqB5WNa5g7zz9vCJr LgRX8CtJnAH7+j5+zX3L/7/GHu+xrG2PvptqRYzN/ZNgTyQWpQHcEo0d6I5kBLf3mRua ayzd9kEOKj9TjlUD5/8lfVELJm7R79Zjy5qAo6LC9wdu++IDbJvghLIYI02X3sVTPGIf akcA== X-Gm-Message-State: AOAM530wp3Hgj9K2UtZ8fUPMOUwLYiqGwCBkwS2NRu3xm5OTOCSTEPuw hF5/IjLlVIKiDWHsJKAbNzos7mRrVyIIC4CCiElw X-Google-Smtp-Source: ABdhPJzRbZDXcw25VHhLF0eLZ54XWa3TRzEG5GxQfT2bUs/TUvtINfmtIvmveM5gXigEA5XsxwS8KdHkl8ORqzm/IA8= X-Received: by 2002:a5d:6d86:0:b0:1f1:f938:6626 with SMTP id l6-20020a5d6d86000000b001f1f9386626mr1894504wrs.701.1646885330817; Wed, 09 Mar 2022 20:08:50 -0800 (PST) MIME-Version: 1.0 References: <20220308124901.9838-1-fidaullah.noonari@gmai.com> In-Reply-To: From: Fidaullah Noonari Date: Thu, 10 Mar 2022 09:08:39 +0500 Message-ID: Subject: Re: [PATCH] usertools: add check for IOMMU support in dpdk-devbind To: Bruce Richardson Cc: stephen@networkplumber.org, dev@dpdk.org Content-Type: text/plain; charset="UTF-8" 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 I agree with your suggestion. I would add new flag for noiommu and submit v2 for the patch. On Tue, Mar 8, 2022 at 5:57 PM Bruce Richardson wrote: > > 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