From: "Jan Beulich" Subject: Re: [PATCH v3 3/3] xen: introduce XENMEM_get_dma_buf and XENMEM_put_dma_buf Date: Thu, 08 Aug 2013 12:43:43 +0100 Message-ID: <5203A08F02000078000EA415@nat28.tlf.novell.com> References: <1375720856-8593-3-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1V7Od8-000819-Dm for xen-devel@lists.xenproject.org; Thu, 08 Aug 2013 11:43:46 +0000 In-Reply-To: <1375720856-8593-3-git-send-email-stefano.stabellini@eu.citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: xen-devel , tim@xen.org, Ian.Campbell@citrix.com List-Id: xen-devel@lists.xenproject.org >>> On 05.08.13 at 18:40, Stefano Stabellini wrote: > @@ -496,7 +496,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) > mfn = page_to_mfn(page); > guest_physmap_add_page(d, gpfn, mfn, exch.out.extent_order); > > - if ( !paging_mode_translate(d) ) > + if ( op == XENMEM_get_dma_buf || !paging_mode_translate(d) ) This is bogus: Whether the translation tables need updating here shouldn't depend on the operation. > @@ -505,6 +505,18 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) > &mfn, 1) ) > rc = -EFAULT; > } > + > + if ( op == XENMEM_get_dma_buf ) > + { > + static int warning; bool_t. Missing blank line. And this should go into the next scope, or the two if-s should be combined. > + if ( guest_physmap_pin_range(d, gpfn, exch.out.extent_order) ) > + { > + if (!warning) { Coding style. > + gdprintk(XENLOG_WARNING, "guest_physmap_pin_range not implemented\n"); Is "not implemented" really the only failure mode? > +static long put_dma_buf(XEN_GUEST_HANDLE_PARAM(xen_put_dma_buf_t) arg) > +{ > + int rc, i; Please no signed variables for loops having an unsigned upper bound. Even more, the bound is xen_ulong_t, i.e. the loop below may end up running forever on 64-bit at least. > @@ -630,8 +690,15 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) > > break; > > + case XENMEM_get_dma_buf: > + /* xen_get_dma_buf_t is identical to xen_memory_exchange_t, so > + * just cast it and reuse memory_exchange */ Then why do you define a new type for it in the first place? And anyway, the naming of the new sub-op isn't really representing what the operation is capable of. XENMEM_exchange_and_pin would seem to come much closer. > case XENMEM_exchange: > - rc = memory_exchange(guest_handle_cast(arg, xen_memory_exchange_t)); > + rc = memory_exchange(op, guest_handle_cast(arg, xen_memory_exchange_t)); > + break; > + > + case XENMEM_put_dma_buf: > + rc = put_dma_buf(guest_handle_cast(arg, xen_put_dma_buf_t)); And similarly this should be XENMEM_unpin or some such. > --- a/xen/include/public/memory.h > +++ b/xen/include/public/memory.h > @@ -459,6 +459,70 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t); > * The zero value is appropiate. > */ > > +#define XENMEM_get_dma_buf 26 > +/* > + * This hypercall is similar to XENMEM_exchange: it exchanges the pages > + * passed in with a new set of pages, contiguous and under 4G if so The mentioning of 4G here is pointless - the hypercall can do all sorts of address range restriction, so why mention this special case? Jan