From patchwork Tue Apr 2 14:24:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1918886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=lYzBQOB5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V89Hp1z7kz1yZ3 for ; Wed, 3 Apr 2024 01:29:26 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rrf6f-0004eC-F6; Tue, 02 Apr 2024 10:27:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rrf60-0003KI-1l for qemu-ppc@nongnu.org; Tue, 02 Apr 2024 10:26:42 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rrf5q-0000XZ-TX for qemu-ppc@nongnu.org; Tue, 02 Apr 2024 10:26:35 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-415446af364so26340065e9.0 for ; Tue, 02 Apr 2024 07:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712067976; x=1712672776; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LiQNL8qlUJUwVLo8ka7ZFh5OPYv1xBVi+fy9VmqgzRE=; b=lYzBQOB5xsn43gK0Cwk6kH7vdBEUOyARdDJv+GMWThn/j/uprIrJ+5xDju6+k2h9Yd OZzvBai9M9LUsBu+p/qQTBAYIwmrK0xAr1RqlFheoZB9IAOklLpbacaXK6nbDNoseX2d 8ChOnaUEEj7LnIeh40pHlzak5qUE2/HW9x46VYr2c2FhVammZ69x2nGyBo94aGh/lqA1 W6GYkYedEHSch55Gk/CFSiD99h6Xd3I1fP9CPcoJdltKqbfMvqw5MtIwzgNL44VDZ0ji eFM7mZ6Y8+uEIlrAEI0xPQsi6Yt1cAwXxj4XP65JW71FPoBsBeAjIh/9l9zTRf9vn/2m Nepg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712067976; x=1712672776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LiQNL8qlUJUwVLo8ka7ZFh5OPYv1xBVi+fy9VmqgzRE=; b=U+mYY2kmXqkEXW4zpB09L96n6U3YCSJ23M/N0e0d+OIdK8RUCR2jWXpZOYmbKJ3+Nu pxnQDvpLAgvNFGizPR0vpN9o3hbeyEgWRbOoDUjhpXRLoylWrFIQvOpQduVmb2marHWh rJpbAjMJ15PGWr8CO5jftmMKwbpxK+HbLehl1eJOCPKbRrpH65YvMPdmcZzh/4afSQ2n C4X+7cEge2RUvLB24Z/8i6hHxg0HwSX+GHHJQJwWUC4jmRm88gAZ8A+1LRvWusR3Zok3 JYlbpXWfM3coXKXlIG+MeuQby3anoCyuLocTwmUVDUJDBp0goHx4MT1AwL39RBANkKCt Xa9Q== X-Gm-Message-State: AOJu0YwZxD9CY/DqjOxeu07ZzcXr/Z2zwcDZuPxupyzoYAP49faP7R68 XsJIvCF+No39u14Oo//5CPj+h4wFjEDy4Kr4MOTwKpCq1st6JKcwLxi+ItWkPGQ= X-Google-Smtp-Source: AGHT+IE6saWf+oB/j8EBTqEFwDKJJ227HWQfzru1atRapCKVrnKsUxhdQi/s7wh3tKOXEde21OYylQ== X-Received: by 2002:adf:f108:0:b0:33e:c68d:d536 with SMTP id r8-20020adff108000000b0033ec68dd536mr10768328wro.15.1712067975793; Tue, 02 Apr 2024 07:26:15 -0700 (PDT) Received: from m1x-phil.lan ([176.187.202.91]) by smtp.gmail.com with ESMTPSA id dn13-20020a0560000c0d00b00341b7d5054bsm14389989wrb.72.2024.04.02.07.26.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Apr 2024 07:26:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, qemu-block@nongnu.org, qemu-arm@nongnu.org, Yajun Wu , Jiri Pirko , "Michael S . Tsirkin" , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Jason Wang Subject: [PULL 15/15] hw/net/virtio-net: fix qemu set used ring flag even vhost started Date: Tue, 2 Apr 2024 16:24:30 +0200 Message-ID: <20240402142431.70700-16-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240402142431.70700-1-philmd@linaro.org> References: <20240402142431.70700-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-ppc@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Yajun Wu When vhost-user or vhost-kernel is handling virtio net datapath, QEMU should not touch used ring. But with vhost-user socket reconnect scenario, in a very rare case (has pending kick event). VRING_USED_F_NO_NOTIFY is set by QEMU in following code path: #0 virtio_queue_split_set_notification (vq=0x7ff5f4c920a8, enable=0) at ../hw/virtio/virtio.c:511 #1 0x0000559d6dbf033b in virtio_queue_set_notification (vq=0x7ff5f4c920a8, enable=0) at ../hw/virtio/virtio.c:576 #2 0x0000559d6dbbbdbc in virtio_net_handle_tx_bh (vdev=0x559d703a6aa0, vq=0x7ff5f4c920a8) at ../hw/net/virtio-net.c:2801 #3 0x0000559d6dbf4791 in virtio_queue_notify_vq (vq=0x7ff5f4c920a8) at ../hw/virtio/virtio.c:2248 #4 0x0000559d6dbf79da in virtio_queue_host_notifier_read (n=0x7ff5f4c9211c) at ../hw/virtio/virtio.c:3525 #5 0x0000559d6d9a5814 in virtio_bus_cleanup_host_notifier (bus=0x559d703a6a20, n=1) at ../hw/virtio/virtio-bus.c:321 #6 0x0000559d6dbf83c9 in virtio_device_stop_ioeventfd_impl (vdev=0x559d703a6aa0) at ../hw/virtio/virtio.c:3774 #7 0x0000559d6d9a55c8 in virtio_bus_stop_ioeventfd (bus=0x559d703a6a20) at ../hw/virtio/virtio-bus.c:259 #8 0x0000559d6d9a53e8 in virtio_bus_grab_ioeventfd (bus=0x559d703a6a20) at ../hw/virtio/virtio-bus.c:199 #9 0x0000559d6dbf841c in virtio_device_grab_ioeventfd (vdev=0x559d703a6aa0) at ../hw/virtio/virtio.c:3783 #10 0x0000559d6d9bde18 in vhost_dev_enable_notifiers (hdev=0x559d707edd70, vdev=0x559d703a6aa0) at ../hw/virtio/vhost.c:1592 #11 0x0000559d6d89a0b8 in vhost_net_start_one (net=0x559d707edd70, dev=0x559d703a6aa0) at ../hw/net/vhost_net.c:266 #12 0x0000559d6d89a6df in vhost_net_start (dev=0x559d703a6aa0, ncs=0x559d7048d890, data_queue_pairs=31, cvq=0) at ../hw/net/vhost_net.c:412 #13 0x0000559d6dbb5b89 in virtio_net_vhost_status (n=0x559d703a6aa0, status=15 '\017') at ../hw/net/virtio-net.c:311 #14 0x0000559d6dbb5e34 in virtio_net_set_status (vdev=0x559d703a6aa0, status=15 '\017') at ../hw/net/virtio-net.c:392 #15 0x0000559d6dbb60d8 in virtio_net_set_link_status (nc=0x559d7048d890) at ../hw/net/virtio-net.c:455 #16 0x0000559d6da64863 in qmp_set_link (name=0x559d6f0b83d0 "hostnet1", up=true, errp=0x7ffdd76569f0) at ../net/net.c:1459 #17 0x0000559d6da7226e in net_vhost_user_event (opaque=0x559d6f0b83d0, event=CHR_EVENT_OPENED) at ../net/vhost-user.c:301 #18 0x0000559d6ddc7f63 in chr_be_event (s=0x559d6f2ffea0, event=CHR_EVENT_OPENED) at ../chardev/char.c:62 #19 0x0000559d6ddc7fdc in qemu_chr_be_event (s=0x559d6f2ffea0, event=CHR_EVENT_OPENED) at ../chardev/char.c:82 This issue causes guest kernel stop kicking device and traffic stop. Add vhost_started check in virtio_net_handle_tx_bh to fix this wrong VRING_USED_F_NO_NOTIFY set. Signed-off-by: Yajun Wu Reviewed-by: Jiri Pirko Acked-by: Michael S. Tsirkin Message-ID: <20240402045109.97729-1-yajunw@nvidia.com> [PMD: Use unlikely()] Signed-off-by: Philippe Mathieu-Daudé --- hw/net/virtio-net.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a6ff000cd9..58014a92ad 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2865,6 +2865,10 @@ static void virtio_net_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq) VirtIONet *n = VIRTIO_NET(vdev); VirtIONetQueue *q = &n->vqs[vq2q(virtio_get_queue_index(vq))]; + if (unlikely(n->vhost_started)) { + return; + } + if (unlikely((n->status & VIRTIO_NET_S_LINK_UP) == 0)) { virtio_net_drop_tx_queue_data(vdev, vq); return;