[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v5 3/4] xen: implement guest_physmap_pin_range and guest_physmap_unpin_range
On Mon, 2013-09-09 at 17:06 +0100, Stefano Stabellini wrote: > guest_physmap_pin_range pins a range of guest pages so that their p2m > mappings won't be changed. > guest_physmap_unpin_range unpins the previously pinned pages. > The pinning is done using one of the spare bits in the p2m ptes. > > Use the newly introduce p2m_walker to implement the two functions on > ARM. > Provide empty stubs for x86. > > > Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> > > > Changes in v5: > - return -EBUSY when the P2M_DMA_PIN check fails; > - rename _guest_physmap_pin_range to pin_one_pte; > - rename _guest_physmap_unpin_range to unpin_one_pte. > > Changes in v4: > - use p2m_walker to implement guest_physmap_pin_range and > guest_physmap_unpin_range; > - return -EINVAL when the P2M_DMA_PIN check fails; > - change the printk into a gdprintk; > - add a comment on what type of page can be pinned. > --- > xen/arch/arm/p2m.c | 48 > ++++++++++++++++++++++++++++++++++++++++++++ > xen/include/asm-arm/mm.h | 4 +++ > xen/include/asm-arm/page.h | 7 +++++- > xen/include/asm-x86/p2m.h | 12 +++++++++++ > 4 files changed, 70 insertions(+), 1 deletions(-) > > diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c > index a9ceacf..bac6c7e 100644 > --- a/xen/arch/arm/p2m.c > +++ b/xen/arch/arm/p2m.c > @@ -154,6 +154,46 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr) > return p2m.maddr; > } > > +static int pin_one_pte(lpae_t *ptep, void *arg, int level) > +{ > + lpae_t pte = *ptep; > + ASSERT(level == 3); > + > + if ( pte.p2m.avail & P2M_DMA_PIN ) > + return -EBUSY; > + pte.p2m.avail |= P2M_DMA_PIN; > + write_pte(ptep, pte); > + return 0; > +} > + > +int guest_physmap_pin_range(struct domain *d, > + xen_pfn_t gpfn, > + unsigned int order) > +{ > + return p2m_walker(d, gpfn << PAGE_SHIFT, order, > + pin_one_pte, NULL); If this fails then you will have left some subset of the pages successfully pinned. You need to clean it up I think, or be fatal to the guest or something. > +} > + > +static int unpin_one_pte(lpae_t *ptep, void *arg, int level) > +{ > + lpae_t pte = *ptep; > + ASSERT(level == 3); > + > + if ( !pte.p2m.avail & P2M_DMA_PIN ) > + return -EBUSY; The error here is that it isn't busy. EINVAL perhaps? > + pte.p2m.avail &= ~P2M_DMA_PIN; > + write_pte(ptep, pte); > + return 0; > +} > + > +int guest_physmap_unpin_range(struct domain *d, > + xen_pfn_t gpfn, > + unsigned int order) > +{ > + return p2m_walker(d, gpfn << PAGE_SHIFT, order, > + unpin_one_pte, NULL); > +} > + > int guest_physmap_mark_populate_on_demand(struct domain *d, > unsigned long gfn, > unsigned int order) > @@ -263,6 +303,14 @@ static int create_p2m_entries(struct domain *d, > cur_second_offset = second_table_offset(addr); > } > > + if ( third[third_table_offset(addr)].p2m.avail & P2M_DMA_PIN ) > + { > + rc = -EINVAL; > + gdprintk(XENLOG_WARNING, "cannot change p2m mapping for > paddr=%"PRIpaddr > + " domid=%d, the page is pinned\n", addr, d->domain_id); > + goto out; > + } > + > flush = third[third_table_offset(addr)].p2m.valid; > > /* Allocate a new RAM page and attach */ > diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h > index 41e9eff..c08cfca 100644 > --- a/xen/include/asm-arm/page.h > +++ b/xen/include/asm-arm/page.h > @@ -153,11 +153,16 @@ typedef struct { > unsigned long hint:1; /* In a block of 16 contiguous entries */ > unsigned long sbz2:1; > unsigned long xn:1; /* eXecute-Never */ > - unsigned long avail:4; /* Ignored by hardware */ > + unsigned long avail:4; /* Ignored by hardware, see below */ > > unsigned long sbz1:5; > } __attribute__((__packed__)) lpae_p2m_t; > > +/* Xen "avail" bits allocation in third level entries */ > +#define P2M_DMA_PIN (1<<0) /* The page has been "pinned": the hypervisor > + promises not to change the p2m mapping. > + Only normal r/w guest RAM can be pinned. > */ Where is that last requirement enforced? > + > /* > * Walk is the common bits of p2m and pt entries which are needed to > * simply walk the table (e.g. for debug). _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |