From nobody Wed May 14 06:11:17 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527770422156131.2757157561416; Thu, 31 May 2018 05:40:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05CC51907FA; Thu, 31 May 2018 12:40:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9815F608EF; Thu, 31 May 2018 12:40:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 37E306B548; Thu, 31 May 2018 12:40:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4VCe4ft016486 for ; Thu, 31 May 2018 08:40:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE8442010CC0; Thu, 31 May 2018 12:40:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1A9E2010CBF for ; Thu, 31 May 2018 12:40:01 +0000 (UTC) Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE6AB10DA9 for ; Thu, 31 May 2018 12:39:49 +0000 (UTC) Received: by mail-wr0-f169.google.com with SMTP id d2-v6so17406711wrm.10 for ; Thu, 31 May 2018 05:39:49 -0700 (PDT) Received: from filip.redhat.com ([213.175.37.12]) by smtp.googlemail.com with ESMTPSA id l5-v6sm19444452wrn.92.2018.05.31.05.39.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 05:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4nJn+x/JzIhGTBsljPH1o5ch3GXx3667b9I4hb0QwYc=; b=kmenEfw95B9JHMrfJnogOPGfqnLkywGrwZJDoCnLoRDeG9HYgbQlF2pVTgwXuRTy7J fW8s+IjZwCj4jMmChmNQ5dHnFOcLDqSKhG3/vccD+dwxDS6eAez4XDigh5HFug6J8ENa KN8n5/I/SIffdOSJ+DdLRBE45c340ayOmFeLI8LBweWR3VtIxHqbvFIqzmGczK7FAADp H7jzoQUyWp95S/e9J1siTjYH5NsvvvX/AtJQ1x8GIFN3UafUmtLVz/6iOgj3gFU1ViYv bXcB8In4pssKRJbznQ9AK+8n7MLeX2J9jJrb8qF9Ak5OAG/hKF7DED1muTONLKj+OGIj dzfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4nJn+x/JzIhGTBsljPH1o5ch3GXx3667b9I4hb0QwYc=; b=DJ1jZDrtYxYeoOb7EZFwC6c6EosLQKSg6rw0uCwdHRkTYptF3RCiqaoDL08h2H76nJ 94AcoXqbt6b8bsKCtNXCXL973aME/1DEqewTwajwDF11Bh/3MKuLuxgClq4kDuy0wWYo U6bK/148nw5kRNt26gHWckOUWK0PyaAF54sBZTlaNwk+6L+uNxJhTrS1q1fdLHU3W7Wa 4yjwFL2dmEFlDTHVR8nm3mBRcuP2OqQWlPj9znkxgxOKw7YutY2qwlCtxqqrvbo/xdVS XwhJNKWI5WeTHYWil71+i3geGvA4vM2meW4bo1fcNApyja74kGBGR5yD7ZLtCKEA8V3m /Klg== X-Gm-Message-State: ALKqPwet5Re98g73fdKapr4JjoEoyq7ptIHCPYG5z8tW5t2r2UXDMG00 UbPQbpPeHMx6RmgTb+Z6SPt2yA== X-Google-Smtp-Source: ADUXVKI+lKBYbu4wQfGpZdSyo0SE+CV/oXdVAQrpbSV+HpU8Hpbo7XviX6DTn0ua5vx02qQcLis20Q== X-Received: by 2002:adf:c4b6:: with SMTP id m51-v6mr5330036wrf.103.1527770388371; Thu, 31 May 2018 05:39:48 -0700 (PDT) From: Filip Alac To: libvir-list@redhat.com Date: Thu, 31 May 2018 14:30:51 +0200 Message-Id: <20180531123054.13831-2-filipalac@gmail.com> In-Reply-To: <20180531123054.13831-1-filipalac@gmail.com> References: <20180531123054.13831-1-filipalac@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 31 May 2018 12:39:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 31 May 2018 12:39:50 +0000 (UTC) for IP:'209.85.128.169' DOMAIN:'mail-wr0-f169.google.com' HELO:'mail-wr0-f169.google.com' FROM:'filipalac@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.128.169 mail-wr0-f169.google.com 209.85.128.169 mail-wr0-f169.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Cc: Filip Alac Subject: [libvirt] [PATCH v3 1/4] virutil: Introduce virHostHasIOMMU X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 31 May 2018 12:40:20 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- src/conf/capabilities.c | 6 ++++++ src/conf/capabilities.h | 3 +++ src/util/virutil.c | 28 ++++++++++++++++++++++++++++ src/util/virutil.h | 2 ++ 4 files changed, 39 insertions(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index dd2fc77f91..ba19d5db8c 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1743,3 +1743,9 @@ virCapabilitiesInitCaches(virCapsPtr caps) virBitmapFree(cpus); return ret; } + +void +virCapabilitiesHostInitIOMMU(virCapsPtr caps) +{ + caps->host.iommu =3D virHostHasIOMMU(); +} diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index f0a06a24df..fe1b9ea455 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -183,6 +183,7 @@ struct _virCapsHost { int nPagesSize; /* size of pagesSize array */ unsigned int *pagesSize; /* page sizes support on the system */ unsigned char host_uuid[VIR_UUID_BUFLEN]; + bool iommu; }; =20 typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr, @@ -327,4 +328,6 @@ void virCapsHostCacheBankFree(virCapsHostCacheBankPtr p= tr); =20 int virCapabilitiesInitCaches(virCapsPtr caps); =20 +void virCapabilitiesHostInitIOMMU(virCapsPtr caps); + #endif /* __VIR_CAPABILITIES_H */ diff --git a/src/util/virutil.c b/src/util/virutil.c index bb4474acd5..7edcda0ee7 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2090,3 +2090,31 @@ virMemoryMaxValue(bool capped) else return LLONG_MAX; } + +bool +virHostHasIOMMU(void) +{ + DIR *iommuDir =3D NULL; + struct dirent *iommuGroup =3D NULL; + bool ret =3D false; + int direrr; + + /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ + if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) + goto cleanup; + + while ((direrr =3D virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { + /* assume we found a group */ + break; + } + + if (direrr < 0 || !iommuGroup) + goto cleanup; + /* okay, iommu is on and recognizes groups */ + + ret =3D true; + + cleanup: + VIR_DIR_CLOSE(iommuDir); + return ret; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index be0f6b0ea8..1ba9635bd9 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long= long value); bool virMemoryLimitIsSet(unsigned long long value); unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE; =20 +bool virHostHasIOMMU(void); + /** * VIR_ASSIGN_IS_OVERFLOW: * @rvalue: value that is checked (evaluated twice) --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list