DPDK patches and discussions
 help / color / mirror / Atom feed
From: Fidaullah Noonari <fidaullah.noonari@emumba.com>
To: stephen@networkplumber.org
Cc: dev@dpdk.org, Fidaullah Noonari <fidaullah.noonari@gmai.com>
Subject: [PATCH] usertools: add check for IOMMU support in dpdk-devbind
Date: Tue,  8 Mar 2022 17:49:01 +0500	[thread overview]
Message-ID: <20220308124901.9838-1-fidaullah.noonari@gmai.com> (raw)

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 <fidaullah.noonari@gmai.com>
---
 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)
 
-- 
2.25.1


             reply	other threads:[~2022-03-08 12:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 12:49 Fidaullah Noonari [this message]
2022-03-08 12:56 ` Bruce Richardson
2022-03-10  4:08   ` Fidaullah Noonari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220308124901.9838-1-fidaullah.noonari@gmai.com \
    --to=fidaullah.noonari@emumba.com \
    --cc=dev@dpdk.org \
    --cc=fidaullah.noonari@gmai.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).