diff mbox series

[4/8] VT-d: refuse to use IOMMU with reserved CAP.ND value

Message ID 0f7136ae-0b52-431d-f789-4b7d5bbecb25@suse.com (mailing list archive)
State New, archived
Headers show
Series IOMMU: assorted follow-on to XSA-400 | expand

Commit Message

Jan Beulich April 11, 2022, 9:37 a.m. UTC
The field taking the value 7 (resulting in 18-bit DIDs when using the
calculation in cap_ndoms(), when the DID fields are only 16 bits wide)
is reserved. Instead of misbehaving in case we would encounter such an
IOMMU, refuse to use it.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Roger Pau Monné April 12, 2022, 9:22 a.m. UTC | #1
On Mon, Apr 11, 2022 at 11:37:28AM +0200, Jan Beulich wrote:
> The field taking the value 7 (resulting in 18-bit DIDs when using the
> calculation in cap_ndoms(), when the DID fields are only 16 bits wide)
> is reserved. Instead of misbehaving in case we would encounter such an
> IOMMU, refuse to use it.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

I would maybe prefer to get more specific error message rather than
"IOMMU: unsupported" and a dump of the iommu registers.

Thanks, Roger.
Jan Beulich April 12, 2022, 10:35 a.m. UTC | #2
On 12.04.2022 11:22, Roger Pau Monné wrote:
> On Mon, Apr 11, 2022 at 11:37:28AM +0200, Jan Beulich wrote:
>> The field taking the value 7 (resulting in 18-bit DIDs when using the
>> calculation in cap_ndoms(), when the DID fields are only 16 bits wide)
>> is reserved. Instead of misbehaving in case we would encounter such an
>> IOMMU, refuse to use it.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks.

> I would maybe prefer to get more specific error message rather than
> "IOMMU: unsupported" and a dump of the iommu registers.

Perhaps, but this extends to other properties being checked as well then,
I would say, and hence may want to be the subject of yet another patch.

Jan
Tian, Kevin April 20, 2022, 6:23 a.m. UTC | #3
> From: Jan Beulich <jbeulich@suse.com>
> Sent: Monday, April 11, 2022 5:37 PM
> 
> The field taking the value 7 (resulting in 18-bit DIDs when using the
> calculation in cap_ndoms(), when the DID fields are only 16 bits wide)
> is reserved. Instead of misbehaving in case we would encounter such an
> IOMMU, refuse to use it.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

> 
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -1267,8 +1267,11 @@ int __init iommu_alloc(struct acpi_drhd_
> 
>      quirk_iommu_caps(iommu);
> 
> +    nr_dom = cap_ndoms(iommu->cap);
> +
>      if ( cap_fault_reg_offset(iommu->cap) +
>           cap_num_fault_regs(iommu->cap) * PRIMARY_FAULT_REG_LEN >
> PAGE_SIZE ||
> +         ((nr_dom - 1) >> 16) /* I.e. cap.nd > 6 */ ||
>           (has_register_based_invalidation(iommu) &&
>            ecap_iotlb_offset(iommu->ecap) >= PAGE_SIZE) )
>      {
> @@ -1294,8 +1297,6 @@ int __init iommu_alloc(struct acpi_drhd_
>      if ( !ecap_coherent(iommu->ecap) )
>          iommu_non_coherent = true;
> 
> -    nr_dom = cap_ndoms(iommu->cap);
> -
>      if ( nr_dom <= DOMID_MASK * 2 + cap_caching_mode(iommu->cap) )
>      {
>          /* Allocate domain id (bit) maps. */
diff mbox series

Patch

--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1267,8 +1267,11 @@  int __init iommu_alloc(struct acpi_drhd_
 
     quirk_iommu_caps(iommu);
 
+    nr_dom = cap_ndoms(iommu->cap);
+
     if ( cap_fault_reg_offset(iommu->cap) +
          cap_num_fault_regs(iommu->cap) * PRIMARY_FAULT_REG_LEN > PAGE_SIZE ||
+         ((nr_dom - 1) >> 16) /* I.e. cap.nd > 6 */ ||
          (has_register_based_invalidation(iommu) &&
           ecap_iotlb_offset(iommu->ecap) >= PAGE_SIZE) )
     {
@@ -1294,8 +1297,6 @@  int __init iommu_alloc(struct acpi_drhd_
     if ( !ecap_coherent(iommu->ecap) )
         iommu_non_coherent = true;
 
-    nr_dom = cap_ndoms(iommu->cap);
-
     if ( nr_dom <= DOMID_MASK * 2 + cap_caching_mode(iommu->cap) )
     {
         /* Allocate domain id (bit) maps. */