aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChirantan Ekbote <chirantan@chromium.org>2018-07-16 20:35:29 -0400
committerDominique Martinet <dominique.martinet@cea.fr>2018-08-12 20:34:59 -0400
commitd28c756caee6e414d9ba367d0b92da24145af2a8 (patch)
treefab71e301177f94c5353f1e05b5d7114090fc25c
parent2557d0c57c0c11af915d0d4d97402527958c0c01 (diff)
9p/net: Fix zero-copy path in the 9p virtio transport
The zero-copy optimization when reading or writing large chunks of data is quite useful. However, the 9p messages created through the zero-copy write path have an incorrect message size: it should be the size of the header + size of the data being written but instead it's just the size of the header. This only works if the server ignores the size field of the message and otherwise breaks the framing of the protocol. Fix this by re-writing the message size field with the correct value. Tested by running `dd if=/dev/zero of=out bs=4k count=1` inside a virtio-9p mount. Link: http://lkml.kernel.org/r/20180717003529.114368-1-chirantan@chromium.org Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Greg Kurz <groug@kaod.org> Tested-by: Greg Kurz <groug@kaod.org> Cc: Dylan Reid <dgreid@chromium.org> Cc: Guenter Roeck <groeck@chromium.org> Cc: stable@vger.kernel.org Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr>
-rw-r--r--net/9p/trans_virtio.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 3f69c428ddf9..bf61ca20e6a5 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -406,6 +406,7 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
406 p9_debug(P9_DEBUG_TRANS, "virtio request\n"); 406 p9_debug(P9_DEBUG_TRANS, "virtio request\n");
407 407
408 if (uodata) { 408 if (uodata) {
409 __le32 sz;
409 int n = p9_get_mapped_pages(chan, &out_pages, uodata, 410 int n = p9_get_mapped_pages(chan, &out_pages, uodata,
410 outlen, &offs, &need_drop); 411 outlen, &offs, &need_drop);
411 if (n < 0) 412 if (n < 0)
@@ -416,6 +417,12 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
416 memcpy(&req->tc->sdata[req->tc->size - 4], &v, 4); 417 memcpy(&req->tc->sdata[req->tc->size - 4], &v, 4);
417 outlen = n; 418 outlen = n;
418 } 419 }
420 /* The size field of the message must include the length of the
421 * header and the length of the data. We didn't actually know
422 * the length of the data until this point so add it in now.
423 */
424 sz = cpu_to_le32(req->tc->size + outlen);
425 memcpy(&req->tc->sdata[0], &sz, sizeof(sz));
419 } else if (uidata) { 426 } else if (uidata) {
420 int n = p9_get_mapped_pages(chan, &in_pages, uidata, 427 int n = p9_get_mapped_pages(chan, &in_pages, uidata,
421 inlen, &offs, &need_drop); 428 inlen, &offs, &need_drop);