x86/asyncpf: fix async page fault issues
PATCH v3 1/1 x86/asyncpf: fix async page fault issues
KVM switched to use interrupt for 'page ready' APF event since Linux v5.10 and the legacy mechanism using #PF was deprecated. Interrupt-based 'page-ready' notification requires KVM_ASYNC_PF_DELIVERY_AS_INT to be set as well in MSR_KVM_ASYNC_PF_EN to enable asyncpf.
Update asyncpf.c for the new interrupt-based notification.
It checks (KVM_FEATURE_ASYNC_PF && KVM_FEATURE_ASYNC_PF_INT) and implement interrupt-based 'page-ready' handler.
To run this test, add the QEMU option "-cpu host" to check CPUID, since KVM_FEATURE_ASYNC_PF_INT can't be detected without "-cpu host".
Based on asyncpf.c, update the usage of how to setup cgroup for different cgroup versions, clean up the include headers and add the 'struct kvm_vcpu_pv_apf_data' with token information for page-ready notifications.
---
The test is based on asyncpf.c and simplifies implementation by reducing the memory access round from 2 to 1.
Changes:
v2 -> v3:
modified the commit message.
v1 -> v2:
removed asyncpf_int.c and asyncpf.h and modified asyncpf.c to use ASYNC_PF_INT.
History:
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
--- lib/x86/processor.h | 6 ++ x86/asyncpf.c | 151 +++++++++++++++++++++++++++----------------- x86/unittests.cfg | 2 +- 3 files changed, 101 insertions(+), 58 deletions(-)
lib/x86/processor.h +6 -0
@@ -263,6 +263,12 @@ static inline bool is_intel(void)#define X86_FEATURE_ARCH_CAPABILITIES (CPUID(0x7, 0, EDX, 29))#define X86_FEATURE_PKS (CPUID(0x7, 0, ECX, 31)) +/* +* KVM defined leafs +*/ +#define KVM_FEATURE_ASYNC_PF (CPUID(0x40000001, 0, EAX, 4)) +#define KVM_FEATURE_ASYNC_PF_INT (CPUID(0x40000001, 0, EAX, 14)) +/* * Extended Leafs, a.k.a. AMD defined */
x86/asyncpf.c +94 -57
201 lines not on this page · raw message
x86/unittests.cfg +1 -1
@@ -172,7 +172,7 @@ extra_params = -cpu max [asyncpf] file = asyncpf.flat -extra_params = -m 2048 +extra_params = -cpu host -m 2048 [emulator] file = emulator.flat
Signature · 1 line
2.39.3
Quoted 10 lines · Dan Wu
KVM switched to use interrupt for 'page ready' APF event since Linux v5.10 and the legacy mechanism using #PF was deprecated. Interrupt-based 'page-ready' notification requires
KVM_ASYNC_PF_DELIVERY_AS_INTto be set as well inMSR_KVM_ASYNC_PF_ENto enable asyncpf.Update
asyncpf.cfor the new interrupt-based notification.
It checks (KVM_FEATURE_ASYNC_PF&&KVM_FEATURE_ASYNC_PF_INT) and implement interrupt-based 'page-ready' handler.[...]
Applied to kvm-x86 next, with one tweak. To avoid failures in the common case of running without configuring cgroups, I changed the asyncpf_num check to skip instead of assert:
if (!asyncpf_num)
report_skip("No async page fault events, cgroup configuration likely needed");
else
report_pass("Serviced %d async page faults events (!PRESENT #PF + READY IRQ)",
asyncpf_num);Thanks!
[1/1] x86/asyncpf: fix async page fault issues
https://github.com/kvm-x86/kvm-unit-tests/commit/3ed8e382d4cb
Hi Sean,
x86/asyncpf.c line 53
Quoted 9 lines · Dan Wu
x86/asyncpf.c +9
-0+struct kvm_vcpu_pv_apf_data { +/* Used for 'page not present' events delivered via #PF */ +uint32_t flags; + +/* Used for 'page ready' events delivered via interrupt notification */ +uint32_t token; + +uint8_t pad[56 ]; +uint32_t enabled;
Cloud you please help cleanup the 'enabled' field when applying? since it has been removed.
Quoted 1 line
+}
apf_reason__attribute__((aligned(64)));