From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 466C1204F66 for ; Thu, 12 Dec 2024 07:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733987154; cv=none; b=A+qN77O8O48Z0pP+P8u4XleFDkp2en1Xky1fqtoklS/4rAZctw/hCnYFPRw9fJHlZ/dY8fij6hB16EA+4yIsm2U8FPhWU3xn8d+8uSE8zK1ijksL70VOZC9gwzy4ELTXMxLx7yl9hdxCKH8oQkPjKDySg/0QHzMPx0XKGPDjXu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733987154; c=relaxed/simple; bh=DSZ+IehQJhmlPIR9/gNF3ubk68Lm13DfgD6eA2ic+cg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: In-Reply-To:Content-Type:Content-Disposition; b=dzIbl59bX4i+brqNKluLgP5c4aBEne7ILHoIRPhtph0QMxALHMPe4ssd2f9V0tR6+cbU0AfVrSVpYXNhNdD3yj92lsTzYoQ1MqY6ah1Zog2CJDBKbIkEqaZ41Xi0MDNEKe57uD2wUtSma4++wWZK8DMgPSNJKMxnEG7T0SBmEeI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HMa8wNY0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HMa8wNY0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733987151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wPeg3BTCLY7xnzRULcn3ix+0YqKjZBn4RoFU3T2fZgc=; b=HMa8wNY0mSTZ9dotnQJcux2UvhDJgcBTuVAvVoQs2xO2uTKS1dUG8TSUHuqSjz3yr3WJe9 CypDfX5cnhqSYsTt2MJYk3pUPmcg5ZsDc72wJYEosdOx6Ghh1r2q8MHk63B6uLvjn38YG9 LVG9g2p49FFk5VZst48KLYYVD/vOQ2I= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-AwFRdQ9JMImpnMkIX7uC5A-1; Thu, 12 Dec 2024 02:05:49 -0500 X-MC-Unique: AwFRdQ9JMImpnMkIX7uC5A-1 X-Mimecast-MFC-AGG-ID: AwFRdQ9JMImpnMkIX7uC5A Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43619b135bcso1414475e9.1 for ; Wed, 11 Dec 2024 23:05:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733987148; x=1734591948; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rti03MdrVXI/elGajytboAaA+i7ZN4OIWBTI355So04=; b=i6vCwqF12OSCBvVEsPsqhl52R2nxvnHU0o+NbPVRcoPLkUT3zKgAZrRLekmddhtZGZ PljEERUFCoT3Cq4ePQHafIc6l3vI+dL8pP39DeZR3QiGFFARRaHMulV7jpATYsL4B0Hx EZXmTP/NLxcOIqx3Z7QjWrXN/r9TbqhtnUZKlciO5ictgah/fO/LJrotYDVqUiHb9SLh Nyv+ALq8uvqpew/Si3in7ElnK/FurnCFQm4E80UYCZWWG9ZRKNNpU0cUIAi6wnQIyDaF ciK8gyccIPKZi1TANyLQ5OiNKqlhzNubBhcHHlQ/N8CeGmpIsRC2047l+W4ehBWGYcEw brew== X-Gm-Message-State: AOJu0Yw3d/FGpvvn6VLEX7AZD1JHhfQbfRInLEfCKWBfzR4ddiqk5CbD WoKwZUVoChHvGFdtD13ns2SFIhuZJu4KkPo8Y6W7X/fuu0dX31yhD5OIWI8AjJXs8bY6dTRG7jY ZbieVBT6zjpnUb20jLxQsYw4W6vyJumYVEwc2enlbgmdRse+I5/pS3U0SwvDVbE+C X-Gm-Gg: ASbGncs4piq7Yc1I+zDoqrgsq1/IZMjfcLJDOstqadK3XhKPZHBhcucmCjT45rTbP7F eDQeZCcWLv0DlFEYJN1Oore4qVyoYc+VntzYdlPagdsLiY3Fvp6nk+BE6v0I/IE44EHrUI1Q83C sFaJ/3FpKMwOLL+5fC7PSkBUcvGqq/+RO4AiBa5WfkqVD3An1Ql8HpUMz2KwCvjVqJRuHMOUfZE usI6PTJWe9fVtrBg8v2paiVgjR40zMzt29aB9FvxG8HXnvibw== X-Received: by 2002:a05:600c:1c85:b0:434:fdbc:5cf7 with SMTP id 5b1f17b1804b1-4361c416003mr39047775e9.27.1733987148533; Wed, 11 Dec 2024 23:05:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHM80JCEN7MZoecTSwl2bXnHH1Ct9tE9wGDfZGHrSJBXJKgu6o9wF6yCI7CnMl4kLTpHYS1ew== X-Received: by 2002:a05:600c:1c85:b0:434:fdbc:5cf7 with SMTP id 5b1f17b1804b1-4361c416003mr39047425e9.27.1733987148104; Wed, 11 Dec 2024 23:05:48 -0800 (PST) Received: from redhat.com ([2a02:14f:179:603a:6ff0:d430:c1c2:5bc9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43625553208sm7354775e9.9.2024.12.11.23.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:05:47 -0800 (PST) Date: Thu, 12 Dec 2024 02:05:42 -0500 From: "Michael S. Tsirkin" To: Koichiro Den Cc: virtualization@lists.linux.dev, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH net v4 0/6] virtio_net: correct netdev_tx_reset_queue() invocation points Message-ID: <20241212020531-mutt-send-email-mst@kernel.org> References: <20241206011047.923923-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20241206011047.923923-1-koichiro.den@canonical.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ssKaiwXx4JPKzfdHJ0wnMGZJ-BLTsyl0_T7Kdl4eKq4_1733987149 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 06, 2024 at 10:10:41AM +0900, Koichiro Den wrote: > When virtnet_close is followed by virtnet_open, some TX completions can > possibly remain unconsumed, until they are finally processed during the > first NAPI poll after the netdev_tx_reset_queue(), resulting in a crash > [1]. Commit b96ed2c97c79 ("virtio_net: move netdev_tx_reset_queue() call > before RX napi enable") was not sufficient to eliminate all BQL crash > scenarios for virtio-net. >=20 > This issue can be reproduced with the latest net-next master by running: > `while :; do ip l set DEV down; ip l set DEV up; done` under heavy networ= k > TX load from inside the machine. >=20 > This patch series resolves the issue and also addresses similar existing > problems: >=20 > (a). Drop netdev_tx_reset_queue() from open/close path. This eliminates t= he > BQL crashes due to the problematic open/close path. >=20 > (b). As a result of (a), netdev_tx_reset_queue() is now explicitly requir= ed > in freeze/restore path. Add netdev_tx_reset_queue() immediately afte= r > free_unused_bufs() invocation. >=20 > (c). Fix missing resetting in virtnet_tx_resize(). > virtnet_tx_resize() has lacked proper resetting since commit > c8bd1f7f3e61 ("virtio_net: add support for Byte Queue Limits"). >=20 > (d). Fix missing resetting in the XDP_SETUP_XSK_POOL path. > Similar to (c), this path lacked proper resetting. Call > netdev_tx_reset_queue() when virtqueue_reset() has actually recycled > unused buffers. thanks Acked-by: Michael S. Tsirkin > This patch series consists of six commits: > [1/6]: Resolves (a) and (b). # also -stable 6.11.y > [2/6]: Minor fix to make [4/6] streamlined. > [3/6]: Prerequisite for (c). # also -stable 6.11.y > [4/6]: Resolves (c) (incl. Prerequisite for (d)) # also -stable 6.11.y > [5/6]: Preresuisite for (d). > [6/6]: Resolves (d). >=20 > Changes for v4: > - move netdev_tx_reset_queue() out of free_unused_bufs() > - submit to net, not net-next > Changes for v3: > - replace 'flushed' argument with 'recycle_done' > Changes for v2: > - add tx queue resetting for (b) to (d) above >=20 > v3: https://lore.kernel.org/all/20241204050724.307544-1-koichiro.den@cano= nical.com/ > v2: https://lore.kernel.org/all/20241203073025.67065-1-koichiro.den@canon= ical.com/ > v1: https://lore.kernel.org/all/20241130181744.3772632-1-koichiro.den@can= onical.com/ >=20 > [1]: > ------------[ cut here ]------------ > kernel BUG at lib/dynamic_queue_limits.c:99! > Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI > CPU: 7 UID: 0 PID: 1598 Comm: ip Tainted: G N 6.12.0net-next_main+ #2 > Tainted: [N]=3DTEST > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), \ > BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 > RIP: 0010:dql_completed+0x26b/0x290 > Code: b7 c2 49 89 e9 44 89 da 89 c6 4c 89 d7 e8 ed 17 47 00 58 65 ff 0d > 4d 27 90 7e 0f 85 fd fe ff ff e8 ea 53 8d ff e9 f3 fe ff ff <0f> 0b 01 > d2 44 89 d1 29 d1 ba 00 00 00 00 0f 48 ca e9 28 ff ff ff > RSP: 0018:ffffc900002b0d08 EFLAGS: 00010297 > RAX: 0000000000000000 RBX: ffff888102398c80 RCX: 0000000080190009 > RDX: 0000000000000000 RSI: 000000000000006a RDI: 0000000000000000 > RBP: ffff888102398c00 R08: 0000000000000000 R09: 0000000000000000 > R10: 00000000000000ca R11: 0000000000015681 R12: 0000000000000001 > R13: ffffc900002b0d68 R14: ffff88811115e000 R15: ffff8881107aca40 > FS: 00007f41ded69500(0000) GS:ffff888667dc0000(0000) > knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 0000556ccc2dc1a0 CR3: 0000000104fd8003 CR4: 0000000000772ef0 > PKRU: 55555554 > Call Trace: > > ? die+0x32/0x80 > ? do_trap+0xd9/0x100 > ? dql_completed+0x26b/0x290 > ? dql_completed+0x26b/0x290 > ? do_error_trap+0x6d/0xb0 > ? dql_completed+0x26b/0x290 > ? exc_invalid_op+0x4c/0x60 > ? dql_completed+0x26b/0x290 > ? asm_exc_invalid_op+0x16/0x20 > ? dql_completed+0x26b/0x290 > __free_old_xmit+0xff/0x170 [virtio_net] > free_old_xmit+0x54/0xc0 [virtio_net] > virtnet_poll+0xf4/0xe30 [virtio_net] > ? __update_load_avg_cfs_rq+0x264/0x2d0 > ? update_curr+0x35/0x260 > ? reweight_entity+0x1be/0x260 > __napi_poll.constprop.0+0x28/0x1c0 > net_rx_action+0x329/0x420 > ? enqueue_hrtimer+0x35/0x90 > ? trace_hardirqs_on+0x1d/0x80 > ? kvm_sched_clock_read+0xd/0x20 > ? sched_clock+0xc/0x30 > ? kvm_sched_clock_read+0xd/0x20 > ? sched_clock+0xc/0x30 > ? sched_clock_cpu+0xd/0x1a0 > handle_softirqs+0x138/0x3e0 > do_softirq.part.0+0x89/0xc0 > > > __local_bh_enable_ip+0xa7/0xb0 > virtnet_open+0xc8/0x310 [virtio_net] > __dev_open+0xfa/0x1b0 > __dev_change_flags+0x1de/0x250 > dev_change_flags+0x22/0x60 > do_setlink.isra.0+0x2df/0x10b0 > ? rtnetlink_rcv_msg+0x34f/0x3f0 > ? netlink_rcv_skb+0x54/0x100 > ? netlink_unicast+0x23e/0x390 > ? netlink_sendmsg+0x21e/0x490 > ? ____sys_sendmsg+0x31b/0x350 > ? avc_has_perm_noaudit+0x67/0xf0 > ? cred_has_capability.isra.0+0x75/0x110 > ? __nla_validate_parse+0x5f/0xee0 > ? __pfx___probestub_irq_enable+0x3/0x10 > ? __create_object+0x5e/0x90 > ? security_capable+0x3b/0x7=1B[I0 > rtnl_newlink+0x784/0xaf0 > ? avc_has_perm_noaudit+0x67/0xf0 > ? cred_has_capability.isra.0+0x75/0x110 > ? stack_depot_save_flags+0x24/0x6d0 > ? __pfx_rtnl_newlink+0x10/0x10 > rtnetlink_rcv_msg+0x34f/0x3f0 > ? do_syscall_64+0x6c/0x180 > ? entry_SYSCALL_64_after_hwframe+0x76/0x7e > ? __pfx_rtnetlink_rcv_msg+0x10/0x10 > netlink_rcv_skb+0x54/0x100 > netlink_unicast+0x23e/0x390 > netlink_sendmsg+0x21e/0x490 > ____sys_sendmsg+0x31b/0x350 > ? copy_msghdr_from_user+0x6d/0xa0 > ___sys_sendmsg+0x86/0xd0 > ? __pte_offset_map+0x17/0x160 > ? preempt_count_add+0x69/0xa0 > ? __call_rcu_common.constprop.0+0x147/0x610 > ? preempt_count_add+0x69/0xa0 > ? preempt_count_add+0x69/0xa0 > ? _raw_spin_trylock+0x13/0x60 > ? trace_hardirqs_on+0x1d/0x80 > __sys_sendmsg+0x66/0xc0 > do_syscall_64+0x6c/0x180 > entry_SYSCALL_64_after_hwframe+0x76/0x7e > RIP: 0033:0x7f41defe5b34 > Code: 15 e1 12 0f 00 f7 d8 64 89 02 b8 ff ff ff ff eb bf 0f 1f 44 00 00 > f3 0f 1e fa 80 3d 35 95 0f 00 00 74 13 b8 2e 00 00 00 0f 05 <48> 3d 00 > f0 ff ff 77 4c c3 0f 1f 00 55 48 89 e5 48 83 ec 20 89 55 > RSP: 002b:00007ffe5336ecc8 EFLAGS: 00000202 ORIG_RAX: 000000000000002e > RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f41defe5b34 > RDX: 0000000000000000 RSI: 00007ffe5336ed30 RDI: 0000000000000003 > RBP: 00007ffe5336eda0 R08: 0000000000000010 R09: 0000000000000001 > R10: 00007ffe5336f6f9 R11: 0000000000000202 R12: 0000000000000003 > R13: 0000000067452259 R14: 0000556ccc28b040 R15: 0000000000000000 > > [...] > ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]--- >=20 > Koichiro Den (6): > virtio_net: correct netdev_tx_reset_queue() invocation point > virtio_net: replace vq2rxq with vq2txq where appropriate > virtio_ring: add a func argument 'recycle_done' to virtqueue_resize() > virtio_net: ensure netdev_tx_reset_queue is called on tx ring resize > virtio_ring: add a func argument 'recycle_done' to virtqueue_reset() > virtio_net: ensure netdev_tx_reset_queue is called on bind xsk for tx >=20 > drivers/net/virtio_net.c | 31 +++++++++++++++++++++++++------ > drivers/virtio/virtio_ring.c | 12 ++++++++++-- > include/linux/virtio.h | 6 ++++-- > 3 files changed, 39 insertions(+), 10 deletions(-) >=20 > --=20 > 2.43.0