|
14 | 14 | #define EXCEPTION_CLASS_CONT 2
|
15 | 15 | #define EXCEPTION_CLASS_PF 3
|
16 | 16 |
|
| 17 | +/* Exception types */ |
| 18 | +#define EXCEPTION_FAULT 0U |
| 19 | +#define EXCEPTION_TRAP 1U |
| 20 | +#define EXCEPTION_ABORT 2U |
| 21 | +#define EXCEPTION_INTERRUPT 3U |
| 22 | + |
17 | 23 | static const uint16_t exception_type[32] = {
|
18 | 24 | [0] = VMX_INT_TYPE_HW_EXP,
|
19 | 25 | [1] = VMX_INT_TYPE_HW_EXP,
|
@@ -49,6 +55,24 @@ static const uint16_t exception_type[32] = {
|
49 | 55 | [31] = VMX_INT_TYPE_HW_EXP
|
50 | 56 | };
|
51 | 57 |
|
| 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 | + |
52 | 76 | static bool is_guest_irq_enabled(struct acrn_vcpu *vcpu)
|
53 | 77 | {
|
54 | 78 | uint64_t guest_rflags, guest_state;
|
@@ -254,6 +278,14 @@ static void vcpu_inject_exception(struct acrn_vcpu *vcpu, uint32_t vector)
|
254 | 278 |
|
255 | 279 | /* retain rip for exception injection */
|
256 | 280 | 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 | + } |
257 | 289 | }
|
258 | 290 |
|
259 | 291 | static int32_t vcpu_inject_hi_exception(struct acrn_vcpu *vcpu)
|
|
0 commit comments