From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BDC99C47DD9 for ; Wed, 27 Mar 2024 11:57:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LUJ31ozu3U99hdGFCD9b2TFfRw8g1PcDFABILW2L92Q=; b=1w844iQpdtkEv5 N3piNuy80XgCHpDtsMqRdiaOa9bT4qTcOvcQLCrgEM2NAVa8uMeH824u28GLm5AF0AosPRaZ/So5x w+s5WHdETBKW7x1PUmT5iQjkb2mAgv8lTEIC2JxVHNsXU1m8EEckBJMdDBwjBCnOwuiEpqrC7m8vF +D1Txnlv91pKa9JsazOpQ/s+Rv5WZoihrSdvOqSiQOz2NamCKixgpuY4DFlIgWKAY1htrcPNGIDOj SCelB17hYu7n4PsyXnKKAxRSYVkGL81JhLxmyFrNy2XWliehQCF/pKx5K8CuiknXpC8nToGJ2XO5W bYNycmpQVCVYu2SfqUtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpRu7-00000008h0q-2pe1; Wed, 27 Mar 2024 11:57:15 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpRu2-00000008gzb-1HGe for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2024 11:57:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711540628; 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: in-reply-to:in-reply-to:references:references; bh=hWri6+tiRPxiqqVnG5Me+/c+BeHQBoEHnxaqpBOMAaM=; b=g+YyVcRTrBoF0zkelwnE7/u9v7MojwI3QlIjTjtkGu4t5eiIzFXDlzhKAU0LTYqejx01F/ cJ8ZFMCGkAG2fRG1fnHgvFa2yivwibA4P7C7iIyBV+xfY3yUxM5u24zvrzIINkJiW9FOrq Y0aMOoYX2lgSVBuSEUcBrSu9kWvj/Kg= 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-85-iOUB9RKlPHi2r3a1PJtwJw-1; Wed, 27 Mar 2024 07:57:06 -0400 X-MC-Unique: iOUB9RKlPHi2r3a1PJtwJw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-414105984aeso36130625e9.0 for ; Wed, 27 Mar 2024 04:57:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711540625; x=1712145425; h=in-reply-to: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=hWri6+tiRPxiqqVnG5Me+/c+BeHQBoEHnxaqpBOMAaM=; b=CYTXg7iGIquarDPmOv4OyUJvkRLCq78Mfvr3oz/A7hKC0I9I+i7tkPkjBCVlqGfG2B hsZb1aVgjOWG1/Qi8xwOyk3Zj3Xd4SjBfdOPhZDbAnwcGtjOL/v0kNPFKdJ2kprgNa7j jKa6V/SjL/i+sL8OF0QOHdDuwT8+1k3GSRnQ51U2klRAbpxFLYS3pRaz8I5EpOrpZvJi LDMzKUSnbFEauSGyLJVnnLbKKqZE3XGj7KK9aLgSBkfF1BCSps9J/Re6gTZv1WMTTQqy eERtS9tYdwZ7rspIs6EFKGVig2A3tOL6ZMJkqxUEOggJgPqTaoP1cov/F93lyU2FZb4y OCcw== X-Forwarded-Encrypted: i=1; AJvYcCWaQWWRGDA1hpvjr2Ch7jlh2gdPXVp8cEDlwSmXj7ZEuCAFHngY1wYNav9UBFrQL/vw9c3gNdEOy/V34yA5l3aIOD3mKOdNRX1Ll1TNaUCXxYdHF+Y= X-Gm-Message-State: AOJu0YxXYHpqhUi3nVT9jPG39+sXYZwFl0EUItQHrSWaMEwKq5ZdfBIj rLP3aEzKPKAuNt56o71uKkuTiLtMIahCXHCQJXKsu/KZWe+/bMOU9fqsUvOwIW42VuiSDtOnO1L kaAnARnOX2tunV3NqckM2WbM3doR6eHZTcV0Pf4nYwb4+KvCjg+FoSIkctnP7Th6QSWOualO1 X-Received: by 2002:a05:600c:3b9e:b0:413:133c:b9c8 with SMTP id n30-20020a05600c3b9e00b00413133cb9c8mr886071wms.33.1711540625450; Wed, 27 Mar 2024 04:57:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjtWZgoLECCahLjXIvmW31Yh+6KWzfZk85gRGbWkJ9cBwuztQZcyvva3YOYYkjVtDSlBU+UA== X-Received: by 2002:a05:600c:3b9e:b0:413:133c:b9c8 with SMTP id n30-20020a05600c3b9e00b00413133cb9c8mr886041wms.33.1711540624781; Wed, 27 Mar 2024 04:57:04 -0700 (PDT) Received: from redhat.com ([2.52.20.36]) by smtp.gmail.com with ESMTPSA id s21-20020a05600c45d500b0041487f70d9fsm1934113wmo.21.2024.03.27.04.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 04:57:04 -0700 (PDT) Date: Wed, 27 Mar 2024 07:56:58 -0400 From: "Michael S. Tsirkin" To: Will Deacon Cc: Keir Fraser , gshan@redhat.com, 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: <20240327075049-mutt-send-email-mst@kernel.org> References: <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> <20240326154628.GA9613@willie-the-truck> MIME-Version: 1.0 In-Reply-To: <20240326154628.GA9613@willie-the-truck> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_045710_473927_9C195E6C X-CRM114-Status: GOOD ( 30.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 26, 2024 at 03:46:29PM +0000, Will Deacon wrote: > 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); Oh wow you are right. We have: if (vq->avail_idx == vq->last_avail_idx) { if (unlikely(vhost_get_avail_idx(vq, &avail_idx))) { vq_err(vq, "Failed to access avail idx at %p\n", &vq->avail->idx); return -EFAULT; } vq->avail_idx = vhost16_to_cpu(vq, avail_idx); if (unlikely((u16)(vq->avail_idx - last_avail_idx) > vq->num)) { vq_err(vq, "Guest moved used index from %u to %u", last_avail_idx, vq->avail_idx); return -EFAULT; } /* If there's nothing new since last we looked, return * invalid. */ if (vq->avail_idx == last_avail_idx) return vq->num; /* Only get avail ring entries after they have been * exposed by guest. */ smp_rmb(); } and so the rmb only happens if avail_idx is not advanced. Actually there is a bunch of code duplication where we assign to avail_idx, too. Will thanks a lot for looking into this! I kept looking into the virtio side for some reason, the fact that it did not trigger with qemu should have been a big hint! -- MST _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel