qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "John Levon" <john.levon@nutanix.com>,
	"Mark Cave-Ayland" <mark.caveayland@nutanix.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 6/6] vfio-user: recycle msg on failure
Date: Wed,  3 Dec 2025 16:12:49 +0100	[thread overview]
Message-ID: <20251203151249.2707207-7-clg@redhat.com> (raw)
In-Reply-To: <20251203151249.2707207-1-clg@redhat.com>

From: John Levon <john.levon@nutanix.com>

If we fail to read an incoming request, recycle the message.

Resolves: Coverity CID 1611807
Resolves: Coverity CID 1611808
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Link: https://lore.kernel.org/qemu-devel/20251203100316.3604456-6-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio-user/proxy.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c
index f2601eada5b9c8010e88bf4b3035a27811769b0d..314dfd23d8af385532bb87219fb3153961942cba 100644
--- a/hw/vfio-user/proxy.c
+++ b/hw/vfio-user/proxy.c
@@ -412,11 +412,22 @@ err:
     for (i = 0; i < numfds; i++) {
         close(fdp[i]);
     }
-    if (isreply && msg != NULL) {
-        /* force an error to keep sending thread from hanging */
-        vfio_user_set_error(msg->hdr, EINVAL);
-        msg->complete = true;
-        qemu_cond_signal(&msg->cv);
+    if (msg != NULL) {
+        if (msg->type == VFIO_MSG_REQ) {
+            /*
+             * Clean up the request message on failure. Change type back to
+             * NOWAIT to free.
+             */
+            msg->type = VFIO_MSG_NOWAIT;
+            vfio_user_recycle(proxy, msg);
+        } else {
+            /*
+             * Report an error back to the sender. Sender will recycle msg.
+             */
+            vfio_user_set_error(msg->hdr, EINVAL);
+            msg->complete = true;
+            qemu_cond_signal(&msg->cv);
+        }
     }
     return -1;
 }
-- 
2.52.0



  parent reply	other threads:[~2025-12-03 15:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-03 15:12 [PULL 0/6] vfio queue Cédric Le Goater
2025-12-03 15:12 ` [PULL 1/6] docs/interop/vfio-user: update protocol specification Cédric Le Goater
2025-12-03 15:12 ` [PULL 2/6] vfio-user: simplify vfio_user_process() Cédric Le Goater
2025-12-03 15:12 ` [PULL 3/6] vfio-user: clarify partial message handling Cédric Le Goater
2025-12-03 15:12 ` [PULL 4/6] vfio-user: refactor out header handling Cédric Le Goater
2025-12-03 15:12 ` [PULL 5/6] vfio-user: simplify vfio_user_recv_one() Cédric Le Goater
2025-12-03 15:12 ` Cédric Le Goater [this message]
2025-12-04 19:37 ` [PULL 0/6] vfio queue Richard Henderson

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=20251203151249.2707207-7-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=john.levon@nutanix.com \
    --cc=mark.caveayland@nutanix.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).