All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Cc: Jim Mattson <jmattson@google.com>
Subject: [PATCH v2 3/3] kvm: vmx: Reduce size of vmcs_field_to_offset_table
Date: Fri, 22 Dec 2017 12:13:13 -0800	[thread overview]
Message-ID: <20171222201313.98795-1-jmattson@google.com> (raw)
In-Reply-To: <CALMp9eRfPjzic1cp5DY_5Pr0b3buoeaA4O-3LKd-TA14iWJeag@mail.gmail.com>

The vmcs_field_to_offset_table was a rather sparse table of short
integers with a maximum index of 0x6c16, amounting to 55342 bytes. Now
that we are considering support for multiple VMCS12 formats, it would
be unfortunate to replicate that large, sparse table. Rotating the
field encoding (as a 16-bit integer) left by 6 reduces that table to
5926 bytes.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/vmx.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 1847000fbb0c..fec38a1614b5 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -714,10 +714,12 @@ static struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu)
 	return &(to_vmx(vcpu)->pi_desc);
 }
 
+#define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
 #define VMCS12_OFFSET(x) offsetof(struct vmcs12, x)
-#define FIELD(number, name)	[number] = VMCS12_OFFSET(name)
-#define FIELD64(number, name)	[number] = VMCS12_OFFSET(name), \
-				[number##_HIGH] = VMCS12_OFFSET(name)+4
+#define FIELD(number, name)	[ROL16(number, 6)] = VMCS12_OFFSET(name)
+#define FIELD64(number, name)						\
+	FIELD(number, name),						\
+	[ROL16(number##_HIGH, 6)] = VMCS12_OFFSET(name) + sizeof(u32)
 
 
 static unsigned long shadow_read_only_fields[] = {
@@ -925,13 +927,17 @@ static const unsigned short vmcs_field_to_offset_table[] = {
 
 static inline short vmcs_field_to_offset(unsigned long field)
 {
-	BUILD_BUG_ON(ARRAY_SIZE(vmcs_field_to_offset_table) > SHRT_MAX);
+	unsigned index;
+
+	if (field >> 15)
+		return -ENOENT;
 
-	if (field >= ARRAY_SIZE(vmcs_field_to_offset_table) ||
-	    vmcs_field_to_offset_table[field] == 0)
+	index = ROL16(field, 6);
+	if (index >= ARRAY_SIZE(vmcs_field_to_offset_table) ||
+	    vmcs_field_to_offset_table[index] == 0)
 		return -ENOENT;
 
-	return vmcs_field_to_offset_table[field];
+	return vmcs_field_to_offset_table[index];
 }
 
 static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
-- 
2.15.1.620.gb9897f4670-goog

  reply	other threads:[~2017-12-22 20:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 20:46 [PATCH 0/3] Reduce the size of the vmcs_field_to_offset_table Jim Mattson
2017-12-21 20:46 ` [PATCH 1/3] kvm: vmx: Introduce VMCS12_MAX_FIELD_INDEX Jim Mattson
2017-12-22 20:11   ` [PATCH v2 " Jim Mattson
2018-01-18 16:46     ` David Hildenbrand
2017-12-21 20:46 ` [PATCH 2/3] kvm: vmx: Change vmcs_field_type to vmcs_field_width Jim Mattson
2017-12-22 20:12   ` [PATCH v2 " Jim Mattson
2017-12-21 20:46 ` [PATCH 3/3] kvm: vmx: Reduce size of vmcs_field_to_offset_table Jim Mattson
2017-12-22 16:26   ` Paolo Bonzini
2017-12-22 18:28     ` Jim Mattson
2017-12-22 20:13       ` Jim Mattson [this message]
2017-12-22 20:09 ` [PATCH v2 0/3] Reduce the size of the vmcs_field_to_offset_table Jim Mattson
2018-01-01 22:55   ` Paolo Bonzini

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=20171222201313.98795-1-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.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.