Commit 06add254 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Shrink the usercopy region of the emulation context

Shuffle a few operand structs to the end of struct x86_emulate_ctxt and
update the cache creation to whitelist only the region of the emulation
context that is expected to be copied to/from user memory, e.g. the
instruction operands, registers, and fetch/io/mem caches.
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2f728d66
...@@ -334,9 +334,6 @@ struct x86_emulate_ctxt { ...@@ -334,9 +334,6 @@ struct x86_emulate_ctxt {
u8 intercept; u8 intercept;
u8 op_bytes; u8 op_bytes;
u8 ad_bytes; u8 ad_bytes;
struct operand src;
struct operand src2;
struct operand dst;
union { union {
int (*execute)(struct x86_emulate_ctxt *ctxt); int (*execute)(struct x86_emulate_ctxt *ctxt);
fastop_t fop; fastop_t fop;
...@@ -364,6 +361,11 @@ struct x86_emulate_ctxt { ...@@ -364,6 +361,11 @@ struct x86_emulate_ctxt {
u8 seg_override; u8 seg_override;
u64 d; u64 d;
unsigned long _eip; unsigned long _eip;
/* Here begins the usercopy section. */
struct operand src;
struct operand src2;
struct operand dst;
struct operand memop; struct operand memop;
/* Fields above regs are cleared together. */ /* Fields above regs are cleared together. */
unsigned long _regs[NR_VCPU_REGS]; unsigned long _regs[NR_VCPU_REGS];
......
...@@ -235,13 +235,13 @@ static struct kmem_cache *x86_emulator_cache; ...@@ -235,13 +235,13 @@ static struct kmem_cache *x86_emulator_cache;
static struct kmem_cache *kvm_alloc_emulator_cache(void) static struct kmem_cache *kvm_alloc_emulator_cache(void)
{ {
return kmem_cache_create_usercopy("x86_emulator", unsigned int useroffset = offsetof(struct x86_emulate_ctxt, src);
sizeof(struct x86_emulate_ctxt), unsigned int size = sizeof(struct x86_emulate_ctxt);
return kmem_cache_create_usercopy("x86_emulator", size,
__alignof__(struct x86_emulate_ctxt), __alignof__(struct x86_emulate_ctxt),
SLAB_ACCOUNT, SLAB_ACCOUNT, useroffset,
0, size - useroffset, NULL);
sizeof(struct x86_emulate_ctxt),
NULL);
} }
static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt); static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment