Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1060256lqt; Tue, 19 Mar 2024 11:23:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZlOHtOv9DLpMHtu8tNF7YjIXtzL0OOjf+J/T4mPdp+OOuZUZIchxQwtahfCtbzjKEMdDjtTHdgzVBKeQuB1JM5hNzzscBq3kRUiQcjQ== X-Google-Smtp-Source: AGHT+IHlHhABfSiAe2Gj8cICSSZ95C+bkxKkAa2qvWdjJzg0ZbACnyY7BG4+mJmTY02FFJBMGF9d X-Received: by 2002:a05:6a00:1806:b0:6e4:62ed:23c3 with SMTP id y6-20020a056a00180600b006e462ed23c3mr17895416pfa.9.1710872599123; Tue, 19 Mar 2024 11:23:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710872599; cv=pass; d=google.com; s=arc-20160816; b=V0bkmXM1evp4DT+vAB0OL5GZ1qgYtntBemutK4e017+x5XBDhdTzr/zhlbOp7ZVB0D d+1yIifILAdVmDRsBCa+bybXwLU+Z5YUF/scLqLvzHafSfZYsvVBYuCCOaAkMMjEysAR w7CYg8a4wW6Ah7Aavl+6pCyBMutBcltASqnXZQ+u+eVyXAYKonkAiB1zsN/5/ifiuDvI 9xRVmiQXAi+S3F4Errf/1zzxl0TFEOfL8MmqTgRlzzebZM6EBtsux8/mH7DEgI3HPFIY tv264Cpu9zQGYy2oZbbbjF97LW5NKy3XV0wEO8ZvvL9PTTP+bFMvfHAut3wUJ8Yj+uAY c7cw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=9Ax/CqmYp376b84AAF7ltXyfNLa1ZwWqxEP8NzfeqbE=; fh=uIlRbSOkZFb29SD4tkIE26jEtSEfxPyvP3ozhuHvxK4=; b=d5qanSvGltRnDc+HJpe6OwDGVyXA5TxQdSY7gM9S2uD6JIeF6jeaezQoVTSKOw1dyB mTSdGjDca1gAHOQ5REs8NpWLXxIsHDEHcnpTix/MwqjslrHGb/eyTeTxxcFTll10GZUY H2lTpWdJrgw/QRwoeXA3Ca0nzYKiTcJmjH7KNeBZw0ivL+IUMdyxbN3Z/q4AgscDkSZZ BKVMZpDYDH5nAaHdc4TsENuAixjIJ2NqAFa44UoB5UeTQvO43nZit6IXncfSMc/Rjwy5 I+btww6dFdcsXE1Hc+HLnP9cK3VkSWilGk7lES9jyfUV0h6GCO4q0zjPuoCzu5hfHge0 mcyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rDbrMCe1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jw35-20020a056a0092a300b006e48649bbe3si12505928pfb.343.2024.03.19.11.23.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 11:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rDbrMCe1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C0084283CB0 for ; Tue, 19 Mar 2024 18:23:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8417238DC3; Tue, 19 Mar 2024 18:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rDbrMCe1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6D905374F2; Tue, 19 Mar 2024 18:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710872577; cv=none; b=T4mcEM87yWFbiKAZS5lMd2ySxnwVxkwAUznMg1cg8LEvyocbjKny0p3v2le1aGiZDGbrk0VC6zINZwNOswQh8DfWLQiX1VvyPAwOmY3u0pTHzwn/2zBKKk1iVC7CR97cKeKjlGPiZCLLBXLJ4UAdadNkq38APdtAQZzqnt6RFE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710872577; c=relaxed/simple; bh=T/xW9xACdijAKdAsTAcfOoYLNSPzlFzEkZf6uy18UYw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jH7CBn+z7OeRnSxRlO0mqKc4uYaaEdMyqN5AjFBQqf1op1g7EQR5SkOSF/4jRQ7+7gUU12j5NGpGVSZLyH1LAvR14mJ43pkNHRzH/D41RK7AmXGMMe5COLfYCEXDJ8N4/9+3q6MJQLgS19syldlOZQEBSUYGrQdWEsXC96xVtao= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rDbrMCe1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBCB6C43390; Tue, 19 Mar 2024 18:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710872576; bh=T/xW9xACdijAKdAsTAcfOoYLNSPzlFzEkZf6uy18UYw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rDbrMCe1KWxt3v/BQGVS9s1d03mwvHYcCBlT2CGLZelWwqbOd4jcvfiEpUbmnti9u x2ThGrn9ImJQ+iQXzvdCo0i0xRcwl22auO9S8+/URavirztZprUPknHUQTqNoov63g 4NMMkghdb207xs1Fig/CIXKZ8buqdnXSg9IHr8KzuTB/8Wt+stdfsEfLGjpZpUKbp+ 6V5HQWcP0TOboD6EyHmdyAx8G3vFBETm99hdEJ7o0QUhC1bdygmUR+Y/iMx4mkuZl2 9H9Wb0DoxAukmvXYqIFwKFV3POZ1g4Qb7whpPQGMtRmYxEb8kTLjRg61/POb5e8KHw coNmgm7TQ5n8Q== Date: Tue, 19 Mar 2024 18:22:51 +0000 From: Will Deacon To: Gavin Shan Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, yihyu@redhat.com, shan.gavin@gmail.com, linux-arm-kernel@lists.infradead.org, Catalin Marinas , mochs@nvidia.com Subject: Re: [PATCH] virtio_ring: Fix the stale index in available ring Message-ID: <20240319182251.GB3121@willie-the-truck> References: <20240314074923.426688-1-gshan@redhat.com> <20240318165924.GA1824@willie-the-truck> <35a6bcef-27cf-4626-a41d-9ec0a338fe28@redhat.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <35a6bcef-27cf-4626-a41d-9ec0a338fe28@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) On Tue, Mar 19, 2024 at 02:59:23PM +1000, Gavin Shan wrote: > On 3/19/24 02:59, Will Deacon wrote: > > On Thu, Mar 14, 2024 at 05:49:23PM +1000, Gavin Shan wrote: > > > The issue is reported by Yihuang Yu who have 'netperf' test on > > > NVidia's grace-grace and grace-hopper machines. The 'netperf' > > > client is started in the VM hosted by grace-hopper machine, > > > while the 'netperf' server is running on grace-grace machine. > > > > > > The VM is started with virtio-net and vhost has been enabled. > > > We observe a error message spew from VM and then soft-lockup > > > report. The error message indicates the data associated with > > > the descriptor (index: 135) has been released, and the queue > > > is marked as broken. It eventually leads to the endless effort > > > to fetch free buffer (skb) in drivers/net/virtio_net.c::start_xmit() > > > and soft-lockup. The stale index 135 is fetched from the available > > > ring and published to the used ring by vhost, meaning we have > > > disordred write to the available ring element and available index. > > > > > > /home/gavin/sandbox/qemu.main/build/qemu-system-aarch64 \ > > > -accel kvm -machine virt,gic-version=host \ > > > : \ > > > -netdev tap,id=vnet0,vhost=on \ > > > -device virtio-net-pci,bus=pcie.8,netdev=vnet0,mac=52:54:00:f1:26:b0 \ > > > > > > [ 19.993158] virtio_net virtio1: output.0:id 135 is not a head! > > > > > > Fix the issue by replacing virtio_wmb(vq->weak_barriers) with stronger > > > virtio_mb(false), equivalent to replaced 'dmb' by 'dsb' instruction on > > > ARM64. It should work for other architectures, but performance loss is > > > expected. > > > > > > Cc: stable@vger.kernel.org > > > Reported-by: Yihuang Yu > > > Signed-off-by: Gavin Shan > > > --- > > > drivers/virtio/virtio_ring.c | 12 +++++++++--- > > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > > index 49299b1f9ec7..7d852811c912 100644 > > > --- a/drivers/virtio/virtio_ring.c > > > +++ b/drivers/virtio/virtio_ring.c > > > @@ -687,9 +687,15 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, > > > avail = vq->split.avail_idx_shadow & (vq->split.vring.num - 1); > > > vq->split.vring.avail->ring[avail] = cpu_to_virtio16(_vq->vdev, head); > > > - /* Descriptors and available array need to be set before we expose the > > > - * new available array entries. */ > > > - virtio_wmb(vq->weak_barriers); > > > + /* > > > + * Descriptors and available array need to be set before we expose > > > + * the new available array entries. virtio_wmb() should be enough > > > + * to ensuere the order theoretically. However, a stronger barrier > > > + * is needed by ARM64. Otherwise, the stale data can be observed > > > + * by the host (vhost). A stronger barrier should work for other > > > + * architectures, but performance loss is expected. > > > + */ > > > + virtio_mb(false); > > > vq->split.avail_idx_shadow++; > > > vq->split.vring.avail->idx = cpu_to_virtio16(_vq->vdev, > > > vq->split.avail_idx_shadow); > > > > Replacing a DMB with a DSB is _very_ unlikely to be the correct solution > > here, especially when ordering accesses to coherent memory. > > > > In practice, either the larger timing different from the DSB or the fact > > that you're going from a Store->Store barrier to a full barrier is what > > makes things "work" for you. Have you tried, for example, a DMB SY > > (e.g. via __smb_mb()). > > > > We definitely shouldn't take changes like this without a proper > > explanation of what is going on. > > > > Thanks for your comments, Will. > > Yes, DMB should work for us. However, it seems this instruction has issues on > NVidia's grace-hopper. It's hard for me to understand how DMB and DSB works > from hardware level. I agree it's not the solution to replace DMB with DSB > before we fully understand the root cause. > > I tried the possible replacement like below. __smp_mb() can avoid the issue like > __mb() does. __ndelay(10) can avoid the issue, but __ndelay(9) doesn't. > > static inline int virtqueue_add_split(struct virtqueue *_vq, ...) > { > : > /* Put entry in available array (but don't update avail->idx until they > * do sync). */ > avail = vq->split.avail_idx_shadow & (vq->split.vring.num - 1); > vq->split.vring.avail->ring[avail] = cpu_to_virtio16(_vq->vdev, head); > > /* Descriptors and available array need to be set before we expose the > * new available array entries. */ > // Broken: virtio_wmb(vq->weak_barriers); > // Broken: __dma_mb(); > // Work: __mb(); > // Work: __smp_mb(); It's pretty weird that __dma_mb() is "broken" but __smp_mb() "works". How confident are you in that result? Will