[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 5/6] libxl: support mapping static shared memory areas during domain creation



On Fri, Aug 25, 2017 at 08:02:55PM +0800, Zhongze Liu wrote:
> Hi Wei,
> 
> >> +/* The caller have to guarentee that sshm->begin < sshm->end */
> >> +static int libxl__sshm_do_map(libxl__gc *gc, uint32_t mid, uint32_t sid,
> >> +                              libxl_static_shm *sshm,
> >> +                              uint64_t mbegin, uint64_t mend)
> >> +{
> >> +    int rc;
> >> +    int i;
> >> +    unsigned int num_mpages, num_spages, offset;
> >> +    int *errs;
> >> +    xen_ulong_t *idxs;
> >> +    xen_pfn_t *gpfns;
> >> +
> >> +    num_mpages = (mend - mbegin) >> 12;
> >> +    num_spages = (sshm->end - sshm->begin) >> 12;
> >> +    offset = sshm->offset >> 12;
> >> +
> >> +    /* Check range. Test offset < mpages first to avoid overflow */
> >> +    if ((offset >= num_mpages) || (num_mpages - offset < num_spages)) {
> >> +        SSHM_ERROR(sid, sshm->id, "exceeds master's address space.");
> >> +        rc = ERROR_INVAL;
> >> +        goto out;
> >> +    }
> >> +
> >> +    /* fill out the pfn's and do the mapping */
> >> +    errs = libxl__calloc(gc, num_spages, sizeof(int));
> >> +    idxs = libxl__calloc(gc, num_spages, sizeof(xen_ulong_t));
> >> +    gpfns = libxl__calloc(gc, num_spages, sizeof(xen_pfn_t));
> >> +    for (i = 0; i < num_spages; i++) {
> >> +        idxs[i] = (mbegin >> 12) + offset + i;
> >> +        gpfns[i]= (sshm->begin >> 12) + i;
> >> +    }
> >> +    rc = xc_domain_add_to_physmap_batch(CTX->xch,
> >> +                                        sid, mid,
> >> +                                        XENMAPSPACE_gmfn_foreign,
> >> +                                        num_spages,
> >> +                                        idxs, gpfns, errs);
> >> +
> >> +    for (i = 0; i< num_spages; i++) {
> >> +        if (errs[i]) {
> >> +            SSHM_ERROR(sid, sshm->id,
> >> +                       "can't map at address 0x%"PRIx64".",
> >> +                       sshm->begin + (offset << 12) );
> >> +            rc = ERROR_FAIL;
> >> +        }
> >> +    }
> >> +    if (rc) goto out;
> >> +
> >
> > How is partial failure handled?
> 
> Em...
> If one of the pages failed, the whole domain won't be constructed. But the
> mapped pages are still occupying the refcount.
> Do you think I should continue or just throw out a warning and let to user to
> decide whether she is going to destroy it or not?

You should be able to roll back by calling remove_from_physmap if
necessary.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.