qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] i386/cpu: Support APX for KVM
@ 2025-12-11  7:09 Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 1/9] i386/cpu: Add APX EGPRs into xsave area Zhao Liu
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

Hi,

This series adds APX (Advanced Performance Extensions) support in QEMU
to enable APX in Guest based on KVM (RFC v1 [1]).

This series is based on CET v5:

https://lore.kernel.org/qemu-devel/20251211060801.3600039-1-zhao1.liu@intel.com/

And you can also find the code here:

https://gitlab.com/zhao.liu/qemu/-/commits/i386-all-for-dmr-v2.1-12-10-2025

Compared with v1 [2], v2 adds:
 * HMP support ("print" & "info registers").
 * gdbstub support.

Thanks for your review!


Overview
========

Intel Advanced Performance Extensions (Intel APX) expands the Intel 64
instruction set architecture with access to more registers (16
additional general-purpose registers (GPRs) R16–R31) and adds various
new features that improve general-purpose performance. The extensions
are designed to provide efficient performance gains across a variety of
workloads without significantly increasing silicon area or power
consumption of the core.

APX spec link (rev.07) is:
https://cdrdv2.intel.com/v1/dl/getContent/861610

At QEMU side, the enabling work mainly includes three parts:

1. save/restore/migrate the xstate of APX.
   * APX xstate is a user xstate, but it reuses MPX xstate area in
     un-compacted XSAVE buffer.
   * To address this, QEMU will reject both APX and MPX if their CPUID
     feature bits are set at the same (in Patch 1).

2. add related CPUIDs support in feature words.

3. debug support, including HMP & gdbstub.


Change Log
==========

Changes sicne v1:
 * Expend current GPR array (CPUX86State.regs) to 32 elements instead of
   a new array.
 * HMP support ("print" & "info registers").
 * gdbstub support.

[1]: KVM RFC: https://lore.kernel.org/kvm/20251110180131.28264-1-chang.seok.bae@intel.com/
[2]: QEMU APX v1: https://lore.kernel.org/qemu-devel/20251118065817.835017-1-zhao1.liu@intel.com/

Thanks and Best Regards,
Zhao
---
Zhao Liu (6):
  i386/machine: Use VMSTATE_UINTTL_SUB_ARRAY for vmstate of
    CPUX86State.regs
  i386/gdbstub: Add APX support for gdbstub
  i386/cpu-dump: Dump entended GPRs for APX supported guest
  i386/monitor: Support EGPRs in hmp_print
  i386/cpu: Support APX CPUIDs
  i386/cpu: Mark APX xstate as migratable

Zide Chen (3):
  i386/cpu: Add APX EGPRs into xsave area
  i386/cpu: Cache EGPRs in CPUX86State
  i386/cpu: Add APX migration support

 configs/targets/x86_64-softmmu.mak |  2 +-
 gdb-xml/i386-64bit-apx.xml         | 26 +++++++++++
 include/migration/cpu.h            |  4 ++
 target/i386/cpu-dump.c             | 30 +++++++++++--
 target/i386/cpu.c                  | 68 ++++++++++++++++++++++++++++-
 target/i386/cpu.h                  | 48 +++++++++++++++++++--
 target/i386/gdbstub.c              | 69 +++++++++++++++++++++++++++++-
 target/i386/machine.c              | 27 +++++++++++-
 target/i386/monitor.c              | 16 +++++++
 target/i386/xsave_helper.c         | 16 +++++++
 10 files changed, 293 insertions(+), 13 deletions(-)
 create mode 100644 gdb-xml/i386-64bit-apx.xml

-- 
2.34.1



^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/9] i386/cpu: Add APX EGPRs into xsave area
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 2/9] i386/machine: Use VMSTATE_UINTTL_SUB_ARRAY for vmstate of CPUX86State.regs Zhao Liu
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

From: Zide Chen <zide.chen@intel.com>

APX feature bit is in CPUID_7_1_EDX[21], and APX has EGPR component with
index 19 in xstate area, EGPR component has 16 64bit regs. Add EGRP
component into xstate area.

Note, APX re-uses the 128-byte XSAVE area that had been previously
allocated by MPX which has been deprecated on Intel processors, so check
whether APX and MPX are set at the same for Guest, if this case happens,
mask off them both to avoid conflict for xsave area.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.com>
Co-developed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 target/i386/cpu.c | 25 +++++++++++++++++++++++++
 target/i386/cpu.h | 17 +++++++++++++++--
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 84adfaf99dc8..16bc4b18266c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2111,6 +2111,12 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT] = {
             { FEAT_7_0_EDX,         CPUID_7_0_EDX_AMX_TILE },
         },
     },
+    [XSTATE_APX_BIT] = {
+        .size = sizeof(XSaveAPX),
+        .features = {
+            { FEAT_7_1_EDX,         CPUID_7_1_EDX_APX },
+        },
+    },
 };
 
 uint32_t xsave_area_size(uint64_t mask, bool compacted)
@@ -9116,6 +9122,25 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         env->features[FEAT_KVM] = 0;
     }
 
+    /*
+     * Since Intel MPX had been previously deprecated, APX re-purposes the
+     * 128-byte XSAVE area that had been previously allocated by MPX (state
+     * component indices 3 and 4, making up a 128-byte area located at an
+     * offset of 960 bytes into an un-compacted XSAVE buffer), as a single
+     * state component housing 128-bytes of storage for EGPRs (8-bytes * 16
+     * registers).
+     *
+     * Check the conflict between MPX and APX before initializing xsave
+     * components.
+     */
+    if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_MPX) &&
+        (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APX)) {
+        mark_unavailable_features(cpu, FEAT_7_0_EBX, CPUID_7_0_EBX_MPX,
+            "this feature is conflict with APX");
+        mark_unavailable_features(cpu, FEAT_7_1_EDX, CPUID_7_1_EDX_APX,
+            "this feature is conflict with MPX");
+    }
+
     x86_cpu_enable_xsave_components(cpu);
 
     /* CPUID[EAX=7,ECX=0].EBX always increased level automatically: */
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 33350602edd3..932982bd5dd6 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -604,6 +604,7 @@ typedef enum X86Seg {
 #define XSTATE_ARCH_LBR_BIT             15
 #define XSTATE_XTILE_CFG_BIT            17
 #define XSTATE_XTILE_DATA_BIT           18
+#define XSTATE_APX_BIT                  19
 
 #define XSTATE_FP_MASK                  (1ULL << XSTATE_FP_BIT)
 #define XSTATE_SSE_MASK                 (1ULL << XSTATE_SSE_BIT)
@@ -620,6 +621,7 @@ typedef enum X86Seg {
 #define XSTATE_ARCH_LBR_MASK            (1ULL << XSTATE_ARCH_LBR_BIT)
 #define XSTATE_XTILE_CFG_MASK           (1ULL << XSTATE_XTILE_CFG_BIT)
 #define XSTATE_XTILE_DATA_MASK          (1ULL << XSTATE_XTILE_DATA_BIT)
+#define XSTATE_APX_MASK                 (1ULL << XSTATE_APX_BIT)
 
 #define XSTATE_DYNAMIC_MASK             (XSTATE_XTILE_DATA_MASK)
 
@@ -636,7 +638,8 @@ typedef enum X86Seg {
                                  XSTATE_BNDCSR_MASK | XSTATE_OPMASK_MASK | \
                                  XSTATE_ZMM_Hi256_MASK | \
                                  XSTATE_Hi16_ZMM_MASK | XSTATE_PKRU_MASK | \
-                                 XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA_MASK)
+                                 XSTATE_XTILE_CFG_MASK | \
+                                 XSTATE_XTILE_DATA_MASK | XSTATE_APX_MASK)
 
 /* CPUID feature bits available in XSS */
 #define CPUID_XSTATE_XSS_MASK   (XSTATE_ARCH_LBR_MASK | XSTATE_CET_U_MASK | \
@@ -1039,6 +1042,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);
 #define CPUID_7_1_EDX_PREFETCHITI       (1U << 14)
 /* Support for Advanced Vector Extensions 10 */
 #define CPUID_7_1_EDX_AVX10             (1U << 19)
+/* Support for Advanced Performance Extensions  */
+#define CPUID_7_1_EDX_APX               (1U << 21)
 
 /* Indicate bit 7 of the IA32_SPEC_CTRL MSR is supported */
 #define CPUID_7_2_EDX_PSFD              (1U << 0)
@@ -1681,6 +1686,8 @@ typedef struct {
 
 #define ARCH_LBR_NR_ENTRIES 32
 
+#define EGPR_NUM  16
+
 /* CPU can't have 0xFFFFFFFF APIC ID, use that value to distinguish
  * that APIC ID hasn't been set yet
  */
@@ -1791,6 +1798,11 @@ typedef struct XSaveXTILEDATA {
     uint8_t xtiledata[8][1024];
 } XSaveXTILEDATA;
 
+/* Ext. save area 19: APX state */
+typedef struct XSaveAPX {
+    uint64_t egprs[EGPR_NUM];
+} XSaveAPX;
+
 QEMU_BUILD_BUG_ON(sizeof(XSaveAVX) != 0x100);
 QEMU_BUILD_BUG_ON(sizeof(XSaveBNDREG) != 0x40);
 QEMU_BUILD_BUG_ON(sizeof(XSaveBNDCSR) != 0x40);
@@ -1803,6 +1815,7 @@ QEMU_BUILD_BUG_ON(sizeof(XSaveCETS) != 0x18);
 QEMU_BUILD_BUG_ON(sizeof(XSaveArchLBR) != 0x328);
 QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) != 0x40);
 QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) != 0x2000);
+QEMU_BUILD_BUG_ON(sizeof(XSaveAPX) != 0x80);
 
 typedef struct ExtSaveArea {
     uint32_t offset, size;
@@ -1817,7 +1830,7 @@ typedef struct ExtSaveArea {
     const FeatureMask features[2];
 } ExtSaveArea;
 
-#define XSAVE_STATE_AREA_COUNT (XSTATE_XTILE_DATA_BIT + 1)
+#define XSAVE_STATE_AREA_COUNT (XSTATE_APX_BIT + 1)
 
 extern ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT];
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/9] i386/machine: Use VMSTATE_UINTTL_SUB_ARRAY for vmstate of CPUX86State.regs
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 1/9] i386/cpu: Add APX EGPRs into xsave area Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 3/9] i386/cpu: Cache EGPRs in CPUX86State Zhao Liu
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

Before expanding the number of elements in the CPUX86State.regs array,
first use VMSTATE_UINTTL_SUB_ARRAY for the regs' vmstate to avoid the
type_check_array failure.

VMSTATE_UINTTL_SUB_ARRAY will also be used for subsequently added elements
in regs array.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changes since v1:
 * New patch.
---
 include/migration/cpu.h | 4 ++++
 target/i386/machine.c   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/migration/cpu.h b/include/migration/cpu.h
index ca7cc0479e79..1335abe22301 100644
--- a/include/migration/cpu.h
+++ b/include/migration/cpu.h
@@ -21,6 +21,8 @@
     VMSTATE_UINT64_V(_f, _s, _v)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
+#define VMSTATE_UINTTL_SUB_ARRAY(_f, _s, _start, _num)                \
+    VMSTATE_UINT64_SUB_ARRAY(_f, _s, _start, _num)
 #define VMSTATE_UINTTL_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
     VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v)
 #define VMSTATE_UINTTL_TEST(_f, _s, _t)                               \
@@ -40,6 +42,8 @@
     VMSTATE_UINT32_V(_f, _s, _v)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
+#define VMSTATE_UINTTL_SUB_ARRAY(_f, _s, _start, _num)                \
+    VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)
 #define VMSTATE_UINTTL_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
     VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)
 #define VMSTATE_UINTTL_TEST(_f, _s, _t)                               \
diff --git a/target/i386/machine.c b/target/i386/machine.c
index 57a968c30db3..0882dc3eb09e 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -1748,7 +1748,7 @@ const VMStateDescription vmstate_x86_cpu = {
     .pre_save = cpu_pre_save,
     .post_load = cpu_post_load,
     .fields = (const VMStateField[]) {
-        VMSTATE_UINTTL_ARRAY(env.regs, X86CPU, CPU_NB_REGS),
+        VMSTATE_UINTTL_SUB_ARRAY(env.regs, X86CPU, 0, CPU_NB_REGS),
         VMSTATE_UINTTL(env.eip, X86CPU),
         VMSTATE_UINTTL(env.eflags, X86CPU),
         VMSTATE_UINT32(env.hflags, X86CPU),
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/9] i386/cpu: Cache EGPRs in CPUX86State
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 1/9] i386/cpu: Add APX EGPRs into xsave area Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 2/9] i386/machine: Use VMSTATE_UINTTL_SUB_ARRAY for vmstate of CPUX86State.regs Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 4/9] i386/gdbstub: Add APX support for gdbstub Zhao Liu
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

From: Zide Chen <zide.chen@intel.com>

Expend general registers array "regs" of CPUX86State to cache entended
GPRs.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.com>
Co-developed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changes since v1:
 * Extend "regs" array instead of a new array.
---
 target/i386/cpu.h          |  7 +++++--
 target/i386/xsave_helper.c | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 932982bd5dd6..9bf5d0b41efe 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1664,12 +1664,15 @@ typedef struct {
     uint64_t mask;
 } MTRRVar;
 
+#define CPU_NB_EREGS64 32
 #define CPU_NB_REGS64 16
 #define CPU_NB_REGS32 8
 
 #ifdef TARGET_X86_64
+#define CPU_NB_EREGS CPU_NB_EREGS64
 #define CPU_NB_REGS CPU_NB_REGS64
 #else
+#define CPU_NB_EREGS CPU_NB_REGS32
 #define CPU_NB_REGS CPU_NB_REGS32
 #endif
 
@@ -1901,7 +1904,7 @@ typedef struct CPUCaches {
 
 typedef struct CPUArchState {
     /* standard registers */
-    target_ulong regs[CPU_NB_REGS];
+    target_ulong regs[CPU_NB_EREGS];
     target_ulong eip;
     target_ulong eflags; /* eflags register. During CPU emulation, CC
                         flags and DF are set to zero because they are
@@ -1958,7 +1961,7 @@ typedef struct CPUArchState {
     float_status mmx_status; /* for 3DNow! float ops */
     float_status sse_status;
     uint32_t mxcsr;
-    ZMMReg xmm_regs[CPU_NB_REGS == 8 ? 8 : 32] QEMU_ALIGNED(16);
+    ZMMReg xmm_regs[CPU_NB_EREGS] QEMU_ALIGNED(16);
     ZMMReg xmm_t0 QEMU_ALIGNED(16);
     MMXReg mmx_t0;
 
diff --git a/target/i386/xsave_helper.c b/target/i386/xsave_helper.c
index 996e9f3bfef5..bab22587320d 100644
--- a/target/i386/xsave_helper.c
+++ b/target/i386/xsave_helper.c
@@ -140,6 +140,14 @@ void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen)
 
         memcpy(tiledata, &env->xtiledata, sizeof(env->xtiledata));
     }
+
+    e = &x86_ext_save_areas[XSTATE_APX_BIT];
+    if (e->size && e->offset && buflen) {
+        XSaveAPX *apx = buf + e->offset;
+
+        memcpy(apx, &env->regs[CPU_NB_REGS],
+               sizeof(env->regs[CPU_NB_REGS]) * (CPU_NB_EREGS - CPU_NB_REGS));
+    }
 #endif
 }
 
@@ -275,5 +283,13 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void *buf, uint32_t buflen)
 
         memcpy(&env->xtiledata, tiledata, sizeof(env->xtiledata));
     }
+
+    e = &x86_ext_save_areas[XSTATE_APX_BIT];
+    if (e->size && e->offset) {
+        const XSaveAPX *apx = buf + e->offset;
+
+        memcpy(&env->regs[CPU_NB_REGS], apx,
+               sizeof(env->regs[CPU_NB_REGS]) * (CPU_NB_EREGS - CPU_NB_REGS));
+    }
 #endif
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 4/9] i386/gdbstub: Add APX support for gdbstub
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (2 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 3/9] i386/cpu: Cache EGPRs in CPUX86State Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 5/9] i386/cpu-dump: Dump entended GPRs for APX supported guest Zhao Liu
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

Add i386-64bit-apx.xml from gdb to allow QEMU gdbstub parse APX EGPRs,
and implement the callbacks to allow gdbstub access EGPRs of guest.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changes since v1:
 * New patch.
---
 configs/targets/x86_64-softmmu.mak |  2 +-
 gdb-xml/i386-64bit-apx.xml         | 26 +++++++++++
 target/i386/cpu.h                  | 16 +++++++
 target/i386/gdbstub.c              | 69 +++++++++++++++++++++++++++++-
 4 files changed, 110 insertions(+), 3 deletions(-)
 create mode 100644 gdb-xml/i386-64bit-apx.xml

diff --git a/configs/targets/x86_64-softmmu.mak b/configs/targets/x86_64-softmmu.mak
index 5619b2bc6865..5180560d4d61 100644
--- a/configs/targets/x86_64-softmmu.mak
+++ b/configs/targets/x86_64-softmmu.mak
@@ -2,5 +2,5 @@ TARGET_ARCH=x86_64
 TARGET_BASE_ARCH=i386
 TARGET_KVM_HAVE_GUEST_DEBUG=y
 TARGET_KVM_HAVE_RESET_PARKED_VCPU=y
-TARGET_XML_FILES= gdb-xml/i386-64bit.xml
+TARGET_XML_FILES= gdb-xml/i386-64bit.xml gdb-xml/i386-64bit-apx.xml
 TARGET_LONG_BITS=64
diff --git a/gdb-xml/i386-64bit-apx.xml b/gdb-xml/i386-64bit-apx.xml
new file mode 100644
index 000000000000..11a4ec67cae4
--- /dev/null
+++ b/gdb-xml/i386-64bit-apx.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2024 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.i386.apx">
+  <reg name="r16" bitsize="64" type="int64"/>
+  <reg name="r17" bitsize="64" type="int64"/>
+  <reg name="r18" bitsize="64" type="int64"/>
+  <reg name="r19" bitsize="64" type="int64"/>
+  <reg name="r20" bitsize="64" type="int64"/>
+  <reg name="r21" bitsize="64" type="int64"/>
+  <reg name="r22" bitsize="64" type="int64"/>
+  <reg name="r23" bitsize="64" type="int64"/>
+  <reg name="r24" bitsize="64" type="int64"/>
+  <reg name="r25" bitsize="64" type="int64"/>
+  <reg name="r26" bitsize="64" type="int64"/>
+  <reg name="r27" bitsize="64" type="int64"/>
+  <reg name="r28" bitsize="64" type="int64"/>
+  <reg name="r29" bitsize="64" type="int64"/>
+  <reg name="r30" bitsize="64" type="int64"/>
+  <reg name="r31" bitsize="64" type="int64"/>
+</feature>
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 9bf5d0b41efe..edc18e4b3da8 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -61,6 +61,22 @@ enum {
     R_R13 = 13,
     R_R14 = 14,
     R_R15 = 15,
+    R_R16 = 16,
+    R_R17 = 17,
+    R_R18 = 18,
+    R_R19 = 19,
+    R_R20 = 20,
+    R_R21 = 21,
+    R_R22 = 22,
+    R_R23 = 23,
+    R_R24 = 24,
+    R_R25 = 25,
+    R_R26 = 26,
+    R_R27 = 27,
+    R_R28 = 28,
+    R_R29 = 29,
+    R_R30 = 30,
+    R_R31 = 31,
 
     R_AL = 0,
     R_CL = 1,
diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index 04c49e802d7d..91943f5ab941 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -27,9 +27,11 @@
 #endif
 
 #ifdef TARGET_X86_64
-static const int gpr_map[16] = {
+static const int gpr_map[CPU_NB_EREGS] = {
     R_EAX, R_EBX, R_ECX, R_EDX, R_ESI, R_EDI, R_EBP, R_ESP,
-    8, 9, 10, 11, 12, 13, 14, 15
+    R_R8, R_R9, R_R10, R_R11, R_R12, R_R13, R_R14, R_R15,
+    R_R16, R_R17, R_R18, R_R19, R_R20, R_R21, R_R22, R_R23,
+    R_R24, R_R25, R_R26, R_R27, R_R28, R_R29, R_R30, R_R31,
 };
 #else
 #define gpr_map gpr_map32
@@ -444,8 +446,71 @@ static int x86_cpu_gdb_write_linux_register(CPUState *cs, uint8_t *mem_buf,
 
 #endif
 
+#ifdef TARGET_X86_64
+static int i386_cpu_gdb_get_egprs(CPUState *cs, GByteArray *mem_buf, int n)
+{
+    CPUX86State *env = &X86_CPU(cs)->env;
+
+    if (n >= 0 && n < EGPR_NUM) {
+        /* EGPRs can be only directly accessible in 64-bit mode. */
+        if (env->hflags & HF_CS64_MASK) {
+            return gdb_get_reg64(mem_buf, env->regs[gpr_map[n + CPU_NB_REGS]]);
+        } else {
+            return gdb_get_regl(mem_buf, 0);
+        }
+    }
+
+    return 0;
+}
+
+static int i386_cpu_gdb_set_egprs(CPUState *cs, uint8_t *mem_buf, int n)
+{
+    CPUX86State *env = &X86_CPU(cs)->env;
+
+    if (n >= 0 && n < EGPR_NUM) {
+        /*
+         * EGPRs can be only directly accessible in 64-bit mode, and require
+         * XCR0[APX_F] (at least for modification in gdbstub) to be enabled.
+         */
+        if (env->hflags & HF_CS64_MASK && env->xcr0 & XSTATE_APX_MASK) {
+            env->regs[gpr_map[n + CPU_NB_REGS]] = ldtul_p(mem_buf);
+
+            /*
+             * Per SDM Vol 1, "Processor Tracking of XSAVE-Managed State",
+             * XSTATE_BV[i] *may* be either 0 or 1 if the state component is
+             * in its initial configuration.
+             *
+             * However, it is observed on Diamond Rapids (DMR) that
+             * XSTATE_BV[APX_F] is set whenever EGPRs are modified, regardless
+             * of the value written (even if zero).
+             *
+             * Since GDB modifies the software register cache directly,
+             * manually force the bit set to emulate this behavior observed
+             * on hardware.
+             */
+            if (!(env->xstate_bv & XSTATE_APX_MASK)) {
+                env->xstate_bv |= XSTATE_APX_MASK;
+            }
+        }
+        return sizeof(target_ulong);
+    }
+    return 0;
+}
+#endif
+
 void x86_cpu_gdb_init(CPUState *cs)
 {
+#ifdef TARGET_X86_64
+    CPUX86State *env = &X86_CPU(cs)->env;
+
+    if (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APX) {
+        gdb_register_coprocessor(cs, i386_cpu_gdb_get_egprs,
+                                 i386_cpu_gdb_set_egprs,
+                                 gdb_find_static_feature("i386-64bit-apx.xml"),
+                                 0);
+    }
+#endif
+
 #ifdef CONFIG_LINUX_USER
     gdb_register_coprocessor(cs, x86_cpu_gdb_read_linux_register,
                              x86_cpu_gdb_write_linux_register,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 5/9] i386/cpu-dump: Dump entended GPRs for APX supported guest
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (3 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 4/9] i386/gdbstub: Add APX support for gdbstub Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 6/9] i386/monitor: Support EGPRs in hmp_print Zhao Liu
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

Dump EGPRs when guest supports APX.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changes since v1:
 * New patch.
---
 target/i386/cpu-dump.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
index 67bf31e0caaf..b51076f87115 100644
--- a/target/i386/cpu-dump.c
+++ b/target/i386/cpu-dump.c
@@ -354,8 +354,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
         qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" PRIx64 " RDX=%016" PRIx64 "\n"
                      "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " RSP=%016" PRIx64 "\n"
                      "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " R11=%016" PRIx64 "\n"
-                     "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " R15=%016" PRIx64 "\n"
-                     "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%d\n",
+                     "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " R15=%016" PRIx64 "\n",
                      env->regs[R_EAX],
                      env->regs[R_EBX],
                      env->regs[R_ECX],
@@ -371,7 +370,32 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
                      env->regs[12],
                      env->regs[13],
                      env->regs[14],
-                     env->regs[15],
+                     env->regs[15]);
+
+        if (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APX) {
+            qemu_fprintf(f, "R16=%016" PRIx64 " R17=%016" PRIx64 " R18=%016" PRIx64 " R19=%016" PRIx64 "\n"
+                         "R20=%016" PRIx64 " R21=%016" PRIx64 " R22=%016" PRIx64 " R23=%016" PRIx64 "\n"
+                         "R24=%016" PRIx64 " R25=%016" PRIx64 " R26=%016" PRIx64 " R27=%016" PRIx64 "\n"
+                         "R28=%016" PRIx64 " R29=%016" PRIx64 " R30=%016" PRIx64 " R31=%016" PRIx64 "\n",
+                         env->regs[16],
+                         env->regs[17],
+                         env->regs[18],
+                         env->regs[19],
+                         env->regs[20],
+                         env->regs[21],
+                         env->regs[22],
+                         env->regs[23],
+                         env->regs[24],
+                         env->regs[25],
+                         env->regs[26],
+                         env->regs[27],
+                         env->regs[28],
+                         env->regs[29],
+                         env->regs[30],
+                         env->regs[31]);
+        }
+
+        qemu_fprintf(f, "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%d\n",
                      env->eip, eflags,
                      eflags & DF_MASK ? 'D' : '-',
                      eflags & CC_O ? 'O' : '-',
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 6/9] i386/monitor: Support EGPRs in hmp_print
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (4 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 5/9] i386/cpu-dump: Dump entended GPRs for APX supported guest Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 7/9] i386/cpu: Add APX migration support Zhao Liu
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

Add EGPRs in monitor_defs[] to allow HMP to access EGPRs.

For example,

(qemu) print $r16

Since monitor_defs[] is used for read-only case, no need to consider
xstate synchronization issues that might be caused by modifying EGPRs
(like what gdbstub did).

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changes since v1:
 * New patch.
---
 target/i386/monitor.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/target/i386/monitor.c b/target/i386/monitor.c
index d2bb873d4947..99b32cb7b0f3 100644
--- a/target/i386/monitor.c
+++ b/target/i386/monitor.c
@@ -623,6 +623,22 @@ const MonitorDef monitor_defs[] = {
     { "r13", offsetof(CPUX86State, regs[13]) },
     { "r14", offsetof(CPUX86State, regs[14]) },
     { "r15", offsetof(CPUX86State, regs[15]) },
+    { "r16", offsetof(CPUX86State, regs[16]) },
+    { "r17", offsetof(CPUX86State, regs[17]) },
+    { "r18", offsetof(CPUX86State, regs[18]) },
+    { "r19", offsetof(CPUX86State, regs[19]) },
+    { "r20", offsetof(CPUX86State, regs[20]) },
+    { "r21", offsetof(CPUX86State, regs[21]) },
+    { "r22", offsetof(CPUX86State, regs[22]) },
+    { "r23", offsetof(CPUX86State, regs[23]) },
+    { "r24", offsetof(CPUX86State, regs[24]) },
+    { "r25", offsetof(CPUX86State, regs[25]) },
+    { "r26", offsetof(CPUX86State, regs[26]) },
+    { "r27", offsetof(CPUX86State, regs[27]) },
+    { "r28", offsetof(CPUX86State, regs[28]) },
+    { "r29", offsetof(CPUX86State, regs[29]) },
+    { "r30", offsetof(CPUX86State, regs[30]) },
+    { "r31", offsetof(CPUX86State, regs[31]) },
 #endif
     { "eflags", offsetof(CPUX86State, eflags) },
     { "eip", offsetof(CPUX86State, eip) },
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 7/9] i386/cpu: Add APX migration support
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (5 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 6/9] i386/monitor: Support EGPRs in hmp_print Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 8/9] i386/cpu: Support APX CPUIDs Zhao Liu
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

From: Zide Chen <zide.chen@intel.com>

Add a VMStateDescription to migrate APX EGPRs.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.com>
Co-developed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changes since v1:
 * Use CPUX86State.regs instead of a new array.
---
 target/i386/machine.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/target/i386/machine.c b/target/i386/machine.c
index 0882dc3eb09e..df550dec4749 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -1741,6 +1741,28 @@ static const VMStateDescription vmstate_cet = {
     },
 };
 
+#ifdef TARGET_X86_64
+static bool apx_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+
+    return !!(env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APX);
+}
+
+static const VMStateDescription vmstate_apx = {
+    .name = "cpu/apx",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = apx_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINTTL_SUB_ARRAY(env.regs, X86CPU, CPU_NB_REGS,
+                                 CPU_NB_EREGS - CPU_NB_REGS),
+        VMSTATE_END_OF_LIST()
+    }
+};
+#endif
+
 const VMStateDescription vmstate_x86_cpu = {
     .name = "cpu",
     .version_id = 12,
@@ -1892,6 +1914,9 @@ const VMStateDescription vmstate_x86_cpu = {
         &vmstate_triple_fault,
         &vmstate_pl0_ssp,
         &vmstate_cet,
+#ifdef TARGET_X86_64
+        &vmstate_apx,
+#endif
         NULL
     }
 };
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 8/9] i386/cpu: Support APX CPUIDs
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (6 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 7/9] i386/cpu: Add APX migration support Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  7:09 ` [PATCH v2 9/9] i386/cpu: Mark APX xstate as migratable Zhao Liu
  2025-12-11  8:08 ` [PATCH v2 0/9] i386/cpu: Support APX for KVM Paolo Bonzini
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu,
	Peter Fang

APX is enumerated by CPUID.(EAX=0x7, ECX=1).EDX[21]. And this feature
bit also indicates the existence of dedicated CPUID leaf 0x29, called
the Intel APX Advanced Performance Extensions Leaf.

