diff options
Diffstat (limited to 'arch/x86/kvm/paging_tmpl.h')
-rw-r--r-- | arch/x86/kvm/paging_tmpl.h | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 84eee43bbe74..9fd78b6e17ad 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h | |||
@@ -82,6 +82,7 @@ struct shadow_walker { | |||
82 | int *ptwrite; | 82 | int *ptwrite; |
83 | pfn_t pfn; | 83 | pfn_t pfn; |
84 | u64 *sptep; | 84 | u64 *sptep; |
85 | gpa_t pte_gpa; | ||
85 | }; | 86 | }; |
86 | 87 | ||
87 | static gfn_t gpte_to_gfn(pt_element_t gpte) | 88 | static gfn_t gpte_to_gfn(pt_element_t gpte) |
@@ -222,7 +223,7 @@ walk: | |||
222 | if (ret) | 223 | if (ret) |
223 | goto walk; | 224 | goto walk; |
224 | pte |= PT_DIRTY_MASK; | 225 | pte |= PT_DIRTY_MASK; |
225 | kvm_mmu_pte_write(vcpu, pte_gpa, (u8 *)&pte, sizeof(pte)); | 226 | kvm_mmu_pte_write(vcpu, pte_gpa, (u8 *)&pte, sizeof(pte), 0); |
226 | walker->ptes[walker->level - 1] = pte; | 227 | walker->ptes[walker->level - 1] = pte; |
227 | } | 228 | } |
228 | 229 | ||
@@ -274,7 +275,8 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page, | |||
274 | return; | 275 | return; |
275 | kvm_get_pfn(pfn); | 276 | kvm_get_pfn(pfn); |
276 | mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0, | 277 | mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0, |
277 | gpte & PT_DIRTY_MASK, NULL, largepage, gpte_to_gfn(gpte), | 278 | gpte & PT_DIRTY_MASK, NULL, largepage, |
279 | gpte & PT_GLOBAL_MASK, gpte_to_gfn(gpte), | ||
278 | pfn, true); | 280 | pfn, true); |
279 | } | 281 | } |
280 | 282 | ||
@@ -301,8 +303,9 @@ static int FNAME(shadow_walk_entry)(struct kvm_shadow_walk *_sw, | |||
301 | mmu_set_spte(vcpu, sptep, access, gw->pte_access & access, | 303 | mmu_set_spte(vcpu, sptep, access, gw->pte_access & access, |
302 | sw->user_fault, sw->write_fault, | 304 | sw->user_fault, sw->write_fault, |
303 | gw->ptes[gw->level-1] & PT_DIRTY_MASK, | 305 | gw->ptes[gw->level-1] & PT_DIRTY_MASK, |
304 | sw->ptwrite, sw->largepage, gw->gfn, sw->pfn, | 306 | sw->ptwrite, sw->largepage, |
305 | false); | 307 | gw->ptes[gw->level-1] & PT_GLOBAL_MASK, |
308 | gw->gfn, sw->pfn, false); | ||
306 | sw->sptep = sptep; | 309 | sw->sptep = sptep; |
307 | return 1; | 310 | return 1; |
308 | } | 311 | } |
@@ -466,10 +469,22 @@ static int FNAME(shadow_invlpg_entry)(struct kvm_shadow_walk *_sw, | |||
466 | struct kvm_vcpu *vcpu, u64 addr, | 469 | struct kvm_vcpu *vcpu, u64 addr, |
467 | u64 *sptep, int level) | 470 | u64 *sptep, int level) |
468 | { | 471 | { |
472 | struct shadow_walker *sw = | ||
473 | container_of(_sw, struct shadow_walker, walker); | ||
469 | 474 | ||
470 | if (level == PT_PAGE_TABLE_LEVEL) { | 475 | /* FIXME: properly handle invlpg on large guest pages */ |
471 | if (is_shadow_present_pte(*sptep)) | 476 | if (level == PT_PAGE_TABLE_LEVEL || |
477 | ((level == PT_DIRECTORY_LEVEL) && is_large_pte(*sptep))) { | ||
478 | struct kvm_mmu_page *sp = page_header(__pa(sptep)); | ||
479 | |||
480 | sw->pte_gpa = (sp->gfn << PAGE_SHIFT); | ||
481 | sw->pte_gpa += (sptep - sp->spt) * sizeof(pt_element_t); | ||
482 | |||
483 | if (is_shadow_present_pte(*sptep)) { | ||
472 | rmap_remove(vcpu->kvm, sptep); | 484 | rmap_remove(vcpu->kvm, sptep); |
485 | if (is_large_pte(*sptep)) | ||
486 | --vcpu->kvm->stat.lpages; | ||
487 | } | ||
473 | set_shadow_pte(sptep, shadow_trap_nonpresent_pte); | 488 | set_shadow_pte(sptep, shadow_trap_nonpresent_pte); |
474 | return 1; | 489 | return 1; |
475 | } | 490 | } |
@@ -480,11 +495,26 @@ static int FNAME(shadow_invlpg_entry)(struct kvm_shadow_walk *_sw, | |||
480 | 495 | ||
481 | static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva) | 496 | static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva) |
482 | { | 497 | { |
498 | pt_element_t gpte; | ||
483 | struct shadow_walker walker = { | 499 | struct shadow_walker walker = { |
484 | .walker = { .entry = FNAME(shadow_invlpg_entry), }, | 500 | .walker = { .entry = FNAME(shadow_invlpg_entry), }, |
501 | .pte_gpa = -1, | ||
485 | }; | 502 | }; |
486 | 503 | ||
504 | spin_lock(&vcpu->kvm->mmu_lock); | ||
487 | walk_shadow(&walker.walker, vcpu, gva); | 505 | walk_shadow(&walker.walker, vcpu, gva); |
506 | spin_unlock(&vcpu->kvm->mmu_lock); | ||
507 | if (walker.pte_gpa == -1) | ||
508 | return; | ||
509 | if (kvm_read_guest_atomic(vcpu->kvm, walker.pte_gpa, &gpte, | ||
510 | sizeof(pt_element_t))) | ||
511 | return; | ||
512 | if (is_present_pte(gpte) && (gpte & PT_ACCESSED_MASK)) { | ||
513 | if (mmu_topup_memory_caches(vcpu)) | ||
514 | return; | ||
515 | kvm_mmu_pte_write(vcpu, walker.pte_gpa, (const u8 *)&gpte, | ||
516 | sizeof(pt_element_t), 0); | ||
517 | } | ||
488 | } | 518 | } |
489 | 519 | ||
490 | static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) | 520 | static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) |
@@ -580,7 +610,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) | |||
580 | nr_present++; | 610 | nr_present++; |
581 | pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); | 611 | pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); |
582 | set_spte(vcpu, &sp->spt[i], pte_access, 0, 0, | 612 | set_spte(vcpu, &sp->spt[i], pte_access, 0, 0, |
583 | is_dirty_pte(gpte), 0, gfn, | 613 | is_dirty_pte(gpte), 0, gpte & PT_GLOBAL_MASK, gfn, |
584 | spte_to_pfn(sp->spt[i]), true, false); | 614 | spte_to_pfn(sp->spt[i]), true, false); |
585 | } | 615 | } |
586 | 616 | ||