qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-char: fix tcp_get_fds
Date: Mon, 3 Nov 2014 17:19:55 +0200	[thread overview]
Message-ID: <20141103151955.GA14401@redhat.com> (raw)
In-Reply-To: <87bnoouxqn.fsf@blackfin.pond.sub.org>

On Mon, Nov 03, 2014 at 04:09:36PM +0100, Markus Armbruster wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > tcp_get_fds API discards fds if there's more than 1 of these.
> 
> s/tcp_get_fds/tcp_get_msgfds/ (subject as well)

Right. Too late as I sent this upstream :(

> What exactly doesn't work without this patch?

It's only used by vhost test. It works by chance because
it's only using 512m ram.

I tweaked vhost user test
to use more memory (3900 instead of 512 M) and it started failing
because it needs 3 fds then.

Not yet upstreaming the test change itself, looking
for ways to avoid using huge pages for this.

> > It's tricky to fix this without API changes in the generic case.
> >
> > However, this API is only used by tests ATM, and tests know how
> > many fds they expect.
> >
> > So let's not waste cycles trying to fix this properly:
> > simply assume at most 16 fds (tests use at most 8 now).
> > assert if some test tries to get more.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  qemu-char.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/qemu-char.c b/qemu-char.c
> > index bd0709b..1c4004c 100644
> > --- a/qemu-char.c
> > +++ b/qemu-char.c
> > @@ -88,6 +88,7 @@
> >  #define READ_BUF_LEN 4096
> >  #define READ_RETRIES 10
> >  #define CHR_MAX_FILENAME_SIZE 256
> > +#define TCP_MAX_FDS 16
> >  
> >  /***********************************************************/
> >  /* Socket address helpers */
> > @@ -2668,6 +2669,8 @@ static int tcp_get_msgfds(CharDriverState *chr, int *fds, int num)
> >      TCPCharDriver *s = chr->opaque;
> >      int to_copy = (s->read_msgfds_num < num) ? s->read_msgfds_num : num;
> >  
> > +    assert(num <= TCP_MAX_FDS);
> > +
> >      if (to_copy) {
> >          int i;
> >  
> 
> This where we copy received fds out of ->read_msgfds.  If someone asks
> for more than TCP_MAX_FDS, the buffer in the next hunk is insufficient.
> > @@ -2762,7 +2765,7 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len)
> >      struct iovec iov[1];
> >      union {
> >          struct cmsghdr cmsg;
> > -        char control[CMSG_SPACE(sizeof(int))];
> > +        char control[CMSG_SPACE(sizeof(int) * TCP_MAX_FDS)];
> >      } msg_control;
> >      int flags = 0;
> >      ssize_t ret;
> 
> This is where we receive the fds into ->read_msgfds.  How many depends
> on sizeof(msg_control).  One before your patch, TCP_MAX_FDS after.
> 
> Reviewed-by: Markus Armbruster <armbru@redhat.com>

  reply	other threads:[~2014-11-03 15:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02 16:53 [Qemu-devel] [PATCH] qemu-char: fix tcp_get_fds Michael S. Tsirkin
2014-11-03 15:09 ` Markus Armbruster
2014-11-03 15:19   ` Michael S. Tsirkin [this message]
2014-11-03 16:06     ` Markus Armbruster
2014-11-03 16:13     ` Markus Armbruster
2014-11-03 16:22       ` Peter Maydell
2014-11-03 16:32         ` Michael S. Tsirkin
2014-11-03 16:35         ` Michael S. Tsirkin
2014-11-04  0:17           ` Peter Maydell
2014-11-04 13:49             ` Michael S. Tsirkin
2014-11-03 16:40       ` Michael S. Tsirkin
2014-11-04  6:50         ` Markus Armbruster
2014-11-27  9:58           ` Markus Armbruster

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=20141103151955.GA14401@redhat.com \
    --to=mst@redhat.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 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).