From nobody Sat Feb 7 18:28:57 2026 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 0319C1373 for ; Wed, 24 Dec 2025 03:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766547884; cv=none; b=EHUdg/yJknxotFUbIXND3zHQFWAbB1b06R1yeWXNRm1tHn69sbYjK3UIH65htCLKNXYuf1jsg0S9YkAJQo25IBNu6dMxHrGQASMttkk9A7I7AKtYmtnQu4onnALC1wa1zG4mE8GXqaMu6a42bn97XlaOjMeCrsi37hCz11MP8wI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766547884; c=relaxed/simple; bh=fTWxo+poNduOUg0IjnFiktP33OycMuTZ5yCyD17HpXc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=SUwxFEd33EQ42EArgE2nTzSHLhQ7A+cSzlxp7OjeDMeY24+CneJSb3Sp55IBgKgj/IHKFwoL9B4XQgfOwK6iM8nJ7uLlzxtt09re9W1dOVNmv+4fTZwkCkQ4W+YG+XOLVZ5wsiE9qYI+CEYSbpgZU3tqXVDqaVaoJJrnZq+wSSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G1bvFe7E; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G1bvFe7E" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-b728a43e410so1026571666b.1 for ; Tue, 23 Dec 2025 19:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766547881; x=1767152681; 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=iqClP1J3Blj4kNw4f75McA5KSMvq9OaxJjrHWGLacHo=; b=G1bvFe7ELBv9e2F6NMJwTQ6r8/bnmBEWar8q4j1pqoN3XEnwzgwt6Q6a4iMd+VYpLD CVPToeWQ5wKVu0cLJ/szVV+LUKzdBFTGyiPTcLS2k1kc2lfxiDKNP7RR3gVMiKSvhu6j +L6cI1gIUTlgFZo31kWGmQvD0ZZc1P8721a4/o9FJKLeCaZd9PumHO2M8dILMvWcD5xc AXV2wUYFRzHM05tymYH+vHAVlpN7GyB7Y13/5lnFGnJ36Kxt7+YKxrC9vglJdAjPZd2M j1gDIaKVPzycCqmBeBV7/7lD/IIeasDV3Sn3u9UZTir7BZqRiMiRbrpS961Em0Ts8H6d duXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766547881; x=1767152681; 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=iqClP1J3Blj4kNw4f75McA5KSMvq9OaxJjrHWGLacHo=; b=eGwPXX7OInyhe+/9XfrJ1fsb0NI7XhTV0RP96XdDO7p5AobLqZsal56ZpboAT9QnYu 95bjV1JuVBJlxlpbZQGmd108uqKTnDaN4FV3dZbxcAnXwCkFasKKXIky+TCR0a7V4ZQh RjzcgKGlfON2ucH3K3q0r7LUYoVwY6tUf4nGFCGiYir6406SMMEl0yJVN8RVZkJLY5RI dQWOcxoEjDiHWrObTl/vDxnvAsRx4gabNpbmY9iH4vjiMoseOf/JVuU5kNg2PbwOrBFY zF5DwptdJ/77Y2IGqe8Ekq+m9Tn2i0B2MzoUCmTYiIn8rXLqk+T7+Obx3ELijIRCOZwo 14QQ== X-Forwarded-Encrypted: i=1; AJvYcCVD2UQgaXHgYGt6nH+dGPeIQ8TrYEKI96tyJVvwEj2hZj/ZIrN6w7SIPdZ2qSZzk2MjBqrjmgMBzXE2kPU=@vger.kernel.org X-Gm-Message-State: AOJu0YxHzLlmd6vkFe0D1XJV1K/43HzHr3p5GPpORyGoYl22IYJpPvNn NYhYxKXmeLbxFElLr8tC4yc+v2pz69QFUuQuduqlhoXF8P9dYplyXvs0 X-Gm-Gg: AY/fxX6/0p4XMOgv/qKoXYjZNEg4X0Z/CFfWJLgxF2reUi5vOjgE5Zee0Jtfa368Dby EUrBcoQuSzNm5cR5XnforoUCKGRfTw0GqQ8YNi/WghzS4kZb9CUoXjL6RKrMjFen8N16iTGH8lC zUQ79SZit3u+Epo9g64CJSzfx3xZvYKWx5bGoTK15ulrfC0m2F6kOx5OfyVHAVfW/omJtGXFAVg Rls9PM0ikmRlgcA/i/tDFeXTS57NWUbmsGKFcM6SRzq0UwAznMWeGQKlP+ilU2p0PZyQOX5x6Ug FqKN3Sp3nvlYF7sKD0ab529VvF2ECRA6gUujqBLT8wnB0lvWiIRt3e/OXPvQI3qVI7rQr6yi+SU LaaD2AaDuwFVZLPp3rFuZ6SaeuxxRXr17tyRHHDHCYlnrGU7CadKHS/WYZdjJfErPBQVYuEdOEM z0KjLfgV5nSUROmO+942DeskoCDO/LYvPTe/3aLZmT X-Google-Smtp-Source: AGHT+IFtFPTf8Y7FfhjP3jw+d9+0TUQIjezaoa1JRTlwOhq0qKOO5sF3sFUhRJYY5TqEtoAzV4yXYw== X-Received: by 2002:a17:907:3e8c:b0:b72:5d08:486c with SMTP id a640c23a62f3a-b8036f5a0cdmr1911426666b.27.1766547881122; Tue, 23 Dec 2025 19:44:41 -0800 (PST) Received: from localhost (mem-185.47.220.165.jmnet.cz. [185.47.220.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037f0b12dsm1621963966b.48.2025.12.23.19.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 19:44:40 -0800 (PST) From: Filip Hejsek Date: Wed, 24 Dec 2025 04:44:06 +0100 Subject: [PATCH] virtio_console: read size from config space during device init 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-fix-v1-1-69d0349692dc@gmail.com> X-B4-Tracking: v=1; b=H4sIAIVhS2kC/x2MQQqAMAzAviI9W9C5ifoV8SCz04Js0ooI4t8dH hNIHlASJoWheEDoYuUUM9RlAX6b40rIS2YwlXG1MRYvlpMT+hQ17YSBb2wW2/ZdRcG1PeTwEMr 6n47T+35/fsk1ZAAAAA== X-Change-ID: 20251224-virtio-console-fix-3d46980ef569 To: Amit Shah , Arnd Bergmann , Greg Kroah-Hartman , Rusty Russell Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1766547879; l=3793; i=filip.hejsek@gmail.com; s=20250912; h=from:subject:message-id; bh=fTWxo+poNduOUg0IjnFiktP33OycMuTZ5yCyD17HpXc=; b=Gy38c1nLgv7mAfyfZdz7Ho1GUKBy/xnez7CbXH71d8vtKp9i0ikf6l6rYkWkosA4HQ6eHK3AJ 4/B/ys2DkRSBrWObSAUnFUHXqGpEHYymLPlilbJdIpCqbEDE6jYnddr X-Developer-Key: i=filip.hejsek@gmail.com; a=ed25519; pk=nakB8gEK3oi+Q/5dBTMCy/LgZL47NP60z1jeDR6O/WU= Previously, the size was only read upon receiving the config interrupt. This interrupt is sent when the size changes. However, we also need to read the initial size. Also make sure to only read the size from config if F_SIZE is enabled. Fixes: 9778829cffd4 ("virtio: console: Store each console's size in the con= sole structure") Signed-off-by: Filip Hejsek --- I found this bug while developing patches for QEMU that add virtio console resize support. If you want to test this, you can get my QEMU patches from [1]. You will need to disable multiport using `-device virtio-serial,max_ports=3D1`. [1]: https://lore.kernel.org/all/20250921-console-resize-v5-0-89e3c6727060@= gmail.com/ As an aside, when I was trying to understand the kernel resizing code, I noticed two things which didn't make sense to me: - Why does use_multiport use __virtio_test_bit instead of virtio_has_feature? - The VIRTIO_CONSOLE_RESIZE handler sets irq_requested to 1, which I think makes no sense? --- drivers/char/virtio_console.c | 52 ++++++++++++++++++++++++++-------------= ---- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 088182e54deb..c355f6d39274 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -1771,32 +1771,40 @@ static void config_intr(struct virtio_device *vdev) schedule_work(&portdev->config_work); } =20 -static void config_work_handler(struct work_struct *work) +static void update_size_from_config(struct ports_device *portdev) { - struct ports_device *portdev; + struct virtio_device *vdev; + struct port *port; + u16 rows, cols; =20 - portdev =3D container_of(work, struct ports_device, config_work); - if (!use_multiport(portdev)) { - struct virtio_device *vdev; - struct port *port; - u16 rows, cols; + vdev =3D portdev->vdev; =20 - vdev =3D portdev->vdev; - virtio_cread(vdev, struct virtio_console_config, cols, &cols); - virtio_cread(vdev, struct virtio_console_config, rows, &rows); + /* + * We'll use this way of resizing only for legacy support. + * For multiport devices, use control messages to indicate + * console size changes so that it can be done per-port. + * + * Don't test F_SIZE at all if we're rproc: not a valid feature. + */ + if (is_rproc_serial(vdev) || + use_multiport(portdev) || + !virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) + return; =20 - port =3D find_port_by_id(portdev, 0); - set_console_size(port, rows, cols); + virtio_cread(vdev, struct virtio_console_config, cols, &cols); + virtio_cread(vdev, struct virtio_console_config, rows, &rows); =20 - /* - * We'll use this way of resizing only for legacy - * support. For newer userspace - * (VIRTIO_CONSOLE_F_MULTPORT+), use control messages - * to indicate console size changes so that it can be - * done per-port. - */ - resize_console(port); - } + port =3D find_port_by_id(portdev, 0); + set_console_size(port, rows, cols); + resize_console(port); +} + +static void config_work_handler(struct work_struct *work) +{ + struct ports_device *portdev; + + portdev =3D container_of(work, struct ports_device, config_work); + update_size_from_config(portdev); } =20 static int init_vqs(struct ports_device *portdev) @@ -2054,6 +2062,8 @@ static int virtcons_probe(struct virtio_device *vdev) __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, VIRTIO_CONSOLE_DEVICE_READY, 1); =20 + update_size_from_config(portdev); + return 0; =20 free_chrdev: --- base-commit: b927546677c876e26eba308550207c2ddf812a43 change-id: 20251224-virtio-console-fix-3d46980ef569 Best regards, --=20 Filip Hejsek