linux-stable/arch/arm64/kvm
Oliver Upton 0a6f0f8702 KVM: arm64: Limit stage2_apply_range() batch size to largest block
commit 5994bc9e05 upstream.

Presently stage2_apply_range() works on a batch of memory addressed by a
stage 2 root table entry for the VM. Depending on the IPA limit of the
VM and PAGE_SIZE of the host, this could address a massive range of
memory. Some examples:

  4 level, 4K paging -> 512 GB batch size

  3 level, 64K paging -> 4TB batch size

Unsurprisingly, working on such a large range of memory can lead to soft
lockups. When running dirty_log_perf_test:

  ./dirty_log_perf_test -m -2 -s anonymous_thp -b 4G -v 48

  watchdog: BUG: soft lockup - CPU#0 stuck for 45s! [dirty_log_perf_:16703]
  Modules linked in: vfat fat cdc_ether usbnet mii xhci_pci xhci_hcd sha3_generic gq(O)
  CPU: 0 PID: 16703 Comm: dirty_log_perf_ Tainted: G           O       6.0.0-smp-DEV #1
  pstate: 80400009 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
  pc : dcache_clean_inval_poc+0x24/0x38
  lr : clean_dcache_guest_page+0x28/0x4c
  sp : ffff800021763990
  pmr_save: 000000e0
  x29: ffff800021763990 x28: 0000000000000005 x27: 0000000000000de0
  x26: 0000000000000001 x25: 00400830b13bc77f x24: ffffad4f91ead9c0
  x23: 0000000000000000 x22: ffff8000082ad9c8 x21: 0000fffafa7bc000
  x20: ffffad4f9066ce50 x19: 0000000000000003 x18: ffffad4f92402000
  x17: 000000000000011b x16: 000000000000011b x15: 0000000000000124
  x14: ffff07ff8301d280 x13: 0000000000000000 x12: 00000000ffffffff
  x11: 0000000000010001 x10: fffffc0000000000 x9 : ffffad4f9069e580
  x8 : 000000000000000c x7 : 0000000000000000 x6 : 000000000000003f
  x5 : ffff07ffa2076980 x4 : 0000000000000001 x3 : 000000000000003f
  x2 : 0000000000000040 x1 : ffff0830313bd000 x0 : ffff0830313bcc40
  Call trace:
   dcache_clean_inval_poc+0x24/0x38
   stage2_unmap_walker+0x138/0x1ec
   __kvm_pgtable_walk+0x130/0x1d4
   __kvm_pgtable_walk+0x170/0x1d4
   __kvm_pgtable_walk+0x170/0x1d4
   __kvm_pgtable_walk+0x170/0x1d4
   kvm_pgtable_stage2_unmap+0xc4/0xf8
   kvm_arch_flush_shadow_memslot+0xa4/0x10c
   kvm_set_memslot+0xb8/0x454
   __kvm_set_memory_region+0x194/0x244
   kvm_vm_ioctl_set_memory_region+0x58/0x7c
   kvm_vm_ioctl+0x49c/0x560
   __arm64_sys_ioctl+0x9c/0xd4
   invoke_syscall+0x4c/0x124
   el0_svc_common+0xc8/0x194
   do_el0_svc+0x38/0xc0
   el0_svc+0x2c/0xa4
   el0t_64_sync_handler+0x84/0xf0
   el0t_64_sync+0x1a0/0x1a4

Use the largest supported block mapping for the configured page size as
the batch granularity. In so doing the walker is guaranteed to visit a
leaf only once.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221007234151.461779-3-oliver.upton@linux.dev
Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-10 16:18:47 +02:00
..
hyp KVM: arm64: nvhe: Fix build with profile optimization 2023-01-18 11:48:47 +01:00
vgic KVM: arm64: vgic-its: Test for valid IRQ in its_sync_lpi_pending_table() 2024-03-01 13:21:48 +01:00
Kconfig Merge branch kvm-arm64/generic-entry into kvmarm-master/next 2021-08-20 12:23:09 +01:00
Makefile KVM: stats: Add fd-based API to read binary stats data 2021-06-24 11:47:57 -04:00
arch_timer.c KVM: arm64: timer: Add support for SW-based deactivation 2021-06-01 10:46:00 +01:00
arm.c KVM: arm64: vgic: Force vcpu vgic teardown on vcpu destroy 2024-01-05 15:13:35 +01:00
debug.c KVM: arm64: MDCR_EL2 is a 64-bit register 2021-08-20 11:12:17 +01:00
fpsimd.c KVM: arm64: Save/restore SVE state for nVHE 2021-03-18 14:23:12 +00:00
guest.c KVM: arm64: Reject 32bit user PSTATE on asymmetric systems 2022-08-25 11:40:29 +02:00
handle_exit.c KVM: arm64: Stop handle_exit() from handling HVC twice when an SError occurs 2022-02-08 18:34:06 +01:00
hypercalls.c KVM: arm64: Allow SMCCC_ARCH_WORKAROUND_3 to be discovered and migrated 2022-03-11 12:22:35 +01:00
inject_fault.c KVM: arm64: Move AArch32 exceptions over to AArch64 sysregs 2020-11-10 11:22:51 +00:00
irq.h
mmio.c KVM: arm64: Make kvm_skip_instr() and co private to HYP 2020-11-10 08:34:24 +00:00
mmu.c KVM: arm64: Limit stage2_apply_range() batch size to largest block 2024-04-10 16:18:47 +02:00
perf.c KVM: arm64: Fix PMU probe ordering 2021-09-20 12:43:34 +01:00
pmu-emul.c KVM: arm64: PMU: Restore the guest's EL0 event counting after migration 2023-04-20 12:13:52 +02:00
pmu.c KVM: arm64: Disable PMU support in protected mode 2021-03-19 12:02:19 +00:00
psci.c KVM: arm64: Fix buffer overflow in kvm_arm_set_fw_reg() 2023-05-01 08:23:23 +09:00
pvtime.c KVM: arm64: Use kvm_write_guest_lock when init stolen time 2020-12-03 19:02:18 +00:00
reset.c Merge branch kvm-arm64/psci/cpu_on into kvmarm-master/next 2021-08-20 12:23:02 +01:00
sys_regs.c KVM: arm64: PMU: Restore the guest's EL0 event counting after migration 2023-04-20 12:13:52 +02:00
sys_regs.h KVM: arm64: Refactor sys_regs.h,c for nVHE reuse 2021-08-20 11:12:17 +01:00
trace.h KVM: arm64: Move virt/kvm/arm to arch/arm64 2020-05-16 15:03:59 +01:00
trace_arm.h KVM: Move arm64's MMU notifier trace events to generic code 2021-04-17 08:30:56 -04:00
trace_handle_exit.h KVM: arm64: Upgrade trace_kvm_arm_set_dreg32() to 64bit 2021-08-20 11:12:18 +01:00
trng.c KVM: arm64: Implement the TRNG hypervisor call 2021-01-25 22:19:31 +00:00
va_layout.c KVM: arm64: Generate final CTR_EL0 value when running in Protected mode 2021-03-25 11:00:33 +00:00
vgic-sys-reg-v3.c KVM: arm64: Drop is_aarch32 trap attribute 2020-11-10 11:22:52 +00:00