From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790018; cv=none; d=zoho.com; s=zohoarc; b=oQSNUiZHDHPufh+RMws3wOEDbWG7d0ObCb5Kf9vKWmXH99jlK7XyoFMg0nzaFU69nyvbwzjUxJhOLeW7sAjVxnPYJY05pHWwEmSCcLvVZWP44YUO+yK4k2wJ3rzEjSO9g2GfAJFQcAzZvYfd2R+U9XADktA9T4Jg032K0my7j5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790018; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KJzkuzayDLEpgcDx8bKfQv9534gZ0qI/6UmpbmddiJo=; b=f4nxVr24zxVD8FrofwpaPb8O1VD5BKB4WylpRgSO8AEdryQ9WLiub8sxaEvjeeKSKoTfguJPqjB8Jb6g7A7H04OgG1tNUY6ze++BpgwYIl4NGqr1s9CZJrKJ2FqmYAEDrJH0+OMXG3B0djhnSOOSu5O2cfhmpFC+7VRoHw812XM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790018215869.2829014197353; Wed, 14 Aug 2019 06:40:18 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUa-0007Mt-6d; Wed, 14 Aug 2019 13:39:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUY-0007KN-Pb for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:06 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e2808958-be98-11e9-8d02-576e85b7af33; Wed, 14 Aug 2019 13:39:05 +0000 (UTC) X-Inumbo-ID: e2808958-be98-11e9-8d02-576e85b7af33 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789945; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ruf1aOix9HSx1EES95Wo6fb+9HqC4tzwpOsCxjC+x0E=; b=HGMQfXA36g2oX/JNakjGbLLhSFfFuvWcAL1nw0vP447wW7LK23X+vqY1 lp7x6ob8O2n7xyI0OypzzwklTUkIj3wLKlP277xl1F1F/FngITPj2zYGL ZtckeEiIw0xggRJUZxhjDWwDAB5ADGbUhfj9PsN2pSXInLvmPR6ONk2IB o=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Ke2+LMyQ+h9oqcjwed9YgNxiupZhTfgOFI+hdXlYMDknyS7rOv6QxXfn764pJ6HFqbrGHdmeZs 1Y/ZQUQQ8GPqHtrlZPx8KObWEgVeCI1XImEvksr9WVI2d/WrHKD/kADjNUhhPguU0XYQeLu/mO PdgROZERqFeABM42/PniZcFZnoml5KBVGc+tfKEMDsj9HshtNr0rxIKmUitXEgPjZHauxC+IDQ NaFcCmqBKr0b+2EMEtMzcNSKS87z/aMfvMKVrh3b3XTgfyYYuNlQoOfOICyPCHOIZ8hvpWiL5c mHA= X-SBRS: 2.7 X-MesageID: 4435858 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4435858" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:43 +0100 Message-ID: <20190814133852.20491-2-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 01/10] x86/hvm/domain: remove the 'hap_enabled' flag X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The hap_enabled() macro can determine whether the feature is available using the domain 'options'; there is no need for a separate flag. NOTE: Furthermore, by extending sanitiziing of the domain 'options', the macro can be transformed into an inline function and re-located to xen/sched.h. This also makes hap_enabled() common, thus allowing removal of an ugly ifdef CONFIG_X86 from the common iommu code. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" Cc: George Dunlap Cc: Ian Jackson Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: George Dunlap v4: - Add missing perentheses and move hap_enabled() v3: - Re-worked as suggested by Jan - Not adding Roger's R-b as the patch has changed substantially v2: - Defer changes to shadow_domain_init() to patch #4 --- xen/arch/x86/domain.c | 13 +++++++------ xen/arch/x86/mm/paging.c | 4 ++-- xen/common/domain.c | 7 +++++++ xen/drivers/passthrough/iommu.c | 2 -- xen/include/asm-x86/hvm/domain.h | 7 ------- xen/include/asm-x86/paging.h | 2 +- xen/include/xen/sched.h | 5 +++++ 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9a6eb89ddc..bc0db03387 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -460,6 +460,12 @@ int arch_sanitise_domain_config(struct xen_domctl_crea= tedomain *config) return -EINVAL; } =20 + if ( (config->flags & XEN_DOMCTL_CDF_hap) && !hvm_hap_supported() ) + { + dprintk(XENLOG_INFO, "HAP enabled but not supported\n"); + return -EINVAL; + } + return 0; } =20 @@ -564,12 +570,7 @@ int arch_domain_create(struct domain *d, HYPERVISOR_COMPAT_VIRT_START(d) =3D is_pv_domain(d) ? __HYPERVISOR_COMPAT_VIRT_START : ~0u; =20 - /* Need to determine if HAP is enabled before initialising paging */ - if ( is_hvm_domain(d) ) - d->arch.hvm.hap_enabled =3D - hvm_hap_supported() && (config->flags & XEN_DOMCTL_CDF_hap); - - if ( (rc =3D paging_domain_init(d, config->flags)) !=3D 0 ) + if ( (rc =3D paging_domain_init(d)) !=3D 0 ) goto fail; paging_initialised =3D true; =20 diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 011089368a..097a27f608 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -632,7 +632,7 @@ void paging_log_dirty_init(struct domain *d, const stru= ct log_dirty_ops *ops) /* CODE FOR PAGING SUPPORT */ /************************************************/ /* Domain paging struct initialization. */ -int paging_domain_init(struct domain *d, unsigned int domcr_flags) +int paging_domain_init(struct domain *d) { int rc; =20 @@ -653,7 +653,7 @@ int paging_domain_init(struct domain *d, unsigned int d= omcr_flags) if ( hap_enabled(d) ) hap_domain_init(d); else - rc =3D shadow_domain_init(d, domcr_flags); + rc =3D shadow_domain_init(d, d->options); =20 return rc; } diff --git a/xen/common/domain.c b/xen/common/domain.c index 744b572195..6109623730 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -313,6 +313,13 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) return -EINVAL; } =20 + if ( !(config->flags & XEN_DOMCTL_CDF_hvm_guest) && + (config->flags & XEN_DOMCTL_CDF_hap) ) + { + dprintk(XENLOG_INFO, "HAP enabled for non-HVM guest\n"); + return -EINVAL; + } + return arch_sanitise_domain_config(config); } =20 diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index f8c3bf53bd..37eb0f7d01 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -573,9 +573,7 @@ int iommu_do_domctl( =20 void iommu_share_p2m_table(struct domain* d) { -#ifdef CONFIG_X86 ASSERT(hap_enabled(d)); -#endif /* * iommu_use_hap_pt(d) cannot be used here because during domain * construction need_iommu(d) will always return false here. diff --git a/xen/include/asm-x86/hvm/domain.h b/xen/include/asm-x86/hvm/dom= ain.h index 6c7c4f5aa6..bcc5621797 100644 --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -156,7 +156,6 @@ struct hvm_domain { =20 struct viridian_domain *viridian; =20 - bool_t hap_enabled; bool_t mem_sharing_enabled; bool_t qemu_mapcache_invalidate; bool_t is_s3_suspended; @@ -195,12 +194,6 @@ struct hvm_domain { }; }; =20 -#ifdef CONFIG_HVM -#define hap_enabled(d) (is_hvm_domain(d) && (d)->arch.hvm.hap_enabled) -#else -#define hap_enabled(d) ({(void)(d); false;}) -#endif - #endif /* __ASM_X86_HVM_DOMAIN_H__ */ =20 /* diff --git a/xen/include/asm-x86/paging.h b/xen/include/asm-x86/paging.h index cf57ca708d..ab7887f23c 100644 --- a/xen/include/asm-x86/paging.h +++ b/xen/include/asm-x86/paging.h @@ -207,7 +207,7 @@ void paging_vcpu_init(struct vcpu *v); =20 /* Set up the paging-assistance-specific parts of a domain struct at * start of day. Called for every domain from arch_domain_create() */ -int paging_domain_init(struct domain *d, unsigned int domcr_flags); +int paging_domain_init(struct domain *d); =20 /* Handler for paging-control ops: operations from user-space to enable * and disable ephemeral shadow modes (test mode and log-dirty mode) and diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 2e6e0d3488..cfe4f375e5 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -954,6 +954,11 @@ static inline bool is_hvm_vcpu(const struct vcpu *v) return is_hvm_domain(v->domain); } =20 +static inline bool hap_enabled(const struct domain *d) +{ + return evaluate_nospec(d->options & XEN_DOMCTL_CDF_hap); +} + static inline bool is_hwdom_pinned_vcpu(const struct vcpu *v) { return (is_hardware_domain(v->domain) && --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790019; cv=none; d=zoho.com; s=zohoarc; b=cQfEd/vsDN2Jb+i5p8MMd+Ppi8VeSjPtOWUIS78As83/Oa8mlnnkQfDG8SIoyBd9WxlQTNjh5JrEx7FsXbWVTCOW9eZTgQAh7TltU4KZJZbJPV+rk7vDKocb11qdUB9rl1jwBmM65ZXFn2ynk0xqAGo9U5eeQz5FlfnVZ3bQc8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790019; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ELBItPKB71Qn1hjvvtYsG4NJV7J97ScbDHbZTWK18+w=; b=OQ4Gz9xZ+dhrkQvqUcE1lMkcZrs9Bm6gJCVNXiLCtBp4AgwqHnDPogh16FsLlvrHOqVDUyKu5Blc9/k9Y5tvQbtSqDYFffPi9Uw6XzIeO7Rdw7AWte0nkPhYM/YQ6Dvp38IaHO+owr4IkfUkiDsd2kIO2cUtipjteN/UBgu4PNw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 156579001949138.05985381761161; Wed, 14 Aug 2019 06:40:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUY-0007JY-4O; Wed, 14 Aug 2019 13:39:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUW-0007Hq-Tx for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:04 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e128e05a-be98-11e9-94b6-bbce0bdbcf19; Wed, 14 Aug 2019 13:39:03 +0000 (UTC) X-Inumbo-ID: e128e05a-be98-11e9-94b6-bbce0bdbcf19 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PJA234S8zvUyh6/q/RPEk5f9ikZq6bKFIX65j1odCAk=; b=Oxevr2nCGSPmxJswUUrYADZRtb5UNzgZfAZc0pNsY+LWRJPONY0I5OQt 3dQvZMgpkVkngWDq4zAq0xgBKq9n4BDuFnsjXD5Tc3tF4AbX304CESmUW nPjFEpPNuN7clPErmZcJRtduts/YV/kleahgv98htowXbKvxdHu+OO7li c=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ygRI2NpNuwk37fe6mgyejs+d2PwLc2BJi3ilCXYmOaHaoz9jY3ifN4z8fKug6AwDUcfTtPMDSl RWsXEhVqao3rXQznM0VldrMV5eCGmOfP9lsMIElS/Rxnkys/24K+9kIqKszPh6kLpdPriEE5Ws 2gxfkvVNuDzYyB159nB9kO2/10JFb9J/FFDoM3O60Elwv3eFJX+yDMUhMpTN+yD0l50eOu1Y+k pUWFuuqGFDta3sRyPY2Nixi2p8PHnU6qwXyrG8BQC1Y6gp6z033q1Ga4BrVpfCP0Wh22UCZmW2 36o= X-SBRS: 2.7 X-MesageID: 4435853 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4435853" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:44 +0100 Message-ID: <20190814133852.20491-3-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 02/10] x86/domain: remove the 'oos_off' flag X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , George Dunlap , Andrew Cooper , Tim Deegan , Paul Durrant , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The flag is not needed since the domain 'options' can now be tested directly. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Tim Deegan Cc: George Dunlap Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" v3: - Force 'oos_off' to be set for PV guests (to avoid call to is_hvm_domain() except in ASSERT) - Dropped Tim's A-b because of the change v2: - Move some of the hunks from patch #3 - Also update the definition of shadow_domain_init() in none.c --- xen/arch/x86/mm/paging.c | 2 +- xen/arch/x86/mm/shadow/common.c | 7 ++++--- xen/arch/x86/mm/shadow/none.c | 2 +- xen/common/domain.c | 16 ++++++++++++---- xen/include/asm-x86/domain.h | 1 - xen/include/asm-x86/shadow.h | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 097a27f608..69aa228e46 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -653,7 +653,7 @@ int paging_domain_init(struct domain *d) if ( hap_enabled(d) ) hap_domain_init(d); else - rc =3D shadow_domain_init(d, d->options); + rc =3D shadow_domain_init(d); =20 return rc; } diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/commo= n.c index fa18de0bb6..1187176993 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -46,7 +46,7 @@ static void sh_clean_dirty_bitmap(struct domain *); =20 /* Set up the shadow-specific parts of a domain struct at start of day. * Called for every domain from arch_domain_create() */ -int shadow_domain_init(struct domain *d, unsigned int domcr_flags) +int shadow_domain_init(struct domain *d) { static const struct log_dirty_ops sh_ops =3D { .enable =3D sh_enable_log_dirty, @@ -62,7 +62,6 @@ int shadow_domain_init(struct domain *d, unsigned int dom= cr_flags) =20 #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) d->arch.paging.shadow.oos_active =3D 0; - d->arch.paging.shadow.oos_off =3D domcr_flags & XEN_DOMCTL_CDF_oos_off; #endif d->arch.paging.shadow.pagetable_dying_op =3D 0; =20 @@ -2523,11 +2522,13 @@ static void sh_update_paging_modes(struct vcpu *v) #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) /* We need to check that all the vcpus have paging enabled to * unsync PTs. */ - if ( is_hvm_domain(d) && !d->arch.paging.shadow.oos_off ) + if ( !(d->options & XEN_DOMCTL_CDF_oos_off) ) { int pe =3D 1; struct vcpu *vptr; =20 + ASSERT(is_hvm_domain(d)); + for_each_vcpu(d, vptr) { if ( !hvm_paging_enabled(vptr) ) diff --git a/xen/arch/x86/mm/shadow/none.c b/xen/arch/x86/mm/shadow/none.c index a70888bd98..2fddf4274c 100644 --- a/xen/arch/x86/mm/shadow/none.c +++ b/xen/arch/x86/mm/shadow/none.c @@ -18,7 +18,7 @@ static void _clean_dirty_bitmap(struct domain *d) ASSERT(is_pv_domain(d)); } =20 -int shadow_domain_init(struct domain *d, unsigned int domcr_flags) +int shadow_domain_init(struct domain *d) { static const struct log_dirty_ops sh_none_ops =3D { .enable =3D _enable_log_dirty, diff --git a/xen/common/domain.c b/xen/common/domain.c index 6109623730..95321482ef 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -313,11 +313,19 @@ static int sanitise_domain_config(struct xen_domctl_c= reatedomain *config) return -EINVAL; } =20 - if ( !(config->flags & XEN_DOMCTL_CDF_hvm_guest) && - (config->flags & XEN_DOMCTL_CDF_hap) ) + if ( !(config->flags & XEN_DOMCTL_CDF_hvm_guest) ) { - dprintk(XENLOG_INFO, "HAP enabled for non-HVM guest\n"); - return -EINVAL; + if ( config->flags & XEN_DOMCTL_CDF_hap ) + { + dprintk(XENLOG_INFO, "HAP enabled for non-HVM guest\n"); + return -EINVAL; + } + + /* + * It is only meaningful for XEN_DOMCTL_CDF_oos_off to be clear + * for HVM guests. + */ + config->flags |=3D XEN_DOMCTL_CDF_oos_off; } =20 return arch_sanitise_domain_config(config); diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 933b85901f..5f9899469c 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -115,7 +115,6 @@ struct shadow_domain { =20 /* OOS */ bool_t oos_active; - bool_t oos_off; =20 /* Has this domain ever used HVMOP_pagetable_dying? */ bool_t pagetable_dying_op; diff --git a/xen/include/asm-x86/shadow.h b/xen/include/asm-x86/shadow.h index f29f0f652b..8ebb89c027 100644 --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -49,7 +49,7 @@ =20 /* Set up the shadow-specific parts of a domain struct at start of day. * Called from paging_domain_init(). */ -int shadow_domain_init(struct domain *d, unsigned int domcr_flags); +int shadow_domain_init(struct domain *d); =20 /* Setup the shadow-specific parts of a vcpu struct. It is called by * paging_vcpu_init() in paging.c */ --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790017; cv=none; d=zoho.com; s=zohoarc; b=bv5ReIKsZIC1RlzsJH25G/cdZxOJgDhQROScoWj5yDA3qVT8ukw6h2dJcz+wticvn7IrxVIf6/HkgcJ5pzfJMYFSjZWXXqdyFYsM4wzaHkoBDyxjry6/tHBe62eFjIMD7EfFGb5gnVp4S1lopvyQGUOPpxAuIBX6Lothi2uHOSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790017; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=nVlGUPXp01Us20Byv6nCsTOiHAS7td74kah/8PtgCwg=; b=OKpwrRowrWwToAhUZkBSqgts/A4wj4sD6F7zBwnLKqE1F6LPmDvw8FA1iF4n4H6tNpzUVys0hIPzuHXB8SUBGcRdRiinOntii2FSylhYFpNxB+4MzqvEa0KmKfG20CWFOjixmGWP5FogDBBY61zOkpbFWbZ6J5gkO9TqdOohAG0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790017404331.54207593151796; Wed, 14 Aug 2019 06:40:17 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUZ-0007L9-5K; Wed, 14 Aug 2019 13:39:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUX-0007Ij-N4 for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:05 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e1c42e34-be98-11e9-a9a9-77b7e450d931; Wed, 14 Aug 2019 13:39:04 +0000 (UTC) X-Inumbo-ID: e1c42e34-be98-11e9-a9a9-77b7e450d931 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uTANhEStMUr8DB/50iAQ+mX4hxx3p6YuBZ8NKQ3xiXY=; b=Wvryr12MP+6hrug/arMmyI3oVUopAtcuGiAqk6YbnVXAwOW2wuFq0ant 9+h3Jvaa1/5bYvZIOtHZp3ii0kw3BHKrXxui+PO/yT/zmrkcAHOA996Xk Ax8LVsHnG8BNM5iFMubJXq4/ZNK0cd+4Ezd/Oz5r2xhUt2Vcc+lbgj4cR w=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: zKU8zec/gE9obL6VVf842QWJUR2QlsI6SrVCDNa+mkCH/Hoqj7NIfCfdYG4cprGz34201xiWvT 6a1oFB3/UVCoiYu8AmjDensy6E4fPQnf7NaHoPWzo6pzJO+CqsvTILEN76Gk1ee4deIcm959RQ Qos1UHo+WFf5IBUDBMr7aDvHXLW1yLqxBWQj79WSzigtgLp0FcJ08vbm0sikJgrWCrr03UTGG8 uTBjSG4j2dDandkzoAHd+riVlZC7u5nTwLXonR+tzGDEFdlLOVzCZKPzVUH56Jj5IPwgVf5JyO Emk= X-SBRS: 2.7 X-MesageID: 4435854 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4435854" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:45 +0100 Message-ID: <20190814133852.20491-4-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 03/10] domain: remove the 'is_xenstore' flag X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich , Daniel De Graaf , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This patch introduces a convenience macro, is_xenstore_domain(), which tests the domain 'options' directly and then uses that in place of the 'is_xenstore' flag. Signed-off-by: Paul Durrant Reviewed-by: "Roger Pau Monn=C3=A9" Acked-by: George Dunlap --- Cc: Andrew Cooper Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu Cc: Daniel De Graaf v2: - Set 'disable_migrate' to true rather 1 --- xen/common/domain.c | 9 +++------ xen/common/domctl.c | 2 +- xen/include/xen/sched.h | 7 +++++-- xen/include/xsm/dummy.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 95321482ef..76e6976617 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -363,7 +363,7 @@ struct domain *domain_create(domid_t domid, if ( hardware_domid < 0 || hardware_domid >=3D DOMID_FIRST_RESERVE= D ) panic("The value of hardware_dom must be a valid domain ID\n"); =20 - d->disable_migrate =3D 1; + d->disable_migrate =3D true; old_hwdom =3D hardware_domain; hardware_domain =3D d; } @@ -442,11 +442,8 @@ struct domain *domain_create(domid_t domid, watchdog_domain_init(d); init_status |=3D INIT_watchdog; =20 - if ( d->options & XEN_DOMCTL_CDF_xs_domain ) - { - d->is_xenstore =3D 1; - d->disable_migrate =3D 1; - } + if ( is_xenstore_domain(d) ) + d->disable_migrate =3D true; =20 d->iomem_caps =3D rangeset_new(d, "I/O Memory", RANGESETF_prettypr= int_hex); d->irq_caps =3D rangeset_new(d, "Interrupts", 0); diff --git a/xen/common/domctl.c b/xen/common/domctl.c index b48e408583..6e6e9b9866 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -186,7 +186,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_= getdomaininfo *info) (d->is_shut_down ? XEN_DOMINF_shutdown : 0) | (d->controller_pause_count > 0 ? XEN_DOMINF_paused : 0) | (d->debugger_attached ? XEN_DOMINF_debugged : 0) | - (d->is_xenstore ? XEN_DOMINF_xs_domain : 0) | + (is_xenstore_domain(d) ? XEN_DOMINF_xs_domain : 0) | (is_hvm_domain(d) ? XEN_DOMINF_hvm_guest : 0) | d->shutdown_code << XEN_DOMINF_shutdownshift; =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index cfe4f375e5..a62161cc54 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -375,8 +375,6 @@ struct domain bool is_privileged; /* Can this guest access the Xen console? */ bool is_console; - /* Is this a xenstore domain (not dom0)? */ - bool is_xenstore; /* Non-migratable and non-restoreable? */ bool disable_migrate; /* Is this guest being debugged by dom0? */ @@ -978,6 +976,11 @@ static inline bool is_vcpu_online(const struct vcpu *v) return !test_bit(_VPF_down, &v->pause_flags); } =20 +static inline bool is_xenstore_domain(const struct domain *d) +{ + return d->options & XEN_DOMCTL_CDF_xs_domain; +} + extern bool sched_smt_power_savings; =20 extern enum cpufreq_controller { diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index ef52bb1764..b8e185e6fa 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -79,7 +79,7 @@ static always_inline int xsm_default_action( { return 0; case XSM_XS_PRIV: - if ( src->is_xenstore ) + if ( is_xenstore_domain(src) ) return 0; } /* fall through */ --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790020; cv=none; d=zoho.com; s=zohoarc; b=J6Mvxqmra5xMF69+XNVoAJ8+n0+bDK6/J81W0czlUVOj6oUQadHLIwqJHfG+PWrRDtusHT58AtxrjlEtIVKF0RCejrpN4CqMY8lKbUSrI5rIBixVIuSbWecWqczPEdTH96q/0C2W6yYQUNZjuzfeTizof8SLwY6J8t3mn+ldsUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790020; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=X2ASHVTOoQPrINGCjQFyCwuCCLP7GRkQZo/yY0H1IIw=; b=fJKsIs0U24Gg15zlHh7pQ1jBlWwBgrgbCgsh0vCgAryq7keVz8OV8v4NVCGH6Nrsd+IKYLckIZwEKxxHfb6VBnLCAHxZmO2fi0+cXp5XDXO3xUUMc98Fd23tgT5vFvuvMG2HUt8t+2GaoQq6GLjTKGx6xucZZz0TntSfaHp6FqE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790020062697.0451127246309; Wed, 14 Aug 2019 06:40:20 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUY-0007KV-QL; Wed, 14 Aug 2019 13:39:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUX-0007Iu-Pa for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:05 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e20f5918-be98-11e9-8915-7b131ac3cab9; Wed, 14 Aug 2019 13:39:04 +0000 (UTC) X-Inumbo-ID: e20f5918-be98-11e9-8915-7b131ac3cab9 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=82ZbikFKs83H7aVvGKJIWGELCj/Vwfn/y9lDcKIpcZI=; b=XCyNE5xjzdEPj6gw23zCe50rwi/Ru54IQaQomBi+8Nflxmf6d0OItrcC hsSLVVkgZ7zMJvsDvkk7hKkuRPlRNxqI4ejXFdITZPTN34W5JfjrpfJb/ GXKzE7ZntOkam7JmAEebGrN7rWZj4njnuj1aV5q250C0YcgYYatBhYLdD 8=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: q4MbN0Vph6JAtjxjD6l9FZrJB5DbB2tz0e7uWexPesD6KJGHhdEWj0iaRNedonJxtmNlkRa/Ac fqJeBnBh551ST42mVsXA+CD6WYVF/rhnKDQbaBEpHKcYcB49PKJJHXPuAH2BA0mdOf0dWcKy8Z 04jC3K+Rr5fc/sBgL4EGkGzqag6QmSxVH/5BgoyJ7KP5vdP0ttBJZbwDhYi80QuEd0KYzF/lEI mq4cfzo3l4oYZNAdx2BUY9j7Oi3hZAVLbQVREkP3zlrADm+4gB7jtvhLF5V2RGFHYXQuzYBn95 UG4= X-SBRS: 2.7 X-MesageID: 4435857 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4435857" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:46 +0100 Message-ID: <20190814133852.20491-5-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 04/10] x86/domain: remove the 's3_integrity' flag X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Paul Durrant , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The flag is not needed since the domain 'options' can now be tested directly. Signed-off-by: Paul Durrant Reviewed-by: "Roger Pau Monn=C3=A9" Reviewed-by: Jan Beulich --- Cc: Andrew Cooper Cc: Wei Liu v4: - s/TBOOT/CONFIG_TBOOT/g v3: - Also sanitise the flag against CONFIG_TBOOT being set --- xen/arch/x86/domain.c | 9 +++++++-- xen/arch/x86/setup.c | 2 +- xen/arch/x86/tboot.c | 2 +- xen/include/asm-x86/domain.h | 2 -- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index bc0db03387..f144d8fe9a 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -466,6 +466,13 @@ int arch_sanitise_domain_config(struct xen_domctl_crea= tedomain *config) return -EINVAL; } =20 + if ( (config->flags & XEN_DOMCTL_CDF_s3_integrity) && + !IS_ENABLED(CONFIG_TBOOT) ) + { + dprintk(XENLOG_INFO, "S3 integrity check not valid without CONFIG_= TBOOT\n"); + return -EINVAL; + } + return 0; } =20 @@ -544,8 +551,6 @@ int arch_domain_create(struct domain *d, d->domain_id); } =20 - d->arch.s3_integrity =3D config->flags & XEN_DOMCTL_CDF_s3_integrity; - emflags =3D config->arch.emulation_flags; =20 if ( is_hardware_domain(d) && is_pv_domain(d) ) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 87fc7c90da..d0b35b0ce2 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -696,7 +696,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) .stop_bits =3D 1 }; struct xen_domctl_createdomain dom0_cfg =3D { - .flags =3D XEN_DOMCTL_CDF_s3_integrity, + .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, .max_evtchn_port =3D -1, .max_grant_frames =3D opt_max_grant_frames, .max_maptrack_frames =3D opt_max_maptrack_frames, diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index f3fdee4d39..3db8a8a8d8 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -212,7 +212,7 @@ static void tboot_gen_domain_integrity(const uint8_t ke= y[TB_KEY_SIZE], vmac_set_key((uint8_t *)key, &ctx); for_each_domain( d ) { - if ( !d->arch.s3_integrity ) + if ( !(d->options & XEN_DOMCTL_CDF_s3_integrity) ) continue; printk("MACing Domain %u\n", d->domain_id); =20 diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 5f9899469c..5c038a1065 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -295,8 +295,6 @@ struct arch_domain uint32_t pci_cf8; uint8_t cmos_idx; =20 - bool_t s3_integrity; - union { struct pv_domain pv; struct hvm_domain hvm; --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790015; cv=none; d=zoho.com; s=zohoarc; b=fC8gS9wEle6ydB0IiM00VlaSUNzANSGqYPhauWNozP32tSJsmXZZYcqXFc5X50iQHP8IccDQb6IeY1/cVunPd1RmfapNZZKnCOFo1IB6z5d/UAOHJAdPvS+Bc7Sxc9fbgZBaI4A9cce1/HCZJdK9HxxzhMycAQZWNWA/2QRQD4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790015; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vGgV5/0MBhYZ5v/lliPd7W5rc+5yS3xfol+ZfGY6ZXU=; b=RrxTnrtOjis0SngNj1ysa1eZJ6ODZCWw6I/FuDeMjiCOFMOupvRb/vBgENrU6hIaEdwF4u9lEkwEQSgR0DrmagI406Md5KQxFJwmbJJQV7jacH/RTlSOSGY1Rnb2vHe+rE2yZipvnfhl9V6txfKk6O4YH54pB/7U4ADzRUTDCTs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790014904406.40710397798694; Wed, 14 Aug 2019 06:40:14 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUR-0007Fz-Bu; Wed, 14 Aug 2019 13:38:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUQ-0007Fr-Oc for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:38:58 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dd56cb5e-be98-11e9-9a41-7bacd4028f1b; Wed, 14 Aug 2019 13:38:57 +0000 (UTC) X-Inumbo-ID: dd56cb5e-be98-11e9-9a41-7bacd4028f1b DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789937; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xRBHsxF99Fi4jK6hb3aMwngDfozyJw28kwfm7JDqIgQ=; b=iNRGeh1OHXHbp+16fnGmMi3HAfbSMc5xGU7pro1xFsXD5BjcmStfzdAO yOQZ6CnbA+cFhYJjFkk0XaQX6UA1RTfeTuHAfsrinD+GlDfpSOU3cf/Do mHuhCgmhJSwPEyFPYAxrx4PzULR75sXt45PPdpAfXUMj+nkpsfROomrEf E=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: JOGW1AFQK7tAgCJ1d33Xz2/dv5NVYTWiTO9wpp7wjNngM1S4pIOjTMaYDplTb3CYtvT62piLq2 TiOKSp0M3njDU5WnhkuyBxsBG5JOTUk7ygCjDM0czym4Wqe5MAVQQSrNogXM1ga106pvmlir6s fdbFC7k18UcnMVe8l/zhvvqfopOLsyXdBCOlYuAFQigdnxMyfZD/Xp8VZqa2J8jQYgkywQ9/KZ 67SsW6gWct3aRcoj5/TlLYnxg7zvRVaUpdn8O6mex9kWvKyKzL09IcQ2zKPnNUuSaQ9PvifDAl 7L0= X-SBRS: 2.7 X-MesageID: 4409643 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4409643" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:47 +0100 Message-ID: <20190814133852.20491-6-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 05/10] domain: introduce XEN_DOMCTL_CDF_iommu flag X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich , Anthony PERARD , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This patch introduces a common domain creation flag to determine whether the domain is permitted to make use of the IOMMU. Currently the flag is always set (for both dom0 and domU) if the IOMMU is globally enabled (i.e. iommu_enabled =3D=3D 1). sanitise_domain_config() is modified to reje= ct the flag if !iommu_enabled. A new helper function, is_iommu_enabled(), is added to test the flag and iommu_domain_init() will return immediately if !is_iommu_enabled(). This is slightly different to the previous behaviour based on !iommu_enabled where the call to arch_iommu_domain_init() was made regardless, however it appears that this call was only necessary to initialize the dt_devices list for ARM such that iommu_release_dt_devices() can be called unconditionally by domain_relinquish_resources(). Adding a simple check of is_iommu_enabled() into iommu_release_dt_devices() keeps this unconditional call working. No functional change should be observed with this patch applied. Subsequent patches will allow the toolstack to control whether use of the IOMMU is enabled for a domain. NOTE: The introduction of the is_iommu_enabled() helper function might seem excessive but its use is expected to increase with subsequent patches. Also, having iommu_domain_init() bail before calling arch_iommu_domain_init() is not strictly necessary, but I think the consequent addition of the call to is_iommu_enabled() in iommu_release_dt_devices() makes the code clearer. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Volodymyr Babchuk Cc: "Roger Pau Monn=C3=A9" Previously part of series https://lists.xenproject.org/archives/html/xen-de= vel/2019-07/msg02267.html v5: - Move is_iommu_enabled() check into iommu_domain_init() - Reject XEN_DOMCTL_CDF_iommu in sanitise_domain_config() if !iommu_enabled - Use evaluate_nospec() in defintion of is_iommu_enabled() --- tools/libxl/libxl_create.c | 8 ++++++++ xen/arch/arm/domain.c | 1 - xen/arch/arm/setup.c | 3 +++ xen/arch/x86/setup.c | 3 +++ xen/common/domain.c | 9 ++++++++- xen/drivers/passthrough/device_tree.c | 3 +++ xen/drivers/passthrough/iommu.c | 6 +++--- xen/include/public/domctl.h | 4 ++++ xen/include/xen/sched.h | 5 +++++ 9 files changed, 37 insertions(+), 5 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 03ce166f4f..050ef042cd 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -555,6 +555,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_conf= ig *d_config, .max_grant_frames =3D b_info->max_grant_frames, .max_maptrack_frames =3D b_info->max_maptrack_frames, }; + libxl_physinfo physinfo; =20 if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) { create.flags |=3D XEN_DOMCTL_CDF_hvm_guest; @@ -564,6 +565,13 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_con= fig *d_config, libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off; } =20 + rc =3D libxl_get_physinfo(ctx, &physinfo); + if (rc < 0) + goto out; + + if (physinfo.cap_hvm_directio) + create.flags |=3D XEN_DOMCTL_CDF_iommu; + /* Ultimately, handle is an array of 16 uint8_t, same as uuid */ libxl_uuid_copy(ctx, (libxl_uuid *)&create.handle, &info->uuid); =20 diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 941bbff4fe..3ff19bc1ca 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -673,7 +673,6 @@ int arch_domain_create(struct domain *d, =20 ASSERT(config !=3D NULL); =20 - /* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc =3D iommu_domain_init(d)) !=3D 0 ) goto fail; =20 diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 215746a5c3..fca1e62901 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -914,6 +914,9 @@ void __init start_xen(unsigned long boot_phys_offset, dom0_cfg.arch.tee_type =3D tee_get_type(); dom0_cfg.max_vcpus =3D dom0_max_vcpus(); =20 + if ( iommu_enabled ) + dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + dom0 =3D domain_create(0, &dom0_cfg, true); if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) =3D=3D NULL) ) panic("Error creating domain 0\n"); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index d0b35b0ce2..fa226a2bab 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1733,6 +1733,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) } dom0_cfg.max_vcpus =3D dom0_max_vcpus(); =20 + if ( iommu_enabled ) + dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + /* Create initial domain 0. */ dom0 =3D domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim); if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) =3D=3D NULL) ) diff --git a/xen/common/domain.c b/xen/common/domain.c index 76e6976617..e832a5c4aa 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -301,7 +301,8 @@ static int sanitise_domain_config(struct xen_domctl_cre= atedomain *config) XEN_DOMCTL_CDF_hap | XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off | - XEN_DOMCTL_CDF_xs_domain) ) + XEN_DOMCTL_CDF_xs_domain | + XEN_DOMCTL_CDF_iommu) ) { dprintk(XENLOG_INFO, "Unknown CDF flags %#x\n", config->flags); return -EINVAL; @@ -328,6 +329,12 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) config->flags |=3D XEN_DOMCTL_CDF_oos_off; } =20 + if ( (config->flags & XEN_DOMCTL_CDF_iommu) && !iommu_enabled ) + { + dprintk(XENLOG_INFO, "IOMMU is not enabled\n"); + return -EINVAL; + } + return arch_sanitise_domain_config(config); } =20 diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index b6eaae7283..d32b172664 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -119,6 +119,9 @@ int iommu_release_dt_devices(struct domain *d) struct dt_device_node *dev, *_dev; int rc; =20 + if ( !is_iommu_enabled(d) ) + return 0; + list_for_each_entry_safe(dev, _dev, &hd->dt_devices, domain_list) { rc =3D iommu_deassign_dt_device(d, dev); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 37eb0f7d01..e61d3d1368 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -151,13 +151,13 @@ int iommu_domain_init(struct domain *d) struct domain_iommu *hd =3D dom_iommu(d); int ret =3D 0; =20 + if ( !is_iommu_enabled(d) ) + return 0; + ret =3D arch_iommu_domain_init(d); if ( ret ) return ret; =20 - if ( !iommu_enabled ) - return 0; - hd->platform_ops =3D iommu_get_ops(); return hd->platform_ops->init(d); } diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 19486d5e32..3f82c78870 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -64,6 +64,10 @@ struct xen_domctl_createdomain { /* Is this a xenstore domain? */ #define _XEN_DOMCTL_CDF_xs_domain 4 #define XEN_DOMCTL_CDF_xs_domain (1U<<_XEN_DOMCTL_CDF_xs_domain) + /* Should this domain be permitted to use the IOMMU? */ +#define _XEN_DOMCTL_CDF_iommu 5 +#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu) + uint32_t flags; =20 /* diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index a62161cc54..07ed66913a 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -981,6 +981,11 @@ static inline bool is_xenstore_domain(const struct dom= ain *d) return d->options & XEN_DOMCTL_CDF_xs_domain; } =20 +static inline bool is_iommu_enabled(const struct domain *d) +{ + return evaluate_nospec(d->options & XEN_DOMCTL_CDF_iommu); +} + extern bool sched_smt_power_savings; =20 extern enum cpufreq_controller { --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790020; cv=none; d=zoho.com; s=zohoarc; b=ng9UJiYd/VofeoGTzQx/dEEjO/G7CFVZlWV68AWF0KjMyhqzTkqXvxqV1lu9pjF3igeSzAzQaNuOwA5pc7W3dblb892qzLPHIXfIcPgm4voN+y55fBOSsaCcqAx3BmUwiX63osXyT7fVt27h/LqnTLjiGa9FQrBrEa5Dh35v2t0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790020; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=o4prAu3YZZNrg/duCLUIM45dIYICho3cYc+Dkxle9uU=; b=Yh5ql0xhKfXo/phZVvGETTA/4aUk+PyS1PeJrkleB0SsVgcdW5Ks2FLwlkPJfCgYdB3WCuvUQJczdkeAqCKAdlmGlyiveLKxEazji7s1pNTP12n4zg4WEjzFyYnwC939zE5LmuUA5NUG1PBvtHjHHah5cfyqrmPi69b3vR4p/00= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790020541425.0754131817931; Wed, 14 Aug 2019 06:40:20 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUX-0007I2-6p; Wed, 14 Aug 2019 13:39:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUV-0007Ha-Tp for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:03 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id de266328-be98-11e9-bfcc-630aa57f3cf4; Wed, 14 Aug 2019 13:38:58 +0000 (UTC) X-Inumbo-ID: de266328-be98-11e9-bfcc-630aa57f3cf4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789938; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NTFZDxTjLoKZ5zgD7XkdFrQAkmbvDsmCnbzLLGYCkow=; b=HEri3NIYrQ9EYKNfts6tw/SGX4lu4SXFIdsbJ1e77BzQIlKz2Fj4NcTJ xikRFT2VApSHlfejdPQisw4ndTDHEiV0JVUoTMV0IsFn9cA7xSnoz7kgl 4EAkc+GGVWZlvrqhjEu5SdL24j/dwBEIMn+to+WYrSU2i/0HUhZsqSjT/ s=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: diwA1I7/c+bnPqEn5tYsP4svGbFGfk3e8svdPei5Ybf0a+VJUE2Mi6wbawj7+c+lkqm6KMxeVa 8fKZ5q+vx6L+vt5s2EGxo0EUKnJWlF/o1Lppt83DGVrK005mRN/gtnTfl7OimFOrMK33VqFvuV MX7xfDSnxnrSW9RNvyYAl2Fv3NNy0+J38mOFetFLs4vVY6g/mWoJEZ27c5YsduMEsQ31Q6r/ig Vsv7DGYMILpz1eZL9hB4cetJ1/43HoxZ9HWgsev+BTCDHynGkbRoSi9da1ZpPjPlmOPj0FEaiE cqc= X-SBRS: 2.7 X-MesageID: 4409646 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4409646" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:48 +0100 Message-ID: <20190814133852.20491-7-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 06/10] use is_iommu_enabled() where appropriate... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Stefano Stabellini , Jun Nakajima , Wei Liu , George Dunlap , Andrew Cooper , Brian Woods , Julien Grall , Paul Durrant , Jan Beulich , Daniel De Graaf , Volodymyr Babchuk , Suravee Suthikulpanit , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) ...rather than testing the global iommu_enabled flag and ops pointer. Now that there is a per-domain flag indicating whether the domain is permitted to use the IOMMU (which determines whether the ops pointer will be set), many tests of the global iommu_enabled flag and ops pointer can be translated into tests of the per-domain flag. Some of the other tests of purely the global iommu_enabled flag can also be translated into tests of the per-domain flag. NOTE: The comment in iommu_share_p2m_table() is also fixed; need_iommu() disappeared some time ago. Also, whilst the style of the 'if' in flask_iommu_resource_use_perm() is fixed, I have not translated any instances of u32 into uint32_t to keep consistency. IMO such a translation would be better done globally for the source module in a separate patch. Signed-off-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Volodymyr Babchuk Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" Cc: Jun Nakajima Cc: Kevin Tian Cc: George Dunlap Cc: Suravee Suthikulpanit Cc: Brian Woods Cc: Daniel De Graaf Previously part of series https://lists.xenproject.org/archives/html/xen-de= vel/2019-07/msg02267.html This patch should be applied after Alexandru Isaila's 'Clean iommu_hap_pt_share enabled code' patch: https://lists.xenproject.org/archives/html/xen-devel/2019-07/msg01708.html v5: - Fix logic in ARM p2m_init() - Make iommu_do_domctl() return -EOPNOTSUPP rather than -ENOSYS if the IOMMU is not enabled - Fix test in pci_enable_acs() - Fix test in flask_iommu_resource_use_perm() --- xen/arch/arm/p2m.c | 2 +- xen/arch/x86/dom0_build.c | 2 +- xen/arch/x86/domctl.c | 4 +-- xen/arch/x86/hvm/hvm.c | 6 ++--- xen/arch/x86/hvm/vioapic.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/mm/p2m-ept.c | 4 +-- xen/drivers/passthrough/amd/iommu_guest.c | 2 +- xen/drivers/passthrough/device_tree.c | 4 +-- xen/drivers/passthrough/io.c | 8 +++--- xen/drivers/passthrough/iommu.c | 31 ++++++++++------------- xen/drivers/passthrough/pci.c | 16 ++++++------ xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/drivers/passthrough/vtd/x86/hvm.c | 2 +- xen/drivers/passthrough/x86/iommu.c | 2 +- xen/xsm/flask/hooks.c | 18 ++++++------- 17 files changed, 53 insertions(+), 56 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index e28ea1c85a..7f1442932a 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1531,7 +1531,7 @@ int p2m_init(struct domain *d) * shared with the CPU, Xen has to make sure that the PT changes have * reached the memory */ - p2m->clean_pte =3D iommu_enabled && + p2m->clean_pte =3D is_iommu_enabled(d) && !iommu_has_feature(d, IOMMU_FEAT_COHERENT_WALK); =20 rc =3D p2m_alloc_table(d); diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index c69570920c..d381784edd 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -356,7 +356,7 @@ unsigned long __init dom0_compute_nr_pages( avail -=3D d->max_vcpus - 1; =20 /* Reserve memory for iommu_dom0_init() (rough estimate). */ - if ( iommu_enabled ) + if ( is_iommu_enabled(d) ) { unsigned int s; =20 diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 2d45e5b8a8..be4b206068 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -715,7 +715,7 @@ long arch_do_domctl( break; =20 ret =3D -ESRCH; - if ( iommu_enabled ) + if ( is_iommu_enabled(d) ) { pcidevs_lock(); ret =3D pt_irq_create_bind(d, bind); @@ -744,7 +744,7 @@ long arch_do_domctl( if ( ret ) break; =20 - if ( iommu_enabled ) + if ( is_iommu_enabled(d) ) { pcidevs_lock(); ret =3D pt_irq_destroy_bind(d, bind); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 029eea3b85..172c860acc 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -465,7 +465,7 @@ void hvm_migrate_timers(struct vcpu *v) =20 void hvm_migrate_pirq(struct hvm_pirq_dpci *pirq_dpci, const struct vcpu *= v) { - ASSERT(iommu_enabled && + ASSERT(is_iommu_enabled(v->domain) && (is_hardware_domain(v->domain) || hvm_domain_irq(v->domain)->dp= ci)); =20 if ( (pirq_dpci->flags & HVM_IRQ_DPCI_MACH_MSI) && @@ -496,7 +496,7 @@ void hvm_migrate_pirqs(struct vcpu *v) { struct domain *d =3D v->domain; =20 - if ( !iommu_enabled || !hvm_domain_irq(d)->dpci ) + if ( !is_iommu_enabled(d) || !hvm_domain_irq(d)->dpci ) return; =20 spin_lock(&d->event_lock); @@ -2264,7 +2264,7 @@ int hvm_set_cr0(unsigned long value, bool may_defer) } =20 if ( ((value ^ old_value) & X86_CR0_CD) && - iommu_enabled && hvm_funcs.handle_cd && + is_iommu_enabled(d) && hvm_funcs.handle_cd && (!rangeset_is_empty(d->iomem_caps) || !rangeset_is_empty(d->arch.ioport_caps) || has_arch_pdevs(d)) ) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 9c25f72b4d..9aeef32a14 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -536,7 +536,7 @@ void vioapic_update_EOI(struct domain *d, u8 vector) =20 ent->fields.remote_irr =3D 0; =20 - if ( iommu_enabled ) + if ( is_iommu_enabled(d) ) { spin_unlock(&d->arch.hvm.irq_lock); hvm_dpci_eoi(d, vioapic->base_gsi + pin, ent); diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 16f14abe8f..ed27e8def7 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1087,7 +1087,7 @@ static int construct_vmcs(struct vcpu *v) vmx_clear_msr_intercept(v, MSR_IA32_SYSENTER_CS, VMX_MSR_RW); vmx_clear_msr_intercept(v, MSR_IA32_SYSENTER_ESP, VMX_MSR_RW); vmx_clear_msr_intercept(v, MSR_IA32_SYSENTER_EIP, VMX_MSR_RW); - if ( paging_mode_hap(d) && (!iommu_enabled || iommu_snoop) ) + if ( paging_mode_hap(d) && (!is_iommu_enabled(d) || iommu_snoop) ) vmx_clear_msr_intercept(v, MSR_IA32_CR_PAT, VMX_MSR_RW); if ( (vmexit_ctl & VM_EXIT_CLEAR_BNDCFGS) && (vmentry_ctl & VM_ENTRY_LOAD_BNDCFGS) ) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 0060310d74..3b3d5b6250 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1210,7 +1210,7 @@ static void vmx_handle_cd(struct vcpu *v, unsigned lo= ng value) { v->arch.hvm.cache_mode =3D NORMAL_CACHE_MODE; vmx_set_guest_pat(v, *pat); - if ( !iommu_enabled || iommu_snoop ) + if ( !is_iommu_enabled(v->domain) || iommu_snoop ) vmx_clear_msr_intercept(v, MSR_IA32_CR_PAT, VMX_MSR_RW); hvm_asid_flush_vcpu(v); /* no need to flush cache */ } diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 6b8468c793..93d031cc6c 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -260,7 +260,7 @@ static bool_t ept_split_super_page(struct p2m_domain *p= 2m, *epte =3D *ept_entry; epte->sp =3D (level > 1); epte->mfn +=3D i * trunk; - epte->snp =3D (iommu_enabled && iommu_snoop); + epte->snp =3D is_iommu_enabled(p2m->domain) && iommu_snoop; epte->suppress_ve =3D 1; =20 ept_p2m_type_to_flags(p2m, epte, epte->sa_p2mt, epte->access); @@ -766,7 +766,7 @@ ept_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t= mfn, new_entry.sp =3D !!i; new_entry.sa_p2mt =3D p2mt; new_entry.access =3D p2ma; - new_entry.snp =3D (iommu_enabled && iommu_snoop); + new_entry.snp =3D is_iommu_enabled(d) && iommu_snoop; =20 /* the caller should take care of the previous page */ new_entry.mfn =3D mfn_x(mfn); diff --git a/xen/drivers/passthrough/amd/iommu_guest.c b/xen/drivers/passth= rough/amd/iommu_guest.c index 7f2dd662af..1f2bcfbe15 100644 --- a/xen/drivers/passthrough/amd/iommu_guest.c +++ b/xen/drivers/passthrough/amd/iommu_guest.c @@ -821,7 +821,7 @@ int guest_iommu_init(struct domain* d) struct guest_iommu *iommu; struct domain_iommu *hd =3D dom_iommu(d); =20 - if ( !is_hvm_domain(d) || !iommu_enabled || !iommuv2_enabled || + if ( !is_hvm_domain(d) || !is_iommu_enabled(d) || !iommuv2_enabled || !has_viommu(d) ) return 0; =20 diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index d32b172664..12f2c4c3f2 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -29,7 +29,7 @@ int iommu_assign_dt_device(struct domain *d, struct dt_de= vice_node *dev) int rc =3D -EBUSY; struct domain_iommu *hd =3D dom_iommu(d); =20 - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(d) ) return -EINVAL; =20 if ( !dt_device_is_protected(dev) ) @@ -71,7 +71,7 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_= device_node *dev) const struct domain_iommu *hd =3D dom_iommu(d); int rc; =20 - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(d) ) return -EINVAL; =20 if ( !dt_device_is_protected(dev) ) diff --git a/xen/drivers/passthrough/io.c b/xen/drivers/passthrough/io.c index 4290c7c710..b292e79382 100644 --- a/xen/drivers/passthrough/io.c +++ b/xen/drivers/passthrough/io.c @@ -434,7 +434,7 @@ int pt_irq_create_bind( if ( vcpu ) pirq_dpci->gmsi.posted =3D true; } - if ( vcpu && iommu_enabled ) + if ( vcpu && is_iommu_enabled(d) ) hvm_migrate_pirq(pirq_dpci, vcpu); =20 /* Use interrupt posting if it is supported. */ @@ -817,7 +817,7 @@ int hvm_do_IRQ_dpci(struct domain *d, struct pirq *pirq) =20 ASSERT(is_hvm_domain(d)); =20 - if ( !iommu_enabled || (!is_hardware_domain(d) && !dpci) || + if ( !is_iommu_enabled(d) || (!is_hardware_domain(d) && !dpci) || !pirq_dpci || !(pirq_dpci->flags & HVM_IRQ_DPCI_MAPPED) ) return 0; =20 @@ -869,7 +869,7 @@ static int _hvm_dpci_msi_eoi(struct domain *d, =20 void hvm_dpci_msi_eoi(struct domain *d, int vector) { - if ( !iommu_enabled || + if ( !is_iommu_enabled(d) || (!hvm_domain_irq(d)->dpci && !is_hardware_domain(d)) ) return; =20 @@ -1001,7 +1001,7 @@ void hvm_dpci_eoi(struct domain *d, unsigned int gues= t_gsi, const struct hvm_irq_dpci *hvm_irq_dpci; const struct hvm_girq_dpci_mapping *girq; =20 - if ( !iommu_enabled ) + if ( !is_iommu_enabled(d) ) return; =20 if ( is_hardware_domain(d) ) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index e61d3d1368..9dace64af9 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -179,7 +179,7 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) =20 check_hwdom_reqs(d); =20 - if ( !iommu_enabled ) + if ( !is_iommu_enabled(d) ) return; =20 register_keyhandler('o', &iommu_dump_p2m_table, "dump iommu p2m table"= , 0); @@ -284,7 +284,7 @@ int iommu_construct(struct domain *d) =20 void iommu_domain_destroy(struct domain *d) { - if ( !iommu_enabled || !dom_iommu(d)->platform_ops ) + if ( !is_iommu_enabled(d) ) return; =20 iommu_teardown(d); @@ -300,7 +300,7 @@ int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn, unsigned long i; int rc =3D 0; =20 - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(d) ) return 0; =20 ASSERT(IS_ALIGNED(dfn_x(dfn), (1ul << page_order))); @@ -360,7 +360,7 @@ int iommu_unmap(struct domain *d, dfn_t dfn, unsigned i= nt page_order, unsigned long i; int rc =3D 0; =20 - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(d) ) return 0; =20 ASSERT(IS_ALIGNED(dfn_x(dfn), (1ul << page_order))); @@ -413,7 +413,7 @@ int iommu_lookup_page(struct domain *d, dfn_t dfn, mfn_= t *mfn, { const struct domain_iommu *hd =3D dom_iommu(d); =20 - if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->lookup_= page ) + if ( !is_iommu_enabled(d) || !hd->platform_ops->lookup_page ) return -EOPNOTSUPP; =20 return iommu_call(hd->platform_ops, lookup_page, d, dfn, mfn, flags); @@ -442,8 +442,8 @@ int iommu_iotlb_flush(struct domain *d, dfn_t dfn, unsi= gned int page_count, const struct domain_iommu *hd =3D dom_iommu(d); int rc; =20 - if ( !iommu_enabled || !hd->platform_ops || - !hd->platform_ops->iotlb_flush || !page_count || !flush_flags ) + if ( !is_iommu_enabled(d) || !hd->platform_ops->iotlb_flush || + !page_count || !flush_flags ) return 0; =20 if ( dfn_eq(dfn, INVALID_DFN) ) @@ -470,8 +470,8 @@ int iommu_iotlb_flush_all(struct domain *d, unsigned in= t flush_flags) const struct domain_iommu *hd =3D dom_iommu(d); int rc; =20 - if ( !iommu_enabled || !hd->platform_ops || - !hd->platform_ops->iotlb_flush_all || !flush_flags ) + if ( !is_iommu_enabled(d) || !hd->platform_ops->iotlb_flush_all || + !flush_flags ) return 0; =20 /* @@ -556,8 +556,8 @@ int iommu_do_domctl( { int ret =3D -ENODEV; =20 - if ( !iommu_enabled ) - return -ENOSYS; + if ( !is_iommu_enabled(d) ) + return -EOPNOTSUPP; =20 #ifdef CONFIG_HAS_PCI ret =3D iommu_do_pci_domctl(domctl, d, u_domctl); @@ -576,9 +576,9 @@ void iommu_share_p2m_table(struct domain* d) ASSERT(hap_enabled(d)); /* * iommu_use_hap_pt(d) cannot be used here because during domain - * construction need_iommu(d) will always return false here. + * construction has_iommu_pt(d) will always return false here. */ - if ( iommu_enabled && iommu_hap_pt_share ) + if ( is_iommu_enabled(d) && iommu_hap_pt_share ) iommu_get_ops()->share_p2m(d); } =20 @@ -608,10 +608,7 @@ int iommu_get_reserved_device_memory(iommu_grdm_t *fun= c, void *ctxt) =20 bool_t iommu_has_feature(struct domain *d, enum iommu_feature feature) { - if ( !iommu_enabled ) - return 0; - - return test_bit(feature, dom_iommu(d)->features); + return is_iommu_enabled(d) && test_bit(feature, dom_iommu(d)->features= ); } =20 static void iommu_dump_p2m_table(unsigned char key) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 7c196ba58b..a56a27f546 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -595,7 +595,7 @@ static void pci_enable_acs(struct pci_dev *pdev) u16 cap, ctrl, seg =3D pdev->seg; u8 bus =3D pdev->bus; =20 - if ( !iommu_enabled ) + if ( !is_iommu_enabled(pdev->domain) ) return; =20 pos =3D pci_find_ext_capability(seg, bus, pdev->devfn, PCI_EXT_CAP_ID_= ACS); @@ -864,7 +864,7 @@ static int pci_clean_dpci_irqs(struct domain *d) { struct hvm_irq_dpci *hvm_irq_dpci =3D NULL; =20 - if ( !iommu_enabled ) + if ( !is_iommu_enabled(d) ) return 0; =20 if ( !is_hvm_domain(d) ) @@ -1333,7 +1333,7 @@ static int iommu_add_device(struct pci_dev *pdev) ASSERT(pcidevs_locked()); =20 hd =3D dom_iommu(pdev->domain); - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(pdev->domain) ) return 0; =20 rc =3D hd->platform_ops->add_device(pdev->devfn, pci_to_dev(pdev)); @@ -1362,7 +1362,7 @@ static int iommu_enable_device(struct pci_dev *pdev) ASSERT(pcidevs_locked()); =20 hd =3D dom_iommu(pdev->domain); - if ( !iommu_enabled || !hd->platform_ops || + if ( !is_iommu_enabled(pdev->domain) || !hd->platform_ops->enable_device ) return 0; =20 @@ -1378,7 +1378,7 @@ static int iommu_remove_device(struct pci_dev *pdev) return -EINVAL; =20 hd =3D dom_iommu(pdev->domain); - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(pdev->domain) ) return 0; =20 for ( devfn =3D pdev->devfn ; pdev->phantom_stride; ) @@ -1421,7 +1421,7 @@ static int assign_device(struct domain *d, u16 seg, u= 8 bus, u8 devfn, u32 flag) struct pci_dev *pdev; int rc =3D 0; =20 - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(d) ) return 0; =20 /* Prevent device assign if mem paging or mem sharing have been=20 @@ -1483,7 +1483,7 @@ int deassign_device(struct domain *d, u16 seg, u8 bus= , u8 devfn) struct pci_dev *pdev =3D NULL; int ret =3D 0; =20 - if ( !iommu_enabled || !hd->platform_ops ) + if ( !is_iommu_enabled(d) ) return -EINVAL; =20 ASSERT(pcidevs_locked()); @@ -1536,7 +1536,7 @@ static int iommu_get_device_group( int i =3D 0; const struct iommu_ops *ops =3D hd->platform_ops; =20 - if ( !iommu_enabled || !ops || !ops->get_device_group_id ) + if ( !is_iommu_enabled(d) || !ops->get_device_group_id ) return 0; =20 group_id =3D ops->get_device_group_id(seg, bus, devfn); diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index 5d72270c5b..01f0bc4689 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1757,7 +1757,7 @@ static void iommu_domain_teardown(struct domain *d) xfree(mrmrr); } =20 - ASSERT(iommu_enabled); + ASSERT(is_iommu_enabled(d)); =20 /* * We can't use iommu_use_hap_pt here because either IOMMU state diff --git a/xen/drivers/passthrough/vtd/x86/hvm.c b/xen/drivers/passthroug= h/vtd/x86/hvm.c index 6675dca027..f77b35815c 100644 --- a/xen/drivers/passthrough/vtd/x86/hvm.c +++ b/xen/drivers/passthrough/vtd/x86/hvm.c @@ -51,7 +51,7 @@ void hvm_dpci_isairq_eoi(struct domain *d, unsigned int i= sairq) struct hvm_irq_dpci *dpci =3D NULL; =20 ASSERT(isairq < NR_ISAIRQS); - if ( !iommu_enabled ) + if ( !is_iommu_enabled(d) ) return; =20 spin_lock(&d->event_lock); diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index fd05075bb5..9879558c17 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -178,7 +178,7 @@ int arch_iommu_populate_page_table(struct domain *d) =20 void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d) { - if ( !iommu_enabled ) + if ( !is_iommu_enabled(d) ) panic("Presently, iommu must be enabled for PVH hardware domain\n"= ); } =20 diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 791c1f66af..5a0f2e723e 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -886,7 +886,7 @@ static int flask_map_domain_msi (struct domain *d, int = irq, const void *data, #endif } =20 -static u32 flask_iommu_resource_use_perm(void) +static u32 flask_iommu_resource_use_perm(struct domain *d) { /* Obtain the permission level required for allowing a domain * to use an assigned device. @@ -899,7 +899,7 @@ static u32 flask_iommu_resource_use_perm(void) */ u32 perm =3D RESOURCE__USE_NOIOMMU; =20 - if (iommu_enabled) + if ( is_iommu_enabled(d) ) perm =3D ( iommu_intremap ? RESOURCE__USE_IOMMU : RESOURCE__USE_IOMMU_NOINTREMAP ); return perm; @@ -910,7 +910,7 @@ static int flask_map_domain_irq (struct domain *d, int = irq, const void *data) u32 sid, dsid; int rc =3D -EPERM; struct avc_audit_data ad; - u32 dperm =3D flask_iommu_resource_use_perm(); + u32 dperm =3D flask_iommu_resource_use_perm(d); =20 if ( irq >=3D nr_static_irqs && data ) { rc =3D flask_map_domain_msi(d, irq, data, &sid, &ad); @@ -976,7 +976,7 @@ static int flask_bind_pt_irq (struct domain *d, struct = xen_domctl_bind_pt_irq *b int rc =3D -EPERM; int irq; struct avc_audit_data ad; - u32 dperm =3D flask_iommu_resource_use_perm(); + u32 dperm =3D flask_iommu_resource_use_perm(d); =20 rc =3D current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD); if ( rc ) @@ -1049,7 +1049,7 @@ static int flask_iomem_permission(struct domain *d, u= int64_t start, uint64_t end =20 data.ssid =3D domain_sid(current->domain); data.dsid =3D domain_sid(d); - data.use_perm =3D flask_iommu_resource_use_perm(); + data.use_perm =3D flask_iommu_resource_use_perm(d); =20 return security_iterate_iomem_sids(start, end, _iomem_has_perm, &data); } @@ -1074,7 +1074,7 @@ static int flask_pci_config_permission(struct domain = *d, uint32_t machine_bdf, u if ( access && (end >=3D 0x10 && start < 0x28) ) perm =3D RESOURCE__SETUP; else - perm =3D flask_iommu_resource_use_perm(); + perm =3D flask_iommu_resource_use_perm(d); =20 AVC_AUDIT_DATA_INIT(&ad, DEV); ad.device =3D (unsigned long) machine_bdf; @@ -1299,7 +1299,7 @@ static int flask_assign_device(struct domain *d, uint= 32_t machine_bdf) u32 dsid, rsid; int rc =3D -EPERM; struct avc_audit_data ad; - u32 dperm =3D flask_iommu_resource_use_perm(); + u32 dperm =3D flask_iommu_resource_use_perm(d); =20 if ( !d ) return flask_test_assign_device(machine_bdf); @@ -1358,7 +1358,7 @@ static int flask_assign_dtdevice(struct domain *d, co= nst char *dtpath) u32 dsid, rsid; int rc =3D -EPERM; struct avc_audit_data ad; - u32 dperm =3D flask_iommu_resource_use_perm(); + u32 dperm =3D flask_iommu_resource_use_perm(d); =20 if ( !d ) return flask_test_assign_dtdevice(dtpath); @@ -1543,7 +1543,7 @@ static int flask_ioport_permission(struct domain *d, = uint32_t start, uint32_t en =20 data.ssid =3D domain_sid(current->domain); data.dsid =3D domain_sid(d); - data.use_perm =3D flask_iommu_resource_use_perm(); + data.use_perm =3D flask_iommu_resource_use_perm(d); =20 return security_iterate_ioport_sids(start, end, _ioport_has_perm, &dat= a); } --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790024; cv=none; d=zoho.com; s=zohoarc; b=XuftyqhxmTAp14KZLZmN93IeRHxEd/e/0ohr6Czw+/WKYGwhw9wdSDCoAIHgA6HXILKPzA/92rGgSYIvpltveSJ56gaO1EnZgnOmEnI9T5XGInULFYIiLyjerknmaYT4Sk0KRfte8S+/59ZUIMxc7avRFiTo/BA4E2X47jCFGmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790024; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZtxwLLiP0bGTPW+BgHXU3ai+wt/v2o36g94hr8vyx+4=; b=kg1UIeIPJTCXs4G56ru//PwTxQgUuMTiOQa97fmExCd9NafLo7PzmVhXjzSg7amucq/1TsozrhZnGWHDuE4eUwB2DGEXGOJTRApC85dzmC516zQP4lv8vrzymp3ktL1AM5wmkMWsPo6ipw0bhov9IckDPPb6xSJXbaRzLJJ8ofQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790024084869.7084932891063; Wed, 14 Aug 2019 06:40:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUZ-0007Li-IS; Wed, 14 Aug 2019 13:39:07 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUY-0007Jo-DD for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:06 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e19f7238-be98-11e9-9417-c391fac7380f; Wed, 14 Aug 2019 13:39:04 +0000 (UTC) X-Inumbo-ID: e19f7238-be98-11e9-9417-c391fac7380f DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jphOz7WlIpnXUS4x3e6sw3Jd0yhb4YXzeKY+Cu/QgsA=; b=ZlTkp+8h8G7xXaCYUPfxVwa4VAPejQPPCSwi9NlO7CepxkxTbnzTk/rp SZoxUHcYKEdmcYPT3W9SwFEzaOiSYyZIzXJfalbjpmcqPvbIMWXPeisGQ UJB6l3RWtfCCFG/FAcz2YIMN68YIHGsp/tWLWsaSkVwKIae419Mli9nWw U=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 2GfSr/AwJ451+/EVUfhlHetZWbzDeQjK0YEZ4iI0Ls7N/iH8IskecXjpZqmhApOYqDNcsbmIqr nUTNjBc63OaGca7pIoahLblR7jSubE/rplXA5ueEp9uj1rdosrY08MhoY9jQObRC8aZD71cYtl X3urnz+eM9Yah3yWNJlmx8bSyqGgtuqBajp9ZKGMaWP2Abn8dUyRtC0Rj67sr2xSQlUwB5XEMG tmXHlXRzjH/LYivErDgzxruNhhIgYj4WKGArxe6BigsHKWjn5fAxnQc0N61B3RGahYmHcCT0uQ RVE= X-SBRS: 2.7 X-MesageID: 4435851 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4435851" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:49 +0100 Message-ID: <20190814133852.20491-8-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 07/10] remove late (on-demand) construction of IOMMU page tables X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Petre Pircalabu , Stefano Stabellini , Razvan Cojocaru , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Tamas K Lengyel , Jan Beulich , Alexandru Isaila , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Now that there is a per-domain IOMMU enable flag, which should be enabled if any device is going to be passed through, stop deferring page table construction until the assignment is done. Also don't tear down the tables again when the last device is de-assigned; defer that task until domain destruction. This allows the has_iommu_pt() helper and iommu_status enumeration to be removed. Calls to has_iommu_pt() are simply replaced by calls to is_iommu_enabled(). Remaining open-code tests of iommu_hap_pt_share can also be replaced by calls to iommu_use_hap_pt(). The arch_iommu_populate_page_table() and iommu_construct() functions become redundant, as does the 'strict mode' dom0 page_list mapping code in iommu_hwdom_init(), and iommu_teardown() can be made static is its only remaining caller, iommu_domain_destroy(), is within the same source module. All in all, about 220 lines of code are removed. NOTE: This patch will cause a small amount of extra resource to be used to accommodate IOMMU page tables that may never be used, since the per-domain IOMMU flag enable flag is currently set to the value of the global iommu_enable flag. A subsequent patch will add an option to the toolstack to allow it to be turned off if there is no intention to assign passthrough hardware to the domain. Signed-off-by: Paul Durrant Reviewed-by: Alexandru Isaila --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Volodymyr Babchuk Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Tim Deegan Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" Cc: Tamas K Lengyel Cc: George Dunlap Cc: Razvan Cojocaru Cc: Petre Pircalabu Previously part of series https://lists.xenproject.org/archives/html/xen-de= vel/2019-07/msg02267.html v5: - Minor style fixes --- xen/arch/arm/p2m.c | 2 +- xen/arch/x86/dom0_build.c | 2 +- xen/arch/x86/hvm/mtrr.c | 5 +- xen/arch/x86/mm/mem_sharing.c | 2 +- xen/arch/x86/mm/paging.c | 2 +- xen/arch/x86/x86_64/mm.c | 2 +- xen/common/memory.c | 4 +- xen/common/vm_event.c | 2 +- xen/drivers/passthrough/device_tree.c | 11 --- xen/drivers/passthrough/iommu.c | 134 ++++++-------------------- xen/drivers/passthrough/pci.c | 12 --- xen/drivers/passthrough/vtd/iommu.c | 10 +- xen/drivers/passthrough/x86/iommu.c | 95 ------------------ xen/include/asm-arm/iommu.h | 2 +- xen/include/asm-x86/iommu.h | 2 +- xen/include/xen/iommu.h | 16 --- xen/include/xen/sched.h | 2 - 17 files changed, 42 insertions(+), 263 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 7f1442932a..692565757e 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1056,7 +1056,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, !mfn_eq(lpae_get_mfn(*entry), lpae_get_mfn(orig_pte)) ) p2m_free_entry(p2m, orig_pte, level); =20 - if ( has_iommu_pt(p2m->domain) && + if ( is_iommu_enabled(p2m->domain) && (lpae_is_valid(orig_pte) || lpae_is_valid(*entry)) ) { unsigned int flush_flags =3D 0; diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index d381784edd..7cfab2dc25 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -365,7 +365,7 @@ unsigned long __init dom0_compute_nr_pages( } =20 need_paging =3D is_hvm_domain(d) && - (!iommu_hap_pt_share || !paging_mode_hap(d)); + (!iommu_use_hap_pt(d) || !paging_mode_hap(d)); for ( ; ; need_paging =3D false ) { nr_pages =3D get_memsize(&dom0_size, avail); diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 7ccd85bcea..5ad15eafe0 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -783,7 +783,8 @@ HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_= load_mtrr_msr, 1, =20 void memory_type_changed(struct domain *d) { - if ( (has_iommu_pt(d) || cache_flush_permitted(d)) && d->vcpu && d->vc= pu[0] ) + if ( (is_iommu_enabled(d) || cache_flush_permitted(d)) && + d->vcpu && d->vcpu[0] ) { p2m_memory_type_changed(d); flush_all(FLUSH_CACHE); @@ -831,7 +832,7 @@ int epte_get_entry_emt(struct domain *d, unsigned long = gfn, mfn_t mfn, return MTRR_TYPE_UNCACHABLE; } =20 - if ( !has_iommu_pt(d) && !cache_flush_permitted(d) ) + if ( !is_iommu_enabled(d) && !cache_flush_permitted(d) ) { *ipat =3D 1; return MTRR_TYPE_WRBACK; diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index a5fe89e339..efb8821768 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1664,7 +1664,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_d= omctl_mem_sharing_op *mec) case XEN_DOMCTL_MEM_SHARING_CONTROL: { rc =3D 0; - if ( unlikely(has_iommu_pt(d) && mec->u.enable) ) + if ( unlikely(is_iommu_enabled(d) && mec->u.enable) ) rc =3D -EXDEV; else d->arch.hvm.mem_sharing_enabled =3D mec->u.enable; diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 69aa228e46..d9a52c4db4 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -213,7 +213,7 @@ int paging_log_dirty_enable(struct domain *d, bool_t lo= g_global) { int ret; =20 - if ( has_iommu_pt(d) && log_global ) + if ( is_iommu_enabled(d) && log_global ) { /* * Refuse to turn on global log-dirty mode diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 1919cae18b..827b3f5e27 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -1433,7 +1433,7 @@ int memory_add(unsigned long spfn, unsigned long epfn= , unsigned int pxm) * shared or being kept in sync then newly added memory needs to be * mapped here. */ - if ( has_iommu_pt(hardware_domain) && + if ( is_iommu_enabled(hardware_domain) && !iommu_use_hap_pt(hardware_domain) && !need_iommu_pt_sync(hardware_domain) ) { diff --git a/xen/common/memory.c b/xen/common/memory.c index d9b35a608c..71445c2f53 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -823,7 +823,7 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_= add_to_physmap *xatp, xatp->gpfn +=3D start; xatp->size -=3D start; =20 - if ( has_iommu_pt(d) ) + if ( is_iommu_enabled(d) ) this_cpu(iommu_dont_flush_iotlb) =3D 1; =20 while ( xatp->size > done ) @@ -844,7 +844,7 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_= add_to_physmap *xatp, } } =20 - if ( has_iommu_pt(d) ) + if ( is_iommu_enabled(d) ) { int ret; =20 diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index 2a1c87e44b..3b18195ebf 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -630,7 +630,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl= _vm_event_op *vec) =20 /* No paging if iommu is used */ rc =3D -EMLINK; - if ( unlikely(has_iommu_pt(d)) ) + if ( unlikely(is_iommu_enabled(d)) ) break; =20 rc =3D -EXDEV; diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 12f2c4c3f2..ea9fd54e3b 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -40,17 +40,6 @@ int iommu_assign_dt_device(struct domain *d, struct dt_d= evice_node *dev) if ( !list_empty(&dev->domain_list) ) goto fail; =20 - /* - * The hwdom is forced to use IOMMU for protecting assigned - * device. Therefore the IOMMU data is already set up. - */ - ASSERT(!is_hardware_domain(d) || - hd->status =3D=3D IOMMU_STATUS_initialized); - - rc =3D iommu_construct(d); - if ( rc ) - goto fail; - /* The flag field doesn't matter to DT device. */ rc =3D hd->platform_ops->assign_device(d, 0, dt_to_dev(dev), 0); =20 diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 9dace64af9..91572aae56 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -146,6 +146,17 @@ static int __init parse_dom0_iommu_param(const char *s) } custom_param("dom0-iommu", parse_dom0_iommu_param); =20 +static void __hwdom_init check_hwdom_reqs(struct domain *d) +{ + if ( iommu_hwdom_none || !paging_mode_translate(d) ) + return; + + arch_iommu_check_autotranslated_hwdom(d); + + iommu_hwdom_passthrough =3D false; + iommu_hwdom_strict =3D true; +} + int iommu_domain_init(struct domain *d) { struct domain_iommu *hd =3D dom_iommu(d); @@ -159,129 +170,44 @@ int iommu_domain_init(struct domain *d) return ret; =20 hd->platform_ops =3D iommu_get_ops(); - return hd->platform_ops->init(d); -} + ret =3D hd->platform_ops->init(d); + if ( ret ) + return ret; =20 -static void __hwdom_init check_hwdom_reqs(struct domain *d) -{ - if ( iommu_hwdom_none || !paging_mode_translate(d) ) - return; + /* + * NB: 'relaxed' h/w domains don't need the IOMMU mappings to be kept + * in-sync with their assigned pages because all host RAM will be + * mapped during hwdom_init(). + */ + if ( is_hardware_domain(d) ) + check_hwdom_reqs(d); /* may modify iommu_hwdom_strict */ =20 - arch_iommu_check_autotranslated_hwdom(d); + if ( !is_hardware_domain(d) || iommu_hwdom_strict ) + hd->need_sync =3D !iommu_use_hap_pt(d); =20 - iommu_hwdom_passthrough =3D false; - iommu_hwdom_strict =3D true; + return 0; } =20 void __hwdom_init iommu_hwdom_init(struct domain *d) { struct domain_iommu *hd =3D dom_iommu(d); =20 - check_hwdom_reqs(d); - if ( !is_iommu_enabled(d) ) return; =20 register_keyhandler('o', &iommu_dump_p2m_table, "dump iommu p2m table"= , 0); =20 - hd->status =3D IOMMU_STATUS_initializing; - /* - * NB: relaxed hw domains don't need sync because all ram is already - * mapped in the iommu page tables. - */ - hd->need_sync =3D iommu_hwdom_strict && !iommu_use_hap_pt(d); - if ( need_iommu_pt_sync(d) ) - { - struct page_info *page; - unsigned int i =3D 0, flush_flags =3D 0; - int rc =3D 0; - - page_list_for_each ( page, &d->page_list ) - { - unsigned long mfn =3D mfn_x(page_to_mfn(page)); - unsigned long dfn =3D mfn_to_gmfn(d, mfn); - unsigned int mapping =3D IOMMUF_readable; - int ret; - - if ( ((page->u.inuse.type_info & PGT_count_mask) =3D=3D 0) || - ((page->u.inuse.type_info & PGT_type_mask) - =3D=3D PGT_writable_page) ) - mapping |=3D IOMMUF_writable; - - ret =3D iommu_map(d, _dfn(dfn), _mfn(mfn), 0, mapping, - &flush_flags); - - if ( !rc ) - rc =3D ret; - - if ( !(i++ & 0xfffff) ) - process_pending_softirqs(); - } - - /* Use while-break to avoid compiler warning */ - while ( iommu_iotlb_flush_all(d, flush_flags) ) - break; - - if ( rc ) - printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n", - d->domain_id, rc); - } - hd->platform_ops->hwdom_init(d); - - hd->status =3D IOMMU_STATUS_initialized; } =20 -void iommu_teardown(struct domain *d) +static void iommu_teardown(struct domain *d) { struct domain_iommu *hd =3D dom_iommu(d); =20 - hd->status =3D IOMMU_STATUS_disabled; hd->platform_ops->teardown(d); tasklet_schedule(&iommu_pt_cleanup_tasklet); } =20 -int iommu_construct(struct domain *d) -{ - struct domain_iommu *hd =3D dom_iommu(d); - - if ( hd->status =3D=3D IOMMU_STATUS_initialized ) - return 0; - - hd->status =3D IOMMU_STATUS_initializing; - - if ( !iommu_use_hap_pt(d) ) - { - int rc; - - hd->need_sync =3D true; - - rc =3D arch_iommu_populate_page_table(d); - if ( rc ) - { - if ( rc !=3D -ERESTART ) - { - hd->need_sync =3D false; - hd->status =3D IOMMU_STATUS_disabled; - } - - return rc; - } - } - - hd->status =3D IOMMU_STATUS_initialized; - - /* - * There may be dirty cache lines when a device is assigned - * and before has_iommu_pt(d) becoming true, this will cause - * memory_type_changed lose effect if memory type changes. - * Call memory_type_changed here to amend this. - */ - memory_type_changed(d); - - return 0; -} - void iommu_domain_destroy(struct domain *d) { if ( !is_iommu_enabled(d) ) @@ -574,11 +500,8 @@ int iommu_do_domctl( void iommu_share_p2m_table(struct domain* d) { ASSERT(hap_enabled(d)); - /* - * iommu_use_hap_pt(d) cannot be used here because during domain - * construction has_iommu_pt(d) will always return false here. - */ - if ( is_iommu_enabled(d) && iommu_hap_pt_share ) + + if ( iommu_use_hap_pt(d) ) iommu_get_ops()->share_p2m(d); } =20 @@ -625,8 +548,7 @@ static void iommu_dump_p2m_table(unsigned char key) ops =3D iommu_get_ops(); for_each_domain(d) { - if ( is_hardware_domain(d) || - dom_iommu(d)->status < IOMMU_STATUS_initialized ) + if ( !is_iommu_enabled(d) ) continue; =20 if ( iommu_use_hap_pt(d) ) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index a56a27f546..5c2051bee3 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1434,13 +1434,6 @@ static int assign_device(struct domain *d, u16 seg, = u8 bus, u8 devfn, u32 flag) if ( !pcidevs_trylock() ) return -ERESTART; =20 - rc =3D iommu_construct(d); - if ( rc ) - { - pcidevs_unlock(); - return rc; - } - pdev =3D pci_get_pdev_by_domain(hardware_domain, seg, bus, devfn); if ( !pdev ) { @@ -1469,8 +1462,6 @@ static int assign_device(struct domain *d, u16 seg, u= 8 bus, u8 devfn, u32 flag) } =20 done: - if ( !has_arch_pdevs(d) && has_iommu_pt(d) ) - iommu_teardown(d); pcidevs_unlock(); =20 return rc; @@ -1519,9 +1510,6 @@ int deassign_device(struct domain *d, u16 seg, u8 bus= , u8 devfn) =20 pdev->fault.count =3D 0; =20 - if ( !has_arch_pdevs(d) && has_iommu_pt(d) ) - iommu_teardown(d); - return ret; } =20 diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index 01f0bc4689..4ac5da197a 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1759,15 +1759,7 @@ static void iommu_domain_teardown(struct domain *d) =20 ASSERT(is_iommu_enabled(d)); =20 - /* - * We can't use iommu_use_hap_pt here because either IOMMU state - * is already changed to IOMMU_STATUS_disabled at this point or - * has always been IOMMU_STATUS_disabled. - * - * We also need to test if HAP is enabled because PV guests can - * enter this path too. - */ - if ( hap_enabled(d) && iommu_hap_pt_share ) + if ( iommu_use_hap_pt(d) ) return; =20 spin_lock(&hd->arch.mapping_lock); diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index 9879558c17..47a3e55213 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -81,101 +81,6 @@ int __init iommu_setup_hpet_msi(struct msi_desc *msi) return ops->setup_hpet_msi ? ops->setup_hpet_msi(msi) : -ENODEV; } =20 -int arch_iommu_populate_page_table(struct domain *d) -{ - struct page_info *page; - int rc =3D 0, n =3D 0; - - spin_lock(&d->page_alloc_lock); - - if ( unlikely(d->is_dying) ) - rc =3D -ESRCH; - - while ( !rc && (page =3D page_list_remove_head(&d->page_list)) ) - { - if ( is_hvm_domain(d) || - (page->u.inuse.type_info & PGT_type_mask) =3D=3D PGT_writable_= page ) - { - unsigned long mfn =3D mfn_x(page_to_mfn(page)); - unsigned long gfn =3D mfn_to_gmfn(d, mfn); - unsigned int flush_flags =3D 0; - - if ( gfn !=3D gfn_x(INVALID_GFN) ) - { - ASSERT(!(gfn >> DEFAULT_DOMAIN_ADDRESS_WIDTH)); - BUG_ON(SHARED_M2P(gfn)); - rc =3D iommu_map(d, _dfn(gfn), _mfn(mfn), PAGE_ORDER_4K, - IOMMUF_readable | IOMMUF_writable, - &flush_flags); - - /* - * We may be working behind the back of a running guest, w= hich - * may change the type of a page at any time. We can't pr= event - * this (for instance, by bumping the type count while map= ping - * the page) without causing legitimate guest type-change - * operations to fail. So after adding the page to the IO= MMU, - * check again to make sure this is still valid. NB that = the - * writable entry in the iommu is harmless until later, wh= en - * the actual device gets assigned. - */ - if ( !rc && !is_hvm_domain(d) && - ((page->u.inuse.type_info & PGT_type_mask) !=3D - PGT_writable_page) ) - { - rc =3D iommu_unmap(d, _dfn(gfn), PAGE_ORDER_4K, &flush= _flags); - /* If the type changed yet again, simply force a retry= . */ - if ( !rc && ((page->u.inuse.type_info & PGT_type_mask)= =3D=3D - PGT_writable_page) ) - rc =3D -ERESTART; - } - } - if ( rc ) - { - page_list_add(page, &d->page_list); - break; - } - } - page_list_add_tail(page, &d->arch.relmem_list); - if ( !(++n & 0xff) && !page_list_empty(&d->page_list) && - hypercall_preempt_check() ) - rc =3D -ERESTART; - } - - if ( !rc ) - { - /* - * The expectation here is that generally there are many normal pa= ges - * on relmem_list (the ones we put there) and only few being in an - * offline/broken state. The latter ones are always at the head of= the - * list. Hence we first move the whole list, and then move back the - * first few entries. - */ - page_list_move(&d->page_list, &d->arch.relmem_list); - while ( !page_list_empty(&d->page_list) && - (page =3D page_list_first(&d->page_list), - (page->count_info & (PGC_state|PGC_broken))) ) - { - page_list_del(page, &d->page_list); - page_list_add_tail(page, &d->arch.relmem_list); - } - } - - spin_unlock(&d->page_alloc_lock); - - if ( !rc ) - /* - * flush_flags are not tracked across hypercall pre-emption so - * assume a full flush is necessary. - */ - rc =3D iommu_iotlb_flush_all( - d, IOMMU_FLUSHF_added | IOMMU_FLUSHF_modified); - - if ( rc && rc !=3D -ERESTART ) - iommu_teardown(d); - - return rc; -} - void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d) { if ( !is_iommu_enabled(d) ) diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h index 904c9aec11..1577e83d2b 100644 --- a/xen/include/asm-arm/iommu.h +++ b/xen/include/asm-arm/iommu.h @@ -21,7 +21,7 @@ struct arch_iommu }; =20 /* Always share P2M Table between the CPU and the IOMMU */ -#define iommu_use_hap_pt(d) (has_iommu_pt(d)) +#define iommu_use_hap_pt(d) is_iommu_enabled(d) =20 const struct iommu_ops *iommu_get_ops(void); void iommu_set_ops(const struct iommu_ops *ops); diff --git a/xen/include/asm-x86/iommu.h b/xen/include/asm-x86/iommu.h index facf835ada..6d024d5c0e 100644 --- a/xen/include/asm-x86/iommu.h +++ b/xen/include/asm-x86/iommu.h @@ -81,7 +81,7 @@ extern const struct iommu_init_ops *iommu_init_ops; =20 /* Are we using the domain P2M table as its IOMMU pagetable? */ #define iommu_use_hap_pt(d) \ - (hap_enabled(d) && has_iommu_pt(d) && iommu_hap_pt_share) + (hap_enabled(d) && is_iommu_enabled(d) && iommu_hap_pt_share) =20 void iommu_update_ire_from_apic(unsigned int apic, unsigned int reg, unsig= ned int value); unsigned int iommu_read_apic_from_ire(unsigned int apic, unsigned int reg); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 48f87480a7..5b9611a134 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -74,15 +74,9 @@ int deassign_device(struct domain *d, u16 seg, u8 bus, u= 8 devfn); =20 void arch_iommu_domain_destroy(struct domain *d); int arch_iommu_domain_init(struct domain *d); -int arch_iommu_populate_page_table(struct domain *d); void arch_iommu_check_autotranslated_hwdom(struct domain *d); void arch_iommu_hwdom_init(struct domain *d); =20 -int iommu_construct(struct domain *d); - -/* Function used internally, use iommu_domain_destroy */ -void iommu_teardown(struct domain *d); - /* * The following flags are passed to map operations and passed by lookup * operations. @@ -249,13 +243,6 @@ struct iommu_ops { # define iommu_vcall iommu_call #endif =20 -enum iommu_status -{ - IOMMU_STATUS_disabled, - IOMMU_STATUS_initializing, - IOMMU_STATUS_initialized -}; - struct domain_iommu { struct arch_iommu arch; =20 @@ -270,9 +257,6 @@ struct domain_iommu { /* Features supported by the IOMMU */ DECLARE_BITMAP(features, IOMMU_FEAT_count); =20 - /* Status of guest IOMMU mappings */ - enum iommu_status status; - /* * Does the guest reqire mappings to be synchonized, to maintain * the default dfn =3D=3D pfn map. (See comment on dfn at the top of diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 07ed66913a..61bc75ba71 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -964,10 +964,8 @@ static inline bool is_hwdom_pinned_vcpu(const struct v= cpu *v) } =20 #ifdef CONFIG_HAS_PASSTHROUGH -#define has_iommu_pt(d) (dom_iommu(d)->status !=3D IOMMU_STATUS_disabled) #define need_iommu_pt_sync(d) (dom_iommu(d)->need_sync) #else -#define has_iommu_pt(d) false #define need_iommu_pt_sync(d) false #endif =20 --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790015; cv=none; d=zoho.com; s=zohoarc; b=Z+1XT4kyDtGPpvsqEtR+CKhEyrF+xFpRGBhjjk+n6jLQW2leOME2Akcm15ERBKQw8/cRDqrtbcpUP/fkrSwSQkmr8rBJI5W9WbEHomiKxlELS1NgAL1tt2oqtyXC65BrA93PLYg3Nqk/PHNvEc8sJlT3t08vG3fF2TMzXeDH2cY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790015; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=iMdadeMKiy2FCMLXylgZFvJzynd1lKdz1eNybMOpOdU=; b=TnDnp38/pBnpgzjsqHa0X/FWfH/KYqK/yFj1T7QsED7CchzQuuiu/qfvTKc6OdpScdKl0jYZVMzD1UkCONKvUo2pdjgfMKyAAU7VK8uOlhNW+rkEdom4ztw8va6qjj/xvY1RnoW3TaOuHC5uAep98101eEUxgT/R3K3LzN6Lvzk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790015486157.73560877592797; Wed, 14 Aug 2019 06:40:15 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUS-0007GU-L4; Wed, 14 Aug 2019 13:39:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUR-0007G4-Hp for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:38:59 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id de59128c-be98-11e9-9945-67a4d7df2fd2; Wed, 14 Aug 2019 13:38:58 +0000 (UTC) X-Inumbo-ID: de59128c-be98-11e9-9945-67a4d7df2fd2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789938; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XoP+Ep1LjuyfMh3xkOMzOmkpdlgSwlaCnjNlFeCb0Ic=; b=avB7dfie7S14A6/+3HYXbLEkaoWEHSAC/pnz5ZDGBrIkD/tvJzoIsRal 6iQDLKT9Y30slnxM+b+Q0E4yiq4Zu0q7Dnxhod5Y01h+0uVxTfNeB5pqC wGGcZituGYgbQ54TeAPz0UR2Prb0mVBUpBUAGWqpXzR/TCZzuNNiXTMgU o=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: T1eLWcrApcxMYO/px1GnUoZv/j1BR6mxjgPYepvAv8yLTqkjM/jZNxkIMq6dJvJOR8QvEvpkPz DT5oLA5pBmzdTHdfa4Tx0orsFIOA2lE21cR1SkcZeJJFK+CzxGkO+nAlFrgFQU+qjGju/0R5B0 KpXKM0uPl2pg0U3esHw9IbXY2choprDa/ACZy9C4c5ifw4ikZC2IzZN4WdEdx0sWLvzAvB8rSB GUYtjYL+uaiKeyVt4NP6A/keEPFvMCXD+rnO7Mpk+cx1hUCWfO+LHgEnLG83j5Om0LumtMTqy9 KJw= X-SBRS: 2.7 X-MesageID: 4409645 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4409645" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:50 +0100 Message-ID: <20190814133852.20491-9-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 08/10] make passthrough/pci.c:deassign_device() static X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Paul Durrant , Jan Beulich Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This function is only ever called from within the same source module and really has no business being declared xen/iommu.h. This patch relocates the function ahead of the first called and makes it static. Signed-off-by: Paul Durrant Acked-by: Jan Beulich --- Previously part of series https://lists.xenproject.org/archives/html/xen-de= vel/2019-07/msg02267.html v5: - minor style fixes - use %pd, rather than d%d --- xen/drivers/passthrough/pci.c | 93 ++++++++++++++++++----------------- xen/include/xen/iommu.h | 1 - 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 5c2051bee3..28b77b3e30 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -889,6 +889,53 @@ static int pci_clean_dpci_irqs(struct domain *d) return 0; } =20 +/* caller should hold the pcidevs_lock */ +static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, + uint8_t devfn) +{ + const struct domain_iommu *hd =3D dom_iommu(d); + struct pci_dev *pdev; + int ret =3D 0; + + if ( !is_iommu_enabled(d) ) + return -EINVAL; + + ASSERT(pcidevs_locked()); + pdev =3D pci_get_pdev_by_domain(d, seg, bus, devfn); + if ( !pdev ) + return -ENODEV; + + while ( pdev->phantom_stride ) + { + devfn +=3D pdev->phantom_stride; + if ( PCI_SLOT(devfn) !=3D PCI_SLOT(pdev->devfn) ) + break; + ret =3D hd->platform_ops->reassign_device(d, hardware_domain, devf= n, + pci_to_dev(pdev)); + if ( !ret ) + continue; + + printk(XENLOG_G_ERR "%pd: deassign %04x:%02x:%02x.%u failed (%d)\n= ", + d, seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), ret); + return ret; + } + + devfn =3D pdev->devfn; + ret =3D hd->platform_ops->reassign_device(d, hardware_domain, devfn, + pci_to_dev(pdev)); + if ( ret ) + { + dprintk(XENLOG_G_ERR, + "%pd: deassign device (%04x:%02x:%02x.%u) failed\n", + d, seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + return ret; + } + + pdev->fault.count =3D 0; + + return ret; +} + int pci_release_devices(struct domain *d) { struct pci_dev *pdev; @@ -1467,52 +1514,6 @@ static int assign_device(struct domain *d, u16 seg, = u8 bus, u8 devfn, u32 flag) return rc; } =20 -/* caller should hold the pcidevs_lock */ -int deassign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) -{ - const struct domain_iommu *hd =3D dom_iommu(d); - struct pci_dev *pdev =3D NULL; - int ret =3D 0; - - if ( !is_iommu_enabled(d) ) - return -EINVAL; - - ASSERT(pcidevs_locked()); - pdev =3D pci_get_pdev_by_domain(d, seg, bus, devfn); - if ( !pdev ) - return -ENODEV; - - while ( pdev->phantom_stride ) - { - devfn +=3D pdev->phantom_stride; - if ( PCI_SLOT(devfn) !=3D PCI_SLOT(pdev->devfn) ) - break; - ret =3D hd->platform_ops->reassign_device(d, hardware_domain, devf= n, - pci_to_dev(pdev)); - if ( !ret ) - continue; - - printk(XENLOG_G_ERR "d%d: deassign %04x:%02x:%02x.%u failed (%d)\n= ", - d->domain_id, seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), r= et); - return ret; - } - - devfn =3D pdev->devfn; - ret =3D hd->platform_ops->reassign_device(d, hardware_domain, devfn, - pci_to_dev(pdev)); - if ( ret ) - { - dprintk(XENLOG_G_ERR, - "d%d: deassign device (%04x:%02x:%02x.%u) failed\n", - d->domain_id, seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); - return ret; - } - - pdev->fault.count =3D 0; - - return ret; -} - static int iommu_get_device_group( struct domain *d, u16 seg, u8 bus, u8 devfn, XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs) diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 5b9611a134..4b6871936c 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -70,7 +70,6 @@ int iommu_hardware_setup(void); int iommu_domain_init(struct domain *d); void iommu_hwdom_init(struct domain *d); void iommu_domain_destroy(struct domain *d); -int deassign_device(struct domain *d, u16 seg, u8 bus, u8 devfn); =20 void arch_iommu_domain_destroy(struct domain *d); int arch_iommu_domain_init(struct domain *d); --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565790019; cv=none; d=zoho.com; s=zohoarc; b=lQiwL67D+PPQDXVmENjniLRHZFH/LDli4n70hOH5EQOEFltgndGg7TokMpqNJ4SWc4kFHnJtX8vnqev01GK6NCAgeXax0jqA3ZbjYlClc51CUWt9WL5ZxVtbBw+pLIgl2ns6FhoPuzhh9Rt/eqqDFe2s17Hwxa4bExgJSmUSRsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565790019; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+0AUoqO3E0EvK0xNHJogcGc3RVX/bwCsxrFWs99D10s=; b=dxu3UMQy/Qye2SqSbBdsYNTdwIkCjc1rEiIZFgNIz4c4FKHR5vrRjYo+COsggfPd6ACYcH+mWcRuAvafjByIlZruE68oTiruC1YYqU03JqAjxmMqpbbOdfaS/32l1n6hy0ZaeDqBEq7Iuap9HXYRWrdBfXMzBqH59/cKOljmzCQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565790019344786.981316775021; Wed, 14 Aug 2019 06:40:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUW-0007Hr-UH; Wed, 14 Aug 2019 13:39:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtUV-0007HS-JG for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:39:03 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e0b764de-be98-11e9-b5b0-a3dfe2777f73; Wed, 14 Aug 2019 13:39:02 +0000 (UTC) X-Inumbo-ID: e0b764de-be98-11e9-b5b0-a3dfe2777f73 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565789942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iDygmZtVTKPxgahM0UJftCkn5WcAfV6HQLhE9XLfL8w=; b=C1w+DeuDvE8j43UhdOpAUCtgmEF4b8y8XZmAkDL4ReYr2Z+JqdJ5/jyq mQJ86LWeBqWxm7DySV5omV1TTW8lz3KPRgxktqSv8UnmXTbGsCHKUAfmx qg0v0rfdR51Bs3T5gR2IKpnZ62Hwg/rDIN3vaUiOzC987/NaWeCFxeGcM A=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: azEUGD3UXc6vrR7q9NMhdEcPmEa4HyppeDGh86IBwegCvMqxFD5DnmwSAONVGJ3qZCa4V2YfNR 1l02IctiXogJN5NAImyGkwei0xhxBYu9jOKmvzaSIXW4FXHTeHdKdc8hs41dWLp2riC7FkTL3n yUwDRIWjevRB6vARTH/s5uUtabCQJccNIAicFoO+sccAPhojOnvHN8Dnup3FwOy2WfeIbbZU7G USxRXsNSv5Yhz1/qtSsuUhuZ7urmQZ1ZKzvBkXd/ZFLen0Uy6epaVF4+pr1aJJLoEfvru7tVaR dMs= X-SBRS: 2.7 X-MesageID: 4409651 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4409651" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:51 +0100 Message-ID: <20190814133852.20491-10-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 09/10] iommu: tidy up iommu_use_hap_pt() and need_iommu_pt_sync() macros X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Thes macros really ought to live in the common xen/iommu.h header rather then being distributed amongst architecture specific iommu headers and xen/sched.h. This patch moves them there. NOTE: Disabling 'sharept' in the command line iommu options should really be hard error on ARM (as opposed to just being ignored), so avoid parsing that option if CONFIG_ARM is set. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu Cc: Volodymyr Babchuk Cc: "Roger Pau Monn=C3=A9" Previously part of https://lists.xenproject.org/archives/html/xen-devel/201= 9-07/msg02267.html --- xen/drivers/passthrough/iommu.c | 2 ++ xen/include/asm-arm/iommu.h | 3 --- xen/include/asm-x86/iommu.h | 4 ---- xen/include/xen/iommu.h | 11 +++++++++++ xen/include/xen/sched.h | 6 ------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 91572aae56..965740f6f7 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -102,8 +102,10 @@ static int __init parse_iommu_param(const char *s) iommu_hwdom_passthrough =3D val; else if ( (val =3D parse_boolean("dom0-strict", s, ss)) >=3D 0 ) iommu_hwdom_strict =3D val; +#ifndef CONFIG_ARM else if ( (val =3D parse_boolean("sharept", s, ss)) >=3D 0 ) iommu_hap_pt_share =3D val; +#endif else rc =3D -EINVAL; =20 diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h index 1577e83d2b..77a94b29eb 100644 --- a/xen/include/asm-arm/iommu.h +++ b/xen/include/asm-arm/iommu.h @@ -20,9 +20,6 @@ struct arch_iommu void *priv; }; =20 -/* Always share P2M Table between the CPU and the IOMMU */ -#define iommu_use_hap_pt(d) is_iommu_enabled(d) - const struct iommu_ops *iommu_get_ops(void); void iommu_set_ops(const struct iommu_ops *ops); =20 diff --git a/xen/include/asm-x86/iommu.h b/xen/include/asm-x86/iommu.h index 6d024d5c0e..25d2aee9a9 100644 --- a/xen/include/asm-x86/iommu.h +++ b/xen/include/asm-x86/iommu.h @@ -79,10 +79,6 @@ struct iommu_init_ops { =20 extern const struct iommu_init_ops *iommu_init_ops; =20 -/* Are we using the domain P2M table as its IOMMU pagetable? */ -#define iommu_use_hap_pt(d) \ - (hap_enabled(d) && is_iommu_enabled(d) && iommu_hap_pt_share) - void iommu_update_ire_from_apic(unsigned int apic, unsigned int reg, unsig= ned int value); unsigned int iommu_read_apic_from_ire(unsigned int apic, unsigned int reg); int iommu_setup_hpet_msi(struct msi_desc *); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 4b6871936c..5e7ca98170 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -268,6 +268,17 @@ struct domain_iommu { #define iommu_set_feature(d, f) set_bit(f, dom_iommu(d)->features) #define iommu_clear_feature(d, f) clear_bit(f, dom_iommu(d)->features) =20 +/* Are we using the domain P2M table as its IOMMU pagetable? */ +#define iommu_use_hap_pt(d) \ + (hap_enabled(d) && is_iommu_enabled(d) && iommu_hap_pt_share) + +/* Does the IOMMU pagetable need to be kept synchronized with the P2M */ +#ifdef CONFIG_HAS_PASSTHROUGH +#define need_iommu_pt_sync(d) (dom_iommu(d)->need_sync) +#else +#define need_iommu_pt_sync(d) false +#endif + int __must_check iommu_suspend(void); void iommu_resume(void); void iommu_crash_shutdown(void); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 61bc75ba71..470fa384a0 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -963,12 +963,6 @@ static inline bool is_hwdom_pinned_vcpu(const struct v= cpu *v) cpumask_weight(v->cpu_hard_affinity) =3D=3D 1); } =20 -#ifdef CONFIG_HAS_PASSTHROUGH -#define need_iommu_pt_sync(d) (dom_iommu(d)->need_sync) -#else -#define need_iommu_pt_sync(d) false -#endif - static inline bool is_vcpu_online(const struct vcpu *v) { return !test_bit(_VPF_down, &v->pause_flags); --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 16:57:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565791160; cv=none; d=zoho.com; s=zohoarc; b=a3StBJYN6es99JN0K5+hE0f5YejnDECQjPiNZT7T/xcPPmr7ZRDOBkyIU12vWsbW3Nayqgq5izDGx6MGp3+QddcVEalh56AVSf/jZ1aOWc8W/Mt1V6xJEA8tFuDmbzXcxzpv3BibgqVz6Pp02OV23kWBb5kGs4fyHegX1iC7Cqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565791160; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1H9HavuzXWPbN3OkbwIbIvha8J5E1V8ti0n1suRYSgQ=; b=WVi7i99kLaPT68i6Zj434NUM3QMGXMGw22RQ2YW0SB402Zb6d/iZMMBTCJA5E3BTf5wMRynr+su30PlGW530pAiObE7Y+xKRHjlZzIMwTavb8y/x9pW2mVttMoEar6U1lNs8/Q+FDPKgO3TikS8KmeniOKA69mAIHXsNRggbwXo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565791160197622.7893617888413; Wed, 14 Aug 2019 06:59:20 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtmd-0001QL-4b; Wed, 14 Aug 2019 13:57:47 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxtmb-0001QG-KJ for xen-devel@lists.xenproject.org; Wed, 14 Aug 2019 13:57:45 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7bc504de-be9b-11e9-a22f-9fb308a85071; Wed, 14 Aug 2019 13:57:42 +0000 (UTC) X-Inumbo-ID: 7bc504de-be9b-11e9-a22f-9fb308a85071 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565791062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W8E3uvdvU/2b7ZN/k03eFZVfgYymjqsuxq04yVthOH4=; b=XaWtnyDN85fRI9+peBnHQpz394V75CCGEnoHYN4XaIxgO1SMpBZgeTWv JDIE8QNMGYdS0XVHLlej1HtABh4G77/P/aVQx8lbgMhgCM4IGAl6V5/hQ o5vwpzqlfz8o4oJxXod2w9GFQ7NrDPre04sPzLXjpqSa8jOguSs86VrBc I=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: kLSvBXeaOtvsezAYQqiC7O1Ouk62T3T9YXYs83x8nlLT2/BK/vWsffJuA1y3TDG6qSI/8oRWyg i7wcSCnym65G8DKPM4ygegpr2MvtsaRMWtMMb/6negw7Rn2FzwE2xXFBfm/qS2LZ/o2H1xFe34 DR/npJKcXRw4L9dArHwiAfAFZbC3uWWoiBNL3egQkcLHPd0d6nNg9v4pBeKTD44DZarFmt3fqa lTU69qtCGb9ClVbCQdC87CwoYSMzTxOJRt1bJHl7m61DRXfkIbXhmlaLHUzWOvdnPr02ilji41 /O8= X-SBRS: 2.7 X-MesageID: 4410718 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,385,1559534400"; d="scan'208";a="4410718" From: Paul Durrant To: Date: Wed, 14 Aug 2019 14:38:52 +0100 Message-ID: <20190814133852.20491-11-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190814133852.20491-1-paul.durrant@citrix.com> References: <20190814133852.20491-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 10/10] introduce a 'passthrough' configuration option to xl.cfg... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich , Anthony PERARD , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) ...and hence the ability to disable IOMMU mappings, and control EPT sharing. This patch introduces a new 'libxl_passthrough' enumeration into libxl_domain_create_info. The value will be set by xl either when it parses a new 'passthrough' option in xl.cfg, or implicitly if there is passthrough hardware specified for the domain. If the value of the passthrough configuration option is 'disabled' then the XEN_DOMCTL_CDF_iommu flag will be clear in the xen_domctl_createdomain flags, thus allowing the toolstack to control whether the domain gets IOMMU mappings or not (where previously they were globally set). If the value of the passthrough configuration option is 'sync_pt' then a new 'iommu_opts' field in xen_domctl_createdomain will be set with the value XEN_DOMCTL_IOMMU_no_sharept. This will override the global default set in iommu_hap_pt_share, thus allowing the toolstack to control whether EPT sharing is used for the domain. NOTE: The call to libxl_get_physinfo() in libxl__domain_make() is left in place to allow attempts to passthrough hardware on a hypervisor with disabled IOMMU support to be rejected early. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Anthony PERARD Cc: Volodymyr Babchuk Cc: "Roger Pau Monn=C3=A9" Previously part of series https://lists.xenproject.org/archives/html/xen-de= vel/2019-07/msg02267.html v5: - Expand xen_domctl_createdomain flags field and hence bump interface version - Fix spelling mistakes in context line --- docs/man/xl.cfg.5.pod.in | 52 +++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 5 ++++ tools/libxl/libxl_create.c | 16 +++++++++- tools/libxl/libxl_types.idl | 7 +++++ tools/xl/xl_parse.c | 38 ++++++++++++++++++++++++ xen/arch/arm/domain.c | 10 ++++++- xen/arch/x86/domain.c | 2 +- xen/common/domain.c | 7 +++++ xen/drivers/passthrough/iommu.c | 13 ++++++++- xen/include/public/domctl.h | 6 +++- xen/include/xen/iommu.h | 19 ++++++++---- 11 files changed, 164 insertions(+), 11 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index c99d40307e..c669524bec 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -605,6 +605,58 @@ option should only be used with a trusted device tree. Note that the partial device tree should avoid using the phandle 65000 which is reserved by the toolstack. =20 +=3Ditem B + +Specify whether IOMMU mappings are enabled for the domain and hence whether +it will be enabled for passthrough hardware. Valid values for this option +are: + +=3Dover 4 + +=3Ditem B + +IOMMU mappings are disabled for the domain and so hardware may not be +passed through. + +This option is the default if no passthrough hardware is specified +in the domain's configuration. + +=3Ditem B + +This option means that IOMMU mappings will be synchronized with the +domain's P2M table as follows: + +For a PV domain, all writable pages assigned to the domain are identity +mapped by MFN in the IOMMU page table. Thus a device driver running in the +domain may program passthrough hardware for DMA using MFN values +(i.e. host/machine frame numbers) looked up in its P2M. + +For an HVM domain, all non-foreign RAM pages present in its P2M will be +mapped by GFN in the IOMMU page table. Thus a device driver running in the +domain may program passthrough hardware using GFN values (i.e. guest +physical frame numbers) without any further translation. + +This option is the default if the domain is PV and passthrough hardware +is specified in the configuration. + +This option is not available on Arm. + +=3Ditem B + +This option is unavailable for a PV domain. For an HVM domain, this option +means that the IOMMU will be programmed to directly reference the domain's +P2M table as its page table. From the point of view of a device driver +running in the domain this is functionally equivalent to B but +places less load on the hypervisor and so should generally be selected in +preference. However, the availability of this option is hardware specific +and thus, if it is specified for a domain running on hardware that does +not allow it, B will be used instead. + +This option is the default if the domain is HVM and passthrough hardware +is specified in the configuration. + +=3Dback + =3Dback =20 =3Dhead2 Devices diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 9bacfb97f0..5de7c07a41 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -394,6 +394,11 @@ */ #define LIBXL_HAVE_EXTENDED_VKB 1 =20 +/* + * libxl_domain_create_info has libxl_passthrough enumeration. + */ +#define LIBXL_HAVE_CREATEINFO_PASSTHROUGH 1 + /* * libxl ABI compatibility * diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 050ef042cd..ad5f36484a 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -565,12 +565,26 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_co= nfig *d_config, libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off; } =20 + LOG(DETAIL, "passthrough: %s", + libxl_passthrough_to_string(info->passthrough)); + rc =3D libxl_get_physinfo(ctx, &physinfo); if (rc < 0) goto out; =20 - if (physinfo.cap_hvm_directio) + if (info->passthrough !=3D LIBXL_PASSTHROUGH_DISABLED) + { + if (!physinfo.cap_hvm_directio) { + LOGED(ERROR, *domid, "passthrough not available"); + rc =3D ERROR_FAIL; + goto out; + } + create.flags |=3D XEN_DOMCTL_CDF_iommu; + } + + if (info->passthrough =3D=3D LIBXL_PASSTHROUGH_SYNC_PT) + create.iommu_opts |=3D XEN_DOMCTL_IOMMU_no_sharept; =20 /* Ultimately, handle is an array of 16 uint8_t, same as uuid */ libxl_uuid_copy(ctx, (libxl_uuid *)&create.handle, &info->uuid); diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index b61399ce36..7e37de8646 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -263,6 +263,12 @@ libxl_vkb_backend =3D Enumeration("vkb_backend", [ (2, "LINUX") ]) =20 +libxl_passthrough =3D Enumeration("passthrough", [ + (0, "disabled"), + (1, "sync_pt"), + (2, "share_pt"), + ]) + # # Complex libxl types # @@ -408,6 +414,7 @@ libxl_domain_create_info =3D Struct("domain_create_info= ",[ ("pool_name", string), ("run_hotplug_scripts",libxl_defbool), ("driver_domain",libxl_defbool), + ("passthrough", libxl_passthrough), ], dir=3DDIR_IN) =20 libxl_domain_restore_params =3D Struct("domain_restore_params", [ diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index e105bda2bb..c904604008 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2326,6 +2326,44 @@ skip_vfb: } } =20 + if (!xlu_cfg_get_string(config, "passthrough", &buf, 0)) { + libxl_passthrough o; + + e =3D libxl_passthrough_from_string(buf, &o); + if (e) { + fprintf(stderr, + "ERROR: unknown passthrough option '%s'\n", + buf); + exit(-ERROR_FAIL); + } + + switch (o) { + case LIBXL_PASSTHROUGH_DISABLED: + if (d_config->num_pcidevs || d_config->num_dtdevs) { + fprintf(stderr, + "ERROR: passthrough disabled but devices are speci= fied\n"); + exit(-ERROR_FAIL); + } + case LIBXL_PASSTHROUGH_SHARE_PT: + if (c_info->type =3D=3D LIBXL_DOMAIN_TYPE_PV) { + fprintf(stderr, + "ERROR: passthrough=3D\"share_pt\" not valid for P= V domain\n"); + exit(-ERROR_FAIL); + } + default: + break; + } + + c_info->passthrough =3D o; + } else if (d_config->num_pcidevs || d_config->num_dtdevs) { + /* + * Passthrough devices are specified so set an appropriate + * default value. + */ + c_info->passthrough =3D (c_info->type =3D=3D LIBXL_DOMAIN_TYPE_PV)= ? + LIBXL_PASSTHROUGH_SYNC_PT : LIBXL_PASSTHROUGH_SHARE_PT; + } + if (!xlu_cfg_get_list(config, "usbctrl", &usbctrls, 0, 0)) { d_config->num_usbctrls =3D 0; d_config->usbctrls =3D NULL; diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 3ff19bc1ca..ec28ba1efd 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -614,6 +614,14 @@ int arch_sanitise_domain_config(struct xen_domctl_crea= tedomain *config) return -EINVAL; } =20 + /* Always share P2M Table between the CPU and the IOMMU */ + if ( config->iommu_opts & XEN_DOMCTL_IOMMU_no_sharept ) + { + dprintk(XENLOG_INFO, + "Unsupported iommu option: XEN_DOMCTL_IOMMU_no_sharept\n"); + return -EINVAL; + } + /* Fill in the native GIC version, passed back to the toolstack. */ if ( config->arch.gic_version =3D=3D XEN_DOMCTL_CONFIG_GIC_NATIVE ) { @@ -673,7 +681,7 @@ int arch_domain_create(struct domain *d, =20 ASSERT(config !=3D NULL); =20 - if ( (rc =3D iommu_domain_init(d)) !=3D 0 ) + if ( (rc =3D iommu_domain_init(d, config->iommu_opts)) !=3D 0 ) goto fail; =20 if ( (rc =3D p2m_init(d)) !=3D 0 ) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index f144d8fe9a..4f7dad49c5 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -604,7 +604,7 @@ int arch_domain_create(struct domain *d, if ( (rc =3D init_domain_irq_mapping(d)) !=3D 0 ) goto fail; =20 - if ( (rc =3D iommu_domain_init(d)) !=3D 0 ) + if ( (rc =3D iommu_domain_init(d, config->iommu_opts)) !=3D 0 ) goto fail; =20 psr_domain_init(d); diff --git a/xen/common/domain.c b/xen/common/domain.c index e832a5c4aa..142b08174b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -308,6 +308,13 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) return -EINVAL; } =20 + if ( !(config->flags & XEN_DOMCTL_CDF_iommu) && config->iommu_opts ) + { + dprintk(XENLOG_INFO, + "IOMMU options specified but IOMMU not enabled\n"); + return -EINVAL; + } + if ( config->max_vcpus < 1 ) { dprintk(XENLOG_INFO, "No vCPUS\n"); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 965740f6f7..550657c16b 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -159,7 +159,7 @@ static void __hwdom_init check_hwdom_reqs(struct domain= *d) iommu_hwdom_strict =3D true; } =20 -int iommu_domain_init(struct domain *d) +int iommu_domain_init(struct domain *d, unsigned int opts) { struct domain_iommu *hd =3D dom_iommu(d); int ret =3D 0; @@ -176,6 +176,15 @@ int iommu_domain_init(struct domain *d) if ( ret ) return ret; =20 + /* + * Use shared page tables for HAP and IOMMU if the global option + * is enabled (from which we can infer the h/w is capable) and + * the domain options do not disallow it. HAP must, of course, also + * be enabled. + */ + hd->hap_pt_share =3D hap_enabled(d) && iommu_hap_pt_share && + !(opts & XEN_DOMCTL_IOMMU_no_sharept); + /* * NB: 'relaxed' h/w domains don't need the IOMMU mappings to be kept * in-sync with their assigned pages because all host RAM will be @@ -187,6 +196,8 @@ int iommu_domain_init(struct domain *d) if ( !is_hardware_domain(d) || iommu_hwdom_strict ) hd->need_sync =3D !iommu_use_hap_pt(d); =20 + ASSERT(!(hd->need_sync && hd->hap_pt_share)); + return 0; } =20 diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 3f82c78870..922ed50a11 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -38,7 +38,7 @@ #include "hvm/save.h" #include "memory.h" =20 -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000011 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000012 =20 /* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. @@ -70,6 +70,10 @@ struct xen_domctl_createdomain { =20 uint32_t flags; =20 +#define _XEN_DOMCTL_IOMMU_no_sharept 0 +#define XEN_DOMCTL_IOMMU_no_sharept (1U<<_XEN_DOMCTL_IOMMU_no_sharept) + uint32_t iommu_opts; + /* * Various domain limits, which impact the quantity of resources (glob= al * mapping space, xenheap, etc) a guest may consume. diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 5e7ca98170..01025e372b 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -67,7 +67,7 @@ extern unsigned int iommu_dev_iotlb_timeout; int iommu_setup(void); int iommu_hardware_setup(void); =20 -int iommu_domain_init(struct domain *d); +int iommu_domain_init(struct domain *d, unsigned int opts); void iommu_hwdom_init(struct domain *d); void iommu_domain_destroy(struct domain *d); =20 @@ -257,9 +257,17 @@ struct domain_iommu { DECLARE_BITMAP(features, IOMMU_FEAT_count); =20 /* - * Does the guest reqire mappings to be synchonized, to maintain - * the default dfn =3D=3D pfn map. (See comment on dfn at the top of - * include/xen/mm.h). + * Does the guest share HAP mapping with the IOMMU? This is always + * true for ARM systems and may be true for x86 systems where the + * the hardware is capable. + */ + bool hap_pt_share; + + /* + * Does the guest require mappings to be synchronized, to maintain + * the default dfn =3D=3D pfn map? (See comment on dfn at the top of + * include/xen/mm.h). Note that hap_pt_share =3D=3D false does not + * necessarily imply this is true. */ bool need_sync; }; @@ -269,8 +277,7 @@ struct domain_iommu { #define iommu_clear_feature(d, f) clear_bit(f, dom_iommu(d)->features) =20 /* Are we using the domain P2M table as its IOMMU pagetable? */ -#define iommu_use_hap_pt(d) \ - (hap_enabled(d) && is_iommu_enabled(d) && iommu_hap_pt_share) +#define iommu_use_hap_pt(d) (dom_iommu(d)->hap_pt_share) =20 /* Does the IOMMU pagetable need to be kept synchronized with the P2M */ #ifdef CONFIG_HAS_PASSTHROUGH --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel