Skip to content

Commit 46ac18c

Browse files
committed
iommu/amd: Check PM_LEVEL_SIZE() condition in locked section
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 <[email protected]> Fixes: 754265b ("iommu/amd: Fix race in increase_address_space()") Reviewed-by: Jerry Snitselaar <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent ec21f17 commit 46ac18c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ static void free_pagetable(struct protection_domain *domain)
14641464
* to 64 bits.
14651465
*/
14661466
static bool increase_address_space(struct protection_domain *domain,
1467+
unsigned long address,
14671468
gfp_t gfp)
14681469
{
14691470
unsigned long flags;
@@ -1472,8 +1473,8 @@ static bool increase_address_space(struct protection_domain *domain,
14721473

14731474
spin_lock_irqsave(&domain->lock, flags);
14741475

1475-
if (WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL))
1476-
/* address space already 64 bit large */
1476+
if (address <= PM_LEVEL_SIZE(domain->mode) ||
1477+
WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL))
14771478
goto out;
14781479

14791480
pte = (void *)get_zeroed_page(gfp);
@@ -1506,7 +1507,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
15061507
BUG_ON(!is_power_of_2(page_size));
15071508

15081509
while (address > PM_LEVEL_SIZE(domain->mode))
1509-
*updated = increase_address_space(domain, gfp) || *updated;
1510+
*updated = increase_address_space(domain, address, gfp) || *updated;
15101511

15111512
level = domain->mode - 1;
15121513
pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)];

0 commit comments

Comments
 (0)