All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thanos Makatos <thanos.makatos@nutanix.com>
To: Thanos Makatos <thanos.makatos@nutanix.com>,
	John Johnson <john.g.johnson@oracle.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: RE: [RFC v4 08/21] vfio-user: define socket receive functions
Date: Tue, 15 Feb 2022 14:50:24 +0000	[thread overview]
Message-ID: <DM8PR02MB80052AF463504BB4BBA397F48B349@DM8PR02MB8005.namprd02.prod.outlook.com> (raw)
In-Reply-To: <DM8PR02MB8005963C1D2E796FB7420FBC8B349@DM8PR02MB8005.namprd02.prod.outlook.com>

> > +/*
> > + * Receive and process one incoming message.
> > + *
> > + * For replies, find matching outgoing request and wake any waiters.
> > + * For requests, queue in incoming list and run request BH.
> > + */
> > +static int vfio_user_recv_one(VFIOProxy *proxy)
> > +{
> > +    VFIOUserMsg *msg = NULL;
> > +    g_autofree int *fdp = NULL;
> > +    VFIOUserFDs *reqfds;
> > +    VFIOUserHdr hdr;
> > +    struct iovec iov = {
> > +        .iov_base = &hdr,
> > +        .iov_len = sizeof(hdr),
> > +    };
> > +    bool isreply = false;
> > +    int i, ret;
> > +    size_t msgleft, numfds = 0;
> > +    char *data = NULL;
> > +    char *buf = NULL;
> > +    Error *local_err = NULL;
> > +
> > +    /*
> > +     * Read header
> > +     */
> > +    ret = qio_channel_readv_full(proxy->ioc, &iov, 1, &fdp, &numfds,
> > +                                 &local_err);
> > +    if (ret == QIO_CHANNEL_ERR_BLOCK) {
> > +        return ret;
> > +    }
> > +    if (ret <= 0) {
> > +        /* read error or other side closed connection */
> > +        if (ret == 0) {
> > +            error_setg(&local_err, "vfio_user_recv server closed socket");
> > +        } else {
> > +            error_prepend(&local_err, "vfio_user_recv");
> > +        }
> > +        goto fatal;
> > +    }
> > +    if (ret < sizeof(msg)) {
> > +        error_setg(&local_err, "vfio_user_recv short read of header");
> > +        goto fatal;
> > +    }
> 
> Print received size for debug purposes?
> 
> > +
> > +    /*
> > +     * Validate header
> > +     */
> > +    if (hdr.size < sizeof(VFIOUserHdr)) {
> > +        error_setg(&local_err, "vfio_user_recv bad header size");
> > +        goto fatal;
> > +    }
> 
> Print header size?
> 
> > +    switch (hdr.flags & VFIO_USER_TYPE) {
> > +    case VFIO_USER_REQUEST:
> > +        isreply = false;
> > +        break;
> > +    case VFIO_USER_REPLY:
> > +        isreply = true;
> > +        break;
> > +    default:
> > +        error_setg(&local_err, "vfio_user_recv unknown message type");
> > +        goto fatal;
> > +    }
> 
> Print message type?
> 
> > +
> > +    /*
> > +     * For replies, find the matching pending request.
> > +     * For requests, reap incoming FDs.
> > +     */
> > +    if (isreply) {
> > +        QTAILQ_FOREACH(msg, &proxy->pending, next) {
> > +            if (hdr.id == msg->id) {
> > +                break;
> > +            }
> > +        }
> > +        if (msg == NULL) {
> > +            error_setg(&local_err, "vfio_user_recv unexpected reply");
> > +            goto err;
> > +        }
> > +        QTAILQ_REMOVE(&proxy->pending, msg, next);
> > +
> > +        /*
> > +         * Process any received FDs
> > +         */
> > +        if (numfds != 0) {
> > +            if (msg->fds == NULL || msg->fds->recv_fds < numfds) {
> > +                error_setg(&local_err, "vfio_user_recv unexpected FDs");
> > +                goto err;
> > +            }
> > +            msg->fds->recv_fds = numfds;
> > +            memcpy(msg->fds->fds, fdp, numfds * sizeof(int));
> > +        }
> > +    } else {
> > +        if (numfds != 0) {
> > +            reqfds = vfio_user_getfds(numfds);
> > +            memcpy(reqfds->fds, fdp, numfds * sizeof(int));
> > +        } else {
> > +            reqfds = NULL;
> > +        }
> > +    }
> > +
> > +    /*
> > +     * Put the whole message into a single buffer.
> > +     */
> > +    if (isreply) {
> > +        if (hdr.size > msg->rsize) {
> > +            error_setg(&local_err,
> > +                       "vfio_user_recv reply larger than recv buffer");
> > +            goto err;
> > +        }
> 
> Print hdr.size and msg->rsize?
> 
> > +        *msg->hdr = hdr;
> > +        data = (char *)msg->hdr + sizeof(hdr);
> > +    } else {
> > +        if (hdr.size > max_xfer_size) {
> > +            error_setg(&local_err, "vfio_user_recv request larger than max");
> > +            goto err;
> > +        }
> 
> Print hdr.size?

On second thought, should we dump the entire header in case of such errors? If not by default then at least in debug builds?

  reply	other threads:[~2022-02-15 14:53 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12  0:43 [RFC v4 00/21] vfio-user client John Johnson
2022-01-12  0:43 ` [RFC v4 01/21] vfio-user: introduce vfio-user protocol specification John Johnson
2022-02-14 13:10   ` Thanos Makatos
2022-03-09 22:34   ` Alex Williamson
2022-03-10 10:20     ` John Levon
2022-03-14  6:04     ` John Johnson
2022-03-15 21:43     ` Thanos Makatos
2022-03-15 22:28       ` Alex Williamson
2022-07-22  6:23     ` John Johnson
2022-01-12  0:43 ` [RFC v4 02/21] vfio-user: add VFIO base abstract class John Johnson
2022-01-12  0:43 ` [RFC v4 03/21] vfio-user: add container IO ops vector John Johnson
2022-01-12  0:43 ` [RFC v4 04/21] vfio-user: add region cache John Johnson
2022-03-09 23:40   ` Alex Williamson
2022-01-12  0:43 ` [RFC v4 05/21] vfio-user: add device IO ops vector John Johnson
2022-01-12  0:43 ` [RFC v4 06/21] vfio-user: Define type vfio_user_pci_dev_info John Johnson
2022-01-12  0:43 ` [RFC v4 07/21] vfio-user: connect vfio proxy to remote server John Johnson
2022-01-12  0:43 ` [RFC v4 08/21] vfio-user: define socket receive functions John Johnson
2022-02-03 21:53   ` Thanos Makatos
2022-02-04 12:42     ` Thanos Makatos
2022-02-07  7:07       ` John Johnson
2022-02-15 13:35   ` Thanos Makatos
2022-02-15 14:50     ` Thanos Makatos [this message]
2022-02-16  2:09       ` John Johnson
2022-02-16  9:31         ` Thanos Makatos
2022-01-12  0:43 ` [RFC v4 09/21] vfio-user: define socket send functions John Johnson
2022-01-26 10:17   ` Thanos Makatos
2022-02-07  7:09     ` John Johnson
2022-01-12  0:43 ` [RFC v4 10/21] vfio-user: get device info John Johnson
2022-01-12  0:43 ` [RFC v4 11/21] vfio-user: get region info John Johnson
2022-01-12  0:43 ` [RFC v4 12/21] vfio-user: region read/write John Johnson
2022-01-26 21:57   ` Thanos Makatos
2022-01-12  0:43 ` [RFC v4 13/21] vfio-user: pci_user_realize PCI setup John Johnson
2022-01-12  0:43 ` [RFC v4 14/21] vfio-user: get and set IRQs John Johnson
2022-01-12  0:43 ` [RFC v4 15/21] vfio-user: proxy container connect/disconnect John Johnson
2022-01-12  0:43 ` [RFC v4 16/21] vfio-user: dma map/unmap operations John Johnson
2022-01-12  0:43 ` [RFC v4 17/21] vfio-user: secure DMA support John Johnson
2022-01-12  0:43 ` [RFC v4 18/21] vfio-user: dma read/write operations John Johnson
2022-01-12  0:43 ` [RFC v4 19/21] vfio-user: pci reset John Johnson
2022-01-12  0:43 ` [RFC v4 20/21] vfio-user: migration support John Johnson
2022-02-11 13:31   ` Thanos Makatos
2022-02-14 18:50     ` John Johnson
2022-02-15 14:53       ` Thanos Makatos
2022-01-12  0:43 ` [RFC v4 21/21] Only set qemu file error if saving state so the file exists John Johnson

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=DM8PR02MB80052AF463504BB4BBA397F48B349@DM8PR02MB8005.namprd02.prod.outlook.com \
    --to=thanos.makatos@nutanix.com \
    --cc=john.g.johnson@oracle.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 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.