From nobody Sat May 11 17:27:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kingsoft.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627610391544589.7563279365319; Thu, 29 Jul 2021 18:59:51 -0700 (PDT) Received: from localhost ([::1]:45812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9HoT-0000Sq-Vn for importer@patchew.org; Thu, 29 Jul 2021 21:59:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9Hng-00088c-AB for qemu-devel@nongnu.org; Thu, 29 Jul 2021 21:59:00 -0400 Received: from [114.255.44.146] (port=39573 helo=mail.kingsoft.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9Hnd-0007aT-3B for qemu-devel@nongnu.org; Thu, 29 Jul 2021 21:58:59 -0400 Received: from mail.kingsoft.com (localhost [10.88.1.79]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.kingsoft.com (SMG-1-NODE-87) with SMTP id 2B.0D.12443.2DC53016; Fri, 30 Jul 2021 09:58:42 +0800 (HKT) Received: from KSbjmail3.kingsoft.cn (10.88.1.78) by KSBJMAIL4.kingsoft.cn (10.88.1.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 30 Jul 2021 09:58:41 +0800 Received: from KSbjmail3.kingsoft.cn ([fe80::7d5f:5fcb:9c30:789b]) by KSBJMAIL3.kingsoft.cn ([fe80::7d5f:5fcb:9c30:789b%6]) with mapi id 15.01.2176.014; Fri, 30 Jul 2021 09:58:41 +0800 X-AuditID: 0a580157-e15ff7000006309b-29-61035cd15bb9 From: =?utf-8?B?QUlFUlBBVElKSUFORzEgW+iJvuWwlOW4leaPkOaxn8K36Zi/5biD6YO96LWb?= =?utf-8?B?5Lmw5o+QXQ==?= To: "lvivier@redhat.com" , "amit@kernel.org" , "qemu-devel@nongnu.org" , "stefanha@redhat.com" , "mst@redhat.com" Subject: [PATCH] hw/char/virtio-serial-bus: fix: Unpop throttled VirtQueueElement to queue before discard vq data Thread-Topic: [PATCH] hw/char/virtio-serial-bus: fix: Unpop throttled VirtQueueElement to queue before discard vq data Thread-Index: AQHXfhCIoeZCoIzDgkWI30flJ82In6tWICuAgASwioA= Date: Fri, 30 Jul 2021 01:58:41 +0000 Message-ID: <918AA6D7-F6C6-4A0E-8E65-6C7ECF148304@kingsoft.com> References: <2904D378-AA27-4510-A3C8-7E2E34DF37EF@kingsoft.com> <330EE4BB-DE8D-4D4A-9E6E-08E50BDA5E45@kingsoft.com> In-Reply-To: <330EE4BB-DE8D-4D4A-9E6E-08E50BDA5E45@kingsoft.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.88.2.22] Content-Type: text/plain; charset="utf-8" Content-ID: <4592EBBE170B6A4C8AA901D4B726320F@kingsoft.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkkeLIzCtJLcpLzFFi42LhimD0170Uw5xo0L6O0eLz3TnsFp8apCz+ /3rFanG8dweLxetJ/1kdWD02repk83hybTOTx/t9V9kCmKO4bFJSczLLUov07RK4Ms5du8Ne 0CJesa1xLXsD4w6xLkZODgkBE4m/t1ezdjFycQgJTGeSOPLjOzOE84JRYuumPqjMHkaJD8e/ sIE4bALtjBKHD08Hy4gI3GSUOLf0OBPIMGGBYomnv/8D9XMAJSokbv1JAQmLCFhJtFxdywZi swioSpzZdYYRpIRXwF5i42l+kLCQQKlE3/5uVhCbU8BB4uaxbSwgNqOArMS0R/fBpjMLiEvM nTaLFeJsAYkle84zQ9iiEi8f/4OKy0lsONHJDjKeWUBTYv0ufYhWa4mdeyYxQtiKElO6H7KD 2LwCghInZz5hmcAoNgvJhlkI3bOQdM9C0j0LSfcCRtZVjCzFuemGmxghsRW+g3Fe00e9Q4xM HIyHGCU4mJVEeF//+J8gxJuSWFmVWpQfX1Sak1p8iFGag0VJnLfk4L8EIYH0xJLU7NTUgtQi mCwTB6dUA5Pd/DcFqd3GPekJnBfiuf67PjJUNshRdu1Rrux8dMg8ob2qUXF9ml1vd0TOk0Bl nXDuufudYu7WcRuv/xCvxOs86dN9wznhGRZl33Wbne1j4urrLgsfKnXsXNFpfkOyyfa/6euo 5btObTZUe+q4si/lescezr9yj5n5Vgkdu/JeZjbbhNMhoWJlffcL+H9bfLZ/2ryf1WNSl+3E s+ofv0z69jFwtX6xLgtT4tXk03fjomL/JZ+dmlgTulw7Wd1To9aoNup0cnbIlmTj0BqNr36v f9W/crhQfNTurUpgV1vV0vzgiPQl2pcl0qZOE9Ur4JfoPOmxt6d+d+6fxe8XVNjV6nKdWK1t Z5y06akSS3FGoqEWc1FxIgAW9PPNHAMAAA== X-Host-Lookup-Failed: Reverse DNS lookup failed for 114.255.44.146 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=114.255.44.146; envelope-from=AIERPATIJIANG1@kingsoft.com; helo=mail.kingsoft.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1627610397673100001 Ports enter a "throttled" state when writing to the chardev would block. The current output VirtQueueElement is kept around until the chardev becomes writable again. Because closing the virtio serial device does not reset the queue, we cannot directly discard this element, otherwise the control variables of the front and back ends of the queue are inconsistent such as used_index. We should u= npop the VirtQueueElement to queue, let discard_vq_data process it. The test environment: kernel: linux-5.12 Qemu command: Qemu-system-x86 -machine pc,accel=3Dkvm \ -cpu host,host-phys-bits \ -smp 4 \ -m 4G \ -kernel ./kernel \ -display none \ -nodefaults \ -serial mon:stdio \ -append "panic=3D1 no_timer_check noreplace-smp rootflags=3Ddata=3Dorde= red rootfstype=3Dext4 console=3DttyS0 reboot=3Dk root=3D/dev/vda1 rw" \ -drive id=3Dos,file=3D./disk,if=3Dnone \ -device virtio-blk-pci,drive=3Dos \ -device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x4 \ -chardev socket,id=3Dcharchannel0,path=3D/tmp/char-dev-test,server,nowa= it \ -device virtserialport,bus=3Dvirtio-serial0.0,nr=3D1,chardev=3Dcharchanne= l0,id=3Dchannel0,name=3Dorg.qemu.guest_agent.0 full up virtio queue after VM started: Cat /large-file > /dev/vport1p1 Host side: Open and close character device sockets repeatedly After awhile we can=E2=80=99t write any request to /dev/vport1p1 at VM side= , VM kernel soft lockup at drivers/char/virtio_console.c: __send_to_port Signed-off-by: Arafatms diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index dd6bc27b3b..36236defdf 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -150,8 +150,12 @@ static void discard_vq_data(VirtQueue *vq, VirtIODevic= e *vdev) static void discard_throttle_data(VirtIOSerialPort *port) { + if (!virtio_queue_ready(port->ovq)) { + return; + } + if (port->elem) { - virtqueue_detach_element(port->ovq, port->elem, 0); + virtqueue_unpop(port->ovq, port->elem, 0); g_free(port->elem); port->elem =3D NULL; }