Skip to content

Commit 19ace7d

Browse files
Lai Jiangshansean-jc
authored andcommitted
KVM: x86/mmu: Skip calling mmu->sync_spte() when the spte is 0
Sync the spte only when the spte is set and avoid the indirect branch. Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com> Link: https://lore.kernel.org/r/20230216235321.735214-5-jiangshanlai@gmail.com [sean: add wrapper instead of open coding each check] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 91ca767 commit 19ace7d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,14 @@ static bool kvm_sync_page_check(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
19331933
return true;
19341934
}
19351935

1936+
static int kvm_sync_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int i)
1937+
{
1938+
if (!sp->spt[i])
1939+
return 0;
1940+
1941+
return vcpu->arch.mmu->sync_spte(vcpu, sp, i);
1942+
}
1943+
19361944
static int __kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
19371945
{
19381946
int flush = 0;
@@ -1942,7 +1950,7 @@ static int __kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
19421950
return -1;
19431951

19441952
for (i = 0; i < SPTE_ENT_PER_PAGE; i++) {
1945-
int ret = vcpu->arch.mmu->sync_spte(vcpu, sp, i);
1953+
int ret = kvm_sync_spte(vcpu, sp, i);
19461954

19471955
if (ret < -1)
19481956
return -1;
@@ -5766,7 +5774,7 @@ static void __kvm_mmu_invalidate_addr(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu
57665774
struct kvm_mmu_page *sp = sptep_to_sp(iterator.sptep);
57675775

57685776
if (sp->unsync) {
5769-
int ret = mmu->sync_spte(vcpu, sp, iterator.index);
5777+
int ret = kvm_sync_spte(vcpu, sp, iterator.index);
57705778

57715779
if (ret < 0)
57725780
mmu_page_zap_pte(vcpu->kvm, sp, iterator.sptep, NULL);

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static int FNAME(sync_spte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int
892892
gpa_t pte_gpa;
893893
gfn_t gfn;
894894

895-
if (!sp->spt[i])
895+
if (WARN_ON_ONCE(!sp->spt[i]))
896896
return 0;
897897

898898
first_pte_gpa = FNAME(get_level1_sp_gpa)(sp);

0 commit comments

Comments
 (0)