Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3450375lqp; Tue, 26 Mar 2024 09:24:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUlyHt7BQURVYTSysy4l+cNRS1IOgF30b4T/q+DaGiXCtF19Fp1ICqNHuxEjsK+M+PlDPkVHA72ejeapw1mdLkGvOGBmZScH7paEpR7SA== X-Google-Smtp-Source: AGHT+IGtE6piEQ53S469BAPGl3mFx9yGb7YgjUuRIZcztGb4qVcwV53w94ybelahpAS51P0SMihm X-Received: by 2002:a05:6a00:6c8c:b0:6e7:34f5:f0ea with SMTP id jc12-20020a056a006c8c00b006e734f5f0eamr2741974pfb.17.1711470244197; Tue, 26 Mar 2024 09:24:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711470244; cv=pass; d=google.com; s=arc-20160816; b=Q290LpEZOQuEmwwbIafP2LNg3vpazki+F0+m2gI7wIAfBqc0uxei58NdUOz2skDXs0 VduNo7INfsxFBujjmFsX9RZrEmCUgMMH3+tK4GIWK45m3zdwsxjJu57tm0cx0caTkhxs fJFDdWpc10CppXLxqOtQwIJSPD8xWNMrghSFSBXZH2RMRC9ychhWEwrRNDflYOj1Rw5J GzZ41P1ZOc8+pRnKMf9dHmMbPWdsKJsEI1gA/xnv2HqhtNym60NnUnnwFneeBkDBesFK DvZDOYR2MxrJJ3lD8iKoEL/V9jbO2fzeQvrHAylUHlRLpDkGlA8Ed+klUFZ4r8zDs4Kn QJrg== 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=gdFHRvV1zjI9NKXaOGsV3yIGlOjoGNxIbxUklJdVRHc=; fh=aoxCHVx6kDx7mGMTZO8gq5fSj7IohdxNi3Rapy3tWV8=; b=PFMH5CDD9CNdIhg2+oMfLIfLYPUgm6DmZtcJusWRBx0P7WAWMcRdWnDVNrQ+gbPl26 rA3gCgy0Cv3aNwBLZxAxk254qb29wW/4cU2SzYfR8bYt14nGwDYcbMwqkUCLQUS7OjNQ VkrggthepGhQgA+6cv0jKvDba0dFDIhQZta916vYXFL1JzE0+dSf6c8Ioh18rFyxSJyw fRseBxHkaD7Hk99RuvVaGT0SUVm4uffoWdd0c/GrRNx6uHGKBpwt8wRWeGr9A3IWyyUS OLRKJVX6fAQzI7UdxoCYrawlY0IAUvMDiO8TcAGuanz5xp2qg4jTdjgqzja4ZnP8by4O wKoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EtXOD6iW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119389-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 71-20020a63004a000000b005e838a81bf7si10145268pga.480.2024.03.26.09.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:24:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119389-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EtXOD6iW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119389-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119389-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 28C91B2A930 for ; Tue, 26 Mar 2024 15:53:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26BEB13C9AF; Tue, 26 Mar 2024 15:46:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EtXOD6iW" 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 44E7013C3C4; Tue, 26 Mar 2024 15:46:34 +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=1711467995; cv=none; b=eikQpBj7jQPmVE04jJ4MXRBgD/hW9Ok8w6eXyGrm0a71JGQRMD16ZPNJf63ir4T1PPXO8NUon6WwAeibkEG/LCTzyT06IIu5mfkZxHxnMEt80NCMATxnlZ103hWgX+SKxQoChWLlPtODzLErADPfZTTjFKTQwqwPV1ccdkLBGJc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711467995; c=relaxed/simple; bh=blMMUCS6bBwkEUeKDfD5/uqKHUYqqABX3cMRG8GSLtw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PnEmZfaRFCq0CywlbKY1GikGDLB63uh219sNsDQb+IApCUEuX2ndjej8Kt5VbUnolY1oSaLYpthueKJqmFyXAlMXojp6q0U3rZ7k9NJE0v9UO7sCEhBPuDDIG2cIjKO7RKtyRC1OApB3J8V1Na3w6sMpzrrEzIlfCl0iZRd0A7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EtXOD6iW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89CCFC43394; Tue, 26 Mar 2024 15:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711467994; bh=blMMUCS6bBwkEUeKDfD5/uqKHUYqqABX3cMRG8GSLtw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EtXOD6iWSamqz0Z4Z2qRKxQx5zenEIGgmpVobYercZRuxN04pSqre+436BYwczR1z xUOu00ogyzPBJ8VMxe2OtroDVVpSOLB9/VDJc3ZtWe9Z8trBwb5AzHdzZ6dBKnOl7S j23/yCWp4ziRHXMaC4sTcB6jaRBAmL2VMghON5PvuR+B9aWB5BflLQY32JLyjdhCsI BFqWK+dSiPl0qkEXLWxqlVE2TCrHh3fn6sneuVVO7ZmLsgcCjohsGQd4eIra3LxnNF Wsa3oI7oWDa/z1ouDfCokJH30C5BAgGAnoVMjquuwSGVql191lxWXcTwXXZCLOrny9 dZV3fMT7ND9gA== Date: Tue, 26 Mar 2024 15:46:29 +0000 From: Will Deacon To: Keir Fraser , gshan@redhat.com Cc: "Michael S. Tsirkin" , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, 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: <20240326154628.GA9613@willie-the-truck> References: <35a6bcef-27cf-4626-a41d-9ec0a338fe28@redhat.com> <20240319182251.GB3121@willie-the-truck> <9500adaf-0075-4ae9-92db-7e310b6598b0@redhat.com> <20240319203540-mutt-send-email-mst@kernel.org> <3a6c8b23-af9c-47a7-8c22-8e0a78154bd3@redhat.com> <20240320030215-mutt-send-email-mst@kernel.org> <1dcec730-ec26-46f4-ba4c-06101fcc599e@redhat.com> <20240326033809-mutt-send-email-mst@kernel.org> <20240326114313.GA9482@willie-the-truck> 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: <20240326114313.GA9482@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) On Tue, Mar 26, 2024 at 11:43:13AM +0000, Will Deacon wrote: > On Tue, Mar 26, 2024 at 09:38:55AM +0000, Keir Fraser wrote: > > On Tue, Mar 26, 2024 at 03:49:02AM -0400, Michael S. Tsirkin wrote: > > > > Secondly, the debugging code is enhanced so that the available head for > > > > (last_avail_idx - 1) is read for twice and recorded. It means the available > > > > head for one specific available index is read for twice. I do see the > > > > available heads are different from the consecutive reads. More details > > > > are shared as below. > > > > > > > > From the guest side > > > > =================== > > > > > > > > virtio_net virtio0: output.0:id 86 is not a head! > > > > head to be released: 047 062 112 > > > > > > > > avail_idx: > > > > 000 49665 > > > > 001 49666 <-- > > > > : > > > > 015 49664 > > > > > > what are these #s 49665 and so on? > > > and how large is the ring? > > > I am guessing 49664 is the index ring size is 16 and > > > 49664 % 16 == 0 > > > > More than that, 49664 % 256 == 0 > > > > So again there seems to be an error in the vicinity of roll-over of > > the idx low byte, as I observed in the earlier log. Surely this is > > more than coincidence? > > Yeah, I'd still really like to see the disassembly for both sides of the > protocol here. Gavin, is that something you're able to provide? Worst > case, the host and guest vmlinux objects would be a starting point. > > Personally, I'd be fairly surprised if this was a hardware issue. Ok, long shot after eyeballing the vhost code, but does the diff below help at all? It looks like vhost_vq_avail_empty() can advance the value saved in 'vq->avail_idx' but without the read barrier, possibly confusing vhost_get_vq_desc() in polling mode. Will --->8 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 045f666b4f12..87bff710331a 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2801,6 +2801,7 @@ bool vhost_vq_avail_empty(struct vhost_dev *dev, struct vhost_virtqueue *vq) return false; vq->avail_idx = vhost16_to_cpu(vq, avail_idx); + smp_rmb(); return vq->avail_idx == vq->last_avail_idx; } EXPORT_SYMBOL_GPL(vhost_vq_avail_empty);