Skip to content

Commit 7d94531

Browse files
Ben Gardonbonzini
authored andcommitted
kvm: x86/mmu: Remove disallowed_hugepage_adjust shadow_walk_iterator arg
In order to avoid creating executable hugepages in the TDP MMU PF handler, remove the dependency between disallowed_hugepage_adjust and the shadow_walk_iterator. This will open the function up to being used by the TDP MMU PF handler in a future patch. Tested by running kvm-unit-tests and KVM selftests on an Intel Haswell machine. This series introduced no new failures. This series can be viewed in Gerrit at: https://linux-review.googlesource.com/c/virt/kvm/kvm/+/2538 Signed-off-by: Ben Gardon <bgardon@google.com> Message-Id: <20201014182700.2888246-10-bgardon@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent faaf05b commit 7d94531

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

arch/x86/kvm/mmu/mmu.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,13 +2818,12 @@ static int kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, gfn_t gfn,
28182818
return level;
28192819
}
28202820

2821-
static void disallowed_hugepage_adjust(struct kvm_shadow_walk_iterator it,
2822-
gfn_t gfn, kvm_pfn_t *pfnp, int *levelp)
2821+
static void disallowed_hugepage_adjust(u64 spte, gfn_t gfn, int cur_level,
2822+
kvm_pfn_t *pfnp, int *levelp)
28232823
{
28242824
int level = *levelp;
2825-
u64 spte = *it.sptep;
28262825

2827-
if (it.level == level && level > PG_LEVEL_4K &&
2826+
if (cur_level == level && level > PG_LEVEL_4K &&
28282827
is_shadow_present_pte(spte) &&
28292828
!is_large_pte(spte)) {
28302829
/*
@@ -2834,7 +2833,8 @@ static void disallowed_hugepage_adjust(struct kvm_shadow_walk_iterator it,
28342833
* patching back for them into pfn the next 9 bits of
28352834
* the address.
28362835
*/
2837-
u64 page_mask = KVM_PAGES_PER_HPAGE(level) - KVM_PAGES_PER_HPAGE(level - 1);
2836+
u64 page_mask = KVM_PAGES_PER_HPAGE(level) -
2837+
KVM_PAGES_PER_HPAGE(level - 1);
28382838
*pfnp |= gfn & page_mask;
28392839
(*levelp)--;
28402840
}
@@ -2867,7 +2867,8 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,
28672867
* large page, as the leaf could be executable.
28682868
*/
28692869
if (nx_huge_page_workaround_enabled)
2870-
disallowed_hugepage_adjust(it, gfn, &pfn, &level);
2870+
disallowed_hugepage_adjust(*it.sptep, gfn, it.level,
2871+
&pfn, &level);
28712872

28722873
base_gfn = gfn & ~(KVM_PAGES_PER_HPAGE(it.level) - 1);
28732874
if (it.level == level)

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,
695695
* large page, as the leaf could be executable.
696696
*/
697697
if (nx_huge_page_workaround_enabled)
698-
disallowed_hugepage_adjust(it, gw->gfn, &pfn, &level);
698+
disallowed_hugepage_adjust(*it.sptep, gw->gfn, it.level,
699+
&pfn, &level);
699700

700701
base_gfn = gw->gfn & ~(KVM_PAGES_PER_HPAGE(it.level) - 1);
701702
if (it.level == level)

0 commit comments

Comments
 (0)