diff options
author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2010-08-28 07:20:47 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:51:46 -0400 |
commit | 0beb8d660425aab339ff68e6f4d4528739e8fc4f (patch) | |
tree | 9b30fbca63277dd1c5b74e35c7cb1bcb293ce7e6 | |
parent | 9ad17b10011702cb56c5e32e41ecd5fe281c3574 (diff) |
KVM: MMU: check rmap for every spte
The read-only spte also has reverse mapping, so fix the code to check them,
also modify the function name to fit its doing
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | arch/x86/kvm/mmu.c | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 59bf1d9553a7..1c784b96dac3 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -3644,40 +3644,38 @@ void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep) | |||
3644 | struct kvm_mmu_page *rev_sp; | 3644 | struct kvm_mmu_page *rev_sp; |
3645 | gfn_t gfn; | 3645 | gfn_t gfn; |
3646 | 3646 | ||
3647 | if (is_writable_pte(*sptep)) { | ||
3648 | rev_sp = page_header(__pa(sptep)); | ||
3649 | gfn = kvm_mmu_page_get_gfn(rev_sp, sptep - rev_sp->spt); | ||
3650 | 3647 | ||
3651 | if (!gfn_to_memslot(kvm, gfn)) { | 3648 | rev_sp = page_header(__pa(sptep)); |
3652 | if (!printk_ratelimit()) | 3649 | gfn = kvm_mmu_page_get_gfn(rev_sp, sptep - rev_sp->spt); |
3653 | return; | ||
3654 | printk(KERN_ERR "%s: no memslot for gfn %llx\n", | ||
3655 | audit_msg, gfn); | ||
3656 | printk(KERN_ERR "%s: index %ld of sp (gfn=%llx)\n", | ||
3657 | audit_msg, (long int)(sptep - rev_sp->spt), | ||
3658 | rev_sp->gfn); | ||
3659 | dump_stack(); | ||
3660 | return; | ||
3661 | } | ||
3662 | 3650 | ||
3663 | rmapp = gfn_to_rmap(kvm, gfn, rev_sp->role.level); | 3651 | if (!gfn_to_memslot(kvm, gfn)) { |
3664 | if (!*rmapp) { | 3652 | if (!printk_ratelimit()) |
3665 | if (!printk_ratelimit()) | 3653 | return; |
3666 | return; | 3654 | printk(KERN_ERR "%s: no memslot for gfn %llx\n", |
3667 | printk(KERN_ERR "%s: no rmap for writable spte %llx\n", | 3655 | audit_msg, gfn); |
3668 | audit_msg, *sptep); | 3656 | printk(KERN_ERR "%s: index %ld of sp (gfn=%llx)\n", |
3669 | dump_stack(); | 3657 | audit_msg, (long int)(sptep - rev_sp->spt), |
3670 | } | 3658 | rev_sp->gfn); |
3659 | dump_stack(); | ||
3660 | return; | ||
3671 | } | 3661 | } |
3672 | 3662 | ||
3663 | rmapp = gfn_to_rmap(kvm, gfn, rev_sp->role.level); | ||
3664 | if (!*rmapp) { | ||
3665 | if (!printk_ratelimit()) | ||
3666 | return; | ||
3667 | printk(KERN_ERR "%s: no rmap for writable spte %llx\n", | ||
3668 | audit_msg, *sptep); | ||
3669 | dump_stack(); | ||
3670 | } | ||
3673 | } | 3671 | } |
3674 | 3672 | ||
3675 | void audit_writable_sptes_have_rmaps(struct kvm_vcpu *vcpu) | 3673 | void audit_sptes_have_rmaps(struct kvm_vcpu *vcpu) |
3676 | { | 3674 | { |
3677 | mmu_spte_walk(vcpu, inspect_spte_has_rmap); | 3675 | mmu_spte_walk(vcpu, inspect_spte_has_rmap); |
3678 | } | 3676 | } |
3679 | 3677 | ||
3680 | static void check_writable_mappings_rmap(struct kvm_vcpu *vcpu) | 3678 | static void check_mappings_rmap(struct kvm_vcpu *vcpu) |
3681 | { | 3679 | { |
3682 | struct kvm_mmu_page *sp; | 3680 | struct kvm_mmu_page *sp; |
3683 | int i; | 3681 | int i; |
@@ -3689,12 +3687,9 @@ static void check_writable_mappings_rmap(struct kvm_vcpu *vcpu) | |||
3689 | continue; | 3687 | continue; |
3690 | 3688 | ||
3691 | for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { | 3689 | for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { |
3692 | u64 ent = pt[i]; | 3690 | if (!is_rmap_spte(pt[i])) |
3693 | |||
3694 | if (!(ent & PT_PRESENT_MASK)) | ||
3695 | continue; | ||
3696 | if (!is_writable_pte(ent)) | ||
3697 | continue; | 3691 | continue; |
3692 | |||
3698 | inspect_spte_has_rmap(vcpu->kvm, &pt[i]); | 3693 | inspect_spte_has_rmap(vcpu->kvm, &pt[i]); |
3699 | } | 3694 | } |
3700 | } | 3695 | } |
@@ -3703,7 +3698,7 @@ static void check_writable_mappings_rmap(struct kvm_vcpu *vcpu) | |||
3703 | 3698 | ||
3704 | static void audit_rmap(struct kvm_vcpu *vcpu) | 3699 | static void audit_rmap(struct kvm_vcpu *vcpu) |
3705 | { | 3700 | { |
3706 | check_writable_mappings_rmap(vcpu); | 3701 | check_mappings_rmap(vcpu); |
3707 | count_rmaps(vcpu); | 3702 | count_rmaps(vcpu); |
3708 | } | 3703 | } |
3709 | 3704 | ||
@@ -3746,7 +3741,7 @@ static void kvm_mmu_audit(struct kvm_vcpu *vcpu, const char *msg) | |||
3746 | audit_write_protection(vcpu); | 3741 | audit_write_protection(vcpu); |
3747 | if (strcmp("pre pte write", audit_msg) != 0) | 3742 | if (strcmp("pre pte write", audit_msg) != 0) |
3748 | audit_mappings(vcpu); | 3743 | audit_mappings(vcpu); |
3749 | audit_writable_sptes_have_rmaps(vcpu); | 3744 | audit_sptes_have_rmaps(vcpu); |
3750 | dbg = olddbg; | 3745 | dbg = olddbg; |
3751 | } | 3746 | } |
3752 | 3747 | ||