lkml.org 
[lkml]   [2021]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH v2 03/17] KVM: x86/mmu: Capture 'mmu' in a local variable when allocating roots
From
Grab 'mmu' and do s/vcpu->arch.mmu/mmu to shorten line lengths and yield
smaller diffs when moving code around in future cleanup without forcing
the new code to use the same ugly pattern.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mmu/mmu.c | 58 ++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 2ed3fac1244e..c4f8e59f596c 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3235,7 +3235,8 @@ static hpa_t mmu_alloc_root(struct kvm_vcpu *vcpu, gfn_t gfn, gva_t gva,

static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)
{
- u8 shadow_root_level = vcpu->arch.mmu->shadow_root_level;
+ struct kvm_mmu *mmu = vcpu->arch.mmu;
+ u8 shadow_root_level = mmu->shadow_root_level;
hpa_t root;
unsigned i;

@@ -3244,42 +3245,43 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)

if (!VALID_PAGE(root))
return -ENOSPC;
- vcpu->arch.mmu->root_hpa = root;
+ mmu->root_hpa = root;
} else if (shadow_root_level >= PT64_ROOT_4LEVEL) {
root = mmu_alloc_root(vcpu, 0, 0, shadow_root_level,
true);

if (!VALID_PAGE(root))
return -ENOSPC;
- vcpu->arch.mmu->root_hpa = root;
+ mmu->root_hpa = root;
} else if (shadow_root_level == PT32E_ROOT_LEVEL) {
for (i = 0; i < 4; ++i) {
- MMU_WARN_ON(VALID_PAGE(vcpu->arch.mmu->pae_root[i]));
+ MMU_WARN_ON(VALID_PAGE(mmu->pae_root[i]));

root = mmu_alloc_root(vcpu, i << (30 - PAGE_SHIFT),
i << 30, PT32_ROOT_LEVEL, true);
if (!VALID_PAGE(root))
return -ENOSPC;
- vcpu->arch.mmu->pae_root[i] = root | PT_PRESENT_MASK;
+ mmu->pae_root[i] = root | PT_PRESENT_MASK;
}
- vcpu->arch.mmu->root_hpa = __pa(vcpu->arch.mmu->pae_root);
+ mmu->root_hpa = __pa(mmu->pae_root);
} else
BUG();

/* root_pgd is ignored for direct MMUs. */
- vcpu->arch.mmu->root_pgd = 0;
+ mmu->root_pgd = 0;

return 0;
}

static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
{
+ struct kvm_mmu *mmu = vcpu->arch.mmu;
u64 pdptr, pm_mask;
gfn_t root_gfn, root_pgd;
hpa_t root;
int i;

- root_pgd = vcpu->arch.mmu->get_guest_pgd(vcpu);
+ root_pgd = mmu->get_guest_pgd(vcpu);
root_gfn = root_pgd >> PAGE_SHIFT;

if (mmu_check_root(vcpu, root_gfn))
@@ -3289,14 +3291,14 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
* Do we shadow a long mode page table? If so we need to
* write-protect the guests page table root.
*/
- if (vcpu->arch.mmu->root_level >= PT64_ROOT_4LEVEL) {
- MMU_WARN_ON(VALID_PAGE(vcpu->arch.mmu->root_hpa));
+ if (mmu->root_level >= PT64_ROOT_4LEVEL) {
+ MMU_WARN_ON(VALID_PAGE(mmu->root_hpa));

root = mmu_alloc_root(vcpu, root_gfn, 0,
- vcpu->arch.mmu->shadow_root_level, false);
+ mmu->shadow_root_level, false);
if (!VALID_PAGE(root))
return -ENOSPC;
- vcpu->arch.mmu->root_hpa = root;
+ mmu->root_hpa = root;
goto set_root_pgd;
}

@@ -3306,7 +3308,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
* the shadow page table may be a PAE or a long mode page table.
*/
pm_mask = PT_PRESENT_MASK;
- if (vcpu->arch.mmu->shadow_root_level == PT64_ROOT_4LEVEL) {
+ if (mmu->shadow_root_level == PT64_ROOT_4LEVEL) {
pm_mask |= PT_ACCESSED_MASK | PT_WRITABLE_MASK | PT_USER_MASK;

/*
@@ -3314,21 +3316,21 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
* with 64-bit only when needed. Unlike 32-bit NPT, it doesn't
* need to be in low mem. See also lm_root below.
*/
- if (!vcpu->arch.mmu->pae_root) {
+ if (!mmu->pae_root) {
WARN_ON_ONCE(!tdp_enabled);

- vcpu->arch.mmu->pae_root = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
- if (!vcpu->arch.mmu->pae_root)
+ mmu->pae_root = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
+ if (!mmu->pae_root)
return -ENOMEM;
}
}

for (i = 0; i < 4; ++i) {
- MMU_WARN_ON(VALID_PAGE(vcpu->arch.mmu->pae_root[i]));
- if (vcpu->arch.mmu->root_level == PT32E_ROOT_LEVEL) {
- pdptr = vcpu->arch.mmu->get_pdptr(vcpu, i);
+ MMU_WARN_ON(VALID_PAGE(mmu->pae_root[i]));
+ if (mmu->root_level == PT32E_ROOT_LEVEL) {
+ pdptr = mmu->get_pdptr(vcpu, i);
if (!(pdptr & PT_PRESENT_MASK)) {
- vcpu->arch.mmu->pae_root[i] = 0;
+ mmu->pae_root[i] = 0;
continue;
}
root_gfn = pdptr >> PAGE_SHIFT;
@@ -3340,9 +3342,9 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
PT32_ROOT_LEVEL, false);
if (!VALID_PAGE(root))
return -ENOSPC;
- vcpu->arch.mmu->pae_root[i] = root | pm_mask;
+ mmu->pae_root[i] = root | pm_mask;
}
- vcpu->arch.mmu->root_hpa = __pa(vcpu->arch.mmu->pae_root);
+ mmu->root_hpa = __pa(mmu->pae_root);

/*
* When shadowing 32-bit or PAE NPT with 64-bit NPT, the PML4 and PDP
@@ -3351,24 +3353,24 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
* on demand, as running a 32-bit L1 VMM is very rare. The PDP is
* handled above (to share logic with PAE), deal with the PML4 here.
*/
- if (vcpu->arch.mmu->shadow_root_level == PT64_ROOT_4LEVEL) {
- if (vcpu->arch.mmu->lm_root == NULL) {
+ if (mmu->shadow_root_level == PT64_ROOT_4LEVEL) {
+ if (mmu->lm_root == NULL) {
u64 *lm_root;

lm_root = (void*)get_zeroed_page(GFP_KERNEL_ACCOUNT);
if (!lm_root)
return -ENOMEM;

- lm_root[0] = __pa(vcpu->arch.mmu->pae_root) | pm_mask;
+ lm_root[0] = __pa(mmu->pae_root) | pm_mask;

- vcpu->arch.mmu->lm_root = lm_root;
+ mmu->lm_root = lm_root;
}

- vcpu->arch.mmu->root_hpa = __pa(vcpu->arch.mmu->lm_root);
+ mmu->root_hpa = __pa(mmu->lm_root);
}

set_root_pgd:
- vcpu->arch.mmu->root_pgd = root_pgd;
+ mmu->root_pgd = root_pgd;

return 0;
}
--
2.30.1.766.gb4fecdf3b7-goog
\
 
 \ /
  Last update: 2021-03-05 02:11    [W:0.132 / U:0.808 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site