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 871DEA00C4; Wed, 12 Oct 2022 14:38:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7AF2243053; Wed, 12 Oct 2022 14:38:25 +0200 (CEST) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by mails.dpdk.org (Postfix) with ESMTP id AC3394303E for ; Wed, 12 Oct 2022 14:38:24 +0200 (CEST) Received: by mail-wr1-f50.google.com with SMTP id n12so26006591wrp.10 for ; Wed, 12 Oct 2022 05:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20210112.gappssmtp.com; s=20210112; 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=OBKtsIeeNaNVQ379DDFJNgBnQ6NN+MB54vsX6uajn5Q=; b=YadbHZ4sKY0KpKMM//2x9JSagjp8NimHGztXJjWKZDnpZivIsuDlwajZL1V+yvtdwH 6zfcCdoGu+cjgAiZb1N2DDyQaMjx87c6+h1YTKm0gNVTL5GrBEl1b7DDTuFIw7WpUFKB Cg2FASdqFDJYFDMDIkkES7sHe7ACy+Rmb+cYBQXfEFOzgdTAcyXBfWMplSPZ2nzfp3Rm hiA2CVYSTVzPN2qZdDDkTtqlswArwlASWadJ5sHM8SqiLAJgR10q6nG6UuP92L9VeY4v 1+qSUUhghqrL4mYbPfx2caJfBrC19rAGS93QUHFxuyBEwOyOohSC4+SP+HhHxw/7Dlou tIKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=OBKtsIeeNaNVQ379DDFJNgBnQ6NN+MB54vsX6uajn5Q=; b=4ioY3JKBwCpf5X+g8ddddzbKLWlwmpgDUmtOwWXmJkJynRu3VVVnLJW+E12gq7vPwB 4+QERvI5U6vSsv6Dsy2d5FsMhcXuL8ciRDPPRcjCnkEmTbETMlZac8kUt7IjRv8HVLr0 8gqYG1dwaoGCo2jX04OHMAgNsMvFqSCawmcpQX4ALoHM4JwlgaIsvrqHaz9qs9DU6L7L K90p+0ZrBwjpwRJxfwisxQLd+R4prS51nnYoHmcAhTCEu06XytgELn6Tw/K0G1xRDn9h xMcG4Qx5InKG4bXCtU999MKnGoINHUeEDLSUmKJ91L6ym134x744TLM+7gX0wNIzaX7c DUUg== X-Gm-Message-State: ACrzQf1/5cjHcbMQXn5OWfUqVc6KuXEzZ6wfZqeO0A/oL5wOkpYrj1d0 OnieCzb/ya46zAEpew8stSdx X-Google-Smtp-Source: AMsMyM4JM7ku9KDPxoBzkcPwBfsKCHm2RRHyGlJMtFrfAu6NnImmE6RO/iRdFbMp/VBK0y8GsYJ+Bg== X-Received: by 2002:a5d:588e:0:b0:22e:5601:f6d with SMTP id n14-20020a5d588e000000b0022e56010f6dmr18112926wrf.207.1665578304427; Wed, 12 Oct 2022 05:38:24 -0700 (PDT) Received: from localhost.localdomain (58-65-164-30.nayatel.pk. [58.65.164.30]) by smtp.gmail.com with ESMTPSA id l32-20020a05600c1d2000b003b47b913901sm6540845wms.1.2022.10.12.05.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 05:38:24 -0700 (PDT) From: Fidaullah Noonari To: stephen@networkplumber.org Cc: dev@dpdk.org, Fidaullah Noonari Subject: [PATCH v4] usertools: add check for IOMMU support in dpdk-devbind Date: Wed, 12 Oct 2022 17:38:17 +0500 Message-Id: <20221012123817.112225-1-fidaullah.noonari@emumba.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220321122727.614290-1-fidaullah.noonari@emumba.com> References: <20220321122727.614290-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 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 | 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