]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0024-KVM-x86-emulator-update-the-emulation-mode-after-CR0.patch
c08181cc4cdc0b8ffe98c9299b57aff2a5d7669e
[pve-kernel.git] / patches / kernel / 0024-KVM-x86-emulator-update-the-emulation-mode-after-CR0.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Maxim Levitsky <mlevitsk@redhat.com>
3 Date: Tue, 21 Jun 2022 18:08:56 +0300
4 Subject: [PATCH] KVM: x86: emulator: update the emulation mode after CR0 write
5
6 CR0.PE toggles real/protected mode, thus its update
7 should update the emulation mode.
8
9 This is likely a benign bug because there is no writeback
10 of state, other than the RIP increment, and when toggling
11 CR0.PE, the CPU has to execute code from a very low memory address.
12
13 Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
14 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
15 ---
16 arch/x86/kvm/emulate.c | 13 ++++++++++++-
17 1 file changed, 12 insertions(+), 1 deletion(-)
18
19 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20 index 03a761397599..76c407167449 100644
21 --- a/arch/x86/kvm/emulate.c
22 +++ b/arch/x86/kvm/emulate.c
23 @@ -3647,11 +3647,22 @@ static int em_movbe(struct x86_emulate_ctxt *ctxt)
24
25 static int em_cr_write(struct x86_emulate_ctxt *ctxt)
26 {
27 - if (ctxt->ops->set_cr(ctxt, ctxt->modrm_reg, ctxt->src.val))
28 + int cr_num = ctxt->modrm_reg;
29 + int r;
30 +
31 + if (ctxt->ops->set_cr(ctxt, cr_num, ctxt->src.val))
32 return emulate_gp(ctxt, 0);
33
34 /* Disable writeback. */
35 ctxt->dst.type = OP_NONE;
36 +
37 + if (cr_num == 0) {
38 + /* CR0 write might have updated CR0.PE */
39 + r = update_emulation_mode(ctxt);
40 + if (r != X86EMUL_CONTINUE)
41 + return r;
42 + }
43 +
44 return X86EMUL_CONTINUE;
45 }
46