kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KVM: Minor structure layout changes
@ 2023-02-17 19:33 Mathias Krause
  2023-02-17 19:33 ` [PATCH v2 1/2] KVM: x86: Shrink struct kvm_pmu Mathias Krause
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mathias Krause @ 2023-02-17 19:33 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, Sean Christopherson, Paolo Bonzini, Mathias Krause

v1: https://lore.kernel.org/kvm/20230213163351.30704-1-minipli@grsecurity.net/

This used to be a more exhaustive patch set shrinking kvm_vcpu's size.
But we concluded that this would be too fragile to maintain and would
require a more radical layout change to group often used members
together instead of chopping off individual padding bytes.

The remaining two patches are nonetheless useful, as they either make
the structure layout a more natural fit (as for kvm_pmu, putting the
version atop) or removing pointless padding (kvm_mmu_memory_cache).

Please apply!

Thanks,

Mathias Krause (2):
  KVM: x86: Shrink struct kvm_pmu
  KVM: Shrink struct kvm_mmu_memory_cache

 arch/x86/include/asm/kvm_host.h | 2 +-
 include/linux/kvm_types.h       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] KVM: x86: Shrink struct kvm_pmu
  2023-02-17 19:33 [PATCH v2 0/2] KVM: Minor structure layout changes Mathias Krause
@ 2023-02-17 19:33 ` Mathias Krause
  2023-02-17 19:33 ` [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache Mathias Krause
  2023-03-24 23:37 ` [PATCH v2 0/2] KVM: Minor structure layout changes Sean Christopherson
  2 siblings, 0 replies; 6+ messages in thread
From: Mathias Krause @ 2023-02-17 19:33 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, Sean Christopherson, Paolo Bonzini, Mathias Krause

Move the 'version' member to the beginning of the structure to reuse an
existing hole instead of introducing another one.

This allows us to save 8 bytes for 64 bit builds.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
 arch/x86/include/asm/kvm_host.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 6aaae18f1854..43329c60a6b5 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -516,6 +516,7 @@ struct kvm_pmc {
 #define KVM_PMC_MAX_FIXED	3
 #define KVM_AMD_PMC_MAX_GENERIC	6
 struct kvm_pmu {
+	u8 version;
 	unsigned nr_arch_gp_counters;
 	unsigned nr_arch_fixed_counters;
 	unsigned available_event_types;
@@ -528,7 +529,6 @@ struct kvm_pmu {
 	u64 global_ovf_ctrl_mask;
 	u64 reserved_bits;
 	u64 raw_event_mask;
-	u8 version;
 	struct kvm_pmc gp_counters[KVM_INTEL_PMC_MAX_GENERIC];
 	struct kvm_pmc fixed_counters[KVM_PMC_MAX_FIXED];
 	struct irq_work irq_work;
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache
  2023-02-17 19:33 [PATCH v2 0/2] KVM: Minor structure layout changes Mathias Krause
  2023-02-17 19:33 ` [PATCH v2 1/2] KVM: x86: Shrink struct kvm_pmu Mathias Krause
@ 2023-02-17 19:33 ` Mathias Krause
  2023-03-17 22:45   ` Sean Christopherson
  2023-03-24 23:37 ` [PATCH v2 0/2] KVM: Minor structure layout changes Sean Christopherson
  2 siblings, 1 reply; 6+ messages in thread
From: Mathias Krause @ 2023-02-17 19:33 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, Sean Christopherson, Paolo Bonzini, Mathias Krause

Move the 'capacity' member around to make use of the padding hole on 64
bit systems instead of introducing yet another one.

This allows us to save 8 bytes per instance for 64 bit builds of which,
e.g., x86's struct kvm_vcpu_arch has a few.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
v2: use order as suggested by Sean

 include/linux/kvm_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index 76de36e56cdf..0b2ddce47f11 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -91,11 +91,11 @@ struct gfn_to_pfn_cache {
  * is topped up (__kvm_mmu_topup_memory_cache()).
  */
 struct kvm_mmu_memory_cache {
-	int nobjs;
 	gfp_t gfp_zero;
 	gfp_t gfp_custom;
 	struct kmem_cache *kmem_cache;
 	int capacity;
+	int nobjs;
 	void **objects;
 };
 #endif
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache
  2023-02-17 19:33 ` [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache Mathias Krause
@ 2023-03-17 22:45   ` Sean Christopherson
  2023-03-20 21:37     ` Mathias Krause
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2023-03-17 22:45 UTC (permalink / raw)
  To: Mathias Krause; +Cc: kvm, linux-kernel, Paolo Bonzini

On Fri, Feb 17, 2023, Mathias Krause wrote:
> Move the 'capacity' member around to make use of the padding hole on 64

Nit, 'nobjs' is the field that gets moved in this version.  No need for another
version, I can fix up when applying.

If no one objects, I'll plan on taking this through kvm-x86/generic.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache
  2023-03-17 22:45   ` Sean Christopherson
@ 2023-03-20 21:37     ` Mathias Krause
  0 siblings, 0 replies; 6+ messages in thread
From: Mathias Krause @ 2023-03-20 21:37 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm, linux-kernel, Paolo Bonzini

On 17.03.23 23:45, Sean Christopherson wrote:
> On Fri, Feb 17, 2023, Mathias Krause wrote:
>> Move the 'capacity' member around to make use of the padding hole on 64
> 
> Nit, 'nobjs' is the field that gets moved in this version.  No need for another
> version, I can fix up when applying.

Ahh, forgot to update the changelog after switching the layout. But as
it was 'nobjs' next to 'capacity' for both variants, I wrongly thought
there's no need to. But sure, you're right.

> 
> If no one objects, I'll plan on taking this through kvm-x86/generic.

Thanks,
Mathias

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] KVM: Minor structure layout changes
  2023-02-17 19:33 [PATCH v2 0/2] KVM: Minor structure layout changes Mathias Krause
  2023-02-17 19:33 ` [PATCH v2 1/2] KVM: x86: Shrink struct kvm_pmu Mathias Krause
  2023-02-17 19:33 ` [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache Mathias Krause
@ 2023-03-24 23:37 ` Sean Christopherson
  2 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-03-24 23:37 UTC (permalink / raw)
  To: Sean Christopherson, kvm, Mathias Krause; +Cc: linux-kernel, Paolo Bonzini

On Fri, 17 Feb 2023 20:33:34 +0100, Mathias Krause wrote:
> v1: https://lore.kernel.org/kvm/20230213163351.30704-1-minipli@grsecurity.net/
> 
> This used to be a more exhaustive patch set shrinking kvm_vcpu's size.
> But we concluded that this would be too fragile to maintain and would
> require a more radical layout change to group often used members
> together instead of chopping off individual padding bytes.
> 
> [...]

Applied patch 1 to kvm-x86 pmu, and patch 2 to generic, thanks!

[1/2] KVM: x86: Shrink struct kvm_pmu
      https://github.com/kvm-x86/linux/commit/12aad9164763
[2/2] KVM: Shrink struct kvm_mmu_memory_cache
      https://github.com/kvm-x86/linux/commit/f530b531fb9e

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-24 23:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17 19:33 [PATCH v2 0/2] KVM: Minor structure layout changes Mathias Krause
2023-02-17 19:33 ` [PATCH v2 1/2] KVM: x86: Shrink struct kvm_pmu Mathias Krause
2023-02-17 19:33 ` [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache Mathias Krause
2023-03-17 22:45   ` Sean Christopherson
2023-03-20 21:37     ` Mathias Krause
2023-03-24 23:37 ` [PATCH v2 0/2] KVM: Minor structure layout changes Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).