This new CPUID leaf now is populated with enumerations for a select
set of Intel APX sub-features.

CPUID.(EAX=0x29, ECX=0)
 - EAX
   * Maximum Subleaf CPUID.(EAX=0x29, ECX=0).EAX[31:0] = 0
 - EBX
   * Reserved CPUID.(EAX=0x29, ECX=0).EBX[31:1] = 0
   * APX_NCI_NDD_NF CPUID.(EAX=0x29, ECX=0).EBX[0:0] = 1, which
     enumerates the presence of New Conditional Instructions (NCIs),
     explicit New Data Destination (NDD) controls, and explicit Flags
     Suppression (NF) controls for select sets of EVEX-encoded Intel
     APX instructions (present in EVEX map=4, and EVEX map=2 0x0F38).
 - ECX
   * Reserved CPUID.(EAX=0x29, ECX=0).ECX[31:0] = 0
 - EDX
   * Reserved CPUID.(EAX=0x29, ECX=0).EDX[31:0] = 0

Note, APX_NCI_NDD_NF is documented as always enabled for Intel
processors since APX spec (revision v7.0). Now any Intel processor
that enumerates support for APX_F (CPUID.(EAX=0x7, ECX=1).EDX[21])
will also enumerate support for APX_NCI_NDD_NF.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Co-developed-by: Zide Chen <zide.chen@intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.com>
Co-developed-by: Peter Fang <peter.fang@intel.com>
Signed-off-by: Peter Fang <peter.fang@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 target/i386/cpu.c | 40 +++++++++++++++++++++++++++++++++++++++-
 target/i386/cpu.h |  8 ++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 16bc4b18266c..9cc553a86442 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1036,6 +1036,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
 #define TCG_SGX_12_0_EBX_FEATURES 0
 #define TCG_SGX_12_1_EAX_FEATURES 0
 #define TCG_24_0_EBX_FEATURES 0
+#define TCG_29_0_EBX_FEATURES 0
 
 #if defined CONFIG_USER_ONLY
 #define CPUID_8000_0008_EBX_KERNEL_FEATURES (CPUID_8000_0008_EBX_IBPB | \
@@ -1301,7 +1302,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
             "amx-complex", NULL, "avx-vnni-int16", NULL,
             NULL, NULL, "prefetchiti", NULL,
             NULL, NULL, NULL, "avx10",
-            NULL, NULL, NULL, NULL,
+            NULL, "apx", NULL, NULL,
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
         },
@@ -1345,6 +1346,25 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
         },
         .tcg_features = TCG_24_0_EBX_FEATURES,
     },
+    [FEAT_29_0_EBX] = {
+        .type = CPUID_FEATURE_WORD,
+        .feat_names = {
+            "apx-nci-ndd-nf", NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL,
+        },
+        .cpuid = {
+            .eax = 0x29,
+            .needs_ecx = true, .ecx = 0,
+            .reg = R_EBX,
+        },
+        .tcg_features = TCG_29_0_EBX_FEATURES,
+    },
     [FEAT_8000_0007_EDX] = {
         .type = CPUID_FEATURE_WORD,
         .feat_names = {
@@ -1996,6 +2016,10 @@ static FeatureDep feature_dependencies[] = {
         .from = { FEAT_7_1_EDX,             CPUID_7_1_EDX_AVX10 },
         .to = { FEAT_24_0_EBX,              ~0ull },
     },
+    {
+        .from = { FEAT_7_1_EDX,             CPUID_7_1_EDX_APX },
+        .to = { FEAT_29_0_EBX,              ~0ull },
+    },
 };
 
 typedef struct X86RegisterInfo32 {
@@ -8411,6 +8435,15 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         }
         break;
     }
+    case 0x29:
+        *eax = 0;
+        *ebx = 0;
+        *ecx = 0;
+        *edx = 0;
+        if ((env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APX) && count == 0) {
+            *ebx = env->features[FEAT_29_0_EBX];
+        }
+        break;
     case 0x40000000:
         /*
          * CPUID code in kvm_arch_init_vcpu() ignores stuff
@@ -9190,6 +9223,11 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
             x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x24);
         }
 
+        /* Advanced Performance Extensions (APX) requires CPUID[0x29] */
+        if (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_APX) {
+            x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x29);
+        }
+
         /* SVM requires CPUID[0x8000000A] */
         if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index edc18e4b3da8..08216b343afa 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -710,6 +710,7 @@ typedef enum FeatureWord {
     FEAT_7_1_EDX,       /* CPUID[EAX=7,ECX=1].EDX */
     FEAT_7_2_EDX,       /* CPUID[EAX=7,ECX=2].EDX */
     FEAT_24_0_EBX,      /* CPUID[EAX=0x24,ECX=0].EBX */
+    FEAT_29_0_EBX,      /* CPUID[EAX=0x29,ECX=0].EBX */
     FEATURE_WORDS,
 } FeatureWord;
 
@@ -1092,6 +1093,13 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);
                                          CPUID_24_0_EBX_AVX10_256 | \
                                          CPUID_24_0_EBX_AVX10_512)
 
+/*
+ * New Conditional Instructions (NCIs), explicit New Data Destination (NDD)
+ * controls, and explicit Flags Suppression (NF) controls for select sets of
+ * EVEX-encoded Intel APX instructions
+ */
+#define CPUID_29_0_EBX_APX_NCI_NDD_NF         (1U << 0)
+
 /* RAS Features */
 #define CPUID_8000_0007_EBX_OVERFLOW_RECOV    (1U << 0)
 #define CPUID_8000_0007_EBX_SUCCOR      (1U << 1)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 9/9] i386/cpu: Mark APX xstate as migratable
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (7 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 8/9] i386/cpu: Support APX CPUIDs Zhao Liu
@ 2025-12-11  7:09 ` Zhao Liu
  2025-12-11  8:08 ` [PATCH v2 0/9] i386/cpu: Support APX for KVM Paolo Bonzini
  9 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  7:09 UTC (permalink / raw)
  To: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé,
	Peter Xu, Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao, Zhao Liu

