On Mon, Aug 23, 2010 at 07:17:20PM +0300, Avi Kivity wrote:Something like this? (only compile tested)+static int apf_put_user(struct kvm_vcpu *vcpu, u32 val)This nice cache needs to be outside apf to reduce complexity for
+{
+ if (unlikely(vcpu->arch.apf_memslot_ver !=
+ vcpu->kvm->memslot_version)) {
+ u64 gpa = vcpu->arch.apf_msr_val& ~0x3f;
+ unsigned long addr;
+ int offset = offset_in_page(gpa);
+
+ addr = gfn_to_hva(vcpu->kvm, gpa>> PAGE_SHIFT);
+ vcpu->arch.apf_data = (u32 __user *)(addr + offset);
+ if (kvm_is_error_hva(addr)) {
+ vcpu->arch.apf_data = NULL;
+ return -EFAULT;
+ }
+ }
+
+ return put_user(val, vcpu->arch.apf_data);
+}
reviewers and since it is useful for others.
Would be good to have memslot-cached kvm_put_guest() and kvm_get_guest().