From nobody Mon Feb 9 02:13:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489600954352743.6477945936672; Wed, 15 Mar 2017 11:02:34 -0700 (PDT) Received: from localhost ([::1]:38842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coDFm-00035S-PK for importer@patchew.org; Wed, 15 Mar 2017 14:02:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coDEl-00033z-6c for qemu-devel@nongnu.org; Wed, 15 Mar 2017 14:01:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coDEk-0006l4-Cb for qemu-devel@nongnu.org; Wed, 15 Mar 2017 14:01:27 -0400 Received: from mail.kernel.org ([198.145.29.136]:59036) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coDEk-0006kY-6X for qemu-devel@nongnu.org; Wed, 15 Mar 2017 14:01:26 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3207D20382; Wed, 15 Mar 2017 18:01:24 +0000 (UTC) Received: from redhat.com (pool-96-237-235-121.bstnma.fios.verizon.net [96.237.235.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C0420202DD; Wed, 15 Mar 2017 18:01:22 +0000 (UTC) Date: Wed, 15 Mar 2017 20:01:21 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1489600837-11541-3-git-send-email-mst@redhat.com> References: <1489600837-11541-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1489600837-11541-1-git-send-email-mst@redhat.com> X-Mailer: git-send-email 2.8.0.287.g0deeb61 X-Mutt-Fcc: =sent X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 198.145.29.136 Subject: [Qemu-devel] [PULL 2/7] virtio: guard against NULL pfn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cornelia Huck , Peter Maydell , Jason Wang , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Wang To avoid access stale memory region cache after reset, this patch check the existence of virtqueue pfn for all exported virtqueue access helpers before trying to use them. Cc: Cornelia Huck Cc: Paolo Bonzini Reviewed-by: Cornelia Huck Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index efce4b3..9164579 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -318,6 +318,10 @@ int virtio_queue_ready(VirtQueue *vq) * Called within rcu_read_lock(). */ static int virtio_queue_empty_rcu(VirtQueue *vq) { + if (unlikely(!vq->vring.avail)) { + return 1; + } + if (vq->shadow_avail_idx !=3D vq->last_avail_idx) { return 0; } @@ -329,6 +333,10 @@ int virtio_queue_empty(VirtQueue *vq) { bool empty; =20 + if (unlikely(!vq->vring.avail)) { + return 1; + } + if (vq->shadow_avail_idx !=3D vq->last_avail_idx) { return 0; } @@ -431,6 +439,10 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElem= ent *elem, return; } =20 + if (unlikely(!vq->vring.used)) { + return; + } + idx =3D (idx + vq->used_idx) % vq->vring.num; =20 uelem.id =3D elem->index; @@ -448,6 +460,10 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count) return; } =20 + if (unlikely(!vq->vring.used)) { + return; + } + /* Make sure buffer is written before we update index. */ smp_wmb(); trace_virtqueue_flush(vq, count); @@ -546,6 +562,16 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned= int *in_bytes, int64_t len =3D 0; int rc; =20 + if (unlikely(!vq->vring.desc)) { + if (in_bytes) { + *in_bytes =3D 0; + } + if (out_bytes) { + *out_bytes =3D 0; + } + return; + } + rcu_read_lock(); idx =3D vq->last_avail_idx; total_bufs =3D in_total =3D out_total =3D 0; --=20 MST