]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blobdiff - arch/x86/kvm/emulate.c
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[mirror_ubuntu-kernels.git] / arch / x86 / kvm / emulate.c
index 7ba4ec77feeba9fb1c36f6de128c9b638471e702..89b11e7dca8aa5d994122fdf7d1831bda5952df7 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/stringify.h>
 #include <asm/debugreg.h>
 #include <asm/nospec-branch.h>
+#include <asm/ibt.h>
 
 #include "x86.h"
 #include "tss.h"
 #define X16(x...) X8(x), X8(x)
 
 #define NR_FASTOP (ilog2(sizeof(ulong)) + 1)
-#define FASTOP_SIZE 8
+#define FASTOP_SIZE (8 * (1 + HAS_KERNEL_IBT))
 
 struct opcode {
        u64 flags;
@@ -311,7 +312,8 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 #define __FOP_FUNC(name) \
        ".align " __stringify(FASTOP_SIZE) " \n\t" \
        ".type " name ", @function \n\t" \
-       name ":\n\t"
+       name ":\n\t" \
+       ASM_ENDBR
 
 #define FOP_FUNC(name) \
        __FOP_FUNC(#name)
@@ -433,21 +435,23 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 /*
  * Depending on .config the SETcc functions look like:
  *
+ * ENDBR       [4 bytes; CONFIG_X86_KERNEL_IBT]
  * SETcc %al   [3 bytes]
  * RET         [1 byte]
  * INT3        [1 byte; CONFIG_SLS]
  *
- * Which gives possible sizes 4 or 5.  When rounded up to the
- * next power-of-two alignment they become 4 or 8.
+ * Which gives possible sizes 4, 5, 8 or 9.  When rounded up to the
+ * next power-of-two alignment they become 4, 8 or 16 resp.
  */
-#define SETCC_LENGTH   (4 + IS_ENABLED(CONFIG_SLS))
-#define SETCC_ALIGN    (4 << IS_ENABLED(CONFIG_SLS))
+#define SETCC_LENGTH   (ENDBR_INSN_SIZE + 4 + IS_ENABLED(CONFIG_SLS))
+#define SETCC_ALIGN    (4 << IS_ENABLED(CONFIG_SLS) << HAS_KERNEL_IBT)
 static_assert(SETCC_LENGTH <= SETCC_ALIGN);
 
 #define FOP_SETCC(op) \
        ".align " __stringify(SETCC_ALIGN) " \n\t" \
        ".type " #op ", @function \n\t" \
        #op ": \n\t" \
+       ASM_ENDBR \
        #op " %al \n\t" \
        __FOP_RET(#op)
 
@@ -3536,8 +3540,10 @@ static int em_rdpid(struct x86_emulate_ctxt *ctxt)
 {
        u64 tsc_aux = 0;
 
-       if (ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux))
+       if (!ctxt->ops->guest_has_rdpid(ctxt))
                return emulate_ud(ctxt);
+
+       ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux);
        ctxt->dst.val = tsc_aux;
        return X86EMUL_CONTINUE;
 }
@@ -3638,7 +3644,7 @@ static int em_wrmsr(struct x86_emulate_ctxt *ctxt)
 
        msr_data = (u32)reg_read(ctxt, VCPU_REGS_RAX)
                | ((u64)reg_read(ctxt, VCPU_REGS_RDX) << 32);
-       r = ctxt->ops->set_msr(ctxt, msr_index, msr_data);
+       r = ctxt->ops->set_msr_with_filter(ctxt, msr_index, msr_data);
 
        if (r == X86EMUL_IO_NEEDED)
                return r;
@@ -3655,7 +3661,7 @@ static int em_rdmsr(struct x86_emulate_ctxt *ctxt)
        u64 msr_data;
        int r;
 
-       r = ctxt->ops->get_msr(ctxt, msr_index, &msr_data);
+       r = ctxt->ops->get_msr_with_filter(ctxt, msr_index, &msr_data);
 
        if (r == X86EMUL_IO_NEEDED)
                return r;