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 81C9E45A9F; Wed, 2 Oct 2024 20:15:09 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6007340299; Wed, 2 Oct 2024 20:15:09 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 4416A40268 for ; Wed, 2 Oct 2024 20:15:07 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71c702b2d50so127213b3a.1 for ; Wed, 02 Oct 2024 11:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727892906; x=1728497706; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1OcKwufrw/XHo9y6njTFCqe2p5SH8C5MlAiEWaFK+4U=; b=hEnb4/z68xkstFzdU6ezhnS5pQHq0TEPz8a1pcDUYe0zKdbwXkWMCPZNko50Vwu3XW mgdwOzC3Sdgtgp/DY5sqHWNOmOv8xhcOPZlmp5lE2U0APwVR+NkmxBVpqAERKXNU20JS s1r199kklr61Uyo8MxYu3B5Rfzhk+N5er/T6Q64TKVXnoh0aGFc1oyLhm+jUwU0Fs3Eo ZTci6jCeh4/A00SQiwzAqwlYi0iF6xXduZlazJXVj5IUMDfJVW9Dmf9XIoNZUlgTpcBG arGqVw5bvHv+5cM+nizQEnaNCwHaHEoUv+go4clmjRFQgSG00YBlisF7ir4RxzaHQ++x p03Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727892906; x=1728497706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1OcKwufrw/XHo9y6njTFCqe2p5SH8C5MlAiEWaFK+4U=; b=lG3LLwsjZg/plDv7yba996NCTofAPtwnfjJhtfTkBSLfVJ6CC4IWXdRpMUGHZvwtP6 jT3BlqXeILc4oRojn1Nw54ZjDm+z2JD+CdLN323N4xQq1Bw2MZdhQU3qHbwDIb8CHGBI BZbhBvg21ZkpfyrfwsXcxoHZqBStCt5fzJL4D1NrgLyjdm0mOAbSAHLFhXcYGYkFzG00 yAWfBKiYG/gVG1KDhaSjnjsnL5eSJi2acpexLfKG5LZTSUw13Bo3Khc/8IAmcMrVPkvj o9+u9cFDIDEKAhN7W2SsEa6JO5oAEN1EBq12s6aXXzUXtmbn1AvcBUBiZ9t7ONpsS+Ye G9Eg== X-Gm-Message-State: AOJu0YzP141JEkm0Fi/i2x48lQldoCaOPGlcJhCCvuagA45R7hO2Oe7q TaKIgEi+H096EpnZ1FOz7odA97JBsqDEar9F0j+bVFo6HM+UHpQ07KWs8f/KrgENKl8+INoSQL+ r X-Google-Smtp-Source: AGHT+IFhKGZl1MxHxaCpNagSsFI7jY85wkl4JHcVp/KktJoc0KhCzWrssIX319+ynjyCaGEvKysuPA== X-Received: by 2002:a05:6a20:c6c2:b0:1cf:51a1:8e89 with SMTP id adf61e73a8af0-1d5f23fb2c9mr5142390637.47.1727892906128; Wed, 02 Oct 2024 11:15:06 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b264bb2b8sm10135125b3a.61.2024.10.02.11.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 11:15:05 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Fidaullah Noonari , Stephen Hemminger Subject: [PATCH] usertools/devbind: add support for non-IOMMU mode Date: Wed, 2 Oct 2024 11:13:12 -0700 Message-ID: <20241002181456.159647-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20221012123817.112225-1-fidaullah.noonari@emumba.com> References: <20221012123817.112225-1-fidaullah.noonari@emumba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Fidaullah Noonari 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 Signed-off-by: Stephen Hemminger --- 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