DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v2] usertools: add check for IOMMU support in dpdk-devbind
@ 2022-03-15  6:26 Fidaullah Noonari
  2022-03-15  9:17 ` Bruce Richardson
  2022-03-21 12:27 ` [PATCH v3] " Fidaullah Noonari
  0 siblings, 2 replies; 13+ messages in thread
From: Fidaullah Noonari @ 2022-03-15  6:26 UTC (permalink / raw)
  To: stephen; +Cc: dev, Fidaullah Noonari

binding with vfio driver, when IOMMU is disabled, causes program to crash.
this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
disabled, it changes vfio into unsafe noiommu mode and prints warning
message.

Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
---
 usertools/dpdk-devbind.py | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index ace4627218..91fa4c7620 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -96,6 +96,7 @@
 b_flag = None
 status_flag = False
 force_flag = False
+noiommu_flag = False
 args = []
 
 
@@ -466,9 +467,30 @@ 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
+    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 OSError as err:
+        sys.exit("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
+                % (filename, err))
+    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
+    global noiommu_flag
 
     # a common user error is to forget to specify the driver the devices need to
     # be bound to. check if the driver is a valid device, and if it is, show
@@ -492,6 +514,14 @@ def bind_all(dev_list, driver, force=False):
     except ValueError as ex:
         sys.exit(ex)
 
+    # check for IOMMU support
+    if not check_iommu():
+        if noiommu_flag:
+            enable_noiommu_mode()
+        elif driver == "vfio-pci":
+            print("Warning: IOMMU support is disabled")
+            print("Info: use --noiommu-mode for binding in noiommu mode")
+
     for d in dev_list:
         bind_one(d, driver, force)
 
@@ -634,6 +664,7 @@ def parse_args():
     global status_flag
     global status_dev
     global force_flag
