On 5/5/22 20:14, isaku.yamahata@xxxxxxxxx wrote:
+/* + * Private page can't be release on mmu_notifier without losing page contents. + * The help, callback, from backing store is needed to allow page migration. + * For now, pin the page. + */ +static bool kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, + struct kvm_page_fault *fault, int *r) +{ + hva_t hva = gfn_to_hva_memslot(fault->slot, fault->gfn); + struct page *page[1]; + unsigned int flags; + int npages; + + fault->map_writable = false; + fault->pfn = KVM_PFN_ERR_FAULT; + *r = -1; + if (hva == KVM_HVA_ERR_RO_BAD || hva == KVM_HVA_ERR_BAD) + return true; + + /* TDX allows only RWX. Read-only isn't supported. */ + WARN_ON_ONCE(!fault->write); + flags = FOLL_WRITE | FOLL_LONGTERM; + + npages = pin_user_pages_fast(hva, 1, flags, page); + if (npages != 1) + return true; + + fault->map_writable = true; + fault->pfn = page_to_pfn(page[0]); + return false; +} +
This function is present also in the memfd notifier series. For the next postings, can you remove all the KVM bits from the series and include it yourself?
Thanks, Paolo