All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 10/13] KVM: x86: Shrink the usercopy region of the emulation context
Date: Fri, 22 Nov 2019 14:39:56 -0800	[thread overview]
Message-ID: <20191122223959.13545-11-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191122223959.13545-1-sean.j.christopherson@intel.com>

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: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/kvm_emulate.h |  8 +++++---
 arch/x86/kvm/x86.c         | 12 ++++++------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h
index 844e833609db..c25133080666 100644
--- a/arch/x86/kvm/kvm_emulate.h
+++ b/arch/x86/kvm/kvm_emulate.h
@@ -318,9 +318,6 @@ struct x86_emulate_ctxt {
 	u8 intercept;
 	u8 op_bytes;
 	u8 ad_bytes;
-	struct operand src;
-	struct operand src2;
-	struct operand dst;
 	int (*execute)(struct x86_emulate_ctxt *ctxt);
 	int (*check_perm)(struct x86_emulate_ctxt *ctxt);
 	/*
@@ -345,6 +342,11 @@ struct x86_emulate_ctxt {
 	u8 seg_override;
 	u64 d;
 	unsigned long _eip;
+
+	/* Here begins the usercopy section. */
+	struct operand src;
+	struct operand src2;
+	struct operand dst;
 	struct operand memop;
 	/* Fields above regs are cleared together. */
 	unsigned long _regs[NR_VCPU_REGS];
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 548cf3b659f5..418717876ad0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -231,13 +231,13 @@ static struct kmem_cache *x86_emulator_cache;
 
 static struct kmem_cache *kvm_alloc_emulator_cache(void)
 {
-	return kmem_cache_create_usercopy("x86_emulator",
-					  sizeof(struct x86_emulate_ctxt),
+	unsigned int useroffset = offsetof(struct x86_emulate_ctxt, src);
+	unsigned int size = sizeof(struct x86_emulate_ctxt);
+
+	return kmem_cache_create_usercopy("x86_emulator", size,
 					  __alignof__(struct x86_emulate_ctxt),
-					  SLAB_ACCOUNT,
-					  0,
-					  sizeof(struct x86_emulate_ctxt),
-					  NULL);
+					  SLAB_ACCOUNT, useroffset,
+					  size - useroffset, NULL);
 }
 
 static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt);
-- 
2.24.0


  parent reply	other threads:[~2019-11-22 22:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 22:39 [PATCH 00/13] KVM: x86: Allow userspace to disable the emulator Sean Christopherson
2019-11-22 22:39 ` [PATCH 01/13] KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant Sean Christopherson
2019-11-22 22:39 ` [PATCH 02/13] KVM: x86: Explicitly pass an exception struct to check_intercept Sean Christopherson
2019-11-22 22:39 ` [PATCH 03/13] KVM: x86: Move emulation-only helpers to emulate.c Sean Christopherson
2019-11-22 22:39 ` [PATCH 04/13] KVM: x86: Refactor R/W page helper to take the emulation context Sean Christopherson
2019-11-22 22:39 ` [PATCH 05/13] KVM: x86: Refactor emulated exception injection to take the emul context Sean Christopherson
2019-11-22 22:39 ` [PATCH 06/13] KVM: x86: Refactor emulate tracepoint to explicitly take context Sean Christopherson
2019-11-22 22:39 ` [PATCH 07/13] KVM: x86: Refactor init_emulate_ctxt() " Sean Christopherson
2019-11-22 22:39 ` [PATCH 08/13] KVM: x86: Dynamically allocate per-vCPU emulation context Sean Christopherson
2019-11-22 22:39 ` [PATCH 09/13] KVM: x86: Move kvm_emulate.h into KVM's private directory Sean Christopherson
2019-11-22 22:39 ` Sean Christopherson [this message]
2019-11-22 22:39 ` [PATCH 11/13] KVM: x86: Add helper to "handle" internal emulation error Sean Christopherson
2019-11-22 22:39 ` [PATCH 12/13] KVM: x86: Add variable to control existence of emulator Sean Christopherson
2019-11-22 22:39 ` [PATCH 13/13] KVM: x86: Allow userspace to disable the kernel's emulator Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191122223959.13545-11-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.