From: Stefan Hajnoczi <stefanha@gmail.com>
To: Changpeng Liu <changpeng.liu@intel.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com,
sgazare@redhat.com
Subject: Re: [Qemu-devel] [PATCH] vhost-user-blk: enable discard/write zeroes features
Date: Mon, 14 Jan 2019 10:41:47 +0000 [thread overview]
Message-ID: <20190114104147.GC7038@stefanha-x1.localdomain> (raw)
In-Reply-To: <1547451317-21375-1-git-send-email-changpeng.liu@intel.com>
[-- Attachment #1: Type: text/plain, Size: 2755 bytes --]
On Mon, Jan 14, 2019 at 03:35:17PM +0800, Changpeng Liu wrote:
> Linux commit 1f23816b8 "virtio_blk: add discard and write zeroes support"
> added the support in the Guest kernel, while here enable the feature bits
> support with vhost-user-blk driver. Also enable the test example utility
> with DISCARD command support.
The commit message mentions write zeroes but this patch only covers
discard. Will you send a separate patch for write zeros?
> Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
CCed Stefano, who is working on hw/block/virtio-blk.c emulation support.
> @@ -157,6 +161,29 @@ vub_writev(VubReq *req, struct iovec *iov, uint32_t iovcnt)
> return rc;
> }
>
> +static int
> +vub_discard(VubReq *req, struct iovec *iov, uint32_t iovcnt)
> +{
> + if (iovcnt != 1) {
This is a virtio specification violation. The iovec layout is
intentionally not part of the specification, leaving the guest driver
free to choose its preferred layout.
The device backend must accept any layout, including splitting a struct
across iovecs or even many small iovecs of just 1 byte!
> + fprintf(stderr, "Invalid Discard IOV count\n");
> + return -1;
> + }
> +
> + #if defined(__linux__) && defined(BLKDISCARD)
> + VubDev *vdev_blk = req->vdev_blk;
> + struct virtio_blk_discard_write_zeroes *desc =
> + (struct virtio_blk_discard_write_zeroes *)iov->iov_base;
Missing input size check. Even if this example isn't used in
production, it's important to validate inputs since other people will
implement their vhost-user backend based on this example.
Please check that sizeof(*desc) bytes are really available before
accessing it.
> + case VIRTIO_BLK_T_DISCARD: {
> + int rc;
> + rc = vub_discard(req, &elem->out_sg[1], out_num);
> + if (rc == 0) {
> req->in->status = VIRTIO_BLK_S_OK;
> - req->size = elem->in_sg[0].iov_len;
> - vub_req_complete(req);
> - break;
> - }
> - default: {
> + } else {
> req->in->status = VIRTIO_BLK_S_UNSUPP;
Is there no IOERR case? BLKDISCARD can probably fail due to an I/O
error and that shouldn't be reported as UNSUPP.
> @@ -454,7 +492,7 @@ vub_get_blocksize(int fd)
>
> #if defined(__linux__) && defined(BLKSSZGET)
> if (ioctl(fd, BLKSSZGET, &blocksize) == 0) {
> - return blocklen;
> + return blocksize;
> }
> #endif
Unrelated bug fix? Please submit a separate patch.
Do you know why the patchew, Travis, etc continuous integration systems
didn't detect the compile error? Please ensure that
contrib/vhost-user-blk/ is covered by CI.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2019-01-14 10:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-14 7:35 [Qemu-devel] [PATCH] vhost-user-blk: enable discard/write zeroes features Changpeng Liu
2019-01-14 10:41 ` Stefan Hajnoczi [this message]
2019-01-15 2:32 ` Liu, Changpeng
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=20190114104147.GC7038@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=changpeng.liu@intel.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgazare@redhat.com \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).