+    global noiommu_flag
     global args
 
     parser = argparse.ArgumentParser(
@@ -687,6 +718,12 @@ def parse_args():
 Override restriction on binding devices in use by Linux"
 WARNING: This can lead to loss of network connection and should be used with caution.
 """)
+    parser.add_argument(
+        '--noiommu-mode',
+        action='store_true',
+        help="""
+if IOMMU is not available, Enables no IOMMU mode for vfio drivers.
+        """)
     parser.add_argument(
         'devices',
         metavar='DEVICE',
@@ -706,6 +743,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.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] usertools: add check for IOMMU support in dpdk-devbind
  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
  1 sibling, 0 replies; 13+ messages in thread
From: Bruce Richardson @ 2022-03-15  9:17 UTC (permalink / raw)
  To: Fidaullah Noonari; +Cc: stephen, dev

On Tue, Mar 15, 2022 at 11:26:52AM +0500, Fidaullah Noonari wrote:
> binding with vfio driver, when IOMMU is disabled, causes program to crash.
> this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
> disabled, it changes vfio into unsafe noiommu mode and prints warning
> message.
> 
> Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
> ---

Hi,

patch generally looks good, but some more feedback inline below. The main
thing missing is that we should probably also check the current value of
the vfio noiommu flag and take that into account when printing warnings or
errors.

/Bruce

>  usertools/dpdk-devbind.py | 39 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index ace4627218..91fa4c7620 100755
> --- a/usertools/dpdk-devbind.py
> +++ b/usertools/dpdk-devbind.py
> @@ -96,6 +96,7 @@
>  b_flag = None
>  status_flag = False
>  force_flag = False
> +noiommu_flag = False
>  args = []
>  
>  
> @@ -466,9 +467,30 @@ 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
> +    return False

I'd suggest renaming the function for clarity, since "check_iommu" is
a little unclear as to what the return value is i.e. false could mean you
can't check, rather than it doesn't have one. "has_iommu()" might be
clearer.

Can probably be shortened to one-line body:

    def has_iommu():
        """..."""
        return len(os.listdir("/sys/class/iommu")) > 0

> +
> +
> +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 OSError as err:
> +        sys.exit("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
> +                % (filename, err))
> +    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
> +    global noiommu_flag
>  
>      # a common user error is to forget to specify the driver the devices need to
>      # be bound to. check if the driver is a valid device, and if it is, show
> @@ -492,6 +514,14 @@ def bind_all(dev_list, driver, force=False):
>      except ValueError as ex:
>          sys.exit(ex)
>  
> +    # check for IOMMU support
> +    if not check_iommu():
> +        if noiommu_flag:
> +            enable_noiommu_mode()
> +        elif driver == "vfio-pci":
> +            print("Warning: IOMMU support is disabled")
> +            print("Info: use --noiommu-mode for binding in noiommu mode")
> +

Rather than just warning here, I think this needs a little extra check to
see if no-iommu mode is already enabled. If so, just continue, if it is
not, then the warning should be an error and no binding should be
attempted.

>      for d in dev_list:
>          bind_one(d, driver, force)
>  
> @@ -634,6 +664,7 @@ def parse_args():
>      global status_flag
>      global status_dev
>      global force_flag
> +    global noiommu_flag
>      global args
>  
>      parser = argparse.ArgumentParser(
> @@ -687,6 +718,12 @@ def parse_args():
>  Override restriction on binding devices in use by Linux"
>  WARNING: This can lead to loss of network connection and should be used with caution.
>  """)
> +    parser.add_argument(
> +        '--noiommu-mode',
> +        action='store_true',
> +        help="""
> +if IOMMU is not available, Enables no IOMMU mode for vfio drivers.
> +        """)
>      parser.add_argument(
>          'devices',
>          metavar='DEVICE',
> @@ -706,6 +743,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.25.1
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind
  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 ` Fidaullah Noonari
  2022-03-31 14:37   ` Burakov, Anatoly
                     ` (3 more replies)
  1 sibling, 4 replies; 13+ messages in thread
From: Fidaullah Noonari @ 2022-03-21 12:27 UTC (permalink / raw)
  To: stephen; +Cc: dev, Fidaullah Noonari

binding with vfio driver, when IOMMU is disabled, causes program to crash.
this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
disabled, it changes vfio into unsafe noiommu mode and prints warning
message.

Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
---
 usertools/dpdk-devbind.py | 47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index ace4627218..e2181efac8 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -96,6 +96,7 @@
 b_flag = None
 status_flag = False
 force_flag = False
+noiommu_flag = False
 args = []
 
 
@@ -466,6 +467,39 @@ 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("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
+                % (filename, err))
+
+    if not noiommu_flag:
+        print("Error: failed to bind vfio-pci - IOMMU support is disabled")
+        print("Info: use --noiommu-mode for binding in noiommu mode")
+        sys.exit()
+
+    try:
+        with open(filename, "w") as f:
+            f.write("1")
+            f.close()
+    except OSError as err:
+        sys.exit("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
+                % (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
@@ -492,6 +526,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)
 
@@ -634,6 +672,7 @@ def parse_args():
     global status_flag
     global status_dev
     global force_flag
+    global noiommu_flag
     global args
 
     parser = argparse.ArgumentParser(
@@ -687,6 +726,12 @@ def parse_args():
 Override restriction on binding devices in use by Linux"
 WARNING: This can lead to loss of network connection and should be used with caution.
 """)
+    parser.add_argument(
+        '--noiommu-mode',
+        action='store_true',
+        help="""
+if IOMMU is not available, Enables no IOMMU mode for vfio drivers.
+        """)
     parser.add_argument(
         'devices',
         metavar='DEVICE',
@@ -706,6 +751,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.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind
  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-12 12:38   ` [PATCH v4] " Fidaullah Noonari
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Burakov, Anatoly @ 2022-03-31 14:37 UTC (permalink / raw)
  To: Fidaullah Noonari, stephen; +Cc: dev

On 21-Mar-22 12:27 PM, Fidaullah Noonari wrote:
> binding with vfio driver, when IOMMU is disabled, causes program to crash.
> this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
> disabled, it changes vfio into unsafe noiommu mode and prints warning
> message.
> 
> Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
> ---

Hi,

> +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("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
> +                % (filename, err))

Nitpick, but maybe use f-strings instead of old-school string interpolation?

> +
> +    if not noiommu_flag:
> +        print("Error: failed to bind vfio-pci - IOMMU support is disabled")
> +        print("Info: use --noiommu-mode for binding in noiommu mode")
> +        sys.exit()
> +
> +    try:
> +        with open(filename, "w") as f:
> +            f.write("1")
> +            f.close()
> +    except OSError as err:
> +        sys.exit("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
> +                % (filename, err))

Same as above.

Otherwise LGTM,

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind
  2022-03-31 14:37   ` Burakov, Anatoly
@ 2022-03-31 14:44     ` Bruce Richardson
  2022-10-10 23:02       ` Thomas Monjalon
  0 siblings, 1 reply; 13+ messages in thread
From: Bruce Richardson @ 2022-03-31 14:44 UTC (permalink / raw)
  To: Burakov, Anatoly; +Cc: Fidaullah Noonari, stephen, dev

On Thu, Mar 31, 2022 at 03:37:40PM +0100, Burakov, Anatoly wrote:
> On 21-Mar-22 12:27 PM, Fidaullah Noonari wrote:
> > binding with vfio driver, when IOMMU is disabled, causes program to crash.
> > this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
> > disabled, it changes vfio into unsafe noiommu mode and prints warning
> > message.
> > 
> > Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
> > ---
> 
> Hi,
> 
> > +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("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
> > +                % (filename, err))
> 
> Nitpick, but maybe use f-strings instead of old-school string interpolation?
> 

Do we still not need to support some distros that don't have Python earlier
than 3.6, where this support was added? 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind
  2022-03-31 14:44     ` Bruce Richardson
@ 2022-10-10 23:02       ` Thomas Monjalon
  0 siblings, 0 replies; 13+ messages in thread
From: Thomas Monjalon @ 2022-10-10 23:02 UTC (permalink / raw)
  To: Fidaullah Noonari, Bruce Richardson
  Cc: Burakov, Anatoly, dev, stephen, Robin Jarry

31/03/2022 16:44, Bruce Richardson:
> On Thu, Mar 31, 2022 at 03:37:40PM +0100, Burakov, Anatoly wrote:
> > On 21-Mar-22 12:27 PM, Fidaullah Noonari wrote:
> > > binding with vfio driver, when IOMMU is disabled, causes program to crash.
> > > this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
> > > disabled, it changes vfio into unsafe noiommu mode and prints warning
> > > message.
> > > 
> > > Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
> > > ---
> > 
> > Hi,
> > 
> > > +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("Error: failed to enable unsafe noiommu mode - Cannot open %s: %s"
> > > +                % (filename, err))
> > 
> > Nitpick, but maybe use f-strings instead of old-school string interpolation?
> > 
> 
> Do we still not need to support some distros that don't have Python earlier
> than 3.6, where this support was added? 

The requirements have been upgraded to Python 3.6 with the new pmdinfo.

Are we waiting for a new version?





^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4] usertools: add check for IOMMU support in dpdk-devbind
  2022-03-21 12:27 ` [PATCH v3] " Fidaullah Noonari
  2022-03-31 14:37   ` Burakov, Anatoly
@ 2022-10-12 12:38   ` Fidaullah Noonari
  2024-07-01 17:51     ` Stephen Hemminger
  2024-10-02 18:13     ` [PATCH] usertools/devbind: add support for non-IOMMU mode Stephen Hemminger
  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
  3 siblings, 2 replies; 13+ messages in thread
From: Fidaullah Noonari @ 2022-10-12 12:38 UTC (permalink / raw)
  To: stephen; +Cc: dev, Fidaullah Noonari

binding with vfio driver, when IOMMU is disabled, causes program to crash.
this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
disabled, it changes vfio into unsafe noiommu mode and prints warning
message.

Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
---
 usertools/dpdk-devbind.py | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 4d9c1be666..d875ff23d6 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -100,6 +100,7 @@
 b_flag = None
 status_flag = False
 force_flag = False
+noiommu_flag = False
 args = []
 
 
@@ -470,6 +471,37 @@ 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 enable unsafe noiommu mode - Cannot open {filename}: {err}")
+
+    if not noiommu_flag:
+        print("Error: failed to bind vfio-pci - IOMMU support is disabled")
+        print("Info: use --noiommu-mode for binding in noiommu mode")
+        sys.exit()
+
+    try:
+        with open(filename, "w") as f:
+            f.write("1")
+            f.close()
+    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
@@ -496,6 +528,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)
 
