All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Julien Grall <julien.grall@linaro.org>
Cc: sstabellini@kernel.org, andre.przywara@linaro.org,
	xen-devel@lists.xen.org
Subject: Re: [v2 02/16] xen/arm: raw_copy_to_guest_helper: Rework the prototype and rename it
Date: Tue, 12 Dec 2017 11:51:20 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1712121151120.8052@sstabellini-ThinkPad-X260> (raw)
In-Reply-To: <20171212190212.5535-3-julien.grall@linaro.org>

On Tue, 12 Dec 2017, Julien Grall wrote:
> All the helpers within arch/arm/guestcopy.c are doing the same things:
> copy data from/to the guest.
> 
> At the moment, the logic is duplicated in each helpers making more
> difficult to implement new variant.
> 
> The first step for the consolidation is to get a common prototype and a
> base. For convenience (it is at the beginning of the file!),
> raw_copy_to_guest_helper is chosen.
> 
> The function is now renamed copy_guest to show it will be a
> generic function to copy data from/to the guest. Note that for now, only
> copying to guest virtual address is supported. Follow-up patches will
> extend the support.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>     Changes in v2:
>         - Use vaddr_t
>         - Use uint64_t for addr in copy_guest
>         - Add a BUILD_BUG_ON to make sure vaddr_t fit in uint64_t.
> ---
>  xen/arch/arm/guestcopy.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c
> index 2620e659b4..08d0fa0a83 100644
> --- a/xen/arch/arm/guestcopy.c
> +++ b/xen/arch/arm/guestcopy.c
> @@ -7,11 +7,13 @@
>  
>  #define COPY_flush_dcache   (1U << 0)
>  
> -static unsigned long raw_copy_to_guest_helper(void *to, const void *from,
> -                                              unsigned len, int flags)
> +static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
> +                                unsigned int flags)
>  {
>      /* XXX needs to handle faults */
> -    unsigned offset = (vaddr_t)to & ~PAGE_MASK;
> +    unsigned offset = addr & ~PAGE_MASK;
> +
> +    BUILD_BUG_ON((sizeof(addr)) < sizeof(vaddr_t));
>  
>      while ( len )
>      {
> @@ -19,21 +21,21 @@ static unsigned long raw_copy_to_guest_helper(void *to, const void *from,
>          unsigned size = min(len, (unsigned)PAGE_SIZE - offset);
>          struct page_info *page;
>  
> -        page = get_page_from_gva(current, (vaddr_t) to, GV2M_WRITE);
> +        page = get_page_from_gva(current, addr, GV2M_WRITE);
>          if ( page == NULL )
>              return len;
>  
>          p = __map_domain_page(page);
>          p += offset;
> -        memcpy(p, from, size);
> +        memcpy(p, buf, size);
>          if ( flags & COPY_flush_dcache )
>              clean_dcache_va_range(p, size);
>  
>          unmap_domain_page(p - offset);
>          put_page(page);
>          len -= size;
> -        from += size;
> -        to += size;
> +        buf += size;
> +        addr += size;
>          /*
>           * After the first iteration, guest virtual address is correctly
>           * aligned to PAGE_SIZE.
> @@ -46,13 +48,13 @@ static unsigned long raw_copy_to_guest_helper(void *to, const void *from,
>  
>  unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len)
>  {
> -    return raw_copy_to_guest_helper(to, from, len, 0);
> +    return copy_guest((void *)from, (vaddr_t)to, len, 0);
>  }
>  
>  unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
>                                               unsigned len)
>  {
> -    return raw_copy_to_guest_helper(to, from, len, COPY_flush_dcache);
> +    return copy_guest((void *)from, (vaddr_t)to, len, COPY_flush_dcache);
>  }
>  
>  unsigned long raw_clear_guest(void *to, unsigned len)
> -- 
> 2.11.0
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2017-12-12 19:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-12 19:01 [v2 00/16] xen/arm: Stage-2 handling cleanup Julien Grall
2017-12-12 19:01 ` [v2 01/16] xen/arm: raw_copy_to_guest_helper: Rename flush_dcache to flags Julien Grall
2017-12-12 19:01 ` [v2 02/16] xen/arm: raw_copy_to_guest_helper: Rework the prototype and rename it Julien Grall
2017-12-12 19:51   ` Stefano Stabellini [this message]
2017-12-12 19:01 ` [v2 03/16] xen/arm: Extend copy_to_guest to support copying from guest VA and use it Julien Grall
2017-12-12 19:54   ` Stefano Stabellini
2017-12-12 19:02 ` [v2 04/16] xen/arm: Extend copy_to_guest to support zeroing " Julien Grall
2017-12-12 19:57   ` Stefano Stabellini
2017-12-12 19:02 ` [v2 05/16] xen/arm: guest_copy: Extend the prototype to pass the vCPU Julien Grall
2017-12-12 20:00   ` Stefano Stabellini
2017-12-12 19:02 ` [v2 06/16] xen/arm: Extend copy_to_guest to support copying from/to guest physical address Julien Grall
2017-12-12 20:06   ` Stefano Stabellini
2017-12-12 19:02 ` [v2 07/16] xen/arm: Introduce copy_to_guest_phys_flush_dcache Julien Grall
2017-12-12 20:10   ` Stefano Stabellini
2017-12-12 19:02 ` [v2 08/16] xen/arm: kernel: Rework kernel_zimage_load to use the generic copy helper Julien Grall
2017-12-12 19:02 ` [v2 09/16] xen/arm: domain_build: Rework initrd_load " Julien Grall
2017-12-12 19:02 ` [v2 10/16] xen/arm: domain_build: Use copy_to_guest_phys_flush_dcache in dtb_load Julien Grall
2017-12-12 19:02 ` [v2 11/16] xen/arm: p2m: Rename p2m_flush_tlb and p2m_flush_tlb_sync Julien Grall
2017-12-12 19:02 ` [v2 12/16] xen/arm: p2m: Introduce p2m_tlb_flush_sync, export it and use it Julien Grall
2017-12-12 19:02 ` [v2 13/16] xen/arm: p2m: Fold p2m_tlb_flush into p2m_force_tlb_flush_sync Julien Grall
2017-12-12 19:02 ` [v2 14/16] xen/arm: traps: Remove the field gva from mmio_info_t Julien Grall
2017-12-12 19:02 ` [v2 15/16] xen/arm: traps: Move the definition of mmio_info_t in try_handle_mmio Julien Grall
2017-12-12 19:02 ` [v2 16/16] xen/arm: traps: Merge do_trap_instr_abort_guest and do_trap_data_abort_guest Julien Grall
2017-12-12 20:11   ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.10.1712121151120.8052@sstabellini-ThinkPad-X260 \
    --to=sstabellini@kernel.org \
    --cc=andre.przywara@linaro.org \
    --cc=julien.grall@linaro.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.