APX xstate is user xstate. The related registers are cached in
X86CPUState. And there's a vmsd "vmstate_apx" to migrate these
registers.

Thus, it's safe to mark it as migratable.

Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 target/i386/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 9cc553a86442..f703b1478d71 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1544,7 +1544,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
         .migratable_flags = XSTATE_FP_MASK | XSTATE_SSE_MASK |
             XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | XSTATE_BNDCSR_MASK |
             XSTATE_OPMASK_MASK | XSTATE_ZMM_Hi256_MASK | XSTATE_Hi16_ZMM_MASK |
-            XSTATE_PKRU_MASK | XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA_MASK,
+            XSTATE_PKRU_MASK | XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA_MASK |
+            XSTATE_APX_MASK,
     },
     [FEAT_XSAVE_XCR0_HI] = {
         .type = CPUID_FEATURE_WORD,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/9] i386/cpu: Support APX for KVM
  2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
                   ` (8 preceding siblings ...)
  2025-12-11  7:09 ` [PATCH v2 9/9] i386/cpu: Mark APX xstate as migratable Zhao Liu
@ 2025-12-11  8:08 ` Paolo Bonzini
  2025-12-11  9:16   ` Zhao Liu
  9 siblings, 1 reply; 14+ messages in thread
From: Paolo Bonzini @ 2025-12-11  8:08 UTC (permalink / raw)
  To: Zhao Liu, Alex Bennée, Philippe Mathieu-Daudé, Peter Xu,
	Fabiano Rosas
  Cc: qemu-devel, kvm, Chang S . Bae, Zide Chen, Xudong Hao

On 12/11/25 08:09, Zhao Liu wrote:
> Hi,
> 
> This series adds APX (Advanced Performance Extensions) support in QEMU
> to enable APX in Guest based on KVM (RFC v1 [1]).
> 
> This series is based on CET v5:
> 
> https://lore.kernel.org/qemu-devel/20251211060801.3600039-1-zhao1.liu@intel.com/
> 
> And you can also find the code here:
> 
> https://gitlab.com/zhao.liu/qemu/-/commits/i386-all-for-dmr-v2.1-12-10-2025
> 
> Compared with v1 [2], v2 adds:
>   * HMP support ("print" & "info registers").
>   * gdbstub support.
> 
> Thanks for your review!

Great, thanks!  Just one question, should the CPUID feature be "apx" or 
"apxf" (and therefore CPUID_7_1_EDX_APXF)?  I can fix that myself of course.

Thanks,

Paolo

> 
> Overview
> ========
> 
> Intel Advanced Performance Extensions (Intel APX) expands the Intel 64
> instruction set architecture with access to more registers (16
> additional general-purpose registers (GPRs) R16–R31) and adds various
> new features that improve general-purpose performance. The extensions
> are designed to provide efficient performance gains across a variety of
> workloads without significantly increasing silicon area or power
> consumption of the core.
> 
> APX spec link (rev.07) is:
> https://cdrdv2.intel.com/v1/dl/getContent/861610
> 
> At QEMU side, the enabling work mainly includes three parts:
> 
> 1. save/restore/migrate the xstate of APX.
>     * APX xstate is a user xstate, but it reuses MPX xstate area in
>       un-compacted XSAVE buffer.
>     * To address this, QEMU will reject both APX and MPX if their CPUID
>       feature bits are set at the same (in Patch 1).
> 
> 2. add related CPUIDs support in feature words.
> 
> 3. debug support, including HMP & gdbstub.
> 
> 
> Change Log
> ==========
> 
> Changes sicne v1:
>   * Expend current GPR array (CPUX86State.regs) to 32 elements instead of
>     a new array.
>   * HMP support ("print" & "info registers").
>   * gdbstub support.
> 
> [1]: KVM RFC: https://lore.kernel.org/kvm/20251110180131.28264-1-chang.seok.bae@intel.com/
> [2]: QEMU APX v1: https://lore.kernel.org/qemu-devel/20251118065817.835017-1-zhao1.liu@intel.com/
> 
> Thanks and Best Regards,
> Zhao
> ---
> Zhao Liu (6):
>    i386/machine: Use VMSTATE_UINTTL_SUB_ARRAY for vmstate of
>      CPUX86State.regs
>    i386/gdbstub: Add APX support for gdbstub
>    i386/cpu-dump: Dump entended GPRs for APX supported guest
>    i386/monitor: Support EGPRs in hmp_print
>    i386/cpu: Support APX CPUIDs
>    i386/cpu: Mark APX xstate as migratable
> 
> Zide Chen (3):
>    i386/cpu: Add APX EGPRs into xsave area
>    i386/cpu: Cache EGPRs in CPUX86State
>    i386/cpu: Add APX migration support
> 
>   configs/targets/x86_64-softmmu.mak |  2 +-
>   gdb-xml/i386-64bit-apx.xml         | 26 +++++++++++
>   include/migration/cpu.h            |  4 ++
>   target/i386/cpu-dump.c             | 30 +++++++++++--
>   target/i386/cpu.c                  | 68 ++++++++++++++++++++++++++++-
>   target/i386/cpu.h                  | 48 +++++++++++++++++++--
>   target/i386/gdbstub.c              | 69 +++++++++++++++++++++++++++++-
>   target/i386/machine.c              | 27 +++++++++++-
>   target/i386/monitor.c              | 16 +++++++
>   target/i386/xsave_helper.c         | 16 +++++++
>   10 files changed, 293 insertions(+), 13 deletions(-)
>   create mode 100644 gdb-xml/i386-64bit-apx.xml
> 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/9] i386/cpu: Support APX for KVM
  2025-12-11  8:08 ` [PATCH v2 0/9] i386/cpu: Support APX for KVM Paolo Bonzini
@ 2025-12-11  9:16   ` Zhao Liu
  2025-12-11  9:42     ` Paolo Bonzini
  0 siblings, 1 reply; 14+ messages in thread
From: Zhao Liu @ 2025-12-11  9:16 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Peter Xu,
	Fabiano Rosas, qemu-devel, kvm, Chang S . Bae, Zide Chen,
	Xudong Hao

On Thu, Dec 11, 2025 at 09:08:33AM +0100, Paolo Bonzini wrote:
> Date: Thu, 11 Dec 2025 09:08:33 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: Re: [PATCH v2 0/9] i386/cpu: Support APX for KVM
> 
> On 12/11/25 08:09, Zhao Liu wrote:
> > Hi,
> > 
> > This series adds APX (Advanced Performance Extensions) support in QEMU
> > to enable APX in Guest based on KVM (RFC v1 [1]).
> > 
> > This series is based on CET v5:
> > 
> > https://lore.kernel.org/qemu-devel/20251211060801.3600039-1-zhao1.liu@intel.com/
> > 
> > And you can also find the code here:
> > 
> > https://gitlab.com/zhao.liu/qemu/-/commits/i386-all-for-dmr-v2.1-12-10-2025
> > 
> > Compared with v1 [2], v2 adds:
> >   * HMP support ("print" & "info registers").
> >   * gdbstub support.
> > 
> > Thanks for your review!
> 
> Great, thanks!  Just one question, should the CPUID feature be "apx" or
> "apxf" (and therefore CPUID_7_1_EDX_APXF)?  I can fix that myself of course.

Good point! I didn't realize this.

1) Per APX spec:

(APX adds) CPUID Enumeration for APX_F (APX Foundation).

2) And gcc also use apx_f:

https://codebrowser.dev/gcc/gcc/config/i386/cpuid.h.html#_M/bit_APX_F

3) ...and we already have "avx512f".

So you're right, I should use "apxf" and CPUID_7_1_EDX_APXF.

Since APX CPUID appears in several patches, I can respin a new version
quickly.

Thanks,
Zhao




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/9] i386/cpu: Support APX for KVM
  2025-12-11  9:16   ` Zhao Liu
@ 2025-12-11  9:42     ` Paolo Bonzini
  2025-12-11 11:42       ` Zhao Liu
  0 siblings, 1 reply; 14+ messages in thread
From: Paolo Bonzini @ 2025-12-11  9:42 UTC (permalink / raw)
  To: Zhao Liu
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Peter Xu,
	Fabiano Rosas, qemu-devel, kvm, Chang S . Bae, Zide Chen,
	Xudong Hao

On 12/11/25 10:16, Zhao Liu wrote:
> On Thu, Dec 11, 2025 at 09:08:33AM +0100, Paolo Bonzini wrote:
>> Great, thanks!  Just one question, should the CPUID feature be "apx" or
>> "apxf" (and therefore CPUID_7_1_EDX_APXF)?  I can fix that myself of course.
> 
> Good point! I didn't realize this.
> 
> 1) Per APX spec:
> 
> (APX adds) CPUID Enumeration for APX_F (APX Foundation).
> 
> 2) And gcc also use apx_f:
> 
> https://codebrowser.dev/gcc/gcc/config/i386/cpuid.h.html#_M/bit_APX_F
> 
> 3) ...and we already have "avx512f".
> 
> So you're right, I should use "apxf" and CPUID_7_1_EDX_APXF.
> 
> Since APX CPUID appears in several patches, I can respin a new version
> quickly.

No problem, I have done a quick pass with "sed" on the patches and 
reapplied them.  I do ask you to respin the Diamond Rapids series 
though, on top of the for-upstream tag of 
https://gitlab.com/bonzini/qemu (currently going through CI).

Applied for 11.0!

Paolo



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/9] i386/cpu: Support APX for KVM
  2025-12-11  9:42     ` Paolo Bonzini
@ 2025-12-11 11:42       ` Zhao Liu
  0 siblings, 0 replies; 14+ messages in thread
From: Zhao Liu @ 2025-12-11 11:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alex Bennée, Philippe Mathieu-Daudé, Peter Xu,
	Fabiano Rosas, qemu-devel, kvm, Chang S . Bae, Zide Chen,
	Xudong Hao

> No problem, I have done a quick pass with "sed" on the patches and reapplied
> them.  I do ask you to respin the Diamond Rapids series though, on top of
> the for-upstream tag of https://gitlab.com/bonzini/qemu (currently going
> through CI).
> 
> Applied for 11.0!

Thank you!

BTW, could you please have a look at this clean up on outdated SPR
comments:

https://lore.kernel.org/qemu-devel/20251118080837.837505-1-zhao1.liu@intel.com/

I feel it's better to clear SPR comments before DMR touches AMX.

Thanks,
Zhao



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-12-11 11:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11  7:09 [PATCH v2 0/9] i386/cpu: Support APX for KVM Zhao Liu
2025-12-11  7:09 ` [PATCH v2 1/9] i386/cpu: Add APX EGPRs into xsave area Zhao Liu
2025-12-11  7:09 ` [PATCH v2 2/9] i386/machine: Use VMSTATE_UINTTL_SUB_ARRAY for vmstate of CPUX86State.regs Zhao Liu
2025-12-11  7:09 ` [PATCH v2 3/9] i386/cpu: Cache EGPRs in CPUX86State Zhao Liu
2025-12-11  7:09 ` [PATCH v2 4/9] i386/gdbstub: Add APX support for gdbstub Zhao Liu
2025-12-11  7:09 ` [PATCH v2 5/9] i386/cpu-dump: Dump entended GPRs for APX supported guest Zhao Liu
2025-12-11  7:09 ` [PATCH v2 6/9] i386/monitor: Support EGPRs in hmp_print Zhao Liu
2025-12-11  7:09 ` [PATCH v2 7/9] i386/cpu: Add APX migration support Zhao Liu
2025-12-11  7:09 ` [PATCH v2 8/9] i386/cpu: Support APX CPUIDs Zhao Liu
2025-12-11  7:09 ` [PATCH v2 9/9] i386/cpu: Mark APX xstate as migratable Zhao Liu
2025-12-11  8:08 ` [PATCH v2 0/9] i386/cpu: Support APX for KVM Paolo Bonzini
2025-12-11  9:16   ` Zhao Liu
2025-12-11  9:42     ` Paolo Bonzini
2025-12-11 11:42       ` Zhao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).