From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com, gleb@redhat.com, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 3/5] qemu-kvm: use upstream sregs save/restore code
Date: Sat, 23 Oct 2010 20:05:27 -0200 [thread overview]
Message-ID: <20101023220718.673533374@amt.cnet> (raw)
In-Reply-To: 20101023220524.049191736@amt.cnet
[-- Attachment #1: qemu-kvm-x86-4 --]
[-- Type: text/plain, Size: 10815 bytes --]
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/qemu-kvm-x86.c
===================================================================
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -709,55 +709,6 @@ static void kvm_reset_mpstate(CPUState *
#endif
}
-static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
-{
- lhs->selector = rhs->selector;
- lhs->base = rhs->base;
- lhs->limit = rhs->limit;
- lhs->type = 3;
- lhs->present = 1;
- lhs->dpl = 3;
- lhs->db = 0;
- lhs->s = 1;
- lhs->l = 0;
- lhs->g = 0;
- lhs->avl = 0;
- lhs->unusable = 0;
-}
-
-static void set_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
-{
- unsigned flags = rhs->flags;
- lhs->selector = rhs->selector;
- lhs->base = rhs->base;
- lhs->limit = rhs->limit;
- lhs->type = (flags >> DESC_TYPE_SHIFT) & 15;
- lhs->present = (flags & DESC_P_MASK) != 0;
- lhs->dpl = rhs->selector & 3;
- lhs->db = (flags >> DESC_B_SHIFT) & 1;
- lhs->s = (flags & DESC_S_MASK) != 0;
- lhs->l = (flags >> DESC_L_SHIFT) & 1;
- lhs->g = (flags & DESC_G_MASK) != 0;
- lhs->avl = (flags & DESC_AVL_MASK) != 0;
- lhs->unusable = 0;
-}
-
-static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs)
-{
- lhs->selector = rhs->selector;
- lhs->base = rhs->base;
- lhs->limit = rhs->limit;
- lhs->flags =
- (rhs->type << DESC_TYPE_SHIFT)
- | (rhs->present * DESC_P_MASK)
- | (rhs->dpl << DESC_DPL_SHIFT)
- | (rhs->db << DESC_B_SHIFT)
- | (rhs->s * DESC_S_MASK)
- | (rhs->l << DESC_L_SHIFT)
- | (rhs->g * DESC_G_MASK)
- | (rhs->avl * DESC_AVL_MASK);
-}
-
#define XSAVE_CWD_RIP 2
#define XSAVE_CWD_RDP 4
#define XSAVE_MXCSR 6
@@ -769,7 +720,6 @@ static void get_seg(SegmentCache *lhs, c
void kvm_arch_load_regs(CPUState *env, int level)
{
struct kvm_regs regs;
- struct kvm_sregs sregs;
struct kvm_msr_entry msrs[100];
int rc, n, i;
@@ -802,55 +752,7 @@ void kvm_arch_load_regs(CPUState *env, i
kvm_put_xsave(env);
kvm_put_xcrs(env);
- memset(sregs.interrupt_bitmap, 0, sizeof(sregs.interrupt_bitmap));
- if (env->interrupt_injected >= 0) {
- sregs.interrupt_bitmap[env->interrupt_injected / 64] |=
- (uint64_t)1 << (env->interrupt_injected % 64);
- }
-
- if ((env->eflags & VM_MASK)) {
- set_v8086_seg(&sregs.cs, &env->segs[R_CS]);
- set_v8086_seg(&sregs.ds, &env->segs[R_DS]);
- set_v8086_seg(&sregs.es, &env->segs[R_ES]);
- set_v8086_seg(&sregs.fs, &env->segs[R_FS]);
- set_v8086_seg(&sregs.gs, &env->segs[R_GS]);
- set_v8086_seg(&sregs.ss, &env->segs[R_SS]);
- } else {
- set_seg(&sregs.cs, &env->segs[R_CS]);
- set_seg(&sregs.ds, &env->segs[R_DS]);
- set_seg(&sregs.es, &env->segs[R_ES]);
- set_seg(&sregs.fs, &env->segs[R_FS]);
- set_seg(&sregs.gs, &env->segs[R_GS]);
- set_seg(&sregs.ss, &env->segs[R_SS]);
-
- if (env->cr[0] & CR0_PE_MASK) {
- /* force ss cpl to cs cpl */
- sregs.ss.selector = (sregs.ss.selector & ~3) |
- (sregs.cs.selector & 3);
- sregs.ss.dpl = sregs.ss.selector & 3;
- }
- }
-
- set_seg(&sregs.tr, &env->tr);
- set_seg(&sregs.ldt, &env->ldt);
-
- sregs.idt.limit = env->idt.limit;
- sregs.idt.base = env->idt.base;
- sregs.gdt.limit = env->gdt.limit;
- sregs.gdt.base = env->gdt.base;
-
- sregs.cr0 = env->cr[0];
- sregs.cr2 = env->cr[2];
- sregs.cr3 = env->cr[3];
- sregs.cr4 = env->cr[4];
-
- sregs.cr8 = cpu_get_apic_tpr(env->apic_state);
- sregs.apic_base = cpu_get_apic_base(env->apic_state);
-
- sregs.efer = env->efer;
-
- kvm_set_sregs(env, &sregs);
-
+ kvm_put_sregs(env);
/* msrs */
n = 0;
/* Remember to increase msrs size if you add new registers below */
@@ -923,10 +825,8 @@ void kvm_arch_load_regs(CPUState *env, i
void kvm_arch_save_regs(CPUState *env)
{
struct kvm_regs regs;
- struct kvm_sregs sregs;
struct kvm_msr_entry msrs[100];
- uint32_t hflags;
- uint32_t i, n, rc, bit;
+ uint32_t i, n, rc;
assert(kvm_cpu_is_stopped(env) || env->thread_id == kvm_get_thread_id());
@@ -957,81 +857,7 @@ void kvm_arch_save_regs(CPUState *env)
kvm_get_xsave(env);
kvm_get_xcrs(env);
- kvm_get_sregs(env, &sregs);
-
- /* There can only be one pending IRQ set in the bitmap at a time, so try
- to find it and save its number instead (-1 for none). */
- env->interrupt_injected = -1;
- for (i = 0; i < ARRAY_SIZE(sregs.interrupt_bitmap); i++) {
- if (sregs.interrupt_bitmap[i]) {
- bit = ctz64(sregs.interrupt_bitmap[i]);
- env->interrupt_injected = i * 64 + bit;
- break;
- }
- }
-
- get_seg(&env->segs[R_CS], &sregs.cs);
- get_seg(&env->segs[R_DS], &sregs.ds);
- get_seg(&env->segs[R_ES], &sregs.es);
- get_seg(&env->segs[R_FS], &sregs.fs);
- get_seg(&env->segs[R_GS], &sregs.gs);
- get_seg(&env->segs[R_SS], &sregs.ss);
-
- get_seg(&env->tr, &sregs.tr);
- get_seg(&env->ldt, &sregs.ldt);
-
- env->idt.limit = sregs.idt.limit;
- env->idt.base = sregs.idt.base;
- env->gdt.limit = sregs.gdt.limit;
- env->gdt.base = sregs.gdt.base;
-
- env->cr[0] = sregs.cr0;
- env->cr[2] = sregs.cr2;
- env->cr[3] = sregs.cr3;
- env->cr[4] = sregs.cr4;
-
- cpu_set_apic_base(env->apic_state, sregs.apic_base);
-
- env->efer = sregs.efer;
- //cpu_set_apic_tpr(env, sregs.cr8);
-
-#define HFLAG_COPY_MASK ~( \
- HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \
- HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \
- HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \
- HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK)
-
- hflags = (env->segs[R_CS].flags >> DESC_DPL_SHIFT) & HF_CPL_MASK;
- hflags |= (env->cr[0] & CR0_PE_MASK) << (HF_PE_SHIFT - CR0_PE_SHIFT);
- hflags |= (env->cr[0] << (HF_MP_SHIFT - CR0_MP_SHIFT)) &
- (HF_MP_MASK | HF_EM_MASK | HF_TS_MASK);
- hflags |= (env->eflags & (HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK));
- hflags |= (env->cr[4] & CR4_OSFXSR_MASK) <<
- (HF_OSFXSR_SHIFT - CR4_OSFXSR_SHIFT);
-
- if (env->efer & MSR_EFER_LMA) {
- hflags |= HF_LMA_MASK;
- }
-
- if ((hflags & HF_LMA_MASK) && (env->segs[R_CS].flags & DESC_L_MASK)) {
- hflags |= HF_CS32_MASK | HF_SS32_MASK | HF_CS64_MASK;
- } else {
- hflags |= (env->segs[R_CS].flags & DESC_B_MASK) >>
- (DESC_B_SHIFT - HF_CS32_SHIFT);
- hflags |= (env->segs[R_SS].flags & DESC_B_MASK) >>
- (DESC_B_SHIFT - HF_SS32_SHIFT);
- if (!(env->cr[0] & CR0_PE_MASK) ||
- (env->eflags & VM_MASK) ||
- !(hflags & HF_CS32_MASK)) {
- hflags |= HF_ADDSEG_MASK;
- } else {
- hflags |= ((env->segs[R_DS].base |
- env->segs[R_ES].base |
- env->segs[R_SS].base) != 0) <<
- HF_ADDSEG_SHIFT;
- }
- }
- env->hflags = (env->hflags & HFLAG_COPY_MASK) | hflags;
+ kvm_get_sregs(env);
/* msrs */
n = 0;
Index: qemu-kvm/target-i386/kvm.c
===================================================================
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -578,6 +578,8 @@ int kvm_arch_init(KVMState *s, int smp_c
return kvm_init_identity_map_page(s);
}
+
+#endif
static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
{
@@ -628,6 +630,8 @@ static void get_seg(SegmentCache *lhs, c
| (rhs->avl * DESC_AVL_MASK);
}
+#ifdef OBSOLETE_KVM_IMPL
+
static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set)
{
if (set)
@@ -759,8 +763,6 @@ static int kvm_put_xcrs(CPUState *env)
#endif
}
-#ifdef OBSOLETE_KVM_IMPL
-
static int kvm_put_sregs(CPUState *env)
{
struct kvm_sregs sregs;
@@ -815,8 +817,6 @@ static int kvm_put_sregs(CPUState *env)
return kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs);
}
-#endif
-
static void kvm_msr_entry_set(struct kvm_msr_entry *entry,
uint32_t index, uint64_t value)
{
@@ -972,8 +972,6 @@ static int kvm_get_xcrs(CPUState *env)
#endif
}
-#ifdef OBSOLETE_KVM_IMPL
-
static int kvm_get_sregs(CPUState *env)
{
struct kvm_sregs sregs;
@@ -1063,6 +1061,8 @@ static int kvm_get_sregs(CPUState *env)
return 0;
}
+#ifdef OBSOLETE_KVM_IMPL
+
static int kvm_get_msrs(CPUState *env)
{
struct {
Index: qemu-kvm/qemu-kvm.c
===================================================================
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -472,16 +472,6 @@ int kvm_set_regs(CPUState *env, struct k
return kvm_vcpu_ioctl(env, KVM_SET_REGS, regs);
}
-int kvm_get_sregs(CPUState *env, struct kvm_sregs *sregs)
-{
- return kvm_vcpu_ioctl(env, KVM_GET_SREGS, sregs);
-}
-
-int kvm_set_sregs(CPUState *env, struct kvm_sregs *sregs)
-{
- return kvm_vcpu_ioctl(env, KVM_SET_SREGS, sregs);
-}
-
#ifdef KVM_CAP_MP_STATE
int kvm_get_mpstate(CPUState *env, struct kvm_mp_state *mp_state)
{
Index: qemu-kvm/qemu-kvm.h
===================================================================
--- qemu-kvm.orig/qemu-kvm.h
+++ qemu-kvm/qemu-kvm.h
@@ -207,39 +207,6 @@ int kvm_get_regs(CPUState *env, struct k
*/
int kvm_set_regs(CPUState *env, struct kvm_regs *regs);
-/*!
- * \brief Read VCPU system registers
- *
- * This gets the non-GP registers from the VCPU and outputs them
- * into a kvm_sregs structure
- *
- * \note This function returns a \b copy of the VCPUs registers.\n
- * If you wish to modify the VCPUs non-GP registers, you should call
- * kvm_set_sregs()
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should get dumped
- * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
- * registers values
- * \return 0 on success
- */
-int kvm_get_sregs(CPUState *env, struct kvm_sregs *regs);
-
-/*!
- * \brief Write VCPU system registers
- *
- * This sets the non-GP registers on the VCPU from a kvm_sregs structure
- *
- * \note When this function returns, the regs pointer and the data it points to
- * can be discarded
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should get dumped
- * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
- * registers values
- * \return 0 on success
- */
-int kvm_set_sregs(CPUState *env, struct kvm_sregs *regs);
-
#ifdef KVM_CAP_MP_STATE
/*!
* * \brief Read VCPU MP state
next prev parent reply other threads:[~2010-10-23 22:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-23 22:05 [patch 0/5] use upstream x86 state save/restore code Marcelo Tosatti
2010-10-23 22:05 ` [patch 1/5] qemu-kvm: kill xsave/xcrs helpers Marcelo Tosatti
2010-10-23 22:05 ` [patch 2/5] qemu-kvm: use upstream fpu/xsave/xcrs save/restore code Marcelo Tosatti
2010-10-23 22:05 ` Marcelo Tosatti [this message]
2010-10-23 22:05 ` [patch 4/5] qemu-kvm: use upstream regs " Marcelo Tosatti
2010-10-23 22:05 ` [patch 5/5] qemu-kvm: use upstream msr " Marcelo Tosatti
2010-10-24 13:46 ` [patch 0/5] use upstream x86 state " Avi Kivity
2010-10-24 21:05 ` Marcelo Tosatti
2010-10-25 9:56 ` Avi Kivity
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=20101023220718.673533374@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.