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 7A9E1A00BE; Tue, 15 Mar 2022 07:27:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 09DF640395; Tue, 15 Mar 2022 07:27:32 +0100 (CET) Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by mails.dpdk.org (Postfix) with ESMTP id 4922B4014F for ; Tue, 15 Mar 2022 07:27:31 +0100 (CET) Received: by mail-ej1-f46.google.com with SMTP id bi12so39002567ejb.3 for ; Mon, 14 Mar 2022 23:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3zb7Nvpvih31nZNabLwp9k6Y8aqlav3bLQ/qNlCE18M=; b=r1ApwfxyShnLERG6ZiWbCaLcaAR7UsOdJeoi+Rra+dI9yfINmKXasO2HpqlK4tFQMv finYd8gMrh1MV7aD3E31hSD2f9oR/ZXdtMnBk4zlmohSNQUTIbcZvjBZsLTMiep1D6Uk docIxd3654Am/3Dg/EPTyJhGdPiqd7EKMDPd3lrpKA6N0jQusWhVMKjClyZ99qSmzxh+ QWE2ZQnei436tl4hnSAOAtLgWu2FZjsLM8eEyjUVgEUS2sy1pfJag/OdliJ3qyO3qwR5 lQpH+5tk+X4U4RNi4ZpkvFGX3JTdLsq+/Mf1G2/sWzya8F9h2r7xTnIoYaPeyDFPDa7M i+yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3zb7Nvpvih31nZNabLwp9k6Y8aqlav3bLQ/qNlCE18M=; b=0Y6XsjbH8QJ9BVVyoAW5vAh4jA2FJ00X3/krzwza+CqZUMf5bopEFElSs3vRoJN9mc mE2GSBTipNphEEF9bJZ0pg7+lW2BZVtMycnnOP9dfss8C6wyouxjOGpLVRuU2ylBWj9H UP3UcEiLU8VrqtqCGXsaVLF2il99VNdLW39TmM5Ihfjoula7TLiEz8UPeoyA6GP1jyig oId/g4CnIqMmGk6pP9vNtz9nabfMlK9zw1AQgqaqzdIQViNxkBa4oBVDtvfBdD01Cdt2 CnuTTmOy7LqUEIbW2MwfCUcZMlSAd8Us/D2gfUXgmMIZXgNcxvXQRgmhsnEzzFQZn/nX Gl0w== X-Gm-Message-State: AOAM532Fga3XV7IlryLv7eR2xd+db2bhq35U7Q89PeVkakvK6XuqF0iZ 8LIf0XAA4P68a4PF3zIcEIAlZLTpH9aQ X-Google-Smtp-Source: ABdhPJwVorOzuq57j7D3hpAV7MiGyhcmBd9XA8rdg338T2depCNQ5UEK3tWp/zlUCMu8/LWJVdt1kw== X-Received: by 2002:a17:907:b590:b0:6cf:48a4:9a4c with SMTP id qx16-20020a170907b59000b006cf48a49a4cmr21132454ejc.6.1647325650964; Mon, 14 Mar 2022 23:27:30 -0700 (PDT) Received: from emumba-Inspiron-3580.Home ([182.191.83.208]) by smtp.gmail.com with ESMTPSA id l9-20020a056402254900b00416b0ec98b5sm7706965edb.45.2022.03.14.23.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 23:27:30 -0700 (PDT) From: Fidaullah Noonari To: stephen@networkplumber.org Cc: dev@dpdk.org, Fidaullah Noonari Subject: [PATCH v2] usertools: add check for IOMMU support in dpdk-devbind Date: Tue, 15 Mar 2022 11:26:52 +0500 Message-Id: <20220315062652.78332-1-fidaullah.noonari@emumba.com> X-Mailer: git-send-email 2.25.1 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 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 --- 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