@@ -638,6 +674,7 @@ def parse_args():
     global status_flag
     global status_dev
     global force_flag
+    global noiommu_flag
     global args
 
     parser = argparse.ArgumentParser(
@@ -691,6 +728,12 @@ def parse_args():
 Override restriction on binding devices in use by Linux"
 WARNING: This can lead to loss of network connection and should be used with caution.
 """)
+    parser.add_argument(
+        '--noiommu-mode',
+        action='store_true',
+        help="""
+if IOMMU is not available, Enables no IOMMU mode for vfio drivers.
+        """)
     parser.add_argument(
         'devices',
         metavar='DEVICE',
@@ -710,6 +753,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.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind
  2022-03-21 12:27 ` [PATCH v3] " Fidaullah Noonari
  2022-03-31 14:37   ` Burakov, Anatoly
  2022-10-12 12:38   ` [PATCH v4] " Fidaullah Noonari
@ 2023-07-06 18:22   ` Stephen Hemminger
  2023-10-31 18:34   ` Stephen Hemminger
  3 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2023-07-06 18:22 UTC (permalink / raw)
  To: Fidaullah Noonari; +Cc: dev

On Mon, 21 Mar 2022 17:27:27 +0500
Fidaullah Noonari <fidaullah.noonari@emumba.com> wrote:

> binding with vfio driver, when IOMMU is disabled, causes program to crash.
> this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
> disabled, it changes vfio into unsafe noiommu mode and prints warning
> message.
> 
> Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
> ---

Minor indentation issues reported by flake8 python checker:

./usertools/dpdk-devbind.py:489:27: E231 missing whitespace after ','
./usertools/dpdk-devbind.py:494:17: E128 continuation line under-indented for visual indent
./usertools/dpdk-devbind.py:507:17: E128 continuation line under-indented for visual indent

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind
  2022-03-21 12:27 ` [PATCH v3] " Fidaullah Noonari
                     ` (2 preceding siblings ...)
  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
  3 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2023-10-31 18:34 UTC (permalink / raw)
  To: Fidaullah Noonari; +Cc: dev

On Mon, 21 Mar 2022 17:27:27 +0500
Fidaullah Noonari <fidaullah.noonari@emumba.com> wrote:

> +
> +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

Note: flake8 reports missing comma after filename in the open() statement.

Overall
Acked-by: Stephen Hemminger <stephen@networkplumber.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4] usertools: add check for IOMMU support in dpdk-devbind
  2022-10-12 12:38   ` [PATCH v4] " Fidaullah Noonari
@ 2024-07-01 17:51     ` Stephen Hemminger
  2024-10-02 18:13     ` [PATCH] usertools/devbind: add support for non-IOMMU mode Stephen Hemminger
  1 sibling, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2024-07-01 17:51 UTC (permalink / raw)
  To: Fidaullah Noonari; +Cc: dev

On Wed, 12 Oct 2022 17:38:17 +0500
Fidaullah Noonari <fidaullah.noonari@emumba.com> wrote:

> binding with vfio driver, when IOMMU is disabled, causes program to crash.
> this patch adds a flag for noiommmu-mode. when this is set, if IOMMU is
> disabled, it changes vfio into unsafe noiommu mode and prints warning
> message.
> 
> Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>

Not sure why this patch got stuck.
The flake8 tool reports:


usertools/dpdk-devbind.py:489:27: E231 missing whitespace after ','
Fix by:

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index e7a5665fa2..a089313db1 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -486,7 +486,7 @@ def check_noiommu_mode():
     filename = "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"
 
     try:
-        with open(filename,"r") as f:
+        with open(filename, "r") as f:
             if f.read(1) == "1":
                 return
     except OSError as err:

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH] usertools/devbind: add support for non-IOMMU mode
  2022-10-12 12:38   ` [PATCH v4] " Fidaullah Noonari
  2024-07-01 17:51     ` Stephen Hemminger
@ 2024-10-02 18:13     ` Stephen Hemminger
  2024-10-03  9:27       ` Bruce Richardson
  1 sibling, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2024-10-02 18:13 UTC (permalink / raw)
  To: dev; +Cc: Fidaullah Noonari, Stephen Hemminger

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] usertools/devbind: add support for non-IOMMU mode
  2024-10-02 18:13     ` [PATCH] usertools/devbind: add support for non-IOMMU mode Stephen Hemminger
@ 2024-10-03  9:27       ` Bruce Richardson
  2024-10-17 15:34         ` Thomas Monjalon
  0 siblings, 1 reply; 13+ messages in thread
From: Bruce Richardson @ 2024-10-03  9:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, Fidaullah Noonari

On Wed, Oct 02, 2024 at 11:13:12AM -0700, Stephen Hemminger wrote:
> 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 
>
Acked-by: Bruce Richardson <bruce.richardson@intel.com> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] usertools/devbind: add support for non-IOMMU mode
  2024-10-03  9:27       ` Bruce Richardson
@ 2024-10-17 15:34         ` Thomas Monjalon
  0 siblings, 0 replies; 13+ messages in thread
From: Thomas Monjalon @ 2024-10-17 15:34 UTC (permalink / raw)
  To: Stephen Hemminger, Fidaullah Noonari; +Cc: dev, Bruce Richardson

03/10/2024 11:27, Bruce Richardson:
> On Wed, Oct 02, 2024 at 11:13:12AM -0700, Stephen Hemminger wrote:
> > 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 
> >
> Acked-by: Bruce Richardson <bruce.richardson@intel.com> 

Applied with few wording changes, thanks.




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-10-17 15:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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     ` [PATCH] usertools/devbind: add support for non-IOMMU mode Stephen Hemminger
2024-10-03  9:27       ` 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

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).