DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Fidaullah Noonari <fidaullah.noonari@emumba.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH] usertools/devbind: add support for non-IOMMU mode
Date: Wed,  2 Oct 2024 11:13:12 -0700	[thread overview]
Message-ID: <20241002181456.159647-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20221012123817.112225-1-fidaullah.noonari@emumba.com>

From: Fidaullah Noonari <fidaullah.noonari@emumba.com>

This patch adds noiommu option to dpdk-devbind.
If the no IOMMU is detected, then if noiommu flag is set
the vfio-pci unsafe_noiommu_mode flag is set.

Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2 - rebase patch and fix some minor stuff
     remove unneeded f.close, simplify error and help messages 

 usertools/dpdk-devbind.py | 40 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index b276e8efc8..db336f519d 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -107,6 +107,7 @@
 b_flag = None
 status_flag = False
 force_flag = False
+noiommu_flag = False
 args = []
 
 
@@ -477,6 +478,34 @@ def unbind_all(dev_list, force=False):
         unbind_one(d, force)
 
 
+def has_iommu():
+    """Check if IOMMU is enabled on system"""
+    return len(os.listdir("/sys/class/iommu")) > 0
+
+
+def check_noiommu_mode():
+    """checks and enables the noiommu mode for vfio drivers"""
+    global noiommu_flag
+    filename = "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"
+
+    try:
+        with open(filename, "r") as f:
+            if f.read(1) == "1":
+                return
+    except OSError as err:
+        sys.exit(f"Error: failed to check unsafe noiommu mode - Cannot open {filename}: {err}")
+
+    if not noiommu_flag:
+        sys.exit("Error: IOMMU support is disabled, use --noiommu-mode for binding in noiommu mode")
+
+    try:
+        with open(filename, "w") as f:
+            f.write("1")
+    except OSError as err:
+        sys.exit(f"Error: failed to enable unsafe noiommu mode - Cannot open {filename}: {err}")
+    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
@@ -503,6 +532,10 @@ def bind_all(dev_list, driver, force=False):
     except ValueError as ex:
         sys.exit(ex)
 
+    # check for IOMMU support
+    if driver == "vfio-pci" and not has_iommu():
+        check_noiommu_mode()
+
     for d in dev_list:
         bind_one(d, driver, force)
 
@@ -648,6 +681,7 @@ def parse_args():
     global status_flag
     global status_dev
     global force_flag
+    global noiommu_flag
     global args
 
     parser = argparse.ArgumentParser(
@@ -694,6 +728,10 @@ def parse_args():
         '--unbind',
         action='store_true',
         help="Unbind a device (equivalent to \"-b none\")")
+    parser.add_argument(
+        '--noiommu-mode',
+        action='store_true',
+        help="If IOMMU is not available, Enables no IOMMU mode for vfio drivers")
     parser.add_argument(
         '--force',
         action='store_true',
@@ -720,6 +758,8 @@ def parse_args():
         status_dev = "all"
     if opt.force:
         force_flag = True
+    if opt.noiommu_mode:
+        noiommu_flag = True
     if opt.bind:
         b_flag = opt.bind
     elif opt.unbind:
-- 
2.45.2


  parent reply	other threads:[~2024-10-02 18:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15  6:26 [PATCH v2] usertools: add check for IOMMU support in dpdk-devbind Fidaullah Noonari
2022-03-15  9:17 ` Bruce Richardson
2022-03-21 12:27 ` [PATCH v3] " Fidaullah Noonari
2022-03-31 14:37   ` Burakov, Anatoly
2022-03-31 14:44     ` Bruce Richardson
2022-10-10 23:02       ` Thomas Monjalon
2022-10-12 12:38   ` [PATCH v4] " Fidaullah Noonari
2024-07-01 17:51     ` Stephen Hemminger
2024-10-02 18:13     ` Stephen Hemminger [this message]
2024-10-03  9:27       ` [PATCH] usertools/devbind: add support for non-IOMMU mode Bruce Richardson
2024-10-17 15:34         ` Thomas Monjalon
2023-07-06 18:22   ` [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind Stephen Hemminger
2023-10-31 18:34   ` Stephen Hemminger

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=20241002181456.159647-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=fidaullah.noonari@emumba.com \
    /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).