From: "Cédric Le Goater" <clg@redhat.com>
To: Mark Cave-Ayland <mark.caveayland@nutanix.com>,
John Levon <john.levon@nutanix.com>,
qemu-devel@nongnu.org
Cc: Thanos Makatos <thanos.makatos@nutanix.com>,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [PATCH v3 3/5] vfio-user: refactor out header handling
Date: Wed, 3 Dec 2025 08:40:39 +0100 [thread overview]
Message-ID: <e5d2d505-009e-412e-b032-8b80af493d32@redhat.com> (raw)
In-Reply-To: <b7a282bc-bd97-4101-bf88-b69aef59eb54@nutanix.com>
Hello John,
On 12/2/25 11:53, Mark Cave-Ayland wrote:
> On 01/12/2025 09:56, John Levon wrote:
>
>> Simplify vfio_user_recv_one() by moving the header handling out to a
>> helper function.
>>
>> Signed-off-by: John Levon <john.levon@nutanix.com>
>> ---
>> hw/vfio-user/proxy.c | 101 +++++++++++++++++++++++++------------------
>> 1 file changed, 60 insertions(+), 41 deletions(-)
>>
>> diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c
>> index 82c76c6665..87e50501af 100644
>> --- a/hw/vfio-user/proxy.c
>> +++ b/hw/vfio-user/proxy.c
>> @@ -218,6 +218,61 @@ static int vfio_user_complete(VFIOUserProxy *proxy, Error **errp)
>> return 1;
>> }
>> +static int vfio_user_recv_hdr(VFIOUserProxy *proxy, Error **errp,
>> + VFIOUserHdr *hdr, int **fdp, size_t *numfdp,
>> + bool *isreply)
>> +{
>> + struct iovec iov = {
>> + .iov_base = hdr,
>> + .iov_len = sizeof(*hdr),
>> + };
>> + int ret;
>> +
>> + /*
>> + * Read header
>> + */
>> + ret = qio_channel_readv_full(proxy->ioc, &iov, 1, fdp, numfdp, 0,
>> + errp);
>> + if (ret == QIO_CHANNEL_ERR_BLOCK) {
>> + return ret;
>> + }
>> +
>> + /* read error or other side closed connection */
>> + if (ret <= 0) {
>> + error_setg(errp, "failed to read header");
>
> Can we use error_setg_errno() here to record the real underlying return code in errp? Otherwise with this change it gets lost due to vfio_user_recv_hdr() always returning -1 if there is an error.
Can you please send a v4 with this change requested by Mark ?
I will then prepare a last QEMU 10.2 PR with this series and
the vfio-user doc update I left behind.
Thanks,
C.
>
>> + return -1;
>> + }
>> +
>> + if (ret < sizeof(*hdr)) {
>> + error_setg(errp, "short read of header");
>> + return -1;
>> + }
>> +
>> + /*
>> + * Validate header
>> + */
>> + if (hdr->size < sizeof(*hdr)) {
>> + error_setg(errp, "bad header size");
>> + return -1;
>> + }
>> +
>> + switch (hdr->flags & VFIO_USER_TYPE) {
>> + case VFIO_USER_REQUEST:
>> + *isreply = false;
>> + break;
>> + case VFIO_USER_REPLY:
>> + *isreply = true;
>> + break;
>> + default:
>> + error_setg(errp, "unknown message type");
>> + return -1;
>> + }
>> +
>> + trace_vfio_user_recv_hdr(proxy->sockname, hdr->id, hdr->command, hdr->size,
>> + hdr->flags);
>> + return 0;
>> +}
>> +
>> /*
>> * Receive and process one incoming message.
>> *
>> @@ -230,10 +285,6 @@ static int vfio_user_recv_one(VFIOUserProxy *proxy, Error **errp)
>> 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;
>> @@ -257,45 +308,13 @@ static int vfio_user_recv_one(VFIOUserProxy *proxy, Error **errp)
>> /* else fall into reading another msg */
>> }
>> - /*
>> - * Read header
>> - */
>> - ret = qio_channel_readv_full(proxy->ioc, &iov, 1, &fdp, &numfds, 0,
>> - errp);
>> - if (ret == QIO_CHANNEL_ERR_BLOCK) {
>> - return ret;
>> - }
>> -
>> - /* read error or other side closed connection */
>> - if (ret <= 0) {
>> - goto fatal;
>> - }
>> -
>> - if (ret < sizeof(hdr)) {
>> - error_setg(errp, "short read of header");
>> - goto fatal;
>> - }
>> -
>> - /*
>> - * Validate header
>> - */
>> - if (hdr.size < sizeof(VFIOUserHdr)) {
>> - error_setg(errp, "bad header size");
>> - goto fatal;
>> - }
>> - switch (hdr.flags & VFIO_USER_TYPE) {
>> - case VFIO_USER_REQUEST:
>> - isreply = false;
>> - break;
>> - case VFIO_USER_REPLY:
>> - isreply = true;
>> - break;
>> - default:
>> - error_setg(errp, "unknown message type");
>> + ret = vfio_user_recv_hdr(proxy, errp, &hdr, &fdp, &numfds, &isreply);
>> + if (ret < 0) {
>> + if (ret == QIO_CHANNEL_ERR_BLOCK) {
>> + return ret;
>> + }
>> goto fatal;
>> }
>> - trace_vfio_user_recv_hdr(proxy->sockname, hdr.id, hdr.command, hdr.size,
>> - hdr.flags);
>> /*
>> * For replies, find the matching pending request.
>
>
> ATB,
>
> Mark.
>
next prev parent reply other threads:[~2025-12-03 7:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 9:56 [PATCH v3 0/5] vfio-user coverity fixes John Levon
2025-12-01 9:56 ` [PATCH v3 1/5] vfio-user: simplify vfio_user_process() John Levon
2025-12-02 10:42 ` Mark Cave-Ayland
2025-12-01 9:56 ` [PATCH v3 2/5] vfio-user: clarify partial message handling John Levon
2025-12-02 10:43 ` Mark Cave-Ayland
2025-12-01 9:56 ` [PATCH v3 3/5] vfio-user: refactor out header handling John Levon
2025-12-02 10:53 ` Mark Cave-Ayland
2025-12-03 7:40 ` Cédric Le Goater [this message]
2025-12-01 9:56 ` [PATCH v3 4/5] vfio-user: simplify vfio_user_recv_one() John Levon
2025-12-02 11:11 ` Mark Cave-Ayland
2025-12-01 9:56 ` [PATCH v3 5/5] vfio-user: recycle msg on failure John Levon
2025-12-02 11:14 ` Mark Cave-Ayland
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=e5d2d505-009e-412e-b032-8b80af493d32@redhat.com \
--to=clg@redhat.com \
--cc=john.levon@nutanix.com \
--cc=mark.caveayland@nutanix.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thanos.makatos@nutanix.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).