[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/pvcalls: return -EINTR from recvmsg when the wait is interrupted


  • To: sstabellini@xxxxxxxxxx, jgross@xxxxxxxx
  • From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@xxxxxxxxxx>
  • Date: Wed, 18 Nov 2026 14:53:31 +0000
  • Arc-authentication-results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
  • Arc-message-signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795013612; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=JhqkB8+ikY0EQHy0mFR/yHf+TqnBEpjGFQ+Trl/H16U=; b=Sef5YFaPiNY9XIJ3KtqBbqW7W7u2RdSbkkrhfxw3xspkq+O793RyUove+h9c4rXp3WL5 snC+uAPOjkjEFjWVhIsW86BZYyYKYSSPVqiEfem5qj6omIc3A9Gpgt5v3BNafvvMdfR+x BSdbRDFUUmJZHwbv/XerhMKDtKGOvGDL9F7CO/zSUxLVrEGKzJEZeUjQ4VFueVIDEJQOL +RWyf8DykIs7Z1fvDoNHxmioAoCJwfw/VwbOa+1+yc/kcfmk7/qpfZEKRHw2t3hRtitIc K+26OaAzV/AjIq+RqRUTHe9LoGGIMQhmT/AWTBeegzu+aUMHSN5YGPKSH6VHygYPvNg==
  • Arc-seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795013612; b=oGKtrIkr2Wv9BIdul9AeXXL/7AUJRYdXSPS3zAV1K9x8pOQptpFXrGZcmojnfDDQkSP+ fg52RYyL6E0ulGHomVvugDkwn4yxd3Mer0+f/nW3HyI8tWirFJ0TTXgwT0PTDQ0EtfUJK SX/oW4fgkbR2QXxoBMcDgwucKP5BiAH0zB5XOU5Ika1qDB0zOsqel7BTNATbMqcQpmYV2 /8FHO3lewJn4yu7/1/kxuN/g7Oh1+j8byTQ+L0ZPu1/CVaHZi6r0zNYNkG8WNvO4J1cam ziA1DEkn07QdNm3bMU6X+UcmBsJrbkTnjJT47zB2Gt9RvCv5fvDZBf2TcFeKzX3GYog==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=k20260515 header.d=kernel.org header.i="@kernel.org" header.h="From:Date:Subject:To:Cc:Reply-To"
  • Authentication-results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
  • Cc: oleksandr_tyshchenko@xxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
  • Delivery-date: Wed, 18 Nov 2026 15:01:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Suyuan Wang <stevewong@xxxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
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;







 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.