Commit eab9f71f authored by Avi Kivity's avatar Avi Kivity

KVM: MMU: Optimize prefetch_page()

Instead of reading each pte individually, read 256 bytes worth of ptes and
batch process them.
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 38d5bc6d
...@@ -460,8 +460,9 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) ...@@ -460,8 +460,9 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu, static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu,
struct kvm_mmu_page *sp) struct kvm_mmu_page *sp)
{ {
int i, offset = 0, r = 0; int i, j, offset, r;
pt_element_t pt; pt_element_t pt[256 / sizeof(pt_element_t)];
gpa_t pte_gpa;
if (sp->role.metaphysical if (sp->role.metaphysical
|| (PTTYPE == 32 && sp->role.level > PT_PAGE_TABLE_LEVEL)) { || (PTTYPE == 32 && sp->role.level > PT_PAGE_TABLE_LEVEL)) {
...@@ -469,19 +470,20 @@ static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu, ...@@ -469,19 +470,20 @@ static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu,
return; return;
} }
if (PTTYPE == 32) pte_gpa = gfn_to_gpa(sp->gfn);
if (PTTYPE == 32) {
offset = sp->role.quadrant << PT64_LEVEL_BITS; offset = sp->role.quadrant << PT64_LEVEL_BITS;
pte_gpa += offset * sizeof(pt_element_t);
}
for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { for (i = 0; i < PT64_ENT_PER_PAGE; i += ARRAY_SIZE(pt)) {
gpa_t pte_gpa = gfn_to_gpa(sp->gfn); r = kvm_read_guest_atomic(vcpu->kvm, pte_gpa, pt, sizeof pt);
pte_gpa += (i+offset) * sizeof(pt_element_t); pte_gpa += ARRAY_SIZE(pt) * sizeof(pt_element_t);
for (j = 0; j < ARRAY_SIZE(pt); ++j)
r = kvm_read_guest_atomic(vcpu->kvm, pte_gpa, &pt, if (r || is_present_pte(pt[j]))
sizeof(pt_element_t)); sp->spt[i+j] = shadow_trap_nonpresent_pte;
if (r || is_present_pte(pt))
sp->spt[i] = shadow_trap_nonpresent_pte;
else else
sp->spt[i] = shadow_notrap_nonpresent_pte; sp->spt[i+j] = shadow_notrap_nonpresent_pte;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment