Actually, in kvm_mmu_unprotect_page() function, it need find out+Shouldn't we always skip invalid gfns?
+#define for_each_gfn_indirect_sp(kvm, sp, gfn, pos, n) \
+ hlist_for_each_entry_safe(sp, pos, n, \
+&kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)], hash_link)\
+ if (sp->gfn == gfn&& !sp->role.direct)
+
+#define for_each_gfn_indirect_valid_sp(kvm, sp, gfn, pos, n) \
+ hlist_for_each_entry_safe(sp, pos, n, \
+&kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)], hash_link)\
+ if (sp->gfn == gfn&& !sp->role.direct&& \
+ !sp->role.invalid)
invalid shadow pages:
| hlist_for_each_entry_safe(sp, node, n, bucket, hash_link)
| if (sp->gfn == gfn&& !sp->role.direct) {
| pgprintk("%s: gfn %lx role %x\n", __func__, gfn,
| sp->role.word);
| r = 1;
| if (kvm_mmu_zap_page(kvm, sp))
| goto restart;
| }
I'm not sure whether we can skip invalid sp here, since it can change this
function's return value. :-(
What about providing both gfn and role to the macro?In current code, no code simply use role and gfn to find sp,
in kvm_mmu_get_page(), we need do other work for
'sp->gfn == gfn&& sp->role != role' sp, and other functions only need compare
some members in role, but not all members.