提交 6dfb14f2 编写于 作者: J Joerg Roedel 提交者: Caspar Zhang

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: NQian Cai <cai@lca.pw>
Fixes: 754265bcab78 ("iommu/amd: Fix race in increase_address_space()")
Reviewed-by: NJerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: NJoerg Roedel <jroedel@suse.de>
Signed-off-by: NWANG Siyuan <Siyuan.Wang@amd.com>
Acked-by: NCaspar Zhang <caspar@linux.alibaba.com>
上级 dd936ba1
...@@ -1341,6 +1341,7 @@ static void domain_flush_devices(struct protection_domain *domain) ...@@ -1341,6 +1341,7 @@ static void domain_flush_devices(struct protection_domain *domain)
* to 64 bits. * to 64 bits.
*/ */
static void increase_address_space(struct protection_domain *domain, static void increase_address_space(struct protection_domain *domain,
unsigned long address,
gfp_t gfp) gfp_t gfp)
{ {
unsigned long flags; unsigned long flags;
...@@ -1348,8 +1349,8 @@ static void increase_address_space(struct protection_domain *domain, ...@@ -1348,8 +1349,8 @@ static void increase_address_space(struct protection_domain *domain,
spin_lock_irqsave(&domain->lock, flags); spin_lock_irqsave(&domain->lock, flags);
if (WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL)) if (address <= PM_LEVEL_SIZE(domain->mode) ||
/* address space already 64 bit large */ WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL))
goto out; goto out;
pte = (void *)get_zeroed_page(gfp); pte = (void *)get_zeroed_page(gfp);
...@@ -1380,7 +1381,7 @@ static u64 *alloc_pte(struct protection_domain *domain, ...@@ -1380,7 +1381,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
BUG_ON(!is_power_of_2(page_size)); BUG_ON(!is_power_of_2(page_size));
while (address > PM_LEVEL_SIZE(domain->mode)) while (address > PM_LEVEL_SIZE(domain->mode))
increase_address_space(domain, gfp); increase_address_space(domain, address, gfp);
level = domain->mode - 1; level = domain->mode - 1;
pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册