From: Stefano Stabellini <sstabellini@kernel.org>
To: Greg Kurz <groug@kaod.org>
Cc: anthony.perard@citrix.com,
Stefano Stabellini <sstabellini@kernel.org>,
Christian Schoenebeck <qemu_oss@crudebyte.com>,
qemu-devel@nongnu.org,
Stefano Stabellini <stefano.stabellini@xilinx.com>
Subject: Re: [PATCH] 9p: init_in_iov_from_pdu can truncate the size
Date: Mon, 6 Jan 2020 11:30:46 -0800 (PST) [thread overview]
Message-ID: <alpine.DEB.2.21.2001061115110.732@sstabellini-ThinkPad-T480s> (raw)
In-Reply-To: <20200106183114.6b1a4de4@bahia.lan>
On Mon, 6 Jan 2020, Greg Kurz wrote:
> On Mon, 06 Jan 2020 16:24:18 +0100
> Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
>
> > On Montag, 6. Januar 2020 14:42:54 CET Greg Kurz wrote:
> > > > diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> > > > index 775e8ff766..68873c3f5f 100644
> > > > --- a/hw/9pfs/virtio-9p-device.c
> > > > +++ b/hw/9pfs/virtio-9p-device.c
> > > > @@ -145,19 +145,15 @@ static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu,
> > > > size_t offset,>
> > > > }
> > > >
> > > > static void virtio_init_in_iov_from_pdu(V9fsPDU *pdu, struct iovec
> > > > **piov,
> > > >
> > > > - unsigned int *pniov, size_t size)
> > > > + unsigned int *pniov, size_t
> > > > *size)
> > > >
> > > > {
> > > >
> > > > V9fsState *s = pdu->s;
> > > > V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
> > > > VirtQueueElement *elem = v->elems[pdu->idx];
> > > > size_t buf_size = iov_size(elem->in_sg, elem->in_num);
> > > >
> > > > - if (buf_size < size) {
> > > > - VirtIODevice *vdev = VIRTIO_DEVICE(v);
> > > > -
> > > > - virtio_error(vdev,
> > > > - "VirtFS reply type %d needs %zu bytes, buffer has
> > > > %zu", - pdu->id + 1, size, buf_size);
> > > > + if (buf_size < *size) {
> > > > + *size = buf_size;
> > > >
> > > > }
> > >
> > > As suggested by Christian in some other mail, it could still make sense to
> > > raise the error if there isn't even enough space to pack a 9p message
> > > header.
> >
> > Another option: Instead of handling this as a hard error (which they probably
> > try to avoid in their use case): putting the handler asleep for a while by
> > calling qemu_co_sleep_ns_wakeable() in this case. Then a bit later transport
> > would eventually have the required buffer size and handler could continue the
> > request without an error.
> >
>
> Waiting for an arbitrary amount of time (how much?) and retrying doesn't give
> any guarantee either that things will go smoothly. If anything, I'd rather have
> the transport to wake up the request when more buffer space gets available.
>
> > But this would require more care. For instance subsequent request handlers
> > would need to check if there was already an event handler asleep, and if so it
> > would either need to wake it up or put itself asleep as well to prevent the
> > request order being processed by server being messed up.
> >
>
> And so on... ie. we would need to handle a queue of sleeping requests IIUC.
> Not really fan to go this way to address what looks like a corner case.
I agree with you that handling requests queuing is complex and overkill
for this. As I don't have a better suggestion, I am going to go with
retaining the error if the allocated buf_size is less than P9_IOHDRSZ.
prev parent reply other threads:[~2020-01-06 19:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-19 0:42 [PATCH] 9p: init_in_iov_from_pdu can truncate the size Stefano Stabellini
2019-12-19 17:08 ` Christian Schoenebeck
2019-12-19 22:36 ` Stefano Stabellini
2019-12-20 12:31 ` Christian Schoenebeck
2020-01-06 13:42 ` Greg Kurz
2020-01-06 15:24 ` Christian Schoenebeck
2020-01-06 17:31 ` Greg Kurz
2020-01-06 19:30 ` Stefano Stabellini [this message]
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.21.2001061115110.732@sstabellini-ThinkPad-T480s \
--to=sstabellini@kernel.org \
--cc=anthony.perard@citrix.com \
--cc=groug@kaod.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu_oss@crudebyte.com \
--cc=stefano.stabellini@xilinx.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).