From: Joerg Roedel <jroedel@suse.de>
Date: Wed, 30 Sep 2020 11:50:36 +0200
Subject: [PATCH] iommu/vt-d: Correctly calculate agaw in domain_init()
Patch-mainline: Never, code refactored and bug not present anymore upstream
References: bsc#1176400
The calculation result can not be larger than iommu->agaw.
Account for that and also set domain->gaw correctly.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/intel-iommu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 3f099cedaaf3..04bd5e73a7cb 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -1863,9 +1863,11 @@ static int domain_init(struct dmar_domain *domain, struct intel_iommu *iommu,
/* calculate AGAW */
if (guest_width > cap_mgaw(iommu->cap))
guest_width = cap_mgaw(iommu->cap);
- domain->gaw = guest_width;
adjust_width = guestwidth_to_adjustwidth(guest_width);
agaw = width_to_agaw(adjust_width);
+ if (agaw > iommu->agaw)
+ agaw = iommu->agaw;
+ domain->gaw = agaw_to_width(agaw);
sagaw = cap_sagaw(iommu->cap);
if (!test_bit(agaw, &sagaw)) {
/* hardware doesn't support it, choose a bigger one */
--
2.16.3