On Tue, Sep 17, 2019 at 04:31:39PM -0700, Sukadev Bhattiprolu wrote: > > Minor: Can this allocation be outside the lock? I guess it would change > the order of cleanup at the end of the function. Cleanup has bitmap_clear which needs be under spinlock, so this order of setup/alloc and cleanup will keep things simple is what I felt. > > > + spin_unlock(&kvmppc_uvmem_pfn_lock); > > + > > + *rmap = uvmem_pfn | KVMPPC_RMAP_UVMEM_PFN; > > + pvt->rmap = rmap; > > + pvt->gpa = gpa; > > + pvt->lpid = lpid; > > + dpage->zone_device_data = pvt; > > + > > + get_page(dpage); > > + return dpage; > > + > > +out_unlock: > > + unlock_page(dpage); > > +out_clear: > > + bitmap_clear(kvmppc_uvmem_pfn_bitmap, uvmem_pfn - pfn_first, 1); > > Reuse variable 'bit' here? Sure. > > > +out: > > + spin_unlock(&kvmppc_uvmem_pfn_lock); > > + return NULL; > > +} > > + > > +/* > > + * Alloc a PFN from private device memory pool and copy page from normal > > + * memory to secure memory using UV_PAGE_IN uvcall. > > + */ > > +static int > > +kvmppc_svm_page_in(struct vm_area_struct *vma, unsigned long start, > > + unsigned long end, unsigned long *rmap, > > + unsigned long gpa, unsigned int lpid, > > + unsigned long page_shift) > > +{ > > + unsigned long src_pfn, dst_pfn = 0; > > + struct migrate_vma mig; > > + struct page *spage; > > + unsigned long pfn; > > + struct page *dpage; > > + int ret = 0; > > + > > + memset(&mig, 0, sizeof(mig)); > > + mig.vma = vma; > > + mig.start = start; > > + mig.end = end; > > + mig.src = &src_pfn; > > + mig.dst = &dst_pfn; > > + > > + ret = migrate_vma_setup(&mig); > > + if (ret) > > + return ret; > > + > > + spage = migrate_pfn_to_page(*mig.src); > > + pfn = *mig.src >> MIGRATE_PFN_SHIFT; > > + if (!spage || !(*mig.src & MIGRATE_PFN_MIGRATE)) { > > + ret = 0; > > Do we want to return success here (and have caller return H_SUCCESS) if > we can't find the source page? spage is NULL for zero page. In this case we return success but there is no UV_PAGE_IN involved. Absence of MIGRATE_PFN_MIGRATE indicates that the requested page can't be migrated. I haven't hit this case till now. Similar check is also present in the nouveau driver. I am not sure if this is strictly needed here. Christoph, Jason - do you know if !(*mig.src & MIGRATE_PFN_MIGRATE) check is required and if so in which cases will it be true? > > + * Fault handler callback when HV touches any page that has been > > Nit: s/callback/callback. Called / Yeah will rephrase. Regards, Bharata.