diff options
| author | Xuheng Li <xuheng@cs.columbia.edu> | 2026-11-09 22:13:36 +0000 |
|---|---|---|
| committer | Marc Zyngier <maz@kernel.org> | 2026-11-11 09:37:55 +0000 |
| commit | e1c5c6db6cc5e0314a773a08a2a7e50021596eee (patch) | |
| tree | 3bf09b156f3cf7a2742464f715fe854260809ef8 /scripts/Makefile.thinlto | |
| parent | fe5946524be82b1eeb1da17949684afc56087ff7 (diff) | |
KVM: arm64: Order a later pinner's accesses after the hyp mapping
Since commit 48d848882395 ("KVM: arm64: Defer EL2 stage-1 mapping on
share"), hyp_pin_shared_mem() maps a shared page into the hypervisor's
stage-1 only when its refcount goes from 0 to 1. The CPU that maps it
runs dsb(ishst); isb() in kvm_pgtable_hyp_map(), which orders that CPU's
own accesses. A CPU that pins the page later sees refcount >= 1, maps
nothing and runs no barrier. It then accesses the page through an
address it computed before taking the locks, so nothing orders its
translation after the other CPU's PTE write. The access can use a
translation performed while the entry was still invalid, and fault.
A host can do this with any pinning hypercall by passing the same page
from two CPUs, for example __pkvm_init_vm() with the same struct kvm:
CPU A CPU B
----- -----
host_kvm = kern_hyp_va_host(x1)
(host_kvm may be translated now,
while its entry is invalid)
__pkvm_init_vm(host_kvm)
hyp_pin_shared_mem()
host/hyp locks
refcount 0 -> 1
pkvm_create_mappings_locked()
kvm_pgtable_hyp_map()
write the valid PTE
dsb(ishst); isb() <- CPU A only
unlock
__pkvm_init_vm(host_kvm)
hyp_pin_shared_mem()
host/hyp locks
refcount 1 -> 2: no mapping,
no barrier
unlock
READ_ONCE(host_kvm->created_vcpus)
uses the old translation:
translation fault -> hyp_panic()
A well-behaved host can hit this too. Since commit cf533b4d3630 ("KVM:
arm64: Validate the host vCPU's VM before reading it under pKVM"),
injecting an exception into a host vCPU that isn't loaded pins its
struct kvm to read the VM's MTE flag. On an MTE-capable host, two vCPUs
of one VM that do this at the same time from __kvm_adjust_pc() take the
same path as CPU B above.
The lock hand-off orders CPU B's loads and stores after CPU A's PTE
write, but not its translation table walks. Arm's herd7 model with
-variant vmsa allows the fault for this shape: a mapping made and
completed with DSB; ISB on one CPU, handed over through a
release/acquire, then used on another CPU through an address it already
held. It forbids the fault once the second CPU runs DSB; ISB after the
acquire.
Make every successful pin end with dsb(ish); isb(), so that the pinning
CPU's later accesses through the range are ordered after the mapping,
whichever pin installed it.
Fixes: 48d848882395 ("KVM: arm64: Defer EL2 stage-1 mapping on share")
Cc: stable@vger.kernel.org
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Signed-off-by: Xuheng Li <xuheng@cs.columbia.edu>
Link: https://patch.msgid.link/20261109-pin-barrier-v2-1-64ca73cae5e3@cs.columbia.edu
Signed-off-by: Marc Zyngier <maz@kernel.org>
Diffstat (limited to 'scripts/Makefile.thinlto')
0 files changed, 0 insertions, 0 deletions
