How about passing the list as a parameter to prepare() and commit()? IfDoes below example code show your meaning correctly?
the lifetime of the list is just prepare/commit, it shouldn't be a global.
+ struct list_head free_list = LIST_HEAD_INIT(&free_list);
hlist_for_each_entry_safe(sp, node, nn, bucket, hash_link) {
if (sp->gfn == gfn&& !sp->role.direct
&& !sp->role.invalid) {
pgprintk("%s: zap %lx %x\n",
__func__, gfn, sp->role.word);
+ kvm_mmu_prepare_zap_page(kvm, sp,&free_list);
}
}
+ kvm_mmu_commit_zap_page(kvm,&free_list);