Re: [PATCH v3 2/2] iommu: Remove cpu-local spinlock

From: Joonas Lahtinen
Date: Wed Jun 01 2016 - 08:40:19 EST


On ke, 2016-06-01 at 12:10 +0100, Chris Wilson wrote:
> By avoiding cross-CPU usage of the per-cpu iova cache, we can forgo
> having a spinlock inside the per-cpu struct. The only place where we
> actually may touch another CPU's data is when performing a cache flush
> after running out of memory. Here, we can instead schedule a task to run
> on the other CPU to do the flush before trying again.
>
> Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
> Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
> Cc: Joerg Roedel <joro@xxxxxxxxxx>
> Cc: iommu@xxxxxxxxxxxxxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> ---
> Âdrivers/iommu/iova.c | 29 ++++++-----------------------
> Â1 file changed, 6 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
> index e23001bfcfee..36cdc8eeab1c 100644
> --- a/drivers/iommu/iova.c
> +++ b/drivers/iommu/iova.c
> @@ -390,6 +390,11 @@ free_iova(struct iova_domain *iovad, unsigned long pfn)
> Â}
> ÂEXPORT_SYMBOL_GPL(free_iova);
> Â
> +static void free_this_cached_iovas(void *info)
> +{
> + free_cpu_cached_iovas(smp_processor_id(), info);
> +}
> +
> Â/**
> Â * alloc_iova_fast - allocates an iova from rcache
> Â * @iovad: - iova domain in question
> @@ -413,17 +418,12 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size,
> Âretry:
> Â new_iova = alloc_iova(iovad, size, limit_pfn, true);
> Â if (!new_iova) {
> - unsigned int cpu;
> -
> Â if (flushed_rcache)
> Â return 0;
> Â
> Â /* Try replenishing IOVAs by flushing rcache. */
> Â flushed_rcache = true;
> - preempt_disable();
> - for_each_online_cpu(cpu)
> - free_cpu_cached_iovas(cpu, iovad);
> - preempt_enable();
> + on_each_cpu(free_this_cached_iovas, iovad, true);

This is not on a hot path, so should be worthy change.

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>

Regards, Joonas

> Â goto retry;
> Â }
> Â
Joonas Lahtinen
Open Source Technology Center
Intel Corporation