| From 638caf2c90bbdfde2090eae2cb1bb489e03e5a50 Mon Sep 17 00:00:00 2001 |
| From: Joerg Roedel <jroedel@suse.de> |
| Date: Fri, 18 Oct 2019 11:34:22 +0200 |
| Subject: [PATCH] iommu/amd: Check PM_LEVEL_SIZE() condition in locked section |
| |
| commit 46ac18c347b00be29b265c28209b0f3c38a1f142 upstream. |
| |
| The increase_address_space() function has to check the PM_LEVEL_SIZE() |
| condition again under the domain->lock to avoid a false trigger of the |
| WARN_ON_ONCE() and to avoid that the address space is increase more |
| often than necessary. |
| |
| Reported-by: Qian Cai <cai@lca.pw> |
| Fixes: 754265bcab78 ("iommu/amd: Fix race in increase_address_space()") |
| Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> |
| Signed-off-by: Joerg Roedel <jroedel@suse.de> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c |
| index 909a97da6595..cbb110046156 100644 |
| --- a/drivers/iommu/amd_iommu.c |
| +++ b/drivers/iommu/amd_iommu.c |
| @@ -1426,6 +1426,7 @@ static void free_pagetable(struct protection_domain *domain) |
| * to 64 bits. |
| */ |
| static void increase_address_space(struct protection_domain *domain, |
| + unsigned long address, |
| gfp_t gfp) |
| { |
| unsigned long flags; |
| @@ -1433,8 +1434,8 @@ static void increase_address_space(struct protection_domain *domain, |
| |
| spin_lock_irqsave(&domain->lock, flags); |
| |
| - if (WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL)) |
| - /* address space already 64 bit large */ |
| + if (address <= PM_LEVEL_SIZE(domain->mode) || |
| + WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL)) |
| goto out; |
| |
| pte = (void *)get_zeroed_page(gfp); |
| @@ -1465,7 +1466,7 @@ static u64 *alloc_pte(struct protection_domain *domain, |
| BUG_ON(!is_power_of_2(page_size)); |
| |
| while (address > PM_LEVEL_SIZE(domain->mode)) |
| - increase_address_space(domain, gfp); |
| + increase_address_space(domain, address, gfp); |
| |
| level = domain->mode - 1; |
| pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; |
| -- |
| 2.7.4 |
| |