Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6673991ybl; Mon, 23 Dec 2019 09:42:17 -0800 (PST) X-Google-Smtp-Source: APXvYqz1XZ2O1ukQPu3oW8kPuM5N3oulXrrC5HPKVwn2QsvAReVt+pOQhekpOPR4ai7zZ9CvdziZ X-Received: by 2002:a9d:6ac1:: with SMTP id m1mr22300003otq.101.1577122937078; Mon, 23 Dec 2019 09:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577122937; cv=none; d=google.com; s=arc-20160816; b=cugFosnqvmuWtLXHZRPmjbJo7pIylnvEKFqKoSkpam4epEwgtaaN6IVT9mk1zHiukd 55rpZriw2Y0KNYKo4RfZ1c6uV/VghhBzY3TtqvGYI+RhtMvDzyrJPuOmYGTEHPDEKPVS RoRCSxe8tGKbbAsDgtvyHw/Ezctc+TtxieZ96HeDHBkZmYJxFepNdFGIIdQg30avgD7X DDlbnKLsDhv5V7IDcatsIe1062fNtX90wcvK/P0XUzfGZAy2sdKJuggdq522FmfuyfIN uWzSbMwOKqYAgOn9RntWvCnxxLGav4KIX9jVNB87vOI6N2XL9PHRXh7Dc/tg7Q/jBk30 SbXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=eNFLSoQe0lR2iyKnAuV1NRMQR96oeCjWqMmsqcgP9RM=; b=f5H0ekZa263PdrMGgLcfAzScSNrIMpw8ACDtIVgnrV+fTgWgQSNmp2cKYaryOxuiP+ CQYZKtpJeTmvXKcMRkab76F1F/IcdSKKdEAwnlmru8FBSw+LaMgLzTpqxjZLOSk42Oxm JSBQIYxxDNcIalJmBJrIJd2VUOoLHbYYk8gsDse9ETK7VPFz/y1AMDW3OAcLYkSAep0J g3dbySt/SSMeGY2S6yAd6gdrAUqNb4r6WFcmLzn4Y2ItjmV0l49k5AvUQLfJWnGfSidb iuZSo1JzkImNifC9GnnWFh2SpDKYQK437daIJ/ytvji+6YfpdmOR3pbnPhYpAhRCnGs9 OycA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=A6UZvDMZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7si9366543otp.284.2019.12.23.09.42.04; Mon, 23 Dec 2019 09:42:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=A6UZvDMZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbfLWRkY (ORCPT + 99 others); Mon, 23 Dec 2019 12:40:24 -0500 Received: from mail-ua1-f68.google.com ([209.85.222.68]:44791 "EHLO mail-ua1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726718AbfLWRkY (ORCPT ); Mon, 23 Dec 2019 12:40:24 -0500 Received: by mail-ua1-f68.google.com with SMTP id c14so4713770uaq.11 for ; Mon, 23 Dec 2019 09:40:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eNFLSoQe0lR2iyKnAuV1NRMQR96oeCjWqMmsqcgP9RM=; b=A6UZvDMZ6PHfMyRnfDW7eocx2YHhfaaGFDnHpYc5aIuoxJebfqe33MkLZGMMFzCLYM ez/SoCKJ9NkLWwppNKcKGJDwR4SIVI//JKriCLqben34vI7aTZurMV5CZBTYlThU+RBi Q0JfMrnt2fRB985Fp4l/iNrZgu6FygN8LSwiel7gKnFpeh6ZB2NvKeUgIa7AVz3ipXxF 6Xb9ZEw15NVPDsVR3sQJFPyYGziFG2zrXpimZmQst9z9MQ8jem8GaUdNZKCIxV5dsOYB BMhQHF5+WkTtVFyA+WzeSpfEFj9VAi/Wr+QYB2MFGqvrei9MemphVg4bfl62O5np62Jm 8LQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eNFLSoQe0lR2iyKnAuV1NRMQR96oeCjWqMmsqcgP9RM=; b=VoIijX8AGeBGz5dprtYL6SHCDcH/fzodaxmd5ESqd4VGEzeoOPD1dJqSkcu5oVbVgA 984yXohIQ967zr6GjVkw4OnDjP1WmRM8I/sdQTc/ymneq6YPN1Gey0YkERuasusx5a9m aWtgbH9Ftn1HlyJNhw/hKedsiZTbxTPE14BxLogKN5SfpV4GfUhe8umeY3VxfGldXGpS QMKPXH6EWx7zmuB0oIYPHI8BVIH3t3yvmg+S+Tlz+mTKctOIjmks7Lxdv+3TKb+o2GRQ IDXnZVTZdMXe3XfqQ5WYay56CZIdqm+pgvTVtFW5UO7GgSPLz/60EyaEOn9ylkqX0WTL KvVw== X-Gm-Message-State: APjAAAVAmHhF376ay8FfzTIP2CxFoKbIoDDnJz0enxQyvEZewh6pImzr 0QASoHB/omVdKMzjH0LQZE3DDBxzKMHue0AUYU1FMQ== X-Received: by 2002:a9f:36ca:: with SMTP id p68mr17497306uap.112.1577122822284; Mon, 23 Dec 2019 09:40:22 -0800 (PST) MIME-Version: 1.0 References: <20191223140322.20013-1-mst@redhat.com> In-Reply-To: <20191223140322.20013-1-mst@redhat.com> From: Alistair Delva Date: Mon, 23 Dec 2019 09:40:11 -0800 Message-ID: Subject: Re: [PATCH net] virtio_net: CTRL_GUEST_OFFLOADS depends on CTRL_VQ To: "Michael S. Tsirkin" Cc: LKML , Willem de Bruijn , Jason Wang , "David S. Miller" , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, On Mon, Dec 23, 2019 at 6:09 AM Michael S. Tsirkin wrote: > > The only way for guest to control offloads (as enabled by > VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) is by sending commands > through CTRL_VQ. So it does not make sense to > acknowledge VIRTIO_NET_F_CTRL_GUEST_OFFLOADS without > VIRTIO_NET_F_CTRL_VQ. > > The spec does not outlaw devices with such a configuration, > but Linux assumed that with VIRTIO_NET_F_CTRL_GUEST_OFFLOADS > control vq is always there, resulting in the following crash > when configuring LRO: > > kernel BUG at drivers/net/virtio_net.c:1591! > invalid opcode: 0000 [#1] PREEMPT SMP PTI > CPU: 1 PID: 483 Comm: Binder:330_1 Not tainted 5.4.5-01326-g19463e9acaac #1 > Hardware name: ChromiumOS crosvm, BIOS 0 > RIP: 0010:virtnet_send_command+0x15d/0x170 [virtio_net] > Code: d8 00 00 00 80 78 02 00 0f 94 c0 65 48 8b 0c 25 28 00 00 00 48 3b 4c 24 70 75 11 48 8d 65 d8 5b 41 5c 41 5d 41 5e 41 5f 5d > +c3 <0f> 0b e8 ec a4 12 c8 66 90 66 2e 0f 1f 84 00 00 00 00 00 55 48 89 > RSP: 0018:ffffb97940e7bb50 EFLAGS: 00010246 > RAX: ffffffffc0596020 RBX: ffffa0e1fc8ea840 RCX: 0000000000000017 > RDX: ffffffffc0596110 RSI: 0000000000000011 RDI: 000000000000000d > RBP: ffffb97940e7bbf8 R08: ffffa0e1fc8ea0b0 R09: ffffa0e1fc8ea0b0 > R10: ffffffffffffffff R11: ffffffffc0590940 R12: 0000000000000005 > R13: ffffa0e1ffad2c00 R14: ffffb97940e7bc08 R15: 0000000000000000 > FS: 0000000000000000(0000) GS:ffffa0e1fd100000(006b) knlGS:00000000e5ef7494 > CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 > CR2: 00000000e5eeb82c CR3: 0000000079b06001 CR4: 0000000000360ee0 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > Call Trace: > ? preempt_count_add+0x58/0xb0 > ? _raw_spin_lock_irqsave+0x36/0x70 > ? _raw_spin_unlock_irqrestore+0x1a/0x40 > ? __wake_up+0x70/0x190 > virtnet_set_features+0x90/0xf0 [virtio_net] > __netdev_update_features+0x271/0x980 > ? nlmsg_notify+0x5b/0xa0 > dev_disable_lro+0x2b/0x190 > ? inet_netconf_notify_devconf+0xe2/0x120 > devinet_sysctl_forward+0x176/0x1e0 > proc_sys_call_handler+0x1f0/0x250 > proc_sys_write+0xf/0x20 > __vfs_write+0x3e/0x190 > ? __sb_start_write+0x6d/0xd0 > vfs_write+0xd3/0x190 > ksys_write+0x68/0xd0 > __ia32_sys_write+0x14/0x20 > do_fast_syscall_32+0x86/0xe0 > entry_SYSENTER_compat+0x7c/0x8e > > A similar crash will likely trigger when enabling XDP. > > Reported-by: Alistair Delva > Reported-by: Willem de Bruijn > Fixes: 3f93522ffab2 ("virtio-net: switch off offloads on demand if possible on XDP set") > Signed-off-by: Michael S. Tsirkin > --- > > Lightly tested. > > Alistair, could you please test and confirm that this resolves the > crash for you? This patch doesn't work. The reason is that NETIF_F_LRO is also turned on by TSO4/TSO6, which your patch didn't check for. So it ends up going through the same path and crashing in the same way. if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6)) dev->features |= NETIF_F_LRO; It sounds like this patch is fixing something slightly differently to my patch fixed. virtnet_set_features() doesn't care about GUEST_OFFLOADS, it only tests against NETIF_F_LRO. Even if "offloads" is zero, it will call virtnet_set_guest_offloads(), which triggers the crash. So either we need to ensure NETIF_F_LRO is never set, or virtnet_set_features needs to be updated to check for GUEST_OFFLOADS, right? > Dave, after testing confirms the fix, pls queue up for stable. > > > drivers/net/virtio_net.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 4d7d5434cc5d..7b8805b47f0d 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -2971,6 +2971,15 @@ static int virtnet_validate(struct virtio_device *vdev) > if (!virtnet_validate_features(vdev)) > return -EINVAL; > > + /* VIRTIO_NET_F_CTRL_GUEST_OFFLOADS does not work without > + * VIRTIO_NET_F_CTRL_VQ. However the virtio spec does not > + * specify that VIRTIO_NET_F_CTRL_GUEST_OFFLOADS depends > + * on VIRTIO_NET_F_CTRL_VQ so devices can set the later but > + * not the former. > + */ > + if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) > + __virtio_clear_bit(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS); > + > if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) { > int mtu = virtio_cread16(vdev, > offsetof(struct virtio_net_config, > -- > MST >