Re: [kvm-unit-tests PATCH v2 0/4] Better backtraces for leaf functions

Mathias Krause
2025-12-19T13:19:15Z

On 18.12.25 19:26, Sean Christopherson wrote:
> VICTORY IS MINE!!!!!!!

🏆

> [...]
> Writing MSR_KVM_WALL_CLOCK_NEW via the AP's VM-Entry load list passes with.
>
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index 510454a6..2d140ee5 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -6,6 +6,7 @@
>
> #include <asm/debugreg.h>
>
> +#include "kvmclock.h"
> #include "vmx.h"
> #include "msr.h"
> #include "processor.h"
> @@ -1967,7 +1968,7 @@ struct vmx_msr_entry {
> u32 index;
> u32 reserved;
> u64 value;
> -} __attribute__((packed));
> +} __attribute__((packed)) __attribute__((aligned(16)));
>
> #define MSR_MAGIC 0x31415926
> struct vmx_msr_entry *exit_msr_store, *entry_msr_load, *exit_msr_load;
> @@ -9861,6 +9862,8 @@ static void vmx_init_signal_test(void)
> */
> }
>
> +static bool use_kvm_wall_clock;
> +
> #define SIPI_SIGNAL_TEST_DELAY 100000000ULL
>
> static void vmx_sipi_test_guest(void)
> @@ -9869,7 +9872,7 @@ static void vmx_sipi_test_guest(void)
> /* wait AP enter guest with activity=WAIT_SIPI */
> while (vmx_get_test_stage() != 1)
> ;
> - delay(SIPI_SIGNAL_TEST_DELAY);
> + // delay(SIPI_SIGNAL_TEST_DELAY);
>
> /* First SIPI signal */
> apic_icr_write(APIC_DEST_PHYSICAL | APIC_DM_STARTUP | APIC_INT_ASSERT, id_map[1]);
> @@ -9903,6 +9906,12 @@ static void vmx_sipi_test_guest(void)
> }
> }
>
> +static const struct vmx_msr_entry msr_load_wall_clock = {
> + .index = MSR_KVM_WALL_CLOCK_NEW,
> + .reserved = 0,
> + .value = 1,
> +};
> +
> static void sipi_test_ap_thread(void *data)
> {
> struct guest_regs *regs = this_cpu_guest_regs();
> @@ -9937,7 +9946,15 @@ static void sipi_test_ap_thread(void *data)
> /* Set guest activity state to wait-for-SIPI state */
> vmcs_write(GUEST_ACTV_STATE, ACTV_WAIT_SIPI);
>
> - vmx_set_test_stage(1);
> + if (use_kvm_wall_clock) {
> + wrmsr(MSR_KVM_WALL_CLOCK_NEW, 0);
> + vmcs_write(ENT_MSR_LD_CNT, 1);
> + vmcs_write(ENTER_MSR_LD_ADDR, virt_to_phys(&msr_load_wall_clock));
> + } else {
> + vmx_set_test_stage(1);
> + }
> +
> + delay(SIPI_SIGNAL_TEST_DELAY);
>
> /* AP enter guest */
> enter_guest();
> @@ -9980,6 +9997,8 @@ static void vmx_sipi_signal_test(void)
> u64 cpu_ctrl_0 = CPU_SECONDARY;
> u64 cpu_ctrl_1 = 0;
>
> + use_kvm_wall_clock = this_cpu_has_kvm() && this_cpu_has(KVM_FEATURE_CLOCKSOURCE2);
> +
> /* passthrough lapic to L2 */
> disable_intercept_for_x2apic_msrs();
> vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) & ~PIN_EXTINT);
> @@ -9996,6 +10015,13 @@ static void vmx_sipi_signal_test(void)
> /* start AP */
> on_cpu_async(1, sipi_test_ap_thread, NULL);
>
> + if (use_kvm_wall_clock) {
> + while (rdmsr(MSR_KVM_WALL_CLOCK_NEW) != 1)
> + cpu_relax();
> +
> + vmx_set_test_stage(1);
> + }
> +
> /* BSP enter guest */
> enter_guest();
> }
>

What a hack! I like it :D

Happy holidays!

Thanks,
Mathias