From nobody Mon Feb 9 00:56:28 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0150316919 for ; Wed, 24 Dec 2025 10:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766573707; cv=none; b=DkK8yELckbi6ZzABQsjBik9dFGoSU5ye0MbMfCvfBHHHPeHWwJj3sZv6h5aGtdwJ2JFVV7JJ2P4eDQeiJGSsSmWDcLkezTF5jPoXqyHyyNS/4J4q74JNjZQEac26nx4+Y5aMhuwOsIK0FUfdA0tSwrRO1m+K/B61IA24mRBriAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766573707; c=relaxed/simple; bh=YJxxyVUIH0LKd1472HrqzJ1zqvb7vGfc8Y7LGrUbm8I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=eNgGAoYD8SIPi7szITPARDOaDJuJrXF0TN8Wp+bgOKXIrJ/cGnBIIbZx3Rc/Y4IT8hU9zIuzldCZI1QHdqGVqXKaBjJ/+KzkrdJ3szuPv2yIDG6B7RPdSpWR5SoSXtNMY07h+1uhu6M6dW/JFDZhfRnimmV6VZ+Mq9dRA+v+yxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=isovalent.com; spf=pass smtp.mailfrom=isovalent.com; dkim=pass (2048-bit key) header.d=isovalent.com header.i=@isovalent.com header.b=bTEKe7Fm; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=isovalent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=isovalent.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=isovalent.com header.i=@isovalent.com header.b="bTEKe7Fm" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-47aa03d3326so37728845e9.3 for ; Wed, 24 Dec 2025 02:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1766573702; x=1767178502; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=6YVPObAxph0NNzQqXtKmHrXXfkoVXAgC9K27LINgZDk=; b=bTEKe7Fm/6UF+c0agmWCeByaLFpn6rd3mbll7WXrm8x39VrCGMbZLdOPGwBPyinfHp JUqZZlZ8VyuJGNwkNrgfb6sWIli0m6j6cdM3UNpOsajiclELVF0kIseZRyLjHPcdguUB sPnNjY8zGs+NyJ6gMknL3XU+W/5AYzzoX28h9mG/rswdPgqv4mQ+4jiByRKCLg9IDYrL j+LrrSZzLrCProkn9xGb9cQV7EZasQQwJuzLDy81Ce4khESX8qPXQc65B8+osntNATBm fAVj9HUq5M8twbW9rsrSOTYS/IyT/Awhi8oTxs12cwmYy8dcPmbROe3f6yAR7YinvsVO AdVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766573702; x=1767178502; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6YVPObAxph0NNzQqXtKmHrXXfkoVXAgC9K27LINgZDk=; b=AIOuHurdLQYx+UHCSkvUlVUQfMflC7zaUd3sP9HMHyHF/EPRiHZFmgGXYAkiFQu1d2 bVlV+C6x7eiMEu/ohwkmJiUrp8XWvujEJMDhlki9ccUzbcVsbd4C1AHQlnaQwXn/dfpi iLY+RQbKxPXuoiQbck1dQQYRbd+BT1T2sT0y8b6AXZoP1F8rn6IKT7Y+BiEVj8vQWM48 lF2CwW377R90i/cU8EEShrU+22FhWS6ygh9DVFWCReMXata+lRbAsw3ytLEAhRMja0zu RdqAZUaNfOisNyBf7WfoarhSzv7+lmyJgAeQtzHE0x6NZzSYulkRJSx65XXFeywnAvmi 6TyQ== X-Forwarded-Encrypted: i=1; AJvYcCVtcK8WQkkVzDFVe8G0I+AkfwcA6u1+hQdD9c/FFftm1JlohQXU32CBaWaSYfPr5FBQIuQCpscFc1Uxm4g=@vger.kernel.org X-Gm-Message-State: AOJu0YwZD8pNP+Qme1ka4E3fhzWiTOCGM0yo7D70WXUzgh70xK3NlLa5 uv4ym1eZYlqSEzWRknGOKmqv2yimyrxvSKY/5C6Q/hD7PwMx+mANXs50WGS2vuBx5G8+EmX4/0o fJaba X-Gm-Gg: AY/fxX6WCXxBfn/SdD9aPTQgmvV2cIlmVqYL7I1MeNjnfjaXyH6RjLzRyEQKE9+iYgM 99msCCZoP2ILAsaFZKL0QDfkqB9Hv/0v/gfwZD1pEjrFpMDygzAB/f+wYax/YuV0dqSPjTwFZW+ dXGFriwybrQF9mnw9JSXo7XoaIMKSO1P14I9UAMVIc5yS2/BsbiE13UIuo/2XRuMCpjq3AJGQ1g sD6Jf3alvo6GSgPG66KiOrwFM7fTmtABndmH4X1l1OhlzAquhABFbd9Cr/NA1AO62FF/GEDR1Ra Hh48gM/IBc41u0je5Dd4XRtUW4nWMC+3NkFxSzV7Lu1tn1DhSQVy+l1ZbFzys+/J8rXi/6PAIu8 cL7mxrqflusRxjpZwZ3/FYGVDEY3Vlisb/m9qMGGht3zHlZ1/iMIPeLkhul9fBvNWAh+CEGzdZJ pH0kBM7DlhXb88tTob X-Google-Smtp-Source: AGHT+IG2oGo0/KRl8OLMUZV/2O7F94LGNUSLFxYl9Aa7ZK9BDlk3PbNHbqqE6+JW5GXsU4J5C4/cfQ== X-Received: by 2002:a05:600c:35c4:b0:475:dd9a:f791 with SMTP id 5b1f17b1804b1-47d195869e7mr203405325e9.28.1766573701534; Wed, 24 Dec 2025 02:55:01 -0800 (PST) Received: from fedora.fritz.box ([2001:a61:11d9:dc01:f21:4d89:1b7a:e08d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47be27c2260sm331937075e9.15.2025.12.24.02.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 02:55:01 -0800 (PST) From: Lorenz Bauer Date: Wed, 24 Dec 2025 11:54:46 +0100 Subject: [PATCH v3] virtio: console: fix lost wakeup when device is written and polled Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251224-virtio-console-lost-wakeup-v3-1-b8ee6812fa68@isovalent.com> X-B4-Tracking: v=1; b=H4sIAHXGS2kC/43NsQ6CMBSF4Vchna2hbS6Ik+9hHGq5lRuRkrZWD eHdLUzGwTj+Z/jOxAJ6wsD2xcQ8JgrkhhxqUzDT6eGCnNrcTJYShBTAE/lIjhs3BNcj712I/KG veB95aaGqDJhWgWUZGD1aeq748ZS7oxCdf61fSSzrX2wSXPC60WCg3gnA+kDBJd3jELfG3dhCJ /nBSfmTk5mDFhtlzsoKI765eZ7fsY5KyBcBAAA= X-Change-ID: 20251215-virtio-console-lost-wakeup-0f566c5cd35f To: Amit Shah , Arnd Bergmann , Greg Kroah-Hartman Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Lorenz Bauer X-Mailer: b4 0.14.2 A process issuing blocking writes to a virtio console may get stuck indefinitely if another thread polls the device. Here is how to trigger the bug: - Thread A writes to the port until the virtqueue is full. - Thread A calls wait_port_writable() and goes to sleep, waiting on port->waitqueue. - The host processes some of the write, marks buffers as used and raises an interrupt. - Before the interrupt is serviced, thread B executes port_fops_poll(). This calls reclaim_consumed_buffers() via will_write_block() and consumes all used buffers. - The interrupt is serviced. vring_interrupt() finds no used buffers via more_used() and returns without waking port->waitqueue. - Thread A is still in wait_event(port->waitqueue), waiting for a wakeup that never arrives. The crux is that invoking reclaim_consumed_buffers() may cause vring_interrupt() to omit wakeups. Fix this by calling reclaim_consumed_buffers() in out_int() before waking. This is similar to the call to discard_port_data() in in_intr() which also frees buffer from a non-sleepable context. This in turn guarantees that port->outvq_full is up to date when handling polling. Since in_intr() already populates port->inbuf we use that to avoid changing reader state. Cc: stable@vger.kernel.org Signed-off-by: Lorenz Bauer --- As far as I can tell all currently maintained stable series kernels need this commit. Applies and builds cleanly on 5.10.247, verified to fix the issue. --- Changes in v3: - Use spin_lock_irq in port_fops_poll (Arnd) - Use spin_lock in out_intr (Arnd) - Link to v2: https://lore.kernel.org/r/20251222-virtio-console-lost-wakeup= -v2-1-5de93cb3f1c1@isovalent.com Changes in v2: - Call reclaim_consumed_buffers() in out_intr instead of issuing another wake. - Link to v1: https://lore.kernel.org/r/20251215-virtio-console-lost-wakeup= -v1-1-79a5c57815e7@isovalent.com --- drivers/char/virtio_console.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 088182e54debd6029ea2c2a5542d7a28500e67b8..e6048e04c3b23d008caa2a1d31d= 4ac6b2841045f 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -971,10 +971,17 @@ static __poll_t port_fops_poll(struct file *filp, pol= l_table *wait) return EPOLLHUP; } ret =3D 0; - if (!will_read_block(port)) + + spin_lock_irq(&port->inbuf_lock); + if (port->inbuf) ret |=3D EPOLLIN | EPOLLRDNORM; - if (!will_write_block(port)) + spin_unlock_irq(&port->inbuf_lock); + + spin_lock_irq(&port->outvq_lock); + if (!port->outvq_full) ret |=3D EPOLLOUT; + spin_unlock_irq(&port->outvq_lock); + if (!port->host_connected) ret |=3D EPOLLHUP; =20 @@ -1705,6 +1712,10 @@ static void out_intr(struct virtqueue *vq) return; } =20 + spin_lock(&port->outvq_lock); + reclaim_consumed_buffers(port); + spin_unlock(&port->outvq_lock); + wake_up_interruptible(&port->waitqueue); } =20 --- base-commit: d358e5254674b70f34c847715ca509e46eb81e6f change-id: 20251215-virtio-console-lost-wakeup-0f566c5cd35f Best regards, --=20 Lorenz Bauer