Skip to content

Commit 827fffe

Browse files
binbinwu1wenlingz
authored andcommitted
hv: exception: fault type exception should set resume flag in rflags
According to SDM 17.3.1.1, for any fault-class exception except a debug exception generated in response to an instruction breakpoint, the value pushed for RF is 1. This patch set Resume Flag for fault class exceptions. Tracked-On: #2405 Signed-off-by: Binbin Wu <binbin.wu@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 2638518 commit 827fffe

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hypervisor/arch/x86/guest/virq.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#define EXCEPTION_CLASS_CONT 2
1515
#define EXCEPTION_CLASS_PF 3
1616

17+
/* Exception types */
18+
#define EXCEPTION_FAULT 0U
19+
#define EXCEPTION_TRAP 1U
20+
#define EXCEPTION_ABORT 2U
21+
#define EXCEPTION_INTERRUPT 3U
22+
1723
static const uint16_t exception_type[32] = {
1824
[0] = VMX_INT_TYPE_HW_EXP,
1925
[1] = VMX_INT_TYPE_HW_EXP,
@@ -49,6 +55,24 @@ static const uint16_t exception_type[32] = {
4955
[31] = VMX_INT_TYPE_HW_EXP
5056
};
5157

58+
static uint8_t get_exception_type(uint32_t vector)
59+
{
60+
uint8_t type;
61+
62+
/* Treat #DB as trap until decide to support Debug Registers */
63+
if ((vector > 31U) || (vector == IDT_NMI)) {
64+
type = EXCEPTION_INTERRUPT;
65+
} else if ((vector == IDT_DB) || (vector == IDT_BP) || (vector == IDT_OF)) {
66+
type = EXCEPTION_TRAP;
67+
} else if ((vector == IDT_DF) || (vector == IDT_MC)) {
68+
type = EXCEPTION_ABORT;
69+
} else {
70+
type = EXCEPTION_FAULT;
71+
}
72+
73+
return type;
74+
}
75+
5276
static bool is_guest_irq_enabled(struct acrn_vcpu *vcpu)
5377
{
5478
uint64_t guest_rflags, guest_state;
@@ -254,6 +278,14 @@ static void vcpu_inject_exception(struct acrn_vcpu *vcpu, uint32_t vector)
254278

255279
/* retain rip for exception injection */
256280
vcpu_retain_rip(vcpu);
281+
282+
/* SDM 17.3.1.1 For any fault-class exception except a debug exception generated in response to an
283+
* instruction breakpoint, the value pushed for RF is 1.
284+
* #DB is treated as Trap in get_exception_type, so RF will not be set for instruction breakpoint.
285+
*/
286+
if (get_exception_type(vector) == EXCEPTION_FAULT) {
287+
vcpu_set_rflags(vcpu, vcpu_get_rflags(vcpu) | HV_ARCH_VCPU_RFLAGS_RF);
288+
}
257289
}
258290

259291
static int32_t vcpu_inject_hi_exception(struct acrn_vcpu *vcpu)

hypervisor/include/arch/x86/irq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ uint32_t irq_to_vector(uint32_t irq);
107107

108108
/* RFLAGS */
109109
#define HV_ARCH_VCPU_RFLAGS_IF (1UL<<9U)
110+
#define HV_ARCH_VCPU_RFLAGS_RF (1UL<<16U)
110111

111112
/* Interruptability State info */
112113
#define HV_ARCH_VCPU_BLOCKED_BY_MOVSS (1UL<<1U)

0 commit comments

Comments
 (0)