From: Zhao Liu <zhao1.liu@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Zide Chen <zide.chen@intel.com>,
Xudong Hao <xudong.hao@intel.com>, Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH v2 3/9] i386/cpu: Cache EGPRs in CPUX86State
Date: Thu, 11 Dec 2025 15:09:36 +0800 [thread overview]
Message-ID: <20251211070942.3612547-4-zhao1.liu@intel.com> (raw)
In-Reply-To: <20251211070942.3612547-1-zhao1.liu@intel.com>
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
next prev parent reply other threads:[~2025-12-11 6:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251211070942.3612547-4-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=alex.bennee@linaro.org \
--cc=chang.seok.bae@intel.com \
--cc=farosas@suse.de \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=xudong.hao@intel.com \
--cc=zide.chen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).