From nobody Tue Jun 16 20:44:27 2026 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDFA12EB5A6 for ; Tue, 21 Apr 2026 06:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776754687; cv=none; b=gxiSQQZoxHrV3lmScGMAqsrpjXEB4bHWDwlVMQbK2M7cFJC8AVidSPVUffeIdnVKNHr2aB5462Nrj1CYah859a3sWehPBUxIE2vaCzEY7TISRYYCQtP6uR//y/FlO+kitxIahKVFREmPCyjbZDn9izB+cqw6SKNXf8PikyHvM/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776754687; c=relaxed/simple; bh=rC3yWuhULcb0nTQeL8PDzenvx7AdZe62dkAzJqC3BIk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=mmVO/7aSiBTAFE3LqNlEbO7qqDQOYXJCIliZ3QWJ8I9ywJ6YJtKHiFxxvobcjhiz2PxhFtbFWHI9BIlMzVfzpdUEL0D0M+dYtYSo/oj16WmGdfd8U/qR21mDPBbAPC6t4XTbo4cOzDv/4/DutaN4Cp63zF+5Cje9HpIF7YOWgXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=lNYgMKEI; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=KeOYRR28; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="lNYgMKEI"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="KeOYRR28" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63L1nbhi2755631 for ; Tue, 21 Apr 2026 06:58:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=ruZ3V50v3wet1iIOwkEIeY oBmZIAlSyQansR1f8dvJY=; b=lNYgMKEIDCO+r3Iei2kFWmiMosVMFYyF15QZuW yWW2RxtPAlwEbJV3i1rmfkRpz0GUlgmDpF+OP2vNZiEFKELfVTEH8uGTcZC6XkRj NZsUuziTy+zpCZCLJFmIs8phCK5wfoFNJbCu1f0O+J77O8v3jaCRNPHdkhkehZlj qwsFcYf5/2P/h4kCM7JN+BAnd1Q5+sbDuQi3LnfOOUthRyNQTeoQw+udggTfuY2r 0hTUDue8c0Mf9x4y9zgK0aMEc8T4ALJWQDPNE6KLKwGQ+cYuMUCkubiRKAvHYWfo tXVXVKNmGnOHhBbOSNqBXQq4QndXctOvtBXZyCvjWSSLIawQ== Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dnh7xm6et-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 21 Apr 2026 06:58:05 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-2d93379001eso1076913eec.1 for ; Mon, 20 Apr 2026 23:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1776754684; x=1777359484; 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=ruZ3V50v3wet1iIOwkEIeYoBmZIAlSyQansR1f8dvJY=; b=KeOYRR28O/RLvV+9+UVMipye+U0JvOmr7WyokVPW/ctDh28Tf6UNRrlaz7IzPbvLzF x0olAfoGnViERNWRbsQaWbGsV5vXfz25wjkkUSovh4om+OtFQEWzfSKOTCQAow6faBPw Wp5qhIvBFwWegv6kKxEzFuB1QOWiM8GkcOIzibmWABZIoLiauXSyOwRtV4KaZqbS/k4O n2MyNCZdqBfbCH57qwgXVn0D8mOXWyjgkLcIKVURMRMsJ/zeMR7d8mn+LtJ0pqoziIju CV0RlCtrtiABDNisq5EgD0T84r/kVylAY9clPP84ato8AmYhyDcwjqtIAQAIvb+w4i68 vpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776754684; x=1777359484; 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=ruZ3V50v3wet1iIOwkEIeYoBmZIAlSyQansR1f8dvJY=; b=XqzaQjj2bW8tSc3+9LWOKfEo3GsduyA8HO44/ULVmuVPzbXWBIYh5RXTpkpIif83eF iSfzazB4cZlst8Ku74Tv1Gm+i6o5Vw9jBjByGbN4frB+r34JF28yJxXc476bvi2vE2QH gKNchqoYt7Y77ez0UF1PHk8HGhHTNUw5OCafUuzq5XwL+tgw0gb+E3tGVVVT+VgR7oXs zNOQW6oDH4d4WdkJDslHEu18d1Z69EbzbUMWaLZATNNY2mLHnDyxuNmqRD1w+tYLSNwE eqTbXo8M0Hr5g0eijYoMfbqWUnix0SPJRXSJkcJ1gr7iT+n3v6qt/YqWavIBFnF5QhKi OUAw== X-Forwarded-Encrypted: i=1; AFNElJ/IOMjV9ROnkkuuppJcM5yL2kFYj384wivRn3RQLfhovXnNOM9Lb8CuV75NUTmUo8wgtIrwP/pJlRsTd/g=@vger.kernel.org X-Gm-Message-State: AOJu0YwVy62434p8t/bmzbB7qi4RgHeFFfZZ5aDB1TQGT6xUOU0M4fUn mBxJ/xbdD9FHWBX1BWhVLj3bQ7XcJYbkmmpz2rgpBJL1gGgHxHrw+0cKQyX22jdKBmtcVg3r+eO RZqFXW4WqsywPYIX/+dOQPclIR+Glc+809YAEfzdZpSHsKYSGU3lFXR4Vq2Yuf6Io16drY9sxbS k= X-Gm-Gg: AeBDietg8laDVnrRAzCRXciIiwohEJIIT2yQCjAfxWYPQjIeSRyIC6ok5tzj1i7PigO i7ELXaZpVSvqHejmhZrNr+D4Ky7b17Ca9Qey8xH+v+SPvHZG5pzMdNlRkIihzu5KvKmQsR/CTGx UJ7tiFZmbAOrEvcihdnpps6wGjEwdI03QUWli3GY2GxyP6M2gAgAuv62TNS3ngqe+7MBlNw/M3Z PR+xzEUbmwqAAJYo95QgSB1NYc4uipCtZMI0wPKgWp52L6Y0Qwk2MCqlHAJlYgY65Zd2nE84927 ZUufDys6agGIc7W8rpdpWz2xTQIVKbrNP2wOnz6Sbsx7oBRd6701GWc/rTiunsqq2frHZJViCJ/ iKoSPql7Bb0lsEiML0X9jCTfQCEQ4P9p8knJyqhylfxpbIEJyjkk1v/GCP4igS5eGoSz0g+Ko+p lxL3CJ X-Received: by 2002:a05:7301:1f17:b0:2ea:3370:6e51 with SMTP id 5a478bee46e88-2ea33706e74mr1292270eec.4.1776754684170; Mon, 20 Apr 2026 23:58:04 -0700 (PDT) X-Received: by 2002:a05:7301:1f17:b0:2ea:3370:6e51 with SMTP id 5a478bee46e88-2ea33706e74mr1292255eec.4.1776754683609; Mon, 20 Apr 2026 23:58:03 -0700 (PDT) Received: from hu-penyan-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e79c2954f6sm14629588eec.30.2026.04.20.23.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2026 23:58:03 -0700 (PDT) From: Peng Yang Date: Mon, 20 Apr 2026 23:57:44 -0700 Subject: [PATCH] virtio_console: add timeout to __send_to_port() spin loop 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: <20260420-add_timeout_to___send_to_port-v1-1-6c32d33bf4f2@oss.qualcomm.com> X-B4-Tracking: v=1; b=H4sIAOcf52kC/yXMQQqDMBBA0avIrBtIQrDQq5QyaDK2U2gimVEK4 t0b6+6/zd9AqDIJ3LoNKq0sXHKDu3QQX0N+kuHUDN763gZvzZASKn+oLIpaEFEop6PmUtU4GyJ dxzj54KA95koTf///++O0LOOboh5T2PcfM2pSzoEAAAA= X-Change-ID: 20260420-add_timeout_to___send_to_port-104ce7bcf241 To: Amit Shah , Arnd Bergmann , Greg Kroah-Hartman Cc: kernel@quicinc.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Peng Yang X-Mailer: b4 0.16-dev-3bfbc X-Developer-Signature: v=1; a=ed25519-sha256; t=1776754683; l=2943; i=peng.yang@oss.qualcomm.com; s=20260420; h=from:subject:message-id; bh=rC3yWuhULcb0nTQeL8PDzenvx7AdZe62dkAzJqC3BIk=; b=ib/+kW5gEtjsqPGa7Q8gDEkdyjYoAsogiBS88KCpRAs+2ucGY/5DOuNdIy+hJKybLOmIj/7Wm qDA4zYX2AvWDDY4pftvcaqqTWuufT3ey/Z3UmFtktvAcBaQ7wDr59yZ X-Developer-Key: i=peng.yang@oss.qualcomm.com; a=ed25519; pk=fY34c9+z3TbzFLgw2yql3bT/tbmxDEuxiVPTYAbRSTY= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIxMDA2NiBTYWx0ZWRfXz2NQTfSnvVV7 tLFhnHjrxjuq4Yz0CJkov03fyS32lF5NA++Jc/wiyr/2yBeJuXyFkSCmSf15b+qz5V1rCzx5Hx2 OTxaKTJ96Pgd6FIgfY4aSrWW1qRyYEZcnF4yN4QoZVAbzyXIlbrf1uXCvrUa96UcvALrL8hna54 0Xp1RC9+rCSm2UoBkndFjMOnW+rCS+ZMDg8Ir53ZukKe/7++IJIP/BsYrY453gp8WT8eh3VXwfF +2vD/azaRFP9Y0AWSeVP0sfoinXu/54DkS/Eoo3rqVnitQI3FV3gMRK5TDkwBd1U7pRPnzy3wXV cfOHzlJ8E7GibK2TRJOj3QzppCHpCa/mzB2KvBt8ZTvSDu8WVHqjJjvDQMKjX70zVq6tu4FMJSn 8/DcNQ+tsVdbnD1YmLRddm7PhqxsH6xqh2RIv+uPmuK7YfzJ5aqzqyyckzYVjpDx6iMvFWMpJg4 Hb21HaTaMZlHmL40Hrw== X-Authority-Analysis: v=2.4 cv=BPmDalQG c=1 sm=1 tr=0 ts=69e71ffd cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=vqeHtFuH3X1APyjPvOwA:9 a=QEXdDO2ut3YA:10 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-ORIG-GUID: 9mrxQnIJXKUfYuJXrjkbKTW-4vPwaw0C X-Proofpoint-GUID: 9mrxQnIJXKUfYuJXrjkbKTW-4vPwaw0C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-21_01,2026-04-20_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 clxscore=1011 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604210066 __send_to_port() busy-waits in virtqueue_get_buf() while holding outvq_lock with IRQs disabled. If the host stops draining the TX virtqueue, this loop never terminates. This was observed during secondary VM boot: virtio_mem plugged memory in multiple iterations, each emitting dev_info() messages through the hvc console. A writev() on the hvc TTY entered __send_to_port() and stalled in the spin loop. When the watchdog bark ISR fired on another CPU, it attempted printk(), which tried to acquire outvq_lock through the same path and spun indefinitely. With all CPUs stuck, the watchdog could not be serviced and triggered a bite. Add a 200 ms deadline using ktime_get_mono_fast_ns() to bound the spin loop. ktime_get_mono_fast_ns() reads the hardware counter directly and is safe to call with IRQs disabled and spinlocks held. The 200 ms value is chosen to be far above normal host response latency (microseconds) to avoid spurious exits, yet well below the watchdog bark-to-bite window (typically 3 s) so that CPUs can escape the loop and complete the bark handler before a bite occurs. Signed-off-by: Peng Yang --- drivers/char/virtio_console.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 9a33217c68d9..b3535681dfe1 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "../tty/hvc/hvc_console.h" =20 #define is_rproc_enabled IS_ENABLED(CONFIG_REMOTEPROC) @@ -601,6 +602,7 @@ static ssize_t __send_to_port(struct port *port, struct= scatterlist *sg, int err; unsigned long flags; unsigned int len; + u64 deadline; =20 out_vq =3D port->out_vq; =20 @@ -632,10 +634,18 @@ static ssize_t __send_to_port(struct port *port, stru= ct scatterlist *sg, * buffer and relax the spinning requirement. The downside is * we need to kmalloc a GFP_ATOMIC buffer each time the * console driver writes something out. + * + * To avoid spinning forever if the host stops processing the + * TX virtqueue (e.g. during VM shutdown), a 200ms deadline is + * used to break out of the loop as a fallback. */ - while (!virtqueue_get_buf(out_vq, &len) - && !virtqueue_is_broken(out_vq)) + deadline =3D ktime_get_mono_fast_ns() + 200ULL * NSEC_PER_MSEC; + while (!virtqueue_get_buf(out_vq, &len) && + !virtqueue_is_broken(out_vq)) { + if (ktime_get_mono_fast_ns() >=3D deadline) + break; cpu_relax(); + } done: spin_unlock_irqrestore(&port->outvq_lock, flags); =20 --- base-commit: 97e797263a5e963da3d1e66e743fd518567dfe37 change-id: 20260420-add_timeout_to___send_to_port-104ce7bcf241 Best regards, -- =20 Peng Yang