@samitouri / QOSamiQemu / commits / 2ecba1510f

target/i386/mshv: populate xsave area offsets

This function is copied verbatim from kvm_cpu_xsave_init(), for MSHV we need to populate the offsets similarly. Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> Reviewed-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> Reviewed-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com> Link: https://lore.kernel.org/r/20260416121116.527927-8-magnuskulke@linux.microsoft.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Magnus Kulke committed Apr 16, 2026 at 14:11 UTC 2ecba1510f80b33967db5336590c0faae79d90b8
1 file changed +31
target/i386/mshv/mshv-cpu.c
+31
@@ -1731,11 +1731,42 @@ int mshv_arch_post_init_vm(int vm_fd)
1731 return ret;
1732 }
1733
1734 +static void mshv_cpu_xsave_init(void)
1735 +{
1736 + static bool first = true;
1737 + uint32_t eax, ebx, ecx, edx;
1738 + int i;
1739 +
1740 + if (!first) {
1741 + return;
1742 + }
1743 + first = false;
1744 +
1745 + /* x87 and SSE states are in the legacy region of the XSAVE area. */
1746 + x86_ext_save_areas[XSTATE_FP_BIT].offset = 0;
1747 + x86_ext_save_areas[XSTATE_SSE_BIT].offset = 0;
1748 +
1749 + for (i = XSTATE_SSE_BIT + 1; i < XSAVE_STATE_AREA_COUNT; i++) {
1750 + ExtSaveArea *esa = &x86_ext_save_areas[i];
1751 +
1752 + if (!esa->size) {
1753 + continue;
1754 + }
1755 + host_cpuid(0xd, i, &eax, &ebx, &ecx, &edx);
1756 + if (eax != 0) {
1757 + assert(esa->size == eax);
1758 + esa->offset = ebx;
1759 + esa->ecx = ecx;
1760 + }
1761 + }
1762 +}
1763 +
1764 static void mshv_cpu_instance_init(CPUState *cs)
1765 {
1766 X86CPU *cpu = X86_CPU(cs);
1767
1768 host_cpu_instance_init(cpu);
1769 + mshv_cpu_xsave_init();
1770 }
1771
1772 static void mshv_cpu_accel_class_init(ObjectClass *oc, const void *data)