]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0024-KVM-x86-emulator-update-the-emulation-mode-after-CR0.patch
update sources to Ubuntu-5.19.0-14.14
[pve-kernel.git] / patches / kernel / 0024-KVM-x86-emulator-update-the-emulation-mode-after-CR0.patch
CommitLineData
54ebe3cb
TL
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Maxim Levitsky <mlevitsk@redhat.com>
3Date: Tue, 21 Jun 2022 18:08:56 +0300
4Subject: [PATCH] KVM: x86: emulator: update the emulation mode after CR0 write
5
6CR0.PE toggles real/protected mode, thus its update
7should update the emulation mode.
8
9This is likely a benign bug because there is no writeback
10of state, other than the RIP increment, and when toggling
11CR0.PE, the CPU has to execute code from a very low memory address.
12
13Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
14Signed-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
19diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20index 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