linux-stable/arch/arm64/include/asm
Gavin Shan 944db7b536 arm64: tlb: Fix TLBI RANGE operand
commit e3ba51ab24 upstream.

KVM/arm64 relies on TLBI RANGE feature to flush TLBs when the dirty
pages are collected by VMM and the page table entries become write
protected during live migration. Unfortunately, the operand passed
to the TLBI RANGE instruction isn't correctly sorted out due to the
commit 117940aa6e ("KVM: arm64: Define kvm_tlb_flush_vmid_range()").
It leads to crash on the destination VM after live migration because
TLBs aren't flushed completely and some of the dirty pages are missed.

For example, I have a VM where 8GB memory is assigned, starting from
0x40000000 (1GB). Note that the host has 4KB as the base page size.
In the middile of migration, kvm_tlb_flush_vmid_range() is executed
to flush TLBs. It passes MAX_TLBI_RANGE_PAGES as the argument to
__kvm_tlb_flush_vmid_range() and __flush_s2_tlb_range_op(). SCALE#3
and NUM#31, corresponding to MAX_TLBI_RANGE_PAGES, isn't supported
by __TLBI_RANGE_NUM(). In this specific case, -1 has been returned
from __TLBI_RANGE_NUM() for SCALE#3/2/1/0 and rejected by the loop
in the __flush_tlb_range_op() until the variable @scale underflows
and becomes -9, 0xffff708000040000 is set as the operand. The operand
is wrong since it's sorted out by __TLBI_VADDR_RANGE() according to
invalid @scale and @num.

Fix it by extending __TLBI_RANGE_NUM() to support the combination of
SCALE#3 and NUM#31. With the changes, [-1 31] instead of [-1 30] can
be returned from the macro, meaning the TLBs for 0x200000 pages in the
above example can be flushed in one shoot with SCALE#3 and NUM#31. The
macro TLBI_RANGE_MASK is dropped since no one uses it any more. The
comments are also adjusted accordingly.

Fixes: 117940aa6e ("KVM: arm64: Define kvm_tlb_flush_vmid_range()")
Cc: stable@kernel.org # v6.6+
Reported-by: Yihuang Yu <yihyu@redhat.com>
Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Link: https://lore.kernel.org/r/20240405035852.1532010-2-gshan@redhat.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-17 11:23:24 +02:00
..
stacktrace arm64: stacktrace: factor out kernel unwind state 2023-12-11 11:42:55 +00:00
vdso arm64: vdso: use SYS_CNTVCTSS_EL0 for gettimeofday 2022-09-09 12:27:25 +01:00
xen arm/xen: Introduce xen_setup_dma_ops() 2022-06-06 08:54:33 +02:00
Kbuild arm64: Factor out cpucap definitions 2023-10-16 12:57:45 +01:00
acenv.h
acpi.h cpuidle, ACPI: Evaluate LPI arch_flags for broadcast timer 2023-10-04 16:31:27 +01:00
alternative-macros.h work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
alternative.h Merge branches 'for-next/kpti', 'for-next/missing-proto-warn', 'for-next/iss2-decode', 'for-next/kselftest', 'for-next/misc', 'for-next/feat_mops', 'for-next/module-alloc', 'for-next/sysreg', 'for-next/cpucap', 'for-next/acpi', 'for-next/kdump', 'for-next/acpi-doc', 'for-next/doc' and 'for-next/tpidr2-fix', remote-tracking branch 'arm64/for-next/perf' into for-next/core 2023-06-23 18:32:20 +01:00
apple_m1_pmu.h drivers/perf: Add Apple icestorm/firestorm CPU PMU driver 2022-03-08 13:32:48 +00:00
arch_gicv3.h arm64: Avoid cpus_have_const_cap() for ARM64_WORKAROUND_CAVIUM_23154 2023-10-16 14:17:07 +01:00
arch_timer.h arm64/arch_timer: Provide noinstr sched_clock_read() functions 2023-06-05 21:11:05 +02:00
archrandom.h arm64: Avoid cpus_have_const_cap() for ARM64_HAS_RNG 2023-10-16 14:17:05 +01:00
arm-cci.h
arm_dsu_pmu.h
arm_pmuv3.h arm64/arm: arm_pmuv3: perf: Don't truncate 64-bit registers 2023-11-07 11:00:57 +00:00
asm-bug.h bug: Use normal relative pointers in 'struct bug_entry' 2022-05-19 23:46:10 +02:00
asm-extable.h arm64: extable: cleanup redundant extable type EX_TYPE_FIXUP 2022-06-28 12:11:47 +01:00
asm-offsets.h
asm-prototypes.h kasan: arm64: support specialized outlined tag mismatch checks 2021-05-26 23:31:26 +01:00
asm-uaccess.h arm64/mm: remove now-superfluous ISBs from TTBR writes 2023-06-15 17:47:54 +01:00
asm_pointer_auth.h arm64/sysreg: Add _EL1 into ID_AA64ISAR2_EL1 definition names 2022-07-05 11:45:46 +01:00
assembler.h arm64: fpsimd: Bring cond_yield asm macro in line with new rules 2024-01-12 12:48:27 +00:00
atomic.h locking/atomic: make atomic*_{cmp,}xchg optional 2023-06-05 09:57:14 +02:00
atomic_ll_sc.h arch: Remove cmpxchg_double 2023-06-05 09:36:39 +02:00
atomic_lse.h arch: Remove cmpxchg_double 2023-06-05 09:36:39 +02:00
barrier.h arm64: uaccess: permit __smp_store_release() to use zero register 2023-03-28 21:13:25 +01:00
bitops.h include: move find.h from asm_generic to linux 2022-01-15 08:47:31 -08:00
bitrev.h
boot.h
brk-imm.h arm64: Support Clang UBSAN trap codes for better reporting 2023-02-08 15:26:58 -08:00
bug.h
cache.h arm64: Kill detection of VPIPT i-cache policy 2023-12-05 11:38:03 +00:00
cacheflush.h arm64: Avoid cpus_have_const_cap() for ARM64_HAS_CACHE_DIC 2023-10-16 14:17:04 +01:00
checksum.h
clocksource.h
cmpxchg.h arch: Remove cmpxchg_double 2023-06-05 09:36:39 +02:00
compat.h arm64: avoid prototype warnings for syscalls 2023-05-25 17:44:01 +01:00
compiler.h arm64: move PAC masks to <asm/pointer_auth.h> 2023-04-13 12:27:11 +01:00
cpu.h arm64: setup: Switch over to GENERIC_CPU_DEVICES using arch_register_cpu() 2023-12-06 12:41:49 +09:00
cpu_ops.h arm64: cpuidle: remove generic cpuidle support 2022-06-23 14:19:33 +01:00
cpucaps.h arm64: Avoid cpus_have_const_cap() for ARM64_WORKAROUND_REPEAT_TLBI 2023-10-16 14:17:07 +01:00
cpufeature.h arm64: fix typo in comments 2024-02-09 16:54:13 +00:00
cpuidle.h arm64: cpuidle: remove generic cpuidle support 2022-06-23 14:19:33 +01:00
cputype.h arm64: Subscribe Microsoft Azure Cobalt 100 to ARM Neoverse N2 errata 2024-02-15 11:47:22 +00:00
crash_core.h arm64: kdump: use generic interface to simplify crashkernel reservation 2023-10-04 10:41:58 -07:00
current.h
daifflags.h arm64: entry: always set GIC_PRIO_PSR_I_SET during entry 2021-05-05 18:13:58 +01:00
dcc.h
debug-monitors.h arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step 2023-04-14 13:39:47 +01:00
device.h
dmi.h
efi.h Merge patch series "riscv: Introduce KASLR" 2023-09-08 11:25:13 -07:00
el2_setup.h KVM: arm64: Disable SME traps for (h)VHE at setup 2023-07-26 17:08:29 +00:00
elf.h arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0 2021-08-20 12:33:06 +02:00
esr.h KVM: arm64: Use helpers to classify exception types reported via ESR 2023-11-30 10:45:28 +00:00
exception.h Merge branches 'for-next/kpti', 'for-next/missing-proto-warn', 'for-next/iss2-decode', 'for-next/kselftest', 'for-next/misc', 'for-next/feat_mops', 'for-next/module-alloc', 'for-next/sysreg', 'for-next/cpucap', 'for-next/acpi', 'for-next/kdump', 'for-next/acpi-doc', 'for-next/doc' and 'for-next/tpidr2-fix', remote-tracking branch 'arm64/for-next/perf' into for-next/core 2023-06-23 18:32:20 +01:00
exec.h
extable.h arm64/bpf: Remove 128MB limit for BPF JIT programs 2021-11-08 22:16:26 +01:00
fb.h arch/arm64: Implement <asm/fb.h> with generic helpers 2023-04-20 10:04:27 +02:00
fixmap.h arm64: mm: always map fixmap at page granularity 2023-04-11 18:55:28 +01:00
fpsimd.h arm64/sme: Restore SME registers on exit from suspend 2024-02-20 12:19:15 +00:00
fpsimdmacros.h arm64: Delete the zero_za macro 2023-12-11 13:18:06 +00:00
ftrace.h tracing: arm64: Avoid missing-prototype warnings 2023-07-12 12:06:04 -04:00
futex.h arm64: extable: add a dedicated uaccess handler 2021-10-21 10:45:22 +01:00
gpr-num.h arm64: gpr-num: support W registers 2021-10-21 10:45:22 +01:00
hardirq.h
hugetlb.h mm: hugetlb: add huge page size param to set_huge_pte_at() 2023-09-29 17:20:47 -07:00
hw_breakpoint.h arm64: move cpu_suspend_set_dbg_restorer() prototype to header 2023-05-25 17:44:01 +01:00
hwcap.h arm64: add FEAT_LSE128 HWCAP 2023-10-13 19:12:34 +01:00
hyp_image.h
hyperv-tlfs.h PCI: hv: Add arm64 Hyper-V vPCI support 2022-01-12 08:24:29 -06:00
hypervisor.h
image.h arm64: Fix dangling references to Documentation/arm64 2023-06-21 08:53:31 -06:00
insn-def.h arm64: move AARCH64_BREAK_FAULT into insn-def.h 2022-02-22 21:25:48 +00:00
insn.h arm64: insn: Add encoders for LDRSB/LDRSH/LDRSW 2023-08-18 15:45:34 +02:00
io.h arm64 : mm: add wrapper function ioremap_prot() 2023-08-18 10:12:36 -07:00
irq.h arm64: irq: include <linux/cpumask.h> 2024-01-12 12:44:18 +00:00
irq_work.h arch: consolidate arch_irq_work_raise prototypes 2023-11-23 11:32:29 +01:00
irqflags.h arm64: Avoid cpus_have_const_cap() for ARM64_HAS_GIC_PRIO_MASKING 2023-10-16 14:17:04 +01:00
jump_label.h arm64 fixes for -rc6 2024-02-23 10:26:43 -08:00
kasan.h kasan/arm64: improve comments for KASAN_SHADOW_START/END 2023-12-29 11:58:43 -08:00
kernel-pgtable.h arm64: mm: Take potential load offset into account when KASLR is off 2023-12-12 11:06:27 +00:00
kexec.h arm64: kdump : take off the protection on crashkernel memory region 2023-04-11 19:24:46 +01:00
kfence.h mm,kfence: decouple kfence from page granularity mapping judgement 2023-03-27 16:15:20 +01:00
kgdb.h
kprobes.h kprobes: unify kprobes_exceptions_nofify() prototypes 2023-11-10 19:59:05 +09:00
kvm_arm.h Merge branch kvm-arm64/fgt-rework into kvmarm-master/next 2023-12-18 17:09:32 +00:00
kvm_asm.h KVM/arm64 updates for Linux 6.6 2023-08-31 13:18:53 -04:00
kvm_emulate.h Merge branch kvm-arm64/nv-6.8-prefix into kvmarm-master/next 2023-12-19 10:06:58 +00:00
kvm_host.h KVM/arm64 updates for Linux 6.8 2024-01-08 08:09:53 -05:00
kvm_hyp.h KVM: arm64: Rename helpers for VHE vCPU load/put 2023-10-20 17:52:01 +00:00
kvm_mmu.h KVM: arm64: Remove VPIPT I-cache handling 2023-12-05 11:38:03 +00:00
kvm_mte.h KVM: arm64: Save/restore MTE registers 2021-06-22 14:08:05 +01:00
kvm_nested.h KVM: arm64: nv: Add non-VHE-EL2->EL1 translation helpers 2023-12-19 09:51:11 +00:00
kvm_pgtable.h KVM: arm64: Support up to 5 levels of translation in kvm_pgtable 2023-11-27 15:03:50 +00:00
kvm_pkvm.h KVM: arm64: Convert translation level parameter to s8 2023-11-27 15:03:50 +00:00
kvm_ptrauth.h
kvm_ras.h KVM: arm64: Treat ESR_EL2 as a 64-bit register 2022-04-29 19:26:27 +01:00
kvm_types.h
linkage.h arm64: Extend support for CONFIG_FUNCTION_ALIGNMENT 2023-01-24 11:49:43 +00:00
lse.h arm64: Remove system_uses_lse_atomics() 2023-10-18 10:58:59 +01:00
memory.h Many singleton patches against the MM code. The patch series which 2024-01-09 11:18:47 -08:00
mman.h arm64/mm: enable ARCH_HAS_VM_GET_PAGE_PROT 2022-04-28 23:16:13 -07:00
mmu.h arm64: Avoid cpus_have_const_cap() for ARM64_UNMAP_KERNEL_AT_EL0 2023-10-16 14:17:06 +01:00
mmu_context.h arm64: Avoid cpus_have_const_cap() for ARM64_HAS_CNP 2023-10-16 14:17:04 +01:00
mmzone.h
module.h arm64: Avoid cpus_have_const_cap() for ARM64_WORKAROUND_843419 2023-10-16 14:17:06 +01:00
module.lds.h arm64: module: mandate MODULE_PLTS 2023-06-06 17:39:05 +01:00
mshyperv.h arm64: hyperv: Add Hyper-V hypercall and register access utilities 2021-08-04 16:54:36 +00:00
mte-def.h arm64: mte: Define the number of bytes for storing the tags in a page 2022-02-15 22:53:29 +00:00
mte-kasan.h arm64: mte: rename TCO routines 2023-04-05 19:42:43 -07:00
mte.h arm64/mm: Hoist synchronization out of set_ptes() loop 2023-10-16 18:27:31 +01:00
neon-intrinsics.h
neon.h
numa.h
page-def.h
page.h mm: add vma_alloc_zeroed_movable_folio() 2023-02-02 22:33:18 -08:00
paravirt.h
paravirt_api_clock.h sched/headers: Add initial new headers as identity mappings 2022-02-23 10:58:28 +01:00
patching.h arm64: patching: Add aarch64_insn_write_literal_u64() 2023-01-24 11:49:43 +00:00
pci.h asm-generic: Add new pci.h and use it 2022-07-22 17:34:57 -05:00
percpu.h arch: Remove cmpxchg_double 2023-06-05 09:36:39 +02:00
perf_event.h arm64: perf: Move PMUv3 driver to drivers/perf 2023-03-27 14:01:18 +01:00
pgalloc.h arm64: mm: Fix VM_BUG_ON(mm != &init_mm) for trans_pgd 2021-11-16 10:12:57 +00:00
pgtable-hwdef.h arm64: add encodings of PIRx_ELx registers 2023-06-06 16:52:41 +01:00
pgtable-prot.h arm64/mm: Add lpa2_is_enabled() kvm_lpa2_is_enabled() stubs 2023-11-27 15:03:50 +00:00
pgtable-types.h
pgtable.h arm64: mm: Always make sw-dirty PTEs hw-dirty in pte_modify 2023-12-12 16:25:26 +00:00
pointer_auth.h arm64: move PAC masks to <asm/pointer_auth.h> 2023-04-13 12:27:11 +01:00
preempt.h arm64: Support PREEMPT_DYNAMIC 2022-02-19 11:11:09 +01:00
probes.h
proc-fns.h
processor.h arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD 2023-12-12 14:31:55 +00:00
ptdump.h ARM: 9255/1: efi/dump UEFI runtime page tables for ARM 2022-11-07 14:19:01 +00:00
ptrace.h arm64: rename ARM64_HAS_IRQ_PRIO_MASKING to ARM64_HAS_GIC_PRIO_MASKING 2023-01-31 16:06:17 +00:00
pvclock-abi.h
rwonce.h arm64: Do not include __READ_ONCE() block in assembly files 2022-03-09 21:56:50 +00:00
scs.h arm64: add scs_patch_vmlinux prototype 2023-05-25 17:44:01 +01:00
sdei.h arm64: sdei: abort running SDEI handlers during crash 2023-08-04 17:35:33 +01:00
seccomp.h
sections.h arm64: entry: Allow the trampoline text to occupy multiple pages 2022-02-15 17:40:28 +00:00
semihost.h serial: earlycon-arm-semihost: Move smh_putc() variants in respective arch's semihost.h 2023-01-19 14:58:19 +01:00
set_memory.h set_memory: allow querying whether set_direct_map_*() is actually enabled 2021-07-08 11:48:20 -07:00
setup.h arm64: mm: Fix "rodata=on" when CONFIG_RODATA_FULL_DEFAULT_ENABLED=y 2023-11-22 18:46:05 +00:00
shmparam.h
signal.h
signal32.h
simd.h arm64: fpsimd: Drop unneeded 'busy' flag 2023-12-12 14:29:16 +00:00
smp.h arm64: smp: Remove dedicated wakeup IPI 2023-09-25 17:15:28 +01:00
smp_plat.h arm64: Add missing header <asm/smp.h> in two files 2021-07-12 13:37:34 +01:00
sparsemem.h mm, treewide: rename MAX_ORDER to MAX_PAGE_ORDER 2024-01-08 15:27:15 -08:00
spectre.h arm64: Fix circular header dependency 2023-12-20 19:26:30 -05:00
spinlock.h
spinlock_types.h locking: Allow to include asm/spinlock_types.h from linux/spinlock_types_raw.h 2021-12-07 15:14:12 +01:00
stack_pointer.h
stackprotector.h stackprotector: actually use get_random_canary() 2022-11-18 02:18:10 +01:00
stacktrace.h arm64: efi: Account for the EFI runtime stack in stack unwinder 2023-01-16 15:27:31 +01:00
stage2_pgtable.h KVM: arm64: Move VTCR_EL2 into struct s2_mmu 2023-10-23 18:48:46 +00:00
stat.h
string.h Revert "arm64: Mitigate MTE issues with str{n}cmp()" 2022-03-07 21:57:02 +00:00
suspend.h
sync_bitops.h
syscall.h tracing: arm64: Avoid missing-prototype warnings 2023-07-12 12:06:04 -04:00
syscall_wrapper.h posix-timers: Get rid of [COMPAT_]SYS_NI() uses 2023-12-20 21:30:27 -08:00
sysreg.h Merge branch 'for-next/sysregs' into for-next/core 2024-01-04 12:28:38 +00:00
system_misc.h arm64: die(): pass 'err' as long 2022-09-16 12:17:03 +01:00
thread_info.h arm64: fpsimd: Preserve/restore kernel mode NEON at context switch 2023-12-12 14:31:54 +00:00
timex.h
tlb.h arm64/mm: Update tlb invalidation routines for FEAT_LPA2 2023-11-27 15:03:50 +00:00
tlbbatch.h arm64: support batched/deferred tlb shootdown during page reclamation/migration 2023-08-18 10:12:37 -07:00
tlbflush.h arm64: tlb: Fix TLBI RANGE operand 2024-04-17 11:23:24 +02:00
topology.h sched/topology: Add a new arch_scale_freq_ref() method 2023-12-23 15:52:34 +01:00
trans_pgd.h arm64: trans_pgd: remove trans_pgd_map_page() 2021-10-01 13:31:01 +01:00
traps.h KVM: arm64: Add handler for MOPS exceptions 2023-10-09 19:54:25 +00:00
uaccess.h arm64/mm: remove now-superfluous ISBs from TTBR writes 2023-06-15 17:47:54 +01:00
unistd.h lsm/stable-6.8 PR 20240105 2024-01-09 12:57:46 -08:00
unistd32.h lsm/stable-6.8 PR 20240105 2024-01-09 12:57:46 -08:00
uprobes.h arm64/uprobes: change the uprobe_opcode_t typedef to fix the sparse warning 2023-01-05 15:26:09 +00:00
vdso.h arm64: vdso32: Remove unused vdso32-offsets.h 2024-01-30 11:59:17 +00:00
vectors.h arm64: Avoid cpus_have_const_cap() for ARM64_UNMAP_KERNEL_AT_EL0 2023-10-16 14:17:06 +01:00
vermagic.h
virt.h KVM: arm64: Handle kvm_arm_init failure correctly in finalize_pkvm 2023-07-11 19:30:14 +00:00
vmalloc.h kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged 2022-03-24 19:06:47 -07:00
vmap_stack.h kasan, arm64: reset pointer tags of vmapped stacks 2022-03-24 19:06:47 -07:00
vncr_mapping.h KVM: arm64: nv: Add include containing the VNCR_EL2 offsets 2023-12-19 09:51:18 +00:00
word-at-a-time.h arm64: mte: rename TCO routines 2023-04-05 19:42:43 -07:00
xor.h lib/xor: make xor prototypes more friendly to compiler vectorization 2022-02-11 20:39:39 +11:00