Commit 61d70d0d authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Kleber Sacilotto de Souza

iommu/ipmmu-vmsa: Fix allocation in atomic context

BugLink: https://bugs.launchpad.net/bugs/1798539

[ Upstream commit 46583e8c ]

When attaching a device to an IOMMU group with
CONFIG_DEBUG_ATOMIC_SLEEP=y:

    BUG: sleeping function called from invalid context at mm/slab.h:421
    in_atomic(): 1, irqs_disabled(): 128, pid: 61, name: kworker/1:1
    ...
    Call trace:
     ...
     arm_lpae_alloc_pgtable+0x114/0x184
     arm_64_lpae_alloc_pgtable_s1+0x2c/0x128
     arm_32_lpae_alloc_pgtable_s1+0x40/0x6c
     alloc_io_pgtable_ops+0x60/0x88
     ipmmu_attach_device+0x140/0x334

ipmmu_attach_device() takes a spinlock, while arm_lpae_alloc_pgtable()
allocates memory using GFP_KERNEL.  Originally, the ipmmu-vmsa driver
had its own custom page table allocation implementation using
GFP_ATOMIC, hence the spinlock was fine.

Fix this by replacing the spinlock by a mutex, like the arm-smmu driver
does.

Fixes: f20ed39f ("iommu/ipmmu-vmsa: Use the ARM LPAE page table allocator")
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 483ac946
...@@ -44,7 +44,7 @@ struct ipmmu_vmsa_domain { ...@@ -44,7 +44,7 @@ struct ipmmu_vmsa_domain {
struct io_pgtable_ops *iop; struct io_pgtable_ops *iop;
unsigned int context_id; unsigned int context_id;
spinlock_t lock; /* Protects mappings */ struct mutex mutex; /* Protects mappings */
}; };
struct ipmmu_vmsa_archdata { struct ipmmu_vmsa_archdata {
...@@ -464,7 +464,7 @@ static struct iommu_domain *ipmmu_domain_alloc(unsigned type) ...@@ -464,7 +464,7 @@ static struct iommu_domain *ipmmu_domain_alloc(unsigned type)
if (!domain) if (!domain)
return NULL; return NULL;
spin_lock_init(&domain->lock); mutex_init(&domain->mutex);
return &domain->io_domain; return &domain->io_domain;
} }
...@@ -488,7 +488,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, ...@@ -488,7 +488,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
struct ipmmu_vmsa_device *mmu = archdata->mmu; struct ipmmu_vmsa_device *mmu = archdata->mmu;
struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain);
unsigned long flags;
unsigned int i; unsigned int i;
int ret = 0; int ret = 0;
...@@ -497,7 +496,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, ...@@ -497,7 +496,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
return -ENXIO; return -ENXIO;
} }
spin_lock_irqsave(&domain->lock, flags); mutex_lock(&domain->mutex);
if (!domain->mmu) { if (!domain->mmu) {
/* The domain hasn't been used yet, initialize it. */ /* The domain hasn't been used yet, initialize it. */
...@@ -513,7 +512,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, ...@@ -513,7 +512,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
ret = -EINVAL; ret = -EINVAL;
} }
spin_unlock_irqrestore(&domain->lock, flags); mutex_unlock(&domain->mutex);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment