linux-stable/arch/arm64
Jean-Philippe Brucker 48118151d8 arm64: mm: Pin down ASIDs for sharing mm with devices
To enable address space sharing with the IOMMU, introduce
arm64_mm_context_get() and arm64_mm_context_put(), that pin down a
context and ensure that it will keep its ASID after a rollover. Export
the symbols to let the modular SMMUv3 driver use them.

Pinning is necessary because a device constantly needs a valid ASID,
unlike tasks that only require one when running. Without pinning, we would
need to notify the IOMMU when we're about to use a new ASID for a task,
and it would get complicated when a new task is assigned a shared ASID.
Consider the following scenario with no ASID pinned:

1. Task t1 is running on CPUx with shared ASID (gen=1, asid=1)
2. Task t2 is scheduled on CPUx, gets ASID (1, 2)
3. Task tn is scheduled on CPUy, a rollover occurs, tn gets ASID (2, 1)
   We would now have to immediately generate a new ASID for t1, notify
   the IOMMU, and finally enable task tn. We are holding the lock during
   all that time, since we can't afford having another CPU trigger a
   rollover. The IOMMU issues invalidation commands that can take tens of
   milliseconds.

It gets needlessly complicated. All we wanted to do was schedule task tn,
that has no business with the IOMMU. By letting the IOMMU pin tasks when
needed, we avoid stalling the slow path, and let the pinning fail when
we're out of shareable ASIDs.

After a rollover, the allocator expects at least one ASID to be available
in addition to the reserved ones (one per CPU). So (NR_ASIDS - NR_CPUS -
1) is the maximum number of ASIDs that can be shared with the IOMMU.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20200918101852.582559-5-jean-philippe@linaro.org
Signed-off-by: Will Deacon <will@kernel.org>
2020-09-28 22:15:38 +01:00
..
boot arm64: dts: k3-am65: Update the RM resource types 2020-08-16 22:01:20 +01:00
configs ARM: SoC driver updates for v5.9 2020-08-03 19:30:59 -07:00
crypto crypto: arm64/gcm - use inline helper to suppress indirect calls 2020-07-09 22:14:32 +10:00
include arm64: mm: Pin down ASIDs for sharing mm with devices 2020-09-28 22:15:38 +01:00
kernel A set of fixes for lockdep, tracing and RCU: 2020-08-30 11:43:50 -07:00
kvm - Fix kernel build with the integrated LLVM assembler which doesn't 2020-08-28 11:37:33 -07:00
lib Merge branch 'rwonce/rework' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux 2020-06-10 14:46:54 -07:00
mm arm64: mm: Pin down ASIDs for sharing mm with devices 2020-09-28 22:15:38 +01:00
net bpf, arm64: Add BPF exception tables 2020-07-31 00:43:40 +02:00
xen arm64: xen: Use modern annotations for assembly functions 2020-01-09 16:09:42 +00:00
Kbuild
Kconfig KVM/arm64 updates for Linux 5.9: 2020-08-09 12:58:23 -04:00
Kconfig.debug arm64: remove TEXT_OFFSET randomization 2020-06-15 13:10:59 +01:00
Kconfig.platforms ARM: new SoC support for v5.9 2020-08-03 19:38:30 -07:00
Makefile arm64: vdso32: make vdso32 install conditional 2020-08-28 13:18:48 +01:00