All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Durrant <Paul.Durrant@citrix.com>
To: 'Jan Beulich' <JBeulich@suse.com>, Wei Liu <wei.liu2@citrix.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH 3/3] xen-netback: handle page straddling in xenvif_set_hash_mapping()
Date: Mon, 3 Sep 2018 09:28:46 +0000	[thread overview]
Message-ID: <fb15bcd613f24b9fac2d75a232ef2665__6220.39031372896$1535966851$gmane$org@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <5B85637E02000078001E2A50@prv1-mh.provo.novell.com>

> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 28 August 2018 16:00
> To: Paul Durrant <Paul.Durrant@citrix.com>; Wei Liu <wei.liu2@citrix.com>
> Cc: davem@davemloft.net; xen-devel <xen-devel@lists.xenproject.org>;
> netdev@vger.kernel.org
> Subject: [PATCH 3/3] xen-netback: handle page straddling in
> xenvif_set_hash_mapping()
> 
> There's no guarantee that the mapping array doesn't cross a page
> boundary. Use a second grant copy operation if necessary.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Personally I think it would be cleaner to out-of-line the allocation of the mapping table and ensure it is page aligned but this works so...

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> 
> ---
>  drivers/net/xen-netback/hash.c |   25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> --- 4.19-rc1-xen-netback-set-hash-mapping.orig/drivers/net/xen-
> netback/hash.c
> +++ 4.19-rc1-xen-netback-set-hash-mapping/drivers/net/xen-
> netback/hash.c
> @@ -334,28 +334,39 @@ u32 xenvif_set_hash_mapping(struct xenvi
>  			    u32 off)
>  {
>  	u32 *mapping = vif->hash.mapping[!vif->hash.mapping_sel];
> -	struct gnttab_copy copy_op = {
> +	unsigned int nr = 1;
> +	struct gnttab_copy copy_op[2] = {{
>  		.source.u.ref = gref,
>  		.source.domid = vif->domid,
>  		.dest.domid = DOMID_SELF,
>  		.len = len * sizeof(*mapping),
>  		.flags = GNTCOPY_source_gref
> -	};
> +	}};
> 
>  	if ((off + len < off) || (off + len > vif->hash.size) ||
>  	    len > XEN_PAGE_SIZE / sizeof(*mapping))
>  		return XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER;
> 
> -	copy_op.dest.u.gmfn = virt_to_gfn(mapping + off);
> -	copy_op.dest.offset = xen_offset_in_page(mapping + off);
> +	copy_op[0].dest.u.gmfn = virt_to_gfn(mapping + off);
> +	copy_op[0].dest.offset = xen_offset_in_page(mapping + off);
> +	if (copy_op[0].dest.offset + copy_op[0].len > XEN_PAGE_SIZE) {
> +		copy_op[1] = copy_op[0];
> +		copy_op[1].source.offset = XEN_PAGE_SIZE -
> copy_op[0].dest.offset;
> +		copy_op[1].dest.u.gmfn = virt_to_gfn(mapping + off + len);
> +		copy_op[1].dest.offset = 0;
> +		copy_op[1].len = copy_op[0].len - copy_op[1].source.offset;
> +		copy_op[0].len = copy_op[1].source.offset;
> +		nr = 2;
> +	}
> 
>  	memcpy(mapping, vif->hash.mapping[vif->hash.mapping_sel],
>  	       vif->hash.size * sizeof(*mapping));
> 
> -	if (copy_op.len != 0) {
> -		gnttab_batch_copy(&copy_op, 1);
> +	if (copy_op[0].len != 0) {
> +		gnttab_batch_copy(copy_op, nr);
> 
> -		if (copy_op.status != GNTST_okay)
> +		if (copy_op[0].status != GNTST_okay ||
> +		    copy_op[nr - 1].status != GNTST_okay)
>  			return
> XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER;
>  	}
> 
> 
> 
> 


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

  parent reply	other threads:[~2018-09-03  9:28 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 14:54 [PATCH 0/3] xen-netback: hash mapping hanling adjustments Jan Beulich
2018-08-28 14:59 ` [PATCH 1/3] xen-netback: fix input validation in xenvif_set_hash_mapping() Jan Beulich
2018-08-28 14:59 ` [PATCH 2/3] xen-netback: validate queue numbers " Jan Beulich
2018-08-29  8:25   ` Wei Liu
2018-08-29  8:25   ` Wei Liu
2018-09-03  9:23   ` Paul Durrant
2018-09-03  9:23   ` Paul Durrant
2018-08-28 14:59 ` Jan Beulich
2018-08-28 15:00 ` [PATCH 3/3] xen-netback: handle page straddling " Jan Beulich
2018-08-28 15:00 ` Jan Beulich
2018-08-29  8:26   ` Wei Liu
2018-08-29  8:26   ` Wei Liu
2018-09-03  9:28   ` Paul Durrant
2018-09-03  9:28   ` Paul Durrant [this message]
2018-09-11  8:12 ` [PATCH 0/3] xen-netback: hash mapping hanling adjustments Jan Beulich
2018-09-11  8:12 ` Jan Beulich
2018-09-11 10:16   ` Wei Liu
2018-09-11 10:16   ` Wei Liu
2018-09-24  7:43     ` Ping: " Jan Beulich
2018-09-24 16:49       ` David Miller
     [not found]         ` <C61B6A85020000F18A491530@prv1-mh.provo.novell.com>
2018-09-25  8:18           ` Jan Beulich
2018-09-25  8:18           ` Jan Beulich
2018-09-24 16:49       ` David Miller
2018-09-24  7:43     ` Jan Beulich
2018-09-25  8:11 ` [PATCH net 0/3 RESEND] xen-netback: hash mapping handling adjustments Jan Beulich
2018-09-25 17:40   ` David Miller
2018-09-25 17:40   ` David Miller
2018-09-25  8:11 ` Jan Beulich
2018-09-25  8:12 ` [PATCH net 1/3 RESEND] xen-netback: fix input validation in xenvif_set_hash_mapping() Jan Beulich
2018-09-25  8:12 ` Jan Beulich
2018-09-25  8:13 ` [PATCH net 2/3 RESEND] xen-netback: validate queue numbers " Jan Beulich
2018-09-25  8:13 ` Jan Beulich
2018-09-25  8:13 ` [PATCH net 3/3 RESEND] xen-netback: handle page straddling " Jan Beulich
2018-09-25  8:13 ` Jan Beulich

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='fb15bcd613f24b9fac2d75a232ef2665__6220.39031372896$1535966851$gmane$org@AMSPEX02CL03.citrite.net' \
    --to=paul.durrant@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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.