qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chenyi Qiang <chenyi.qiang@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Xiaoyao Li <xiaoyao.li@intel.com>
Cc: Chenyi Qiang <chenyi.qiang@intel.com>,
	kvm@vger.kernel.org, qemu-devel@nongnu.org
Subject: [PATCH v2 2/3] i386: kvm: Save&restore triple fault event
Date: Fri, 18 Mar 2022 16:29:33 +0800	[thread overview]
Message-ID: <20220318082934.25030-3-chenyi.qiang@intel.com> (raw)
In-Reply-To: <20220318082934.25030-1-chenyi.qiang@intel.com>

For the direct triple faults, i.e. hardware detected and KVM morphed
to VM-Exit, KVM will never lose them. But for triple faults sythesized
by KVM, e.g. the RSM path, if KVM exits to userspace before the request
is serviced, userspace coud migrate the VM and lose the triple fault.

A new flag KVM_VCPUEVENT_TRIPLE_FAULT is defined to signal that there's
triple fault event waiting to be serviced. Track it and save/restore
during get/set_vcpu_events().

Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
---
 target/i386/cpu.c     |  1 +
 target/i386/cpu.h     |  1 +
 target/i386/kvm/kvm.c | 10 ++++++++++
 3 files changed, 12 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6c7ef1099b..dbfecf46a0 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5918,6 +5918,7 @@ static void x86_cpu_reset(DeviceState *dev)
     env->exception_has_payload = false;
     env->exception_payload = 0;
     env->nmi_injected = false;
+    env->has_triple_fault = false;
 #if !defined(CONFIG_USER_ONLY)
     /* We hard-wire the BSP to the first CPU. */
     apic_designate_bsp(cpu->apic_state, s->cpu_index == 0);
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index e11734ba86..5a2a005ae8 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1659,6 +1659,7 @@ typedef struct CPUArchState {
     uint8_t has_error_code;
     uint8_t exception_has_payload;
     uint64_t exception_payload;
+    bool has_triple_fault;
     uint32_t ins_len;
     uint32_t sipi_vector;
     bool tsc_valid;
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 83d0988302..3159c9cefe 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -4041,6 +4041,10 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level)
         }
     }
 
+    if (env->has_triple_fault) {
+        events.flags |= KVM_VCPUEVENT_TRIPLE_FAULT;
+    }
+
     return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events);
 }
 
@@ -4110,6 +4114,12 @@ static int kvm_get_vcpu_events(X86CPU *cpu)
         }
     }
 
+    if (events.flags & KVM_VCPUEVENT_TRIPLE_FAULT) {
+        env->has_triple_fault = true;
+    } else {
+        env->has_triple_fault = false;
+    }
+
     env->sipi_vector = events.sipi_vector;
 
     return 0;
-- 
2.17.1



  parent reply	other threads:[~2022-03-18  8:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18  8:29 [PATCH v2 0/3] Enable notify VM exit Chenyi Qiang
2022-03-18  8:29 ` [PATCH v2 1/3] linux-headers: Sync the linux headers Chenyi Qiang
2022-03-18  8:29 ` Chenyi Qiang [this message]
2022-03-18  8:29 ` [PATCH v2 3/3] i386: Add notify VM exit support Chenyi Qiang

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=20220318082934.25030-3-chenyi.qiang@intel.com \
    --to=chenyi.qiang@intel.com \
    --cc=ehabkost@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=xiaoyao.li@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).