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 06A5DA04FF; Mon, 21 Mar 2022 13:27:35 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8BB0E427E9; Mon, 21 Mar 2022 13:27:35 +0100 (CET) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mails.dpdk.org (Postfix) with ESMTP id 24F164161A for ; Mon, 21 Mar 2022 13:27:34 +0100 (CET) Received: by mail-wm1-f44.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so8267932wmp.5 for ; Mon, 21 Mar 2022 05:27:34 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=y6etXe/WKYTKUZpb3QnI9S+KCdFTTZlKE9NJhZGO5I0=; b=Qc1qpuGoxX4zEfOj9lziHyIJtE0cMdZPPK8zuSfa5L6ziV1FEZd+pQGWMkPHXGN17c K896QMwxZ289sAWxEuBFQItztaggKSTZJ9/0BTkYfF4KOYIdMAzh7Cvjl6jyKLFwPKe6 KUmww4qdJjE2+M+ER8YoMZEPGdIQfoEy1DDWJtCDAKQCVAayCa+g+QkoW/FLBgZhsFkn WJwNs/KUKnA23geVWfV6SQOorSLkVYjIfcFMqH6/vol2iikFEGhXy+alXjZrV/Z1QRlg Zm8wpzQCm2fnQs+yfQgAHVPJQss3chFgXO50RcWRD7Ow3nTue+NFEmqy9A5mLaaXq6Qg ucLQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=y6etXe/WKYTKUZpb3QnI9S+KCdFTTZlKE9NJhZGO5I0=; b=Csfg5/5MMTw9ePKTt2nld8bLScXkjAovC0kQ3yDMPUrLZHVkjhHG4vyMGW/eRrxuI2 CD1HdrSbkLJD3adwbNVuq8OysHNZdSrwnmLCiVpReSipaQ/UN+i58Ocd2cdC4S93LXgE sN8PPaecFrqSqkQo4D1BLsoHzlmWo4p7i8apu8bSQSX/oq3kZ6CBjJvaSiKRz1KdSzeE uywn1vVP9VlMFwdqKyvARFv49ub/FjgYSTp+RUo8zuZ0qKDOA/CZZJqEEVYeORJZNG9y tGzpYL9fcX+tbIeZsHOiC6z0wgI8ZMGHU+hCEeJRIE1L3gxLIVxDwjLgK9fqrxBM311l L3VQ== X-Gm-Message-State: AOAM532Z6tigQIYXxL/ZcN1Otx9afJsiAc7bse9/aj1GwB3z4ypq5/8Q toJZFCyIy5VBOq92poGJNPXg X-Google-Smtp-Source: ABdhPJwcyIleBReIasbIxb+S+EPsnEJIxBiAFPeszDICq2azSsns/fPohVDp6KhmQZKnWXCRdOSw/Q== X-Received: by 2002:a05:600c:a4a:b0:389:e8fd:54b4 with SMTP id c10-20020a05600c0a4a00b00389e8fd54b4mr19097947wmq.168.1647865653782; Mon, 21 Mar 2022 05:27:33 -0700 (PDT) Received: from emumba-Inspiron-3580.Home ([39.38.44.188]) by smtp.gmail.com with ESMTPSA id l8-20020a5d6688000000b001f04ae0bb6csm12765069wru.58.2022.03.21.05.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 05:27:33 -0700 (PDT) From: Fidaullah Noonari To: stephen@networkplumber.org Cc: dev@dpdk.org, Fidaullah Noonari Subject: [PATCH v3] usertools: add check for IOMMU support in dpdk-devbind Date: Mon, 21 Mar 2022 17:27:27 +0500 Message-Id: <20220321122727.614290-1-fidaullah.noonari@emumba.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315062652.78332-1-fidaullah.noonari@emumba.com> References: <20220315062652.78332-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 | 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