From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: sstabellini@kernel.org, jgross@suse.com
Cc: oleksandr_tyshchenko@epam.com, xen-devel@lists.xenproject.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] xen/pvcalls: return -EINTR from recvmsg when the wait is interrupted
Date: Wed, 18 Nov 2026 14:53:31 +0000 [thread overview]
Message-ID: <20261118-xen-pvcalls-v1-1-5e9d662900a0@gmail.com> (raw)
From: Suyuan Wang <stevewong@hust.edu.cn>
pvcalls_front_recvmsg() waits for data in a loop and ignores what
wait_event_interruptible() returns:
while (!(flags & MSG_DONTWAIT) && !pvcalls_front_read_todo(map)) {
wait_event_interruptible(map->active.inflight_conn_req,
pvcalls_front_read_todo(map));
}
Once a signal is pending, wait_event_interruptible() returns
-ERESTARTSYS right away without sleeping, and the loop calls it again.
The caller then spins with map->active.in_mutex held until data arrives
or the backend reports an error. The signal can't be handled while it
spins, so the task can't be killed either, and other readers of the
socket block on in_mutex.
Return -EINTR when the wait is interrupted, as pvcalls_front_accept()
already does for its interruptible waits. Jump to the end of the
function so that in_mutex is released and pvcalls_exit_sock() is
called.
Found with a static analysis tool and checked by hand.
Fixes: ae0d04052e07 ("xen/pvcalls: implement recvmsg")
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
There are no in-tree callers of pvcalls_front_recvmsg(), so this only
matters to code built on the exported frontend API. That's why I left
out Cc: stable.
Compile tested only (x86_64 with CONFIG_XEN_PVCALLS_FRONTEND=y, W=1 and
sparse show no new warnings). I haven't run it in a Xen guest.
---
drivers/xen/pvcalls-front.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 3e7aa807c317..5d6c8ba66849 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -693,8 +693,11 @@ int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
len = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
while (!(flags & MSG_DONTWAIT) && !pvcalls_front_read_todo(map)) {
- wait_event_interruptible(map->active.inflight_conn_req,
- pvcalls_front_read_todo(map));
+ if (wait_event_interruptible(map->active.inflight_conn_req,
+ pvcalls_front_read_todo(map))) {
+ ret = -EINTR;
+ goto out;
+ }
}
ret = __read_ring(map->active.ring, &map->active.data,
&msg->msg_iter, len, flags);
@@ -706,6 +709,7 @@ int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (ret == -ENOTCONN)
ret = 0;
+out:
mutex_unlock(&map->active.in_mutex);
pvcalls_exit_sock(sock);
return ret;
reply other threads:[~2026-11-18 14:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261118-xen-pvcalls-v1-1-5e9d662900a0@gmail.com \
--to=devnull+shyckless.gmail.com@kernel.org \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=shyckless@gmail.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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
all inboxes | Powered by JetHome®