From nobody Thu Apr 25 11:20:09 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1557321930; cv=none; d=zoho.com; s=zohoarc; b=Or0pO283uv5qhwbtu8DIWYrPsStnAeQITQKEM2i8fFgVG+4uUFD/XBBhuE+bP0OsHy4jlCMGPysM21FY+7W9M+nyOnr9JAfu0yE3zjulCkndAIy1oGuMlGv62oy7ZbAZynlUefS17GXElty++fQxGbUq1QJ6wescLSCv6hNvDyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557321930; 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=6+BDybf+RJtTxGMzHG4+YA7QuLB1k7xlR+Bs6JoQM1w=; b=bL9OM0gkorlZUlWflx0r5z7VX/0tY4uHoJYwu2rVuJsEE4h5sN7NT1cM0F4GLUzZ8cg7dajOc/IWr9n+tRTC+6DdZZtxu6gDGoDpkbnRDZ7RjgSKU8/xj5MlUxduo8UFh+mfI7colzoJ9THbKh/FXZEB/GY0UZJ/vLmr4lN7/r8= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1557321930102915.0102370925359; Wed, 8 May 2019 06:25:30 -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 1hOMYP-0000dE-BW; Wed, 08 May 2019 13:24:13 +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 1hOMYO-0000d9-8W for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:24:12 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8f0ecd8a-7194-11e9-afcc-479c29bd2a1d; Wed, 08 May 2019 13:24:08 +0000 (UTC) X-Inumbo-ID: 8f0ecd8a-7194-11e9-afcc-479c29bd2a1d X-IronPort-AV: E=Sophos;i="5.60,446,1549929600"; d="scan'208";a="85265424" From: Paul Durrant To: Date: Wed, 8 May 2019 14:23:59 +0100 Message-ID: <20190508132403.1454-2-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190508132403.1454-1-paul.durrant@citrix.com> References: <20190508132403.1454-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/5] iommu: trivial re-organisation to avoid unnecessary test 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" An 'if ( !iommu_enabled )' followed by an 'if ( iommu_enabled )' with only a printk() in between seems a little silly. Move the printk() and use 'else' instead. Signed-off-by: Paul Durrant Acked-by: Jan Beulich --- Cc: Jan Beulich --- xen/drivers/passthrough/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index a6697d58fb..b453b32191 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -512,14 +512,14 @@ int __init iommu_setup(void) if ( !iommu_intremap ) iommu_intpost =3D 0; =20 + printk("I/O virtualisation %sabled\n", iommu_enabled ? "en" : "dis"); if ( !iommu_enabled ) { iommu_snoop =3D 0; iommu_hwdom_passthrough =3D false; iommu_hwdom_strict =3D false; } - printk("I/O virtualisation %sabled\n", iommu_enabled ? "en" : "dis"); - if ( iommu_enabled ) + else { printk(" - Dom0 mode: %s\n", iommu_hwdom_passthrough ? "Passthrough" : --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 11:20:09 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1557321932; cv=none; d=zoho.com; s=zohoarc; b=muBpZc5nJFuywJ1w7jOux+XWT5DV0/YjimsSENwbPdFjkRNncPNEK5xF9UfWld8ChjDM9/blxbOr6qYn8av8cmuTWbRl8DV91knkbEPEVeB4jjFrhGwNzNZZJ053wkOVQfaPtk9KoM67NxnokF66Gh452408BaxdPk8Ri5ysSkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557321932; 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=qIJnQUmlBHGncOWLiKlvTtLz4q6+89WVFcyWS+PZeb8=; b=UALYS/j+EufIdvoA7+0dkfa1AY3JK2rdcn8schhdOcYVpJL7WcwZpGZ+ijWThFL3IFoK8Shgj6FAemPKwUlvluq9V1vmYutyYfYN1fovmRIeGuuyR4T1SfBbuJghr4tUxoVz/9pChUTeg/dbUskdyYyYfIQUU7RK5mEXbNr5yxQ= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1557321931944475.9072906902592; Wed, 8 May 2019 06:25:31 -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 1hOMYR-0000dU-K0; Wed, 08 May 2019 13:24:15 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOMYQ-0000dK-Kz for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:24:14 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 926dea57-7194-11e9-843c-bc764e045a96; Wed, 08 May 2019 13:24:13 +0000 (UTC) X-Inumbo-ID: 926dea57-7194-11e9-843c-bc764e045a96 X-IronPort-AV: E=Sophos;i="5.60,446,1549929600"; d="scan'208";a="85265437" From: Paul Durrant To: Date: Wed, 8 May 2019 14:24:00 +0100 Message-ID: <20190508132403.1454-3-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190508132403.1454-1-paul.durrant@citrix.com> References: <20190508132403.1454-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/5] iommu / x86: move call to scan_pci_devices() out of vendor code 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 , Wei Liu , Suravee Suthikulpanit , Andrew Cooper , Paul Durrant , Jan Beulich , Brian Woods , =?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" It's not vendor specific so it shouldn't really be there. Signed-off-by: Paul Durrant --- Cc: Suravee Suthikulpanit Cc: Brian Woods Cc: Kevin Tian Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" --- xen/drivers/passthrough/amd/pci_amd_iommu.c | 3 ++- xen/drivers/passthrough/vtd/iommu.c | 4 ---- xen/drivers/passthrough/x86/iommu.c | 9 ++++++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/pass= through/amd/pci_amd_iommu.c index dbc71ca7d5..872bbe21c2 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -182,7 +182,8 @@ static int __init iov_detect(void) =20 if ( !amd_iommu_perdev_intremap ) printk(XENLOG_WARNING "AMD-Vi: Using global interrupt remap table = is not recommended (see XSA-36)!\n"); - return scan_pci_devices(); + + return 0; } =20 int amd_iommu_alloc_root(struct domain_iommu *hd) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index 7b9e09a084..f9c76f594c 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2372,10 +2372,6 @@ static int __init vtd_setup(void) P(iommu_hap_pt_share, "Shared EPT tables"); #undef P =20 - ret =3D scan_pci_devices(); - if ( ret ) - goto error; - ret =3D init_vtd_hw(); if ( ret ) goto error; diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index 034ac903dd..895c7fb564 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -28,6 +28,8 @@ struct iommu_ops __read_mostly iommu_ops; =20 int __init iommu_hardware_setup(void) { + int rc; + if ( !iommu_init_ops ) return -ENODEV; =20 @@ -37,7 +39,12 @@ int __init iommu_hardware_setup(void) /* x2apic setup may have previously initialised the struct. */ ASSERT(iommu_ops.init =3D=3D iommu_init_ops->ops->init); =20 - return iommu_init_ops->setup(); + rc =3D iommu_init_ops->setup(); + + if ( !rc ) + rc =3D scan_pci_devices(); + + return rc; } =20 int iommu_enable_x2apic(void) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 11:20:09 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1557321938; cv=none; d=zoho.com; s=zohoarc; b=etxqotNhc6xiYpWwIG43whi6Bm66ZtjSBfvBwHEtolhCIABBaRLW4XByzkt6foI80OHnmCarEYZ8N6orf7klf7YO7I323q4eNabwGWpLCVB0OFmYiXkl9GXjg1Zhiw4bfFmbrX+u2pm/A0WBXqupWr5wUwVYgbrMGj6IOiHNi7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557321938; 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=1Zwe9XT3yHbe/UUAfMl+45kkwTNTECfhXg3eGwsc2XY=; b=Om51i0BgRcR+/Yx08+IW6dRCL9zpyce6hA+6XrqMssTNG5sWZZaDZdyJ6yW9SE+wSR9+YEK2TNrmkVAJeWLV+RiRYdrjHrjkLkQkEM2gOMnUXc3MaiS3071Q1Aos5tjlplPUQPJXT+8pjotxHu3q7weL1rFkEIKDSZnWb+YPxDc= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1557321938758381.10150118978015; Wed, 8 May 2019 06:25:38 -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 1hOMYT-0000eQ-Aa; Wed, 08 May 2019 13:24:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOMYS-0000dd-1B for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:24:16 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 92bddcd7-7194-11e9-843c-bc764e045a96; Wed, 08 May 2019 13:24:14 +0000 (UTC) X-Inumbo-ID: 92bddcd7-7194-11e9-843c-bc764e045a96 X-IronPort-AV: E=Sophos;i="5.60,446,1549929600"; d="scan'208";a="85265438" From: Paul Durrant To: Date: Wed, 8 May 2019 14:24:01 +0100 Message-ID: <20190508132403.1454-4-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190508132403.1454-1-paul.durrant@citrix.com> References: <20190508132403.1454-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/5] iommu: move iommu_get_ops() into common code 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 , Wei Liu , Suravee Suthikulpanit , Andrew Cooper , Julien Grall , Paul Durrant , Jan Beulich , Brian Woods , =?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" Currently x86 and ARM differ in their implementation for no good reason. This patch moves the ARM variant of iommu_get/set_ops() helpers into common code and modifies them so they deal with the __initconstrel ops structures used by the x86 IOMMU vendor implementations (adding __initconstrel to the SMMU code to bring it in line). Consequently, a lack of init() method is now taken to mean uninitialized iommu_ops. Also, the printk warning in iommu_set_ops() now becomes an ASSERT. NOTE: This patch also gets rid of the extern intel_iommu_ops as it is no longer necessary. Signed-off-by: Paul Durrant --- Cc: Suravee Suthikulpanit Cc: Brian Woods Cc: Stefano Stabellini Cc: Julien Grall Cc: Jan Beulich Cc: Kevin Tian Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" --- xen/drivers/passthrough/arm/iommu.c | 17 ----------------- xen/drivers/passthrough/arm/smmu.c | 2 +- xen/drivers/passthrough/iommu.c | 15 +++++++++++++++ xen/drivers/passthrough/vtd/extern.h | 1 - xen/drivers/passthrough/vtd/iommu.c | 4 ++-- xen/drivers/passthrough/x86/iommu.c | 16 +++++++--------- xen/include/asm-arm/iommu.h | 3 --- xen/include/asm-x86/iommu.h | 20 ++++++++------------ xen/include/xen/iommu.h | 3 +++ 9 files changed, 36 insertions(+), 45 deletions(-) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/= arm/iommu.c index 325997b19f..c226ed18e3 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -20,23 +20,6 @@ #include #include =20 -static const struct iommu_ops *iommu_ops; - -const struct iommu_ops *iommu_get_ops(void) -{ - return iommu_ops; -} - -void __init iommu_set_ops(const struct iommu_ops *ops) -{ - BUG_ON(ops =3D=3D NULL); - - if ( iommu_ops && iommu_ops !=3D ops ) - printk("WARNING: Cannot set IOMMU ops, already set to a different = value\n"); - - iommu_ops =3D ops; -} - int __init iommu_hardware_setup(void) { struct dt_device_node *np; diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index f151b9f5b5..f01061a218 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -1989,7 +1989,7 @@ static int arm_smmu_domain_set_attr(struct iommu_doma= in *domain, } } =20 -static const struct iommu_ops arm_smmu_ops =3D { +static const struct iommu_ops __initconstrel arm_smmu_ops =3D { .capable =3D arm_smmu_capable, .domain_init =3D arm_smmu_domain_init, .domain_destroy =3D arm_smmu_domain_destroy, diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index b453b32191..d3a6199b77 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -21,6 +21,21 @@ #include #include =20 +static struct iommu_ops __read_mostly iommu_ops; + +const struct iommu_ops *iommu_get_ops(void) +{ + return &iommu_ops; +} + +void __init iommu_set_ops(const struct iommu_ops *ops) +{ + BUG_ON(!ops); + + ASSERT(!iommu_ops.init || iommu_ops.init =3D=3D ops->init); + iommu_ops =3D *ops; +} + static void iommu_dump_p2m_table(unsigned char key); =20 unsigned int __read_mostly iommu_dev_iotlb_timeout =3D 1000; diff --git a/xen/drivers/passthrough/vtd/extern.h b/xen/drivers/passthrough= /vtd/extern.h index 331d6e64f7..0ae5ddf6d0 100644 --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -28,7 +28,6 @@ struct pci_ats_dev; extern bool_t rwbf_quirk; extern const struct iommu_init_ops intel_iommu_init_ops; -extern const struct iommu_ops intel_iommu_ops; =20 void print_iommu_regs(struct acpi_drhd_unit *drhd); void print_vtd_entries(struct iommu *iommu, int bus, int devfn, u64 gmfn); diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index f9c76f594c..db77655260 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2700,7 +2700,7 @@ static void vtd_dump_p2m_table(struct domain *d) vtd_dump_p2m_table_level(hd->arch.pgd_maddr, agaw_to_level(hd->arch.ag= aw), 0, 0); } =20 -const struct iommu_ops __initconstrel intel_iommu_ops =3D { +static const struct iommu_ops __initconstrel _iommu_ops =3D { .init =3D intel_iommu_domain_init, .hwdom_init =3D intel_iommu_hwdom_init, .add_device =3D intel_iommu_add_device, @@ -2733,7 +2733,7 @@ const struct iommu_ops __initconstrel intel_iommu_ops= =3D { }; =20 const struct iommu_init_ops __initconstrel intel_iommu_init_ops =3D { - .ops =3D &intel_iommu_ops, + .ops =3D &_iommu_ops, .setup =3D vtd_setup, .supports_x2apic =3D intel_iommu_supports_eim, }; diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index 895c7fb564..d9eaf1e62b 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -24,7 +24,6 @@ #include =20 const struct iommu_init_ops *__initdata iommu_init_ops; -struct iommu_ops __read_mostly iommu_ops; =20 int __init iommu_hardware_setup(void) { @@ -33,11 +32,7 @@ int __init iommu_hardware_setup(void) if ( !iommu_init_ops ) return -ENODEV; =20 - if ( !iommu_ops.init ) - iommu_ops =3D *iommu_init_ops->ops; - else - /* x2apic setup may have previously initialised the struct. */ - ASSERT(iommu_ops.init =3D=3D iommu_init_ops->ops->init); + iommu_set_ops(iommu_init_ops->ops); =20 rc =3D iommu_init_ops->setup(); =20 @@ -49,20 +44,23 @@ int __init iommu_hardware_setup(void) =20 int iommu_enable_x2apic(void) { + const struct iommu_ops *ops; + if ( system_state < SYS_STATE_active ) { if ( !iommu_supports_x2apic() ) return -EOPNOTSUPP; =20 - iommu_ops =3D *iommu_init_ops->ops; + iommu_set_ops(iommu_init_ops->ops); } else if ( !x2apic_enabled ) return -EOPNOTSUPP; =20 - if ( !iommu_ops.enable_x2apic ) + ops =3D iommu_get_ops(); + if ( !ops->enable_x2apic ) return -EOPNOTSUPP; =20 - return iommu_ops.enable_x2apic(); + return ops->enable_x2apic(); } =20 void iommu_update_ire_from_apic( diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h index 904c9aec11..fb4ca23b69 100644 --- a/xen/include/asm-arm/iommu.h +++ b/xen/include/asm-arm/iommu.h @@ -23,9 +23,6 @@ struct arch_iommu /* Always share P2M Table between the CPU and the IOMMU */ #define iommu_use_hap_pt(d) (has_iommu_pt(d)) =20 -const struct iommu_ops *iommu_get_ops(void); -void iommu_set_ops(const struct iommu_ops *ops); - #endif /* __ARCH_ARM_IOMMU_H__ */ =20 /* diff --git a/xen/include/asm-x86/iommu.h b/xen/include/asm-x86/iommu.h index bbdb05f5f0..2d8716d673 100644 --- a/xen/include/asm-x86/iommu.h +++ b/xen/include/asm-x86/iommu.h @@ -57,14 +57,6 @@ struct arch_iommu struct guest_iommu *g_iommu; }; =20 -extern struct iommu_ops iommu_ops; - -static inline const struct iommu_ops *iommu_get_ops(void) -{ - BUG_ON(!iommu_ops.init); - return &iommu_ops; -} - struct iommu_init_ops { const struct iommu_ops *ops; int (*setup)(void); @@ -83,8 +75,10 @@ int iommu_setup_hpet_msi(struct msi_desc *); =20 static inline int iommu_adjust_irq_affinities(void) { - return iommu_ops.adjust_irq_affinities - ? iommu_ops.adjust_irq_affinities() + const struct iommu_ops *ops =3D iommu_get_ops(); + + return ops->adjust_irq_affinities + ? ops->adjust_irq_affinities() : 0; } =20 @@ -103,8 +97,10 @@ int iommu_enable_x2apic(void); =20 static inline void iommu_disable_x2apic(void) { - if ( x2apic_enabled && iommu_ops.disable_x2apic ) - iommu_ops.disable_x2apic(); + const struct iommu_ops *ops =3D iommu_get_ops(); + + if ( x2apic_enabled && ops->disable_x2apic ) + ops->disable_x2apic(); } =20 extern bool untrusted_msi; diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 5d3c1619c4..b2d429a6ef 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -64,6 +64,9 @@ extern int8_t iommu_hwdom_reserved; =20 extern unsigned int iommu_dev_iotlb_timeout; =20 +const struct iommu_ops *iommu_get_ops(void); +void iommu_set_ops(const struct iommu_ops *ops); + int iommu_setup(void); int iommu_hardware_setup(void); =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 11:20:09 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1557321933; cv=none; d=zoho.com; s=zohoarc; b=Th8f7T3H+f4uM6j4xU33QGDxUSvGsL8ungjkGZcFx9HnJ2phhwScAMXmU28IuMGmBzqnA+f+7pr93CpSyb9ybgxLPOV5heRNamMjX8AYXEY61jQn8dqAyzcjuwm5A61YCeInEedg8HFc9K1DxQ4oiEhd/kgtFjXCKVfhsMUsBWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557321933; 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=B+JwQtfT2KUbEdaHflAEI6gwfXR0rXxWDb5PR+2PRS8=; b=RzCYpk2haPEBpHS1j3/EIHsO/kdNkDN07PmhQ1fj1qBtVK0l9mjdNxw8JaizE2bdgdhlviRU5Uk1qifmRY6rLnVXseR7G8ESV5g12ZXUewSigYx96K9hpGbt5Bu4sAUAx1WcIAvbDR2zoEv3VsO72kjoQedwuVX0RYTGABnBGII= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1557321933910138.8989285628336; Wed, 8 May 2019 06:25:33 -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 1hOMYT-0000ek-Uy; Wed, 08 May 2019 13:24:17 +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 1hOMYS-0000dh-5Y for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:24:16 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 914338ca-7194-11e9-a4bf-abcea8b8197d; Wed, 08 May 2019 13:24:11 +0000 (UTC) X-Inumbo-ID: 914338ca-7194-11e9-a4bf-abcea8b8197d X-IronPort-AV: E=Sophos;i="5.60,446,1549929600"; d="scan'208";a="85265425" From: Paul Durrant To: Date: Wed, 8 May 2019 14:24:02 +0100 Message-ID: <20190508132403.1454-5-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190508132403.1454-1-paul.durrant@citrix.com> References: <20190508132403.1454-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/5] iommu: introduce iommu_groups 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Some devices may share a single PCIe initiator id, e.g. if they are actually legacy PCI devices behind a bridge, and hence DMA from such devices will be subject to the same address translation in the IOMMU. Hence these devices should be treated as a unit for the purposes of assignment. There are also other reasons why multiple devices should be treated as a unit, e.g. those subject to a shared RMRR or those downstream of a bridge that does not support ACS. This patch introduces a new struct iommu_group to act as a container for devices that should be treated as a unit, and builds a list of them as PCI devices are scanned. The iommu_ops already implement a method, get_device_group_id(), that is seemingly intended to return the initiator id for a given SBDF so use this as the mechanism for group assignment in the first instance. Assignment based on shared RMRR or lack of ACS will be dealt with in subsequent patches, as will modifications to the device assignment code. 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 --- xen/drivers/passthrough/iommu.c | 76 +++++++++++++++++++++++++++++++++++++= ++++ xen/drivers/passthrough/pci.c | 3 ++ xen/include/xen/iommu.h | 7 ++++ xen/include/xen/pci.h | 3 ++ 4 files changed, 89 insertions(+) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index d3a6199b77..11319fbaae 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -655,6 +655,82 @@ static void iommu_dump_p2m_table(unsigned char key) } } =20 +#ifdef CONFIG_HAS_PCI + +struct iommu_group { + unsigned int id; + unsigned int index; + struct list_head devs_list; +}; + +static struct radix_tree_root iommu_groups; + +void __init iommu_groups_init(void) +{ + radix_tree_init(&iommu_groups); +} + +static struct iommu_group *alloc_iommu_group(unsigned int id) +{ + struct iommu_group *grp; + static unsigned int index; + + grp =3D xzalloc(struct iommu_group); + if ( !grp ) + return NULL; + + grp->id =3D id; + grp->index =3D index++; + INIT_LIST_HEAD(&grp->devs_list); + + if ( radix_tree_insert(&iommu_groups, id, grp) ) + { + xfree(grp); + grp =3D NULL; + } + + return grp; +} + +static struct iommu_group *get_iommu_group(unsigned int id) +{ + struct iommu_group *grp =3D radix_tree_lookup(&iommu_groups, id); + + if ( !grp ) + grp =3D alloc_iommu_group(id); + + return grp; +} + +int iommu_group_assign(struct pci_dev *pdev) +{ + const struct iommu_ops *ops; + unsigned int id; + struct iommu_group *grp; + + ops =3D iommu_get_ops(); + if ( !ops || !ops->get_device_group_id ) + return 0; + + id =3D ops->get_device_group_id(pdev->seg, pdev->bus, pdev->devfn); + grp =3D get_iommu_group(id); + + if ( ! grp ) + return -ENOMEM; + + if ( iommu_verbose ) + printk(XENLOG_INFO "Assign %04x:%02x:%02x.%u -> IOMMU group %u\n", + pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), grp->index); + + list_add(&pdev->grpdevs_list, &grp->devs_list); + pdev->grp =3D grp; + + return 0; +} + +#endif /* CONFIG_HAS_PCI */ + /* * Local variables: * mode: C diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 8108ed5f9a..6210409741 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -427,6 +427,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg,= u8 bus, u8 devfn) =20 check_pdev(pdev); apply_quirks(pdev); + iommu_group_assign(pdev); =20 return pdev; } @@ -1098,6 +1099,8 @@ int __init scan_pci_devices(void) { int ret; =20 + iommu_groups_init(); + pcidevs_lock(); ret =3D pci_segments_iterate(_scan_pci_devices, NULL); pcidevs_unlock(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index b2d429a6ef..6d6aa12314 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -315,6 +315,13 @@ DECLARE_PER_CPU(bool_t, iommu_dont_flush_iotlb); extern struct spinlock iommu_pt_cleanup_lock; extern struct page_list_head iommu_pt_cleanup_list; =20 +#ifdef CONFIG_HAS_PCI + +void iommu_groups_init(void); +int iommu_group_assign(struct pci_dev *pdev); + +#endif /* CONFIG_HAS_PCI */ + #endif /* _IOMMU_H_ */ =20 /* diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 8b21e8dc84..5fe7525db6 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -75,6 +75,9 @@ struct pci_dev { struct list_head alldevs_list; struct list_head domain_list; =20 + struct list_head grpdevs_list; + struct iommu_group *grp; + struct list_head msi_list; =20 struct arch_msix *msix; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 11:20:09 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1557321932; cv=none; d=zoho.com; s=zohoarc; b=N9UFPsAJpKeJu6BTjL2T3hxh+LHh4H4YZew/6SlVeIE7I++jXWwTA/DkYEONfArlKR8yJ74c7XWinGbhSL7rtSJrfFKUbIdKh41Yr/rX5N2oSP7o4CGIOBwtBMWvickWT4KVAJloVZPGjl3MAghnZnZwsy9O5VwOwhA5WgCZsqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557321932; 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=EvpDjqNMXT36ypJy87++YQ8e+Ax6P5Ep01NpBQGlj5g=; b=GBu6us12jnKdTb0qPi3+NDNdfesgwqHiASOYesEggS5z9cpPIC5l9+7Ba+wFObYXfh2oOr36NhswY/YjGeaJi0r59B+7ewz2Vt8DL6A4zZNVOYU6hcLpVRR8uwoG76tOXg5Clwf++oSg9JxSfWUxqSupXEmb51QqflFc1PcETZU= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1557321932092191.7680192440115; Wed, 8 May 2019 06:25:32 -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 1hOMYT-0000eY-Jw; Wed, 08 May 2019 13:24:17 +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 1hOMYS-0000dg-5Z for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:24:16 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 914d4ca2-7194-11e9-9c8f-03198498a28f; Wed, 08 May 2019 13:24:12 +0000 (UTC) X-Inumbo-ID: 914d4ca2-7194-11e9-9c8f-03198498a28f X-IronPort-AV: E=Sophos;i="5.60,446,1549929600"; d="scan'208";a="85265426" From: Paul Durrant To: Date: Wed, 8 May 2019 14:24:03 +0100 Message-ID: <20190508132403.1454-6-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190508132403.1454-1-paul.durrant@citrix.com> References: <20190508132403.1454-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/5] iommu / pci: re-implement XEN_DOMCTL_get_device_group... 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" ... using the new iommu_group infrastructure. Because 'sibling' devices are now members of the same iommu_group, implement the domctl by looking up the relevant iommu_group and walking the membership list. Signed-off-by: Paul Durrant --- Cc: Jan Beulich --- xen/drivers/passthrough/iommu.c | 65 +++++++++++++++++++++++++++++++++++++= ++++ xen/drivers/passthrough/pci.c | 47 ----------------------------- xen/include/xen/iommu.h | 2 ++ 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 11319fbaae..49140c652e 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -729,6 +729,71 @@ int iommu_group_assign(struct pci_dev *pdev) return 0; } =20 +static struct iommu_group *iommu_group_lookup(uint16_t seg, uint8_t bus, + uint8_t devfn) +{ + unsigned int id =3D 0; + struct iommu_group *grp; + + while ( radix_tree_gang_lookup(&iommu_groups, (void **)&grp, id, 1) ) + { + struct pci_dev *pdev; + + list_for_each_entry ( pdev, &grp->devs_list, grpdevs_list ) + if ( pdev->seg =3D=3D seg && pdev->bus =3D=3D bus && + pdev->devfn =3D=3D devfn ) + return grp; + + id =3D grp->id + 1; + } + + return NULL; +} + +int iommu_get_device_group(struct domain *d, u16 seg, u8 bus, u8 devfn, + XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs) +{ + struct iommu_group *grp; + struct pci_dev *pdev; + int i =3D 0; + + pcidevs_lock(); + + grp =3D iommu_group_lookup(seg, bus, devfn); + if ( !grp ) + { + pcidevs_unlock(); + return 0; + } + + list_for_each_entry ( pdev, &grp->devs_list, grpdevs_list ) + { + uint32_t sbdf; + + if ( i >=3D max_sdevs ) + break; + + if ( pdev->domain !=3D d ) + continue; + + sbdf =3D PCI_SBDF3(pdev->seg, pdev->bus, pdev->devfn); + + if ( xsm_get_device_group(XSM_HOOK, sbdf) ) + continue; + + if ( unlikely(copy_to_guest_offset(buf, i, &sbdf, 1)) ) + { + pcidevs_unlock(); + return -1; + } + i++; + } + + pcidevs_unlock(); + + return i; +} + #endif /* CONFIG_HAS_PCI */ =20 /* diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 6210409741..68b2883ed6 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1554,53 +1554,6 @@ int deassign_device(struct domain *d, u16 seg, u8 bu= s, u8 devfn) return ret; } =20 -static int iommu_get_device_group( - struct domain *d, u16 seg, u8 bus, u8 devfn, - XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs) -{ - const struct domain_iommu *hd =3D dom_iommu(d); - struct pci_dev *pdev; - int group_id, sdev_id; - u32 bdf; - int i =3D 0; - const struct iommu_ops *ops =3D hd->platform_ops; - - if ( !iommu_enabled || !ops || !ops->get_device_group_id ) - return 0; - - group_id =3D ops->get_device_group_id(seg, bus, devfn); - - pcidevs_lock(); - for_each_pdev( d, pdev ) - { - if ( (pdev->seg !=3D seg) || - ((pdev->bus =3D=3D bus) && (pdev->devfn =3D=3D devfn)) ) - continue; - - if ( xsm_get_device_group(XSM_HOOK, (seg << 16) | (pdev->bus << 8)= | pdev->devfn) ) - continue; - - sdev_id =3D ops->get_device_group_id(seg, pdev->bus, pdev->devfn); - if ( (sdev_id =3D=3D group_id) && (i < max_sdevs) ) - { - bdf =3D 0; - bdf |=3D (pdev->bus & 0xff) << 16; - bdf |=3D (pdev->devfn & 0xff) << 8; - - if ( unlikely(copy_to_guest_offset(buf, i, &bdf, 1)) ) - { - pcidevs_unlock(); - return -1; - } - i++; - } - } - - pcidevs_unlock(); - - return i; -} - void iommu_dev_iotlb_flush_timeout(struct domain *d, struct pci_dev *pdev) { pcidevs_lock(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 6d6aa12314..c4e1604bb8 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -319,6 +319,8 @@ extern struct page_list_head iommu_pt_cleanup_list; =20 void iommu_groups_init(void); int iommu_group_assign(struct pci_dev *pdev); +int iommu_get_device_group(struct domain *d, u16 seg, u8 bus, u8 devfn, + XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs); =20 #endif /* CONFIG_HAS_PCI */ =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel