KVM: x86/mmu: Replace tdp_mmu_page with a bit in the role
PATCH 1/1 KVM: x86/mmu: Replace tdp_mmu_page with a bit in the role
Replace sp->tdp_mmu_page with a bit in the page role. This reduces the size of struct kvm_mmu_page by a byte.
Note that in tdp_mmu_init_sp() there is no need to explicitly set sp->role.tdp_mmu=1 for every SP since the role is already copied to all child SPs.
--- arch/x86/include/asm/kvm_host.h | 11 ++++++++--- arch/x86/kvm/mmu/mmu.c | 1 + arch/x86/kvm/mmu/mmu_internal.h | 1 - arch/x86/kvm/mmu/tdp_mmu.c | 1 - arch/x86/kvm/mmu/tdp_mmu.h | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/include/asm/kvm_host.h +8 -3
@@ -304,10 +304,10 @@ struct kvm_kernel_irq_routing_entry;* the number of unique SPs that can theoretically be created is 2^n, where n * is the number of bits that are used to compute the role. * -* But, even though there are 19 bits in the mask below, not all combinations +* But, even though there are 20 bits in the mask below, not all combinations * of modes and flags are possible: * -* - invalid shadow pages are not accounted, so the bits are effectively 18 +* - invalid shadow pages are not accounted, so the bits are effectively 19 * * - quadrant will only be used if has_4_byte_gpte=1 (non-PAE paging); * execonly and ad_disabled are only used for nested EPT which has
@@ -321,6 +321,10 @@ struct kvm_kernel_irq_routing_entry;* - on top of this, smep_andnot_wp and smap_andnot_wp are only set if * cr0_wp=0, therefore these three bits only give rise to 5 possibilities. * +* - When tdp_mmu=1, only a subset of the remaining bits can vary across +* shadow pages: level, invalid, and smm. The rest are fixed, e.g. direct=1, +* access=ACC_ALL, guest_mode=0, etc. +* * Therefore, the maximum number of possible upper-level shadow pages for a * single gfn is a bit less than 2^13. */
@@ -340,7 +344,8 @@ union kvm_mmu_page_role { unsigned ad_disabled:1; unsigned guest_mode:1; unsigned passthrough:1; - unsigned :5; + unsigned tdp_mmu:1; + unsigned:4;/* * This is left at the top of the word so that
arch/x86/kvm/mmu/mmu.c +1 -0
@@ -5128,6 +5128,7 @@ kvm_calc_tdp_mmu_root_page_role(struct kvm_vcpu *vcpu, role.level =kvm_mmu_get_tdp_level (vcpu); role.direct = true; role.has_4_byte_gpte = false; + role.tdp_mmu = tdp_mmu_enabled;return role; }
arch/x86/kvm/mmu/mmu_internal.h +0 -1
@@ -54,7 +54,6 @@ struct kvm_mmu_page {struct list_head link;struct hlist_node hash_link; -bool tdp_mmu_page;bool unsync;u8 mmu_valid_gen;
arch/x86/kvm/mmu/tdp_mmu.c +0 -1
@@ -280,7 +280,6 @@ static void tdp_mmu_init_sp(struct kvm_mmu_page *sp, tdp_ptep_t sptep, sp->role = role; sp->gfn = gfn; sp->ptep = sptep; - sp->tdp_mmu_page = true;trace_kvm_mmu_get_page (sp, true); }
arch/x86/kvm/mmu/tdp_mmu.h +1 -1
@@ -71,7 +71,7 @@ u64 *kvm_tdp_mmu_fast_pf_get_last_sptep(struct kvm_vcpu *vcpu, u64 addr, u64 *spte);#ifdef CONFIG_X86_64 -static inline bool is_tdp_mmu_page (struct kvm_mmu_page *sp) {return sp->tdp_mmu_page; } +static inline bool is_tdp_mmu_page (struct kvm_mmu_page *sp) {return sp->role.tdp_mmu; }#else static inline bool is_tdp_mmu_page (struct kvm_mmu_page *sp) {return false; }#endif
base-commit: de60733246ff4545a0483140c1f21426b8d7cb7f
prerequisite-patch-id: 42a76ce7cec240776c21f674e99e893a3a6bee58
Signature · 1 line
2.39.1.456.gfc5497dd1b-goog
Sean Christopherson
maintainerQuoted 2 lines · David Matlack
Replace
sp->tdp_mmu_pagewith a bit in the page role. This reduces the size of structkvm_mmu_pageby a byte.
No it doesn't. I purposely squeezed the flag into an open byte in commit
ca41c34cab1f ("KVM: x86/mmu: Relocate kvm_mmu_page.tdp_mmu_page for better cache locality")
I double checked just to make sure: the size is 184 bytes before and after.
I'm not opposed to this change, but I also don't see the point. The common code ends up with an arch hook in the appropriate place anyways[*], and I think we'll want to pay careful attention to the cache locality of the struct as whole, e.g. naively dumping the arch crud at the end of the common kvm_mmu_page structure may impact performance, especially for shadow paging.
And just drop the WARN_ON() sanity check in kvm_tdp_mmu_put_root() .
Hmm, actually, if we invert the order for the shadow MMU, e.g. embed "struct kvm_mmu_page" in a "struct kvm_shadow_mmu_page" or whatever, then the size of TDP MMU pages should shrink substantially.
So my vote is to hold off for now and take a closer look at this in the common MMU series proper.
[*] https://lore.kernel.org/all/[email protected]
Quoted 6 lines
Note that in
tdp_mmu_init_sp()there is no need to explicitly set sp->role.tdp_mmu=1 for every SP since the role is already copied to all child SPs.
Drop the trailing slash, otherwise directly clicking the link goes sideways.
Quoted 2 lines
Signed-off-by David Matlack <[email protected]>---
Quoted 10 lines · Sean Christopherson
Quoted 2 lines · David Matlack
Replace
sp->tdp_mmu_pagewith a bit in the page role. This reduces the size of structkvm_mmu_pageby a byte.No it doesn't. I purposely squeezed the flag into an open byte in commit
ca41c34cab1f("KVM: x86/mmu: Relocate kvm_mmu_page.tdp_mmu_page for better cache locality")I double checked just to make sure: the size is 184 bytes before and after.
My mistake, thanks for pointing it out.
Quoted 7 lines
I'm not opposed to this change, but I also don't see the point. The common code ends up with an arch hook in the appropriate place anyways[*], and I think we'll want to pay careful attention to the cache locality of the struct as whole, e.g. naively dumping the arch crud at the end of the common
kvm_mmu_pagestructure may impact performance, especially for shadow paging.
Quoted 8 lines
And just drop the
WARN_ON()sanity check inkvm_tdp_mmu_put_root().Hmm, actually, if we invert the order for the shadow MMU, e.g. embed "struct
kvm_mmu_page" in a "structkvm_shadow_mmu_page" or whatever, then the size of TDP MMU pages should shrink substantially.So my vote is to hold off for now and take a closer look at this in the common MMU series proper.
Sounds good to me.
Quoted 11 lines
[*] https://lore.kernel.org/all/[email protected]
Quoted 6 lines
Note that in
tdp_mmu_init_sp()there is no need to explicitly set sp->role.tdp_mmu=1 for every SP since the role is already copied to all child SPs.Drop the trailing slash, otherwise directly clicking the link goes sideways.
I don't have any problem clicking this link, but I can try to omit the trailing slash in the future.
Sean Christopherson
maintainerQuoted 9 lines · David Matlack
Quoted 5 lines · Sean Christopherson
Quoted 1 line · David Matlack
Drop the trailing slash, otherwise directly clicking the link goes sideways.
I don't have any problem clicking this link, but I can try to omit the trailing slash in the future.
Ha! Figured out what happens. Gmail gets confused and thinks the forward slash indiciates a continuation, e.g. the original mail sends me to:
https://lore.kernel.org/kvm/[email protected]/Signed-off-by
I bet the above now works because there's whitespace. For giggles....
https://lore.kernel.org/kvm/[email protected]/will_it_blend
Quoted 9 lines · Sean Christopherson
Quoted 7 lines · David Matlack
Quoted 5 lines · Sean Christopherson
Quoted 1 line · David Matlack
Drop the trailing slash, otherwise directly clicking the link goes sideways.
Quoted 7 lines
Quoted 2 lines
I don't have any problem clicking this link, but I can try to omit the trailing slash in the future.
Ha! Figured out what happens. Gmail gets confused and thinks the forward slash indiciates a continuation, e.g. the original mail sends me to:
Ohhh I do see the same behavior when clicking the link in my original email. The copy of the link in your reply had nothing on the line after it so clicking it there worked just fine :)
Quoted 5 lines
I bet the above now works because there's whitespace. For giggles....
https://lore.kernel.org/kvm/[email protected]/
will_it_blend