Skip to content

Commit 7b0dd94

Browse files
Binbin Wusean-jc
authored andcommitted
KVM: x86: Consolidate flags for __linearize()
Consolidate @Write and @fetch of __linearize() into a set of flags so that additional flags can be added without needing more/new boolean parameters, to precisely identify the access type. No functional change intended. Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Chao Gao <chao.gao@intel.com> Acked-by: Kai Huang <kai.huang@intel.com> Tested-by: Xuelian Guo <xuelian.guo@intel.com> Link: https://lore.kernel.org/r/20230913124227.12574-2-binbin.wu@linux.intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e9e60c8 commit 7b0dd94

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

arch/x86/kvm/emulate.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ static unsigned insn_alignment(struct x86_emulate_ctxt *ctxt, unsigned size)
687687
static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
688688
struct segmented_address addr,
689689
unsigned *max_size, unsigned size,
690-
bool write, bool fetch,
691-
enum x86emul_mode mode, ulong *linear)
690+
enum x86emul_mode mode, ulong *linear,
691+
unsigned int flags)
692692
{
693693
struct desc_struct desc;
694694
bool usable;
@@ -717,11 +717,11 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
717717
if (!usable)
718718
goto bad;
719719
/* code segment in protected mode or read-only data segment */
720-
if ((((ctxt->mode != X86EMUL_MODE_REAL) && (desc.type & 8))
721-
|| !(desc.type & 2)) && write)
720+
if ((((ctxt->mode != X86EMUL_MODE_REAL) && (desc.type & 8)) || !(desc.type & 2)) &&
721+
(flags & X86EMUL_F_WRITE))
722722
goto bad;
723723
/* unreadable code segment */
724-
if (!fetch && (desc.type & 8) && !(desc.type & 2))
724+
if (!(flags & X86EMUL_F_FETCH) && (desc.type & 8) && !(desc.type & 2))
725725
goto bad;
726726
lim = desc_limit_scaled(&desc);
727727
if (!(desc.type & 8) && (desc.type & 4)) {
@@ -757,8 +757,8 @@ static int linearize(struct x86_emulate_ctxt *ctxt,
757757
ulong *linear)
758758
{
759759
unsigned max_size;
760-
return __linearize(ctxt, addr, &max_size, size, write, false,
761-
ctxt->mode, linear);
760+
return __linearize(ctxt, addr, &max_size, size, ctxt->mode, linear,
761+
write ? X86EMUL_F_WRITE : 0);
762762
}
763763

764764
static inline int assign_eip(struct x86_emulate_ctxt *ctxt, ulong dst)
@@ -771,7 +771,8 @@ static inline int assign_eip(struct x86_emulate_ctxt *ctxt, ulong dst)
771771

772772
if (ctxt->op_bytes != sizeof(unsigned long))
773773
addr.ea = dst & ((1UL << (ctxt->op_bytes << 3)) - 1);
774-
rc = __linearize(ctxt, addr, &max_size, 1, false, true, ctxt->mode, &linear);
774+
rc = __linearize(ctxt, addr, &max_size, 1, ctxt->mode, &linear,
775+
X86EMUL_F_FETCH);
775776
if (rc == X86EMUL_CONTINUE)
776777
ctxt->_eip = addr.ea;
777778
return rc;
@@ -907,8 +908,8 @@ static int __do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt, int op_size)
907908
* boundary check itself. Instead, we use max_size to check
908909
* against op_size.
909910
*/
910-
rc = __linearize(ctxt, addr, &max_size, 0, false, true, ctxt->mode,
911-
&linear);
911+
rc = __linearize(ctxt, addr, &max_size, 0, ctxt->mode, &linear,
912+
X86EMUL_F_FETCH);
912913
if (unlikely(rc != X86EMUL_CONTINUE))
913914
return rc;
914915

arch/x86/kvm/kvm_emulate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ struct x86_instruction_info {
8888
#define X86EMUL_IO_NEEDED 5 /* IO is needed to complete emulation */
8989
#define X86EMUL_INTERCEPTED 6 /* Intercepted by nested VMCB/VMCS */
9090

91+
/* x86-specific emulation flags */
92+
#define X86EMUL_F_WRITE BIT(0)
93+
#define X86EMUL_F_FETCH BIT(1)
94+
9195
struct x86_emulate_ops {
9296
void (*vm_bugged)(struct x86_emulate_ctxt *ctxt);
9397
/*

0 commit comments

Comments
 (0)