From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571940355; cv=none; d=zoho.com; s=zohoarc; b=JJPHJQHrIf1yAc9ahEtY8TZTt8TaQ9dvdlg7SpdLS7UH8RsL729xLnob3/ULPjjGstM8kLpzOKD0j5RBDB8P6jjwPZDKc4nirPXIFuazBc4TKGboniwJ1cD1K4BpfCAq6gteOhWHI34W0lLE/qvNksB9wPFd1wCte7cB1M9CmPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571940355; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=9uOAEi58ET5xgMJaX9or6rmcR66f/uMJxfebNlHdbkM=; b=PZtyEczWKOt5fV4h5teI1jY93xTqsNhbNWQ70lTE/3CIenuqysSrtTAjxf5wt1V6WXML2AahRMY+K2XeCi+N9tyeOnhtG17itZpUFn9quSSuGYMX4xA+Uf128szAFi7Emd7I2/xDi7R8pmZiplSAscdoh2oRUApW8F7iuhfNQB0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15719403550311010.5455994982443; Thu, 24 Oct 2019 11:05:55 -0700 (PDT) Received: from localhost ([::1]:49718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhUf-0004mk-IR for importer@patchew.org; Thu, 24 Oct 2019 14:05:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37911) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNggx-00028z-8K for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNggw-0001kd-3I for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:31 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:50599 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNggw-0001k7-0J for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-HsFOi9gPOja8XOU7xXRLzQ-1; Thu, 24 Oct 2019 13:14:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 318161800DFB; Thu, 24 Oct 2019 17:14:24 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C82A5D70E; Thu, 24 Oct 2019 17:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9uOAEi58ET5xgMJaX9or6rmcR66f/uMJxfebNlHdbkM=; b=XSnzDR2SPR3rzrZbhqiKOPV54iu51IViXhdIAzo6MJSdKXjVh2qTQBgqGYph5JnyBhd/MR c1OQQUxn18kn7wKO+OfwE5/GS+qpGslICXAFiHF+yOiDnA0uEUhpYje0Ga5g7grwvQOFAu mEMudtzJUdPT6Dr68tfB7ZgkSr4jHUk= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 1/9] virtio: basic structure for packed ring Date: Thu, 24 Oct 2019 19:13:58 +0200 Message-Id: <20191024171406.12504-2-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: HsFOi9gPOja8XOU7xXRLzQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Xu Define packed ring structure according to Qemu nomenclature, field data(wrap counter, etc) are also included. Signed-off-by: Wei Xu Signed-off-by: Jason Wang Reviewed-by: Jens Freimann --- hw/virtio/virtio.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 527df03bfd..fdac203cdf 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -43,6 +43,13 @@ typedef struct VRingDesc uint16_t next; } VRingDesc; =20 +typedef struct VRingPackedDesc { + uint64_t addr; + uint32_t len; + uint16_t id; + uint16_t flags; +} VRingPackedDesc; + typedef struct VRingAvail { uint16_t flags; @@ -81,17 +88,25 @@ typedef struct VRing VRingMemoryRegionCaches *caches; } VRing; =20 +typedef struct VRingPackedDescEvent { + uint16_t off_wrap; + uint16_t flags; +} VRingPackedDescEvent ; + struct VirtQueue { VRing vring; =20 /* Next head to pop */ uint16_t last_avail_idx; + bool last_avail_wrap_counter; =20 /* Last avail_idx read from VQ. */ uint16_t shadow_avail_idx; + bool shadow_avail_wrap_counter; =20 uint16_t used_idx; + bool used_wrap_counter; =20 /* Last used index value we have signalled on */ uint16_t signalled_used; --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571940564; cv=none; d=zoho.com; s=zohoarc; b=N2n9Ti94tkoaDA8lMmu0Ok4DaLyft/mAmaVODYlpnOlPHteFkObNZdPTbZ9IS4O2BSH0nuEPXPGNrVcKjxoKQ4bByvTe5toIGRkM6qzYoDlJqEZ3dYwxpzkGBUgmrBVciFV8D5wOrOF0W7hH7LCNasMhkHkrPTwJIL+aYmns8u8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571940564; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=T4PjgDwYwVllCjJyAa4O4jV5g3gFoiQ2rK589sd19L8=; b=bLFxUmacoWHELuaRTG7TkSPUTROCWnp9Br5qQrG65RaYSvE+xRyK+W7lqUezT6GBrCf7ua/EhE84lR28TMWSGvE0pX8NrxJs0SZTmhQdTg0PHcpFFu2xvNVkbD20IVHVrbf1VQHx2CT8qDgWVri/9tP5zxuBbl7fvrmsOTt4HsE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571940564827437.02011187715823; Thu, 24 Oct 2019 11:09:24 -0700 (PDT) Received: from localhost ([::1]:49788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhXz-0002NB-Ad for importer@patchew.org; Thu, 24 Oct 2019 14:09:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37940) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNgh1-0002D1-DB for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNggz-0001p2-Ru for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:35 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:28021 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNggy-0001lg-U1 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-233-d9WzHKqiNyCoPTorYWETTQ-1; Thu, 24 Oct 2019 13:14:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5069D107AD31; Thu, 24 Oct 2019 17:14:27 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A65C5B681; Thu, 24 Oct 2019 17:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T4PjgDwYwVllCjJyAa4O4jV5g3gFoiQ2rK589sd19L8=; b=MRorIbYXiZEvIIiGFbCi2FZpN7mu/4EVpu6nH1kLU/VBDgxRcKbe492nWI5cnDJsl6KC4u Z7d+Z+hVf1t+jMnEmaWNBIuKCVn0uvP9Qd/C7O45XZrAnYvffW7cuVXYylbWYXa28Q/R7C v6T+pwJkociB3U47jopmEHi5NN4HRd0= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 2/9] virtio: device/driver area size calculation refactor for split ring Date: Thu, 24 Oct 2019 19:13:59 +0200 Message-Id: <20191024171406.12504-3-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: d9WzHKqiNyCoPTorYWETTQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Xu There is slight size difference between split/packed rings. This is the refactor of split ring as well as a helper to expanding device and driver area size calculation for packed ring. Signed-off-by: Wei Xu Signed-off-by: Jason Wang Reviewed-by: Jens Freimann --- hw/virtio/virtio.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index fdac203cdf..74cc10fad9 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -159,10 +159,8 @@ static void virtio_init_region_cache(VirtIODevice *vde= v, int n) VRingMemoryRegionCaches *old =3D vq->vring.caches; VRingMemoryRegionCaches *new =3D NULL; hwaddr addr, size; - int event_size; int64_t len; =20 - event_size =3D virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_I= DX) ? 2 : 0; =20 addr =3D vq->vring.desc; if (!addr) { @@ -177,7 +175,7 @@ static void virtio_init_region_cache(VirtIODevice *vdev= , int n) goto err_desc; } =20 - size =3D virtio_queue_get_used_size(vdev, n) + event_size; + size =3D virtio_queue_get_used_size(vdev, n); len =3D address_space_cache_init(&new->used, vdev->dma_as, vq->vring.used, size, true); if (len < size) { @@ -185,7 +183,7 @@ static void virtio_init_region_cache(VirtIODevice *vdev= , int n) goto err_used; } =20 - size =3D virtio_queue_get_avail_size(vdev, n) + event_size; + size =3D virtio_queue_get_avail_size(vdev, n); len =3D address_space_cache_init(&new->avail, vdev->dma_as, vq->vring.avail, size, false); if (len < size) { @@ -2414,14 +2412,20 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vde= v, int n) =20 hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n) { + int s; + + s =3D virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0; return offsetof(VRingAvail, ring) + - sizeof(uint16_t) * vdev->vq[n].vring.num; + sizeof(uint16_t) * vdev->vq[n].vring.num + s; } =20 hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n) { + int s; + + s =3D virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0; return offsetof(VRingUsed, ring) + - sizeof(VRingUsedElem) * vdev->vq[n].vring.num; + sizeof(VRingUsedElem) * vdev->vq[n].vring.num + s; } =20 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n) --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571940765; cv=none; d=zoho.com; s=zohoarc; b=aTMG97MC2TJur/Ed/wSKaBBKScs9qdxlYj/aszJIKeXu2AlYc8LxYPE5hN9D1OrKZP3ek629x/jht4s3xMnW5DksNP8GvBFGLyHjtSJ5XjxvAS6LrmTuaTg4TfdmwojuXR8m+CUD8ncdb2AGt/YsFtP/4TCbv8ka4NuMyY7urtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571940765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f8SAWqFkouDm5WPRgDXUpw1GrKkX+a6ubFyYkDAlOQY=; b=X3hVcQFB314dAv67dVWzkrlhZwRwGHkChoFgehqT/0i4eodX4EOy+xntvZlcY80SKvinuMo6pANhLPgp2m1gSHGivZr07XwgMLgl4QUVtraBW7yhU7rk32Vt434W8ZZm3xaUlfv+Ha5We/i9Nya0WrbBLYV50LaJ95jd/IC5eOg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571940765470918.41915512744; Thu, 24 Oct 2019 11:12:45 -0700 (PDT) Received: from localhost ([::1]:49894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhbH-0007fQ-Uy for importer@patchew.org; Thu, 24 Oct 2019 14:12:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37965) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNgh2-0002Dt-Qz for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNgh1-0001rW-IR for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:36 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:59389 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNgh1-0001qI-Bp for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-A_2ltWQOMtKOyVCJ5XRL0A-1; Thu, 24 Oct 2019 13:14:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D114100550E; Thu, 24 Oct 2019 17:14:30 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id A853F5EE1D; Thu, 24 Oct 2019 17:14:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937274; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f8SAWqFkouDm5WPRgDXUpw1GrKkX+a6ubFyYkDAlOQY=; b=HJrgUyqq99s4MEuk1NBsYzgrNH7AdGpxw4ns+CS2V/uOfE8LTgHF3QvDUGElevY4rFMCuL RDbGSJgfVU76jKaYQfkFhWwSBeCJUBKKiMzTiCN+6LXg6VcQ67JBNsORFKeh1AH1V2knXZ UI/wb8nc2rqxAfM4Z9AszatQcxMKkG0= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 3/9] virtio: Free rng and blk virqueues Date: Thu, 24 Oct 2019 19:14:00 +0200 Message-Id: <20191024171406.12504-4-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: A_2ltWQOMtKOyVCJ5XRL0A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The function virtio_del_queue was not called at these devices unrealize() callbacks. This was detected due to add an allocated element on the next commit (used_elems) and running address sanitizer memory leak detector. Signed-off-by: Eugenio P=C3=A9rez --- hw/block/virtio-blk.c | 5 +++++ hw/virtio/virtio-rng.c | 1 + 2 files changed, 6 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index ed2ddebd2b..ba846fe9dc 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1206,9 +1206,14 @@ static void virtio_blk_device_unrealize(DeviceState = *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOBlock *s =3D VIRTIO_BLK(dev); + VirtIOBlkConf *conf =3D &s->conf; + unsigned i; =20 virtio_blk_data_plane_destroy(s->dataplane); s->dataplane =3D NULL; + for (i =3D 0; i < conf->num_queues; i++) { + virtio_del_queue(vdev, i); + } qemu_del_vm_change_state_handler(s->change); blockdev_mark_auto_del(s->blk); virtio_cleanup(vdev); diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index e93bed020f..b498a20332 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -238,6 +238,7 @@ static void virtio_rng_device_unrealize(DeviceState *de= v, Error **errp) qemu_del_vm_change_state_handler(vrng->vmstate); timer_del(vrng->rate_limit_timer); timer_free(vrng->rate_limit_timer); + virtio_del_queue(vdev, 0); virtio_cleanup(vdev); } =20 --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571941020; cv=none; d=zoho.com; s=zohoarc; b=nObqBszXuVPbeqjIlEyRBpwWubc57zpa5LAs3EqcpgX8bKUG2fuskGz4vwvTIUZIXdie/wtV03sjQCX4HRruy7NQNLnGwMbBzN7yFRWN4lY9Vo9CDlisKItRFR1FtiUfYLFO3r5yleYBEUh0m/bMyci58Iv2Z/GuMq97k8pLlXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571941020; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=q9qT6R2AsZso0IcnHXxeoS7VDvp4qlUcOXRKQylU3C8=; b=AgmIdWIemULIH0idbzCp3MQP3NCp5xmtnsmhZvI+ZPNNqLTBWf7FJnNDZQ6JpD6JLZk1Q3VKXvX3Dm2MKiGimJ2dnhULGxMBggaJm7bpji4VIFuTrqe3QiY8zrNZg8EzkHIVNO885VdeuxL7fqGPH8yaqT32gtJUhRLm015AUws= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571941020718498.70270844185177; Thu, 24 Oct 2019 11:17:00 -0700 (PDT) Received: from localhost ([::1]:49944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhfO-0003td-Fj for importer@patchew.org; Thu, 24 Oct 2019 14:16:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38052) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNghM-0002TV-Rh for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNghH-0001yB-DH for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36788 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNghG-0001xK-20 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-183-YrsHrHIyNcK_nmXD2NRpow-1; Thu, 24 Oct 2019 13:14:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A5442800D49; Thu, 24 Oct 2019 17:14:40 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id C34975B681; Thu, 24 Oct 2019 17:14:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9qT6R2AsZso0IcnHXxeoS7VDvp4qlUcOXRKQylU3C8=; b=atPRYAwCYzeC1eC1o/opaFYtPy3Vh5US6C2r47M4uAniMwLTLLmMrnaKGDtiAkVmQBqtCA UyaCc5YAh5BZwpJ2kDeRwSEEo5bMcauZcW4fBIGALWLjss+1nrmzKE0YF8aiV+Ag89agp5 nnBDQfVktq2lQqtvBJO/VdG6XcNcLvM= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 4/9] virtio: basic packed virtqueue support Date: Thu, 24 Oct 2019 19:14:01 +0200 Message-Id: <20191024171406.12504-5-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: YrsHrHIyNcK_nmXD2NRpow-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jason Wang This patch implements basic support for the packed virtqueue. Compare the split virtqueue which has three rings, packed virtqueue only have one which is supposed to have better cache utilization and more hardware friendly. Please refer virtio specification for more information. Signed-off-by: Wei Xu Signed-off-by: Jason Wang --- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 2 +- hw/scsi/virtio-scsi.c | 3 +- hw/virtio/virtio.c | 900 ++++++++++++++++++++++++++++++++++++++++= ---- include/hw/virtio/virtio.h | 10 +- 5 files changed, 837 insertions(+), 80 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index ba846fe9dc..7dbdeaaab9 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1052,7 +1052,7 @@ static void virtio_blk_save_device(VirtIODevice *vdev= , QEMUFile *f) qemu_put_be32(f, virtio_get_queue_index(req->vq)); } =20 - qemu_put_virtqueue_element(f, &req->elem); + qemu_put_virtqueue_element(vdev, f, &req->elem); req =3D req->next; } qemu_put_sbyte(f, 0); diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 4e0ed829ae..33259042a9 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -708,7 +708,7 @@ static void virtio_serial_save_device(VirtIODevice *vde= v, QEMUFile *f) if (elem_popped) { qemu_put_be32s(f, &port->iov_idx); qemu_put_be64s(f, &port->iov_offset); - qemu_put_virtqueue_element(f, port->elem); + qemu_put_virtqueue_element(vdev, f, port->elem); } } } diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index ee52aa7d17..e8b2b64d09 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -190,11 +190,12 @@ static void virtio_scsi_save_request(QEMUFile *f, SCS= IRequest *sreq) { VirtIOSCSIReq *req =3D sreq->hba_private; VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(req->dev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(req->dev); uint32_t n =3D virtio_get_queue_index(req->vq) - 2; =20 assert(n < vs->conf.num_queues); qemu_put_be32s(f, &n); - qemu_put_virtqueue_element(f, &req->elem); + qemu_put_virtqueue_element(vdev, f, &req->elem); } =20 static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 74cc10fad9..6e7a034d2a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -96,6 +96,7 @@ typedef struct VRingPackedDescEvent { struct VirtQueue { VRing vring; + VirtQueueElement *used_elems; =20 /* Next head to pop */ uint16_t last_avail_idx; @@ -160,6 +161,7 @@ static void virtio_init_region_cache(VirtIODevice *vdev= , int n) VRingMemoryRegionCaches *new =3D NULL; hwaddr addr, size; int64_t len; + bool packed; =20 =20 addr =3D vq->vring.desc; @@ -168,8 +170,10 @@ static void virtio_init_region_cache(VirtIODevice *vde= v, int n) } new =3D g_new0(VRingMemoryRegionCaches, 1); size =3D virtio_queue_get_desc_size(vdev, n); + packed =3D virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED) ? + true : false; len =3D address_space_cache_init(&new->desc, vdev->dma_as, - addr, size, false); + addr, size, packed); if (len < size) { virtio_error(vdev, "Cannot map desc"); goto err_desc; @@ -225,8 +229,8 @@ void virtio_queue_update_rings(VirtIODevice *vdev, int = n) } =20 /* Called within rcu_read_lock(). */ -static void vring_desc_read(VirtIODevice *vdev, VRingDesc *desc, - MemoryRegionCache *cache, int i) +static void vring_split_desc_read(VirtIODevice *vdev, VRingDesc *desc, + MemoryRegionCache *cache, int i) { address_space_read_cached(cache, i * sizeof(VRingDesc), desc, sizeof(VRingDesc)); @@ -370,6 +374,95 @@ int virtio_queue_ready(VirtQueue *vq) return vq->vring.avail !=3D 0; } =20 +static void vring_packed_desc_read_flags(VirtIODevice *vdev, + uint16_t *flags, + MemoryRegionCache *cache, + int i) +{ + address_space_read_cached(cache, + i * sizeof(VRingPackedDesc) + + offsetof(VRingPackedDesc, flags), + flags, sizeof(*flags)); + virtio_tswap16s(vdev, flags); +} + +static void vring_packed_desc_read(VirtIODevice *vdev, + VRingPackedDesc *desc, + MemoryRegionCache *cache, + int i, bool strict_order) +{ + hwaddr off =3D i * sizeof(VRingPackedDesc); + + vring_packed_desc_read_flags(vdev, &desc->flags, cache, i); + + if (strict_order) { + /* Make sure flags is read before the rest fields. */ + smp_rmb(); + } + + address_space_read_cached(cache, off + offsetof(VRingPackedDesc, addr), + &desc->addr, sizeof(desc->addr)); + address_space_read_cached(cache, off + offsetof(VRingPackedDesc, id), + &desc->id, sizeof(desc->id)); + address_space_read_cached(cache, off + offsetof(VRingPackedDesc, len), + &desc->len, sizeof(desc->len)); + virtio_tswap64s(vdev, &desc->addr); + virtio_tswap16s(vdev, &desc->id); + virtio_tswap32s(vdev, &desc->len); +} + +static void vring_packed_desc_write_data(VirtIODevice *vdev, + VRingPackedDesc *desc, + MemoryRegionCache *cache, + int i) +{ + hwaddr off_id =3D i * sizeof(VRingPackedDesc) + + offsetof(VRingPackedDesc, id); + hwaddr off_len =3D i * sizeof(VRingPackedDesc) + + offsetof(VRingPackedDesc, len); + + virtio_tswap32s(vdev, &desc->len); + virtio_tswap16s(vdev, &desc->id); + address_space_write_cached(cache, off_id, &desc->id, sizeof(desc->id)); + address_space_cache_invalidate(cache, off_id, sizeof(desc->id)); + address_space_write_cached(cache, off_len, &desc->len, sizeof(desc->le= n)); + address_space_cache_invalidate(cache, off_len, sizeof(desc->len)); +} + +static void vring_packed_desc_write_flags(VirtIODevice *vdev, + VRingPackedDesc *desc, + MemoryRegionCache *cache, + int i) +{ + hwaddr off =3D i * sizeof(VRingPackedDesc) + offsetof(VRingPackedDesc,= flags); + + virtio_tswap16s(vdev, &desc->flags); + address_space_write_cached(cache, off, &desc->flags, sizeof(desc->flag= s)); + address_space_cache_invalidate(cache, off, sizeof(desc->flags)); +} + +static void vring_packed_desc_write(VirtIODevice *vdev, + VRingPackedDesc *desc, + MemoryRegionCache *cache, + int i, bool strict_order) +{ + vring_packed_desc_write_data(vdev, desc, cache, i); + if (strict_order) { + /* Make sure data is wrote before flags. */ + smp_wmb(); + } + vring_packed_desc_write_flags(vdev, desc, cache, i); +} + +static inline bool is_desc_avail(uint16_t flags, bool wrap_counter) +{ + bool avail, used; + + avail =3D !!(flags & (1 << VRING_PACKED_DESC_F_AVAIL)); + used =3D !!(flags & (1 << VRING_PACKED_DESC_F_USED)); + return (avail !=3D used) && (avail =3D=3D wrap_counter); +} + /* Fetch avail_idx from VQ memory only when we really need to know if * guest has added some buffers. * Called within rcu_read_lock(). */ @@ -390,7 +483,7 @@ static int virtio_queue_empty_rcu(VirtQueue *vq) return vring_avail_idx(vq) =3D=3D vq->last_avail_idx; } =20 -int virtio_queue_empty(VirtQueue *vq) +static int virtio_queue_split_empty(VirtQueue *vq) { bool empty; =20 @@ -412,6 +505,41 @@ int virtio_queue_empty(VirtQueue *vq) return empty; } =20 +static int virtio_queue_packed_empty_rcu(VirtQueue *vq) +{ + struct VRingPackedDesc desc; + VRingMemoryRegionCaches *cache; + + if (unlikely(!vq->vring.desc)) { + return 1; + } + + cache =3D vring_get_region_caches(vq); + vring_packed_desc_read_flags(vq->vdev, &desc.flags, &cache->desc, + vq->last_avail_idx); + + return !is_desc_avail(desc.flags, vq->last_avail_wrap_counter); +} + +static int virtio_queue_packed_empty(VirtQueue *vq) +{ + bool empty; + + rcu_read_lock(); + empty =3D virtio_queue_packed_empty_rcu(vq); + rcu_read_unlock(); + return empty; +} + +int virtio_queue_empty(VirtQueue *vq) +{ + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + return virtio_queue_packed_empty(vq); + } else { + return virtio_queue_split_empty(vq); + } +} + static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len) { @@ -449,10 +577,25 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const V= irtQueueElement *elem, void virtqueue_detach_element(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len) { - vq->inuse--; + vq->inuse -=3D elem->ndescs; virtqueue_unmap_sg(vq, elem, len); } =20 +static void virtqueue_split_rewind(VirtQueue *vq, unsigned int num) +{ + vq->last_avail_idx -=3D num; +} + +static void virtqueue_packed_rewind(VirtQueue *vq, unsigned int num) +{ + if (vq->last_avail_idx < num) { + vq->last_avail_idx =3D vq->vring.num + vq->last_avail_idx - num; + vq->last_avail_wrap_counter ^=3D 1; + } else { + vq->last_avail_idx -=3D num; + } +} + /* virtqueue_unpop: * @vq: The #VirtQueue * @elem: The #VirtQueueElement @@ -464,7 +607,13 @@ void virtqueue_detach_element(VirtQueue *vq, const Vir= tQueueElement *elem, void virtqueue_unpop(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len) { - vq->last_avail_idx--; + + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + virtqueue_packed_rewind(vq, 1); + } else { + virtqueue_split_rewind(vq, 1); + } + virtqueue_detach_element(vq, elem, len); } =20 @@ -485,25 +634,22 @@ bool virtqueue_rewind(VirtQueue *vq, unsigned int num) if (num > vq->inuse) { return false; } - vq->last_avail_idx -=3D num; + vq->inuse -=3D num; + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + virtqueue_packed_rewind(vq, num); + } else { + virtqueue_split_rewind(vq, num); + } return true; } =20 /* Called within rcu_read_lock(). */ -void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, +static void virtqueue_split_fill(VirtQueue *vq, const VirtQueueElement *el= em, unsigned int len, unsigned int idx) { VRingUsedElem uelem; =20 - trace_virtqueue_fill(vq, elem, len, idx); - - virtqueue_unmap_sg(vq, elem, len); - - if (unlikely(vq->vdev->broken)) { - return; - } - if (unlikely(!vq->vring.used)) { return; } @@ -515,16 +661,71 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueEle= ment *elem, vring_used_write(vq, &uelem, idx); } =20 -/* Called within rcu_read_lock(). */ -void virtqueue_flush(VirtQueue *vq, unsigned int count) +static void virtqueue_packed_fill(VirtQueue *vq, const VirtQueueElement *e= lem, + unsigned int len, unsigned int idx) { - uint16_t old, new; + vq->used_elems[idx].index =3D elem->index; + vq->used_elems[idx].len =3D len; + vq->used_elems[idx].ndescs =3D elem->ndescs; +} + +static void virtqueue_packed_fill_desc(VirtQueue *vq, + const VirtQueueElement *elem, + unsigned int idx, + bool strict_order) +{ + uint16_t head; + VRingMemoryRegionCaches *caches; + VRingPackedDesc desc =3D { + .id =3D elem->index, + .len =3D elem->len, + }; + bool wrap_counter =3D vq->used_wrap_counter; + + if (unlikely(!vq->vring.desc)) { + return; + } + + head =3D vq->used_idx + idx; + if (head >=3D vq->vring.num) { + head -=3D vq->vring.num; + wrap_counter ^=3D 1; + } + if (wrap_counter) { + desc.flags |=3D (1 << VRING_PACKED_DESC_F_AVAIL); + desc.flags |=3D (1 << VRING_PACKED_DESC_F_USED); + } else { + desc.flags &=3D ~(1 << VRING_PACKED_DESC_F_AVAIL); + desc.flags &=3D ~(1 << VRING_PACKED_DESC_F_USED); + } + + caches =3D vring_get_region_caches(vq); + vring_packed_desc_write(vq->vdev, &desc, &caches->desc, head, strict_o= rder); +} + +void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len, unsigned int idx) +{ + trace_virtqueue_fill(vq, elem, len, idx); + + virtqueue_unmap_sg(vq, elem, len); =20 if (unlikely(vq->vdev->broken)) { - vq->inuse -=3D count; return; } =20 + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + virtqueue_packed_fill(vq, elem, len, idx); + } else { + virtqueue_split_fill(vq, elem, len, idx); + } +} + +/* Called within rcu_read_lock(). */ +static void virtqueue_split_flush(VirtQueue *vq, unsigned int count) +{ + uint16_t old, new; + if (unlikely(!vq->vring.used)) { return; } @@ -540,6 +741,43 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count) vq->signalled_used_valid =3D false; } =20 +static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count) +{ + unsigned int i, ndescs =3D 0; + + if (unlikely(!vq->vring.desc)) { + return; + } + + for (i =3D 1; i < count; i++) { + virtqueue_packed_fill_desc(vq, &vq->used_elems[i], i, false); + ndescs +=3D vq->used_elems[i].ndescs; + } + virtqueue_packed_fill_desc(vq, &vq->used_elems[0], 0, true); + ndescs +=3D vq->used_elems[0].ndescs; + + vq->inuse -=3D ndescs; + vq->used_idx +=3D ndescs; + if (vq->used_idx >=3D vq->vring.num) { + vq->used_idx -=3D vq->vring.num; + vq->used_wrap_counter ^=3D 1; + } +} + +void virtqueue_flush(VirtQueue *vq, unsigned int count) +{ + if (unlikely(vq->vdev->broken)) { + vq->inuse -=3D count; + return; + } + + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + virtqueue_packed_flush(vq, count); + } else { + virtqueue_split_flush(vq, count); + } +} + void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len) { @@ -592,9 +830,9 @@ enum { VIRTQUEUE_READ_DESC_MORE =3D 1, /* more buffers in chain */ }; =20 -static int virtqueue_read_next_desc(VirtIODevice *vdev, VRingDesc *desc, - MemoryRegionCache *desc_cache, unsigne= d int max, - unsigned int *next) +static int virtqueue_split_read_next_desc(VirtIODevice *vdev, VRingDesc *d= esc, + MemoryRegionCache *desc_cache, + unsigned int max, unsigned int *= next) { /* If this descriptor says it doesn't chain, we're done. */ if (!(desc->flags & VRING_DESC_F_NEXT)) { @@ -611,13 +849,13 @@ static int virtqueue_read_next_desc(VirtIODevice *vde= v, VRingDesc *desc, return VIRTQUEUE_READ_DESC_ERROR; } =20 - vring_desc_read(vdev, desc, desc_cache, *next); + vring_split_desc_read(vdev, desc, desc_cache, *next); return VIRTQUEUE_READ_DESC_MORE; } =20 -void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, - unsigned int *out_bytes, - unsigned max_in_bytes, unsigned max_out_byt= es) +static void virtqueue_split_get_avail_bytes(VirtQueue *vq, + unsigned int *in_bytes, unsigned int *out_byte= s, + unsigned max_in_bytes, unsigned max_out_bytes) { VirtIODevice *vdev =3D vq->vdev; unsigned int max, idx; @@ -627,27 +865,12 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigne= d 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 max =3D vq->vring.num; caches =3D vring_get_region_caches(vq); - if (caches->desc.len < max * sizeof(VRingDesc)) { - virtio_error(vdev, "Cannot map descriptor ring"); - goto err; - } - while ((rc =3D virtqueue_num_heads(vq, idx)) > 0) { MemoryRegionCache *desc_cache =3D &caches->desc; unsigned int num_bufs; @@ -660,7 +883,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned = int *in_bytes, goto err; } =20 - vring_desc_read(vdev, &desc, desc_cache, i); + vring_split_desc_read(vdev, &desc, desc_cache, i); =20 if (desc.flags & VRING_DESC_F_INDIRECT) { if (!desc.len || (desc.len % sizeof(VRingDesc))) { @@ -686,7 +909,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned = int *in_bytes, =20 max =3D desc.len / sizeof(VRingDesc); num_bufs =3D i =3D 0; - vring_desc_read(vdev, &desc, desc_cache, i); + vring_split_desc_read(vdev, &desc, desc_cache, i); } =20 do { @@ -705,7 +928,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned = int *in_bytes, goto done; } =20 - rc =3D virtqueue_read_next_desc(vdev, &desc, desc_cache, max, = &i); + rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache,= max, &i); } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); =20 if (rc =3D=3D VIRTQUEUE_READ_DESC_ERROR) { @@ -727,17 +950,197 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsign= ed int *in_bytes, done: address_space_cache_destroy(&indirect_desc_cache); if (in_bytes) { - *in_bytes =3D in_total; + *in_bytes =3D in_total; + } + if (out_bytes) { + *out_bytes =3D out_total; + } + rcu_read_unlock(); + return; + +err: + in_total =3D out_total =3D 0; + goto done; +} + +static int virtqueue_packed_read_next_desc(VirtQueue *vq, + VRingPackedDesc *desc, + MemoryRegionCache + *desc_cache, + unsigned int max, + unsigned int *next, + bool indirect) +{ + /* If this descriptor says it doesn't chain, we're done. */ + if (!indirect && !(desc->flags & VRING_DESC_F_NEXT)) { + return VIRTQUEUE_READ_DESC_DONE; + } + + ++*next; + if (*next =3D=3D max) { + if (indirect) { + return VIRTQUEUE_READ_DESC_DONE; + } else { + (*next) -=3D vq->vring.num; + } + } + + vring_packed_desc_read(vq->vdev, desc, desc_cache, *next, false); + return VIRTQUEUE_READ_DESC_MORE; +} + +static void virtqueue_packed_get_avail_bytes(VirtQueue *vq, + unsigned int *in_bytes, + unsigned int *out_bytes, + unsigned max_in_bytes, + unsigned max_out_bytes) +{ + VirtIODevice *vdev =3D vq->vdev; + unsigned int max, idx; + unsigned int total_bufs, in_total, out_total; + MemoryRegionCache *desc_cache; + VRingMemoryRegionCaches *caches; + MemoryRegionCache indirect_desc_cache =3D MEMORY_REGION_CACHE_INVALID; + int64_t len =3D 0; + VRingPackedDesc desc; + bool wrap_counter; + + rcu_read_lock(); + idx =3D vq->last_avail_idx; + wrap_counter =3D vq->last_avail_wrap_counter; + total_bufs =3D in_total =3D out_total =3D 0; + + max =3D vq->vring.num; + caches =3D vring_get_region_caches(vq); + + for (;;) { + unsigned int num_bufs =3D total_bufs; + unsigned int i =3D idx; + int rc; + + desc_cache =3D &caches->desc; + vring_packed_desc_read(vdev, &desc, desc_cache, idx, true); + if (!is_desc_avail(desc.flags, wrap_counter)) { + break; + } + + if (desc.flags & VRING_DESC_F_INDIRECT) { + if (desc.len % sizeof(VRingPackedDesc)) { + virtio_error(vdev, "Invalid size for indirect buffer table= "); + goto err; + } + + /* If we've got too many, that implies a descriptor loop. */ + if (num_bufs >=3D max) { + virtio_error(vdev, "Looped descriptor"); + goto err; + } + + /* loop over the indirect descriptor table */ + len =3D address_space_cache_init(&indirect_desc_cache, + vdev->dma_as, + desc.addr, desc.len, false); + desc_cache =3D &indirect_desc_cache; + if (len < desc.len) { + virtio_error(vdev, "Cannot map indirect buffer"); + goto err; + } + + max =3D desc.len / sizeof(VRingPackedDesc); + num_bufs =3D i =3D 0; + vring_packed_desc_read(vdev, &desc, desc_cache, i, false); + } + + do { + /* If we've got too many, that implies a descriptor loop. */ + if (++num_bufs > max) { + virtio_error(vdev, "Looped descriptor"); + goto err; + } + + if (desc.flags & VRING_DESC_F_WRITE) { + in_total +=3D desc.len; + } else { + out_total +=3D desc.len; + } + if (in_total >=3D max_in_bytes && out_total >=3D max_out_bytes= ) { + goto done; + } + + rc =3D virtqueue_packed_read_next_desc(vq, &desc, desc_cache, = max, + &i, desc_cache =3D=3D + &indirect_desc_cache); + } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); + + if (desc_cache =3D=3D &indirect_desc_cache) { + address_space_cache_destroy(&indirect_desc_cache); + total_bufs++; + idx++; + } else { + idx +=3D num_bufs - total_bufs; + total_bufs =3D num_bufs; + } + + if (idx >=3D vq->vring.num) { + idx -=3D vq->vring.num; + wrap_counter ^=3D 1; + } + } + + /* Record the index and wrap counter for a kick we want */ + vq->shadow_avail_idx =3D idx; + vq->shadow_avail_wrap_counter =3D wrap_counter; +done: + address_space_cache_destroy(&indirect_desc_cache); + if (in_bytes) { + *in_bytes =3D in_total; + } + if (out_bytes) { + *out_bytes =3D out_total; + } + rcu_read_unlock(); + return; + +err: + in_total =3D out_total =3D 0; + goto done; +} + +void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, + unsigned int *out_bytes, + unsigned max_in_bytes, unsigned max_out_byt= es) +{ + uint16_t desc_size; + VRingMemoryRegionCaches *caches; + + if (unlikely(!vq->vring.desc)) { + goto err; + } + + caches =3D vring_get_region_caches(vq); + desc_size =3D virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED) ? + sizeof(VRingPackedDesc) : sizeof(VRingDesc= ); + if (caches->desc.len < vq->vring.num * desc_size) { + virtio_error(vq->vdev, "Cannot map descriptor ring"); + goto err; + } + + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + virtqueue_packed_get_avail_bytes(vq, in_bytes, out_bytes, + max_in_bytes, max_out_bytes); + } else { + virtqueue_split_get_avail_bytes(vq, in_bytes, out_bytes, + max_in_bytes, max_out_bytes); + } + + return; +err: + if (in_bytes) { + *in_bytes =3D 0; } if (out_bytes) { - *out_bytes =3D out_total; + *out_bytes =3D 0; } - rcu_read_unlock(); - return; - -err: - in_total =3D out_total =3D 0; - goto done; } =20 int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes, @@ -864,7 +1267,7 @@ static void *virtqueue_alloc_element(size_t sz, unsign= ed out_num, unsigned in_nu return elem; } =20 -void *virtqueue_pop(VirtQueue *vq, size_t sz) +static void *virtqueue_split_pop(VirtQueue *vq, size_t sz) { unsigned int i, head, max; VRingMemoryRegionCaches *caches; @@ -879,9 +1282,6 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) VRingDesc desc; int rc; =20 - if (unlikely(vdev->broken)) { - return NULL; - } rcu_read_lock(); if (virtio_queue_empty_rcu(vq)) { goto done; @@ -917,7 +1317,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) } =20 desc_cache =3D &caches->desc; - vring_desc_read(vdev, &desc, desc_cache, i); + vring_split_desc_read(vdev, &desc, desc_cache, i); if (desc.flags & VRING_DESC_F_INDIRECT) { if (!desc.len || (desc.len % sizeof(VRingDesc))) { virtio_error(vdev, "Invalid size for indirect buffer table"); @@ -935,7 +1335,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) =20 max =3D desc.len / sizeof(VRingDesc); i =3D 0; - vring_desc_read(vdev, &desc, desc_cache, i); + vring_split_desc_read(vdev, &desc, desc_cache, i); } =20 /* Collect all the descriptors */ @@ -966,7 +1366,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) goto err_undo_map; } =20 - rc =3D virtqueue_read_next_desc(vdev, &desc, desc_cache, max, &i); + rc =3D virtqueue_split_read_next_desc(vdev, &desc, desc_cache, max= , &i); } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); =20 if (rc =3D=3D VIRTQUEUE_READ_DESC_ERROR) { @@ -976,6 +1376,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) /* Now copy what we have collected and mapped */ elem =3D virtqueue_alloc_element(sz, out_num, in_num); elem->index =3D head; + elem->ndescs =3D 1; for (i =3D 0; i < out_num; i++) { elem->out_addr[i] =3D addr[i]; elem->out_sg[i] =3D iov[i]; @@ -999,13 +1400,202 @@ err_undo_map: goto done; } =20 -/* virtqueue_drop_all: - * @vq: The #VirtQueue - * Drops all queued buffers and indicates them to the guest - * as if they are done. Useful when buffers can not be - * processed but must be returned to the guest. - */ -unsigned int virtqueue_drop_all(VirtQueue *vq) +static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz) +{ + unsigned int i, max; + VRingMemoryRegionCaches *caches; + MemoryRegionCache indirect_desc_cache =3D MEMORY_REGION_CACHE_INVALID; + MemoryRegionCache *desc_cache; + int64_t len; + VirtIODevice *vdev =3D vq->vdev; + VirtQueueElement *elem =3D NULL; + unsigned out_num, in_num, elem_entries; + hwaddr addr[VIRTQUEUE_MAX_SIZE]; + struct iovec iov[VIRTQUEUE_MAX_SIZE]; + VRingPackedDesc desc; + uint16_t id; + int rc; + + rcu_read_lock(); + if (virtio_queue_packed_empty_rcu(vq)) { + goto done; + } + + /* When we start there are none of either input nor output. */ + out_num =3D in_num =3D elem_entries =3D 0; + + max =3D vq->vring.num; + + if (vq->inuse >=3D vq->vring.num) { + virtio_error(vdev, "Virtqueue size exceeded"); + goto done; + } + + i =3D vq->last_avail_idx; + + caches =3D vring_get_region_caches(vq); + if (caches->desc.len < max * sizeof(VRingDesc)) { + virtio_error(vdev, "Cannot map descriptor ring"); + goto done; + } + + desc_cache =3D &caches->desc; + vring_packed_desc_read(vdev, &desc, desc_cache, i, true); + id =3D desc.id; + if (desc.flags & VRING_DESC_F_INDIRECT) { + if (desc.len % sizeof(VRingPackedDesc)) { + virtio_error(vdev, "Invalid size for indirect buffer table"); + goto done; + } + + /* loop over the indirect descriptor table */ + len =3D address_space_cache_init(&indirect_desc_cache, vdev->dma_a= s, + desc.addr, desc.len, false); + desc_cache =3D &indirect_desc_cache; + if (len < desc.len) { + virtio_error(vdev, "Cannot map indirect buffer"); + goto done; + } + + max =3D desc.len / sizeof(VRingPackedDesc); + i =3D 0; + vring_packed_desc_read(vdev, &desc, desc_cache, i, false); + } + + /* Collect all the descriptors */ + do { + bool map_ok; + + if (desc.flags & VRING_DESC_F_WRITE) { + map_ok =3D virtqueue_map_desc(vdev, &in_num, addr + out_num, + iov + out_num, + VIRTQUEUE_MAX_SIZE - out_num, true, + desc.addr, desc.len); + } else { + if (in_num) { + virtio_error(vdev, "Incorrect order for descriptors"); + goto err_undo_map; + } + map_ok =3D virtqueue_map_desc(vdev, &out_num, addr, iov, + VIRTQUEUE_MAX_SIZE, false, + desc.addr, desc.len); + } + if (!map_ok) { + goto err_undo_map; + } + + /* If we've got too many, that implies a descriptor loop. */ + if (++elem_entries > max) { + virtio_error(vdev, "Looped descriptor"); + goto err_undo_map; + } + + rc =3D virtqueue_packed_read_next_desc(vq, &desc, desc_cache, max,= &i, + desc_cache =3D=3D + &indirect_desc_cache); + } while (rc =3D=3D VIRTQUEUE_READ_DESC_MORE); + + /* Now copy what we have collected and mapped */ + elem =3D virtqueue_alloc_element(sz, out_num, in_num); + for (i =3D 0; i < out_num; i++) { + elem->out_addr[i] =3D addr[i]; + elem->out_sg[i] =3D iov[i]; + } + for (i =3D 0; i < in_num; i++) { + elem->in_addr[i] =3D addr[out_num + i]; + elem->in_sg[i] =3D iov[out_num + i]; + } + + elem->index =3D id; + elem->ndescs =3D (desc_cache =3D=3D &indirect_desc_cache) ? 1 : elem_e= ntries; + vq->last_avail_idx +=3D elem->ndescs; + vq->inuse +=3D elem->ndescs; + + if (vq->last_avail_idx >=3D vq->vring.num) { + vq->last_avail_idx -=3D vq->vring.num; + vq->last_avail_wrap_counter ^=3D 1; + } + + vq->shadow_avail_idx =3D vq->last_avail_idx; + vq->shadow_avail_wrap_counter =3D vq->last_avail_wrap_counter; + + trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num); +done: + address_space_cache_destroy(&indirect_desc_cache); + rcu_read_unlock(); + + return elem; + +err_undo_map: + virtqueue_undo_map_desc(out_num, in_num, iov); + goto done; +} + +void *virtqueue_pop(VirtQueue *vq, size_t sz) +{ + if (unlikely(vq->vdev->broken)) { + return NULL; + } + + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + return virtqueue_packed_pop(vq, sz); + } else { + return virtqueue_split_pop(vq, sz); + } +} + +static unsigned int virtqueue_packed_drop_all(VirtQueue *vq) +{ + VRingMemoryRegionCaches *caches; + MemoryRegionCache *desc_cache; + unsigned int dropped =3D 0; + VirtQueueElement elem =3D {}; + VirtIODevice *vdev =3D vq->vdev; + VRingPackedDesc desc; + + if (unlikely(vdev->broken)) { + return 0; + } + + caches =3D vring_get_region_caches(vq); + desc_cache =3D &caches->desc; + + virtio_queue_set_notification(vq, 0); + + while (vq->inuse < vq->vring.num) { + unsigned int idx =3D vq->last_avail_idx; + /* + * works similar to virtqueue_pop but does not map buffers + * and does not allocate any memory. + */ + vring_packed_desc_read(vdev, &desc, desc_cache, + vq->last_avail_idx , true); + if (!is_desc_avail(desc.flags, vq->last_avail_wrap_counter)) { + break; + } + elem.index =3D desc.id; + elem.ndescs =3D 1; + while (virtqueue_packed_read_next_desc(vq, &desc, desc_cache, + vq->vring.num, &idx, false)= ) { + ++elem.ndescs; + } + /* + * immediately push the element, nothing to unmap + * as both in_num and out_num are set to 0. + */ + virtqueue_push(vq, &elem, 0); + dropped++; + vq->last_avail_idx +=3D elem.ndescs; + if (vq->last_avail_idx >=3D vq->vring.num) { + vq->last_avail_idx -=3D vq->vring.num; + vq->last_avail_wrap_counter ^=3D 1; + } + } + + return dropped; +} + +static unsigned int virtqueue_split_drop_all(VirtQueue *vq) { unsigned int dropped =3D 0; VirtQueueElement elem =3D {}; @@ -1037,6 +1627,23 @@ unsigned int virtqueue_drop_all(VirtQueue *vq) return dropped; } =20 +/* virtqueue_drop_all: + * @vq: The #VirtQueue + * Drops all queued buffers and indicates them to the guest + * as if they are done. Useful when buffers can not be + * processed but must be returned to the guest. + */ +unsigned int virtqueue_drop_all(VirtQueue *vq) +{ + struct VirtIODevice *vdev =3D vq->vdev; + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return virtqueue_packed_drop_all(vq); + } else { + return virtqueue_split_drop_all(vq); + } +} + /* Reading and writing a structure directly to QEMUFile is *awful*, but * it is what QEMU has always done by mistake. We can change it sooner * or later by bumping the version number of the affected vm states. @@ -1093,11 +1700,16 @@ void *qemu_get_virtqueue_element(VirtIODevice *vdev= , QEMUFile *f, size_t sz) elem->out_sg[i].iov_len =3D data.out_sg[i].iov_len; } =20 + if (virtio_host_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + qemu_get_be32s(f, &elem->ndescs); + } + virtqueue_map(vdev, elem); return elem; } =20 -void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem) +void qemu_put_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, + VirtQueueElement *elem) { VirtQueueElementOld data; int i; @@ -1125,6 +1737,11 @@ void qemu_put_virtqueue_element(QEMUFile *f, VirtQue= ueElement *elem) /* Do not save iov_base as above. */ data.out_sg[i].iov_len =3D elem->out_sg[i].iov_len; } + + if (virtio_host_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + qemu_put_be32s(f, &elem->ndescs); + } + qemu_put_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld)); } =20 @@ -1249,6 +1866,9 @@ void virtio_reset(void *opaque) vdev->vq[i].last_avail_idx =3D 0; vdev->vq[i].shadow_avail_idx =3D 0; vdev->vq[i].used_idx =3D 0; + vdev->vq[i].last_avail_wrap_counter =3D true; + vdev->vq[i].shadow_avail_wrap_counter =3D true; + vdev->vq[i].used_wrap_counter =3D true; virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR); vdev->vq[i].signalled_used =3D 0; vdev->vq[i].signalled_used_valid =3D false; @@ -1639,6 +2259,8 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int q= ueue_size, vdev->vq[i].vring.align =3D VIRTIO_PCI_VRING_ALIGN; vdev->vq[i].handle_output =3D handle_output; vdev->vq[i].handle_aio_output =3D NULL; + vdev->vq[i].used_elems =3D g_malloc0(sizeof(VirtQueueElement) * + queue_size); =20 return &vdev->vq[i]; } @@ -1653,6 +2275,7 @@ void virtio_del_queue(VirtIODevice *vdev, int n) vdev->vq[n].vring.num_default =3D 0; vdev->vq[n].handle_output =3D NULL; vdev->vq[n].handle_aio_output =3D NULL; + g_free(vdev->vq[n].used_elems); } =20 static void virtio_set_isr(VirtIODevice *vdev, int value) @@ -1780,6 +2403,13 @@ static bool virtio_virtqueue_needed(void *opaque) return virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1); } =20 +static bool virtio_packed_virtqueue_needed(void *opaque) +{ + VirtIODevice *vdev =3D opaque; + + return virtio_host_has_feature(vdev, VIRTIO_F_RING_PACKED); +} + static bool virtio_ringsize_needed(void *opaque) { VirtIODevice *vdev =3D opaque; @@ -1828,6 +2458,20 @@ static const VMStateDescription vmstate_virtqueue = =3D { } }; =20 +static const VMStateDescription vmstate_packed_virtqueue =3D { + .name =3D "packed_virtqueue_state", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT16(last_avail_idx, struct VirtQueue), + VMSTATE_BOOL(last_avail_wrap_counter, struct VirtQueue), + VMSTATE_UINT16(used_idx, struct VirtQueue), + VMSTATE_BOOL(used_wrap_counter, struct VirtQueue), + VMSTATE_UINT32(inuse, struct VirtQueue), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio_virtqueues =3D { .name =3D "virtio/virtqueues", .version_id =3D 1, @@ -1840,6 +2484,18 @@ static const VMStateDescription vmstate_virtio_virtq= ueues =3D { } }; =20 +static const VMStateDescription vmstate_virtio_packed_virtqueues =3D { + .name =3D "virtio/packed_virtqueues", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D &virtio_packed_virtqueue_needed, + .fields =3D (VMStateField[]) { + VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(vq, struct VirtIODevice, + VIRTIO_QUEUE_MAX, 0, vmstate_packed_virtqueue, VirtQ= ueue), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_ringsize =3D { .name =3D "ringsize_state", .version_id =3D 1, @@ -1972,6 +2628,7 @@ static const VMStateDescription vmstate_virtio =3D { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_packed_virtqueues, NULL } }; @@ -2271,6 +2928,13 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int= version_id) virtio_queue_update_rings(vdev, i); } =20 + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + vdev->vq[i].shadow_avail_idx =3D vdev->vq[i].last_avail_id= x; + vdev->vq[i].shadow_avail_wrap_counter =3D + vdev->vq[i].last_avail_wrap_counte= r; + continue; + } + nheads =3D vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_av= ail_idx; /* Check it isn't doing strange things with descriptor numbers= . */ if (nheads > vdev->vq[i].vring.num) { @@ -2414,6 +3078,10 @@ hwaddr virtio_queue_get_avail_size(VirtIODevice *vde= v, int n) { int s; =20 + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return sizeof(struct VRingPackedDescEvent); + } + s =3D virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0; return offsetof(VRingAvail, ring) + sizeof(uint16_t) * vdev->vq[n].vring.num + s; @@ -2423,23 +3091,83 @@ hwaddr virtio_queue_get_used_size(VirtIODevice *vde= v, int n) { int s; =20 + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return sizeof(struct VRingPackedDescEvent); + } + s =3D virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0; return offsetof(VRingUsed, ring) + sizeof(VRingUsedElem) * vdev->vq[n].vring.num + s; } =20 -uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n) +static unsigned int virtio_queue_packed_get_last_avail_idx(VirtIODevice *v= dev, + int n) +{ + unsigned int avail, used; + + avail =3D vdev->vq[n].last_avail_idx; + avail |=3D ((uint16_t)vdev->vq[n].last_avail_wrap_counter) << 15; + + used =3D vdev->vq[n].used_idx; + used |=3D ((uint16_t)vdev->vq[n].used_wrap_counter) << 15; + + return avail | used << 16; +} + +static uint16_t virtio_queue_split_get_last_avail_idx(VirtIODevice *vdev, + int n) { return vdev->vq[n].last_avail_idx; } =20 -void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t i= dx) +unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n) { - vdev->vq[n].last_avail_idx =3D idx; - vdev->vq[n].shadow_avail_idx =3D idx; + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return virtio_queue_packed_get_last_avail_idx(vdev, n); + } else { + return virtio_queue_split_get_last_avail_idx(vdev, n); + } } =20 -void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n) +static void virtio_queue_packed_set_last_avail_idx(VirtIODevice *vdev, + int n, unsigned int idx) +{ + struct VirtQueue *vq =3D &vdev->vq[n]; + + vq->last_avail_idx =3D vq->shadow_avail_idx =3D idx & 0x7fff; + vq->last_avail_wrap_counter =3D + vq->shadow_avail_wrap_counter =3D !!(idx & 0x8000); + idx >>=3D 16; + vq->used_idx =3D idx & 0x7ffff; + vq->used_wrap_counter =3D !!(idx & 0x8000); +} + +static void virtio_queue_split_set_last_avail_idx(VirtIODevice *vdev, + int n, unsigned int idx) +{ + vdev->vq[n].last_avail_idx =3D idx; + vdev->vq[n].shadow_avail_idx =3D idx; +} + +void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, + unsigned int idx) +{ + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + virtio_queue_packed_set_last_avail_idx(vdev, n, idx); + } else { + virtio_queue_split_set_last_avail_idx(vdev, n, idx); + } +} + +static void virtio_queue_packed_restore_last_avail_idx(VirtIODevice *vdev, + int n) +{ + /* We don't have a reference like avail idx in shared memory */ + return; +} + +static void virtio_queue_split_restore_last_avail_idx(VirtIODevice *vdev, + int n) { rcu_read_lock(); if (vdev->vq[n].vring.desc) { @@ -2449,7 +3177,22 @@ void virtio_queue_restore_last_avail_idx(VirtIODevic= e *vdev, int n) rcu_read_unlock(); } =20 -void virtio_queue_update_used_idx(VirtIODevice *vdev, int n) +void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n) +{ + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + virtio_queue_packed_restore_last_avail_idx(vdev, n); + } else { + virtio_queue_split_restore_last_avail_idx(vdev, n); + } +} + +static void virtio_queue_packed_update_used_idx(VirtIODevice *vdev, int n) +{ + /* used idx was updated through set_last_avail_idx() */ + return; +} + +static void virtio_split_packed_update_used_idx(VirtIODevice *vdev, int n) { rcu_read_lock(); if (vdev->vq[n].vring.desc) { @@ -2458,6 +3201,15 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev= , int n) rcu_read_unlock(); } =20 +void virtio_queue_update_used_idx(VirtIODevice *vdev, int n) +{ + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return virtio_queue_packed_update_used_idx(vdev, n); + } else { + return virtio_split_packed_update_used_idx(vdev, n); + } +} + void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n) { vdev->vq[n].signalled_used_valid =3D false; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 48e8d04ff6..d123d5b181 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -59,6 +59,8 @@ typedef struct VirtQueue VirtQueue; typedef struct VirtQueueElement { unsigned int index; + unsigned int len; + unsigned int ndescs; unsigned int out_num; unsigned int in_num; hwaddr *in_addr; @@ -196,7 +198,8 @@ void virtqueue_map(VirtIODevice *vdev, VirtQueueElement= *elem); void *virtqueue_pop(VirtQueue *vq, size_t sz); unsigned int virtqueue_drop_all(VirtQueue *vq); void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t s= z); -void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem); +void qemu_put_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, + VirtQueueElement *elem); int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes, unsigned int out_bytes); void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, @@ -291,8 +294,9 @@ hwaddr virtio_queue_get_used_addr(VirtIODevice *vdev, i= nt n); hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n); -uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); -void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t i= dx); +unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); +void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, + unsigned int idx); void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n); void virtio_queue_update_used_idx(VirtIODevice *vdev, int n); --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571939405; cv=none; d=zoho.com; s=zohoarc; b=Y+CWztSOJRDqr9cJGeaP/vyqxVWAladc0irt0cUrc/cwBjM/FLk1Bfq7Ec0fGDOgNzWCyxlT4yE1ubkrLO13whxJqacOtRXwESrWlMQoEC6yUc8ZdWxtTxwjvSVky7pheM1itA4PJGS0YrzfTRlavrvWQhcteZxLRXfCItCUkD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571939405; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=nww/FniJPLNWx+uRR3X6O4qY1LasX67m0rwmDB7G99Q=; b=OMMAKNhwJMhGKzxqXv1zTy8+TJFBcU0T0Djn829iCUTTN8e6y2ZtTMawVWYNo5XjpuTzvjk1oFP/Q2o6MSPyMsML22rkgVS5XQdQS5k6IVBPQf9/rlsG3+zV6bSpfn9p9XgDnSiLhRi2qjQ1efC2kdAONiyn6tuFL+5U0iEYijw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571939405416599.667302483432; Thu, 24 Oct 2019 10:50:05 -0700 (PDT) Received: from localhost ([::1]:49326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhFI-0001QB-IV for importer@patchew.org; Thu, 24 Oct 2019 13:50:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38019) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNghJ-0002Ru-Dm for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNghH-0001y3-Cl for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38462 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNghF-0001wZ-5H for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-158-P6BRINxfNwmqHusiVcDBjQ-1; Thu, 24 Oct 2019 13:14:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1DB7100550E; Thu, 24 Oct 2019 17:14:43 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BC545D70E; Thu, 24 Oct 2019 17:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nww/FniJPLNWx+uRR3X6O4qY1LasX67m0rwmDB7G99Q=; b=U0hLkSlXF0OzsWigRF6kHa/fseRik1N/ohCXC4D7yvS0PKPs2eYYpgU2vVBDvOSgSXNbnX qhV0Y71sylKLwdr1GNonozetyM8hgh/yQ0ev71PVFCVUfyXwQcJ68E0jehlnH/2CpnlkFr L83nxW2fijWRAsA6HXapRgpKlmNYS0A= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 5/9] virtio: event suppression support for packed ring Date: Thu, 24 Oct 2019 19:14:02 +0200 Message-Id: <20191024171406.12504-6-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: P6BRINxfNwmqHusiVcDBjQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jason Wang This patch implements event suppression through device/driver area. Please refer virtio specification for more information. Signed-off-by: Wei Xu Signed-off-by: Jason Wang --- hw/virtio/virtio.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 133 insertions(+), 9 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6e7a034d2a..3cf12a62c0 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -240,6 +240,44 @@ static void vring_split_desc_read(VirtIODevice *vdev, = VRingDesc *desc, virtio_tswap16s(vdev, &desc->next); } =20 +static void vring_packed_event_read(VirtIODevice *vdev, + MemoryRegionCache *cache, + VRingPackedDescEvent *e) +{ + hwaddr off_off =3D offsetof(VRingPackedDescEvent, off_wrap); + hwaddr off_flags =3D offsetof(VRingPackedDescEvent, flags); + + address_space_read_cached(cache, off_flags, &e->flags, + sizeof(e->flags)); + /* Make sure flags is seen before off_wrap */ + smp_rmb(); + address_space_read_cached(cache, off_off, &e->off_wrap, + sizeof(e->off_wrap)); + virtio_tswap16s(vdev, &e->off_wrap); + virtio_tswap16s(vdev, &e->flags); +} + +static void vring_packed_off_wrap_write(VirtIODevice *vdev, + MemoryRegionCache *cache, + uint16_t off_wrap) +{ + hwaddr off =3D offsetof(VRingPackedDescEvent, off_wrap); + + virtio_tswap16s(vdev, &off_wrap); + address_space_write_cached(cache, off, &off_wrap, sizeof(off_wrap)); + address_space_cache_invalidate(cache, off, sizeof(off_wrap)); +} + +static void vring_packed_flags_write(VirtIODevice *vdev, + MemoryRegionCache *cache, uint16_t fl= ags) +{ + hwaddr off =3D offsetof(VRingPackedDescEvent, flags); + + virtio_tswap16s(vdev, &flags); + address_space_write_cached(cache, off, &flags, sizeof(flags)); + address_space_cache_invalidate(cache, off, sizeof(flags)); +} + static VRingMemoryRegionCaches *vring_get_region_caches(struct VirtQueue *= vq) { VRingMemoryRegionCaches *caches =3D atomic_rcu_read(&vq->vring.caches); @@ -346,14 +384,8 @@ static inline void vring_set_avail_event(VirtQueue *vq= , uint16_t val) address_space_cache_invalidate(&caches->used, pa, sizeof(val)); } =20 -void virtio_queue_set_notification(VirtQueue *vq, int enable) +static void virtio_queue_split_set_notification(VirtQueue *vq, int enable) { - vq->notification =3D enable; - - if (!vq->vring.desc) { - return; - } - rcu_read_lock(); if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) { vring_set_avail_event(vq, vring_avail_idx(vq)); @@ -369,6 +401,51 @@ void virtio_queue_set_notification(VirtQueue *vq, int = enable) rcu_read_unlock(); } =20 +static void virtio_queue_packed_set_notification(VirtQueue *vq, int enable) +{ + uint16_t off_wrap; + VRingPackedDescEvent e; + VRingMemoryRegionCaches *caches; + + rcu_read_lock(); + caches =3D vring_get_region_caches(vq); + vring_packed_event_read(vq->vdev, &caches->used, &e); + + if (!enable) { + e.flags =3D VRING_PACKED_EVENT_FLAG_DISABLE; + } else if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX))= { + off_wrap =3D vq->shadow_avail_idx | vq->shadow_avail_wrap_counter = << 15; + vring_packed_off_wrap_write(vq->vdev, &caches->used, off_wrap); + /* Make sure off_wrap is wrote before flags */ + smp_wmb(); + e.flags =3D VRING_PACKED_EVENT_FLAG_DESC; + } else { + e.flags =3D VRING_PACKED_EVENT_FLAG_ENABLE; + } + + vring_packed_flags_write(vq->vdev, &caches->used, e.flags); + if (enable) { + /* Expose avail event/used flags before caller checks the avail id= x. */ + smp_mb(); + } + rcu_read_unlock(); +} + +void virtio_queue_set_notification(VirtQueue *vq, int enable) +{ + vq->notification =3D enable; + + if (!vq->vring.desc) { + return; + } + + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + virtio_queue_packed_set_notification(vq, enable); + } else { + virtio_queue_split_set_notification(vq, enable); + } +} + int virtio_queue_ready(VirtQueue *vq) { return vq->vring.avail !=3D 0; @@ -2290,8 +2367,7 @@ static void virtio_set_isr(VirtIODevice *vdev, int va= lue) } } =20 -/* Called within rcu_read_lock(). */ -static bool virtio_should_notify(VirtIODevice *vdev, VirtQueue *vq) +static bool virtio_split_should_notify(VirtIODevice *vdev, VirtQueue *vq) { uint16_t old, new; bool v; @@ -2314,6 +2390,54 @@ static bool virtio_should_notify(VirtIODevice *vdev,= VirtQueue *vq) return !v || vring_need_event(vring_get_used_event(vq), new, old); } =20 +static bool vring_packed_need_event(VirtQueue *vq, bool wrap, + uint16_t off_wrap, uint16_t new, + uint16_t old) +{ + int off =3D off_wrap & ~(1 << 15); + + if (wrap !=3D off_wrap >> 15) { + off -=3D vq->vring.num; + } + + return vring_need_event(off, new, old); +} + +static bool virtio_packed_should_notify(VirtIODevice *vdev, VirtQueue *vq) +{ + VRingPackedDescEvent e; + uint16_t old, new; + bool v; + VRingMemoryRegionCaches *caches; + + caches =3D vring_get_region_caches(vq); + vring_packed_event_read(vdev, &caches->avail, &e); + + old =3D vq->signalled_used; + new =3D vq->signalled_used =3D vq->used_idx; + v =3D vq->signalled_used_valid; + vq->signalled_used_valid =3D true; + + if (e.flags =3D=3D VRING_PACKED_EVENT_FLAG_DISABLE) { + return false; + } else if (e.flags =3D=3D VRING_PACKED_EVENT_FLAG_ENABLE) { + return true; + } + + return !v || vring_packed_need_event(vq, vq->used_wrap_counter, + e.off_wrap, new, old); +} + +/* Called within rcu_read_lock(). */ +static bool virtio_should_notify(VirtIODevice *vdev, VirtQueue *vq) +{ + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return virtio_packed_should_notify(vdev, vq); + } else { + return virtio_split_should_notify(vdev, vq); + } +} + void virtio_notify_irqfd(VirtIODevice *vdev, VirtQueue *vq) { bool should_notify; --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571939554; cv=none; d=zoho.com; s=zohoarc; b=kvfPbZjxl6k0StVaXmYnP83T/1CvuboZjFkEkVy7b1+tK3Ds9V5dGSFPXwATXP9AFu5S3CtW3YSQ9Y8xhhEIJDXbPrXCgJmOOQkxDNu+mMJ1OSBqMJqYZ1gsGT8EfsyHV/VyTe69GPEoa34aYk52JccJBHy8g/CCBC4HJkI+III= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571939554; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=xyirqql+5EtNDJ86ycqPeYP02hFiDOB1Cvgashw0PnI=; b=OqyXr46BVvpcNYYyiiXXVBR7y+cBwnhMZ7C24tBRvVVX+6TVUYhyrOxvFiyZHnq+N7UE2E3InT7lQnm8Kog1KL+Sq6+anhtEt7OXcp/yvSL6gJvXzYW+s5hdXyUAOJJtY9fe6glcglc7zuUHOelPSFNBINKPXGLXwjzWu2clmKM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571939554894662.8856048612482; Thu, 24 Oct 2019 10:52:34 -0700 (PDT) Received: from localhost ([::1]:49446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhHl-0006JH-Ix for importer@patchew.org; Thu, 24 Oct 2019 13:52:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38054) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNghM-0002TX-Rv for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNghL-0001zO-AA for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:56 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:48746 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNghJ-0001yF-Bd for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:55 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-19NpDuwFNu65OzPsxvwnag-1; Thu, 24 Oct 2019 13:14:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD59B107AD31; Thu, 24 Oct 2019 17:14:46 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 254165B681; Thu, 24 Oct 2019 17:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xyirqql+5EtNDJ86ycqPeYP02hFiDOB1Cvgashw0PnI=; b=DkhOurT5E7KZYu956dfwZOc9iT+sKJzcmlL4qf0A9Kjx7x8PRrMgmPaC/lU9TwxIJo5bR1 /coAt+v8SC2EHMNVtr3duAy713AmD/npPx1xgXBsGtPZylKqbHzejH1H5gu4XO2HNsRSng nEpQX2PJij9CDqfceBUpHqAq2dLLGo4= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 6/9] vhost_net: enable packed ring support Date: Thu, 24 Oct 2019 19:14:03 +0200 Message-Id: <20191024171406.12504-7-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 19NpDuwFNu65OzPsxvwnag-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jason Wang Signed-off-by: Jason Wang Reviewed-by: Jens Freimann --- hw/net/vhost_net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index e975700f95..6b82803fa7 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -49,6 +49,7 @@ static const int kernel_feature_bits[] =3D { VIRTIO_F_VERSION_1, VIRTIO_NET_F_MTU, VIRTIO_F_IOMMU_PLATFORM, + VIRTIO_F_RING_PACKED, VHOST_INVALID_FEATURE_BIT }; =20 @@ -74,6 +75,7 @@ static const int user_feature_bits[] =3D { VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_MTU, VIRTIO_F_IOMMU_PLATFORM, + VIRTIO_F_RING_PACKED, =20 /* This bit implies RARP isn't sent by QEMU out of band */ VIRTIO_NET_F_GUEST_ANNOUNCE, --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571941250; cv=none; d=zoho.com; s=zohoarc; b=lipSGyqL/7s58gmKrRgWnuhvhMWVdtllZGvko9S4Nmcajs2NBCAA+beJBwqsnBqKv80gfmzjD2TtP1QdovERWH9UjHqu9/JdO6PlblvUUZ5SpYdBpwSMAfpryH3RAkkm+Qy+HDRxI19LRnJwj5GhULTie5oZ3Mf7BprXirP0fqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571941250; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=w3X+do+JYhJ7B8LOWTY46A3CNCj1POquiFexM3flnpE=; b=O12Oljp8N3Q+juGW2pmGBuv6STlT1lQQlu58/i3ueOD8D3+14FWwpoerVV/Zjs92iYPF5pNHwOwDGcYJU/MWqt0ubr0UKRSRmPJSVHxeQC1ouJWQXhmqLLVc1nMmBn0/iRYjYk7m0otutJhJ5WWmGXBTrwHM9+Z/t8NVo1xieA0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571941250653277.9892518616232; Thu, 24 Oct 2019 11:20:50 -0700 (PDT) Received: from localhost ([::1]:50022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhj7-00012X-3h for importer@patchew.org; Thu, 24 Oct 2019 14:20:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38082) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNghP-0002UF-6E for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNghN-00020M-Qs for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59364 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNghN-0001zz-7J for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:14:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-eP2fYvz9OFyo7pcejDSiXQ-1; Thu, 24 Oct 2019 13:14:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03DBE800D49; Thu, 24 Oct 2019 17:14:50 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4240C5D784; Thu, 24 Oct 2019 17:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937296; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w3X+do+JYhJ7B8LOWTY46A3CNCj1POquiFexM3flnpE=; b=aLaSe3qbfxYxZjlOOps0LOPfih6tkJ9POPJ1jkQnZZo7Y2OuC1n0X/C8xxGr9R55b0/Uvt bZDqNaSqFg82oTK2eTgdOdlLK/Ll4SpYVKyX8nHBbxEanF7x87irqCeK+a8Cgm2fwJKOkN 2O1vjENfm9lIPXhyaa5jLn/0D5tANXI= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 7/9] virtio: add property to enable packed virtqueue Date: Thu, 24 Oct 2019 19:14:04 +0200 Message-Id: <20191024171406.12504-8-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: eP2fYvz9OFyo7pcejDSiXQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jason Wang Signed-off-by: Jason Wang Reviewed-by: Jens Freimann --- include/hw/virtio/virtio.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index d123d5b181..40ddeafadb 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -285,7 +285,9 @@ typedef struct VirtIORNGConf VirtIORNGConf; DEFINE_PROP_BIT64("any_layout", _state, _field, \ VIRTIO_F_ANY_LAYOUT, true), \ DEFINE_PROP_BIT64("iommu_platform", _state, _field, \ - VIRTIO_F_IOMMU_PLATFORM, false) + VIRTIO_F_IOMMU_PLATFORM, false), \ + DEFINE_PROP_BIT64("packed", _state, _field, \ + VIRTIO_F_RING_PACKED, false) =20 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n); bool virtio_queue_enabled(VirtIODevice *vdev, int n); --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571938544; cv=none; d=zoho.com; s=zohoarc; b=AtndjeFQxuue+tuBM1x98R5f7snBYiwbXhQdfUbuSvyhTiZnQYnsZAlN4Amwf6TSzd4J8mHMmEfTJIkzLxQofu6VDQsZ8F99O5/6gVQ/V7xwJBw//qsvIn88X1oT48ZpEFK9qrNNUKTHoHfJVv+tZqS8FEomTKHm3b3XuOAagac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571938544; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QHi/ZcZkuogsRdwJr7LU741XrjKiy2gJElKC2Qe6S0E=; b=Pv4yHDfpWNPEP4uXvkSntM1QsbDOdVTlcuQGCTXsiHY1nNX4zBqG3MY80Lmc0uWa9XhbBzIqd6iVvRHULz4iBtCkYtGtaCCK4ABn1TW8jHCfKNgWDbwLzg2HD/R3Xs6yHcJU4yUZjkVqfKm9Lc3w2JJAKvvoTaQHDl+EoVrnS1g= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571938544715680.1573408752084; Thu, 24 Oct 2019 10:35:44 -0700 (PDT) Received: from localhost ([::1]:48888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNh1T-0001JQ-4y for importer@patchew.org; Thu, 24 Oct 2019 13:35:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38134) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNghV-0002cd-O8 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNghU-00023Y-OM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:05 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:42493 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNghU-00023O-LQ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:04 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-YEA7LjBPM6G2_I9af-Bt7A-1; Thu, 24 Oct 2019 13:15:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9B54107AD31; Thu, 24 Oct 2019 17:14:59 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CB9E61F21; Thu, 24 Oct 2019 17:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937304; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QHi/ZcZkuogsRdwJr7LU741XrjKiy2gJElKC2Qe6S0E=; b=OVkBbmp9bdPHTi8VUfOHOGnKYXT928/IptIFmlUqyVKFP9qQbqFUDRLXrKK0N4tsC4OvmB ItTYU5qXIUthAwXJG3Sn8L+j/7fJvQ2UVwq16sKcUAI8n0h46441doXWeTYxf8CRiQ2q2n GG08GP3vLQFSZntGCR7xAcLwrCpNTFI= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 8/9] virtio: add some rcu comments Date: Thu, 24 Oct 2019 19:14:05 +0200 Message-Id: <20191024171406.12504-9-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: YEA7LjBPM6G2_I9af-Bt7A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3cf12a62c0..9195b08da8 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -278,6 +278,7 @@ static void vring_packed_flags_write(VirtIODevice *vdev, address_space_cache_invalidate(cache, off, sizeof(flags)); } =20 +/* Called within rcu_read_lock(). */ static VRingMemoryRegionCaches *vring_get_region_caches(struct VirtQueue *= vq) { VRingMemoryRegionCaches *caches =3D atomic_rcu_read(&vq->vring.caches); @@ -721,7 +722,6 @@ bool virtqueue_rewind(VirtQueue *vq, unsigned int num) return true; } =20 -/* Called within rcu_read_lock(). */ static void virtqueue_split_fill(VirtQueue *vq, const VirtQueueElement *el= em, unsigned int len, unsigned int idx) { @@ -780,6 +780,7 @@ static void virtqueue_packed_fill_desc(VirtQueue *vq, vring_packed_desc_write(vq->vdev, &desc, &caches->desc, head, strict_o= rder); } =20 +/* Called within rcu_read_lock(). */ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx) { --=20 2.16.5 From nobody Wed May 1 18:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571939726; cv=none; d=zoho.com; s=zohoarc; b=kNBxxMdL6lDKlBHijLxyNcohWTfqi6IUFcw9gtfGnaSwF7s2mVTpsjqW9Kh4Z0e999aSDusRuG0+xQ+nxAxlHzTljHpYwmbHVcAoB5GLnOw2aGi/mRrXQWqml9MYQpcX0/Dm8DH8OUG3aqZQl0QyIVMH/Ijw/kKD437Zzo4VwDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571939726; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0L0Zrn9b9ULLnzAL4jTEe+6gz0IPI+nkF7oR4+uyGRg=; b=QSN4XH3kh5KdYV09NNCvOlRDbwCXagY2jmzn7V/YCjFFeqDPpLiCOzgk3BYIh5g8LS/ruDyp8zLr34asU0QxcETTnmN9fk0DG1D1EwXgeBokctbxWkVH3MetXjgYmJwsOZmQw/kwsmkAzDawro1xSzADjyXSwYhpK46XozoFlr0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571939726834210.07871748551645; Thu, 24 Oct 2019 10:55:26 -0700 (PDT) Received: from localhost ([::1]:49470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNhKU-0002iu-FV for importer@patchew.org; Thu, 24 Oct 2019 13:55:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38161) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNghb-0002n0-Ai for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNgha-00028c-Ar for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:11 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49957 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNgha-000281-7f for qemu-devel@nongnu.org; Thu, 24 Oct 2019 13:15:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-V-IW6TI8MzqGLkC5lfYHWg-1; Thu, 24 Oct 2019 13:15:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31B96107AD31; Thu, 24 Oct 2019 17:15:05 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F0895D70E; Thu, 24 Oct 2019 17:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571937309; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0L0Zrn9b9ULLnzAL4jTEe+6gz0IPI+nkF7oR4+uyGRg=; b=PF8Ht7JyP/NkWxm4dU5hBrPQclLlT0ySMHEMCWyat6Lf3f/lUqUZShnOIL4UjWxqSnYnMO HjsfGNtLg5HwZRI+Eog1nitiExPdossrtNU4+y++FefMOhPCquZorN5t3HwOgXU7E1sW+q Y+itUFEuLR4oXXlnKSaCJD2s7D72SVM= From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH v6 9/9] virtio: Move vdev->broken check to dispatch drop_all Date: Thu, 24 Oct 2019 19:14:06 +0200 Message-Id: <20191024171406.12504-10-eperezma@redhat.com> In-Reply-To: <20191024171406.12504-1-eperezma@redhat.com> References: <20191024171406.12504-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: V-IW6TI8MzqGLkC5lfYHWg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, Amit Shah , Jason Wang , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Previous commits did the same with others virtqueue_ functions, but this check was repeated in the split and the packed version. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/virtio.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9195b08da8..828c27de1f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1631,10 +1631,6 @@ static unsigned int virtqueue_packed_drop_all(VirtQu= eue *vq) VirtIODevice *vdev =3D vq->vdev; VRingPackedDesc desc; =20 - if (unlikely(vdev->broken)) { - return 0; - } - caches =3D vring_get_region_caches(vq); desc_cache =3D &caches->desc; =20 @@ -1680,10 +1676,6 @@ static unsigned int virtqueue_split_drop_all(VirtQue= ue *vq) VirtIODevice *vdev =3D vq->vdev; bool fEventIdx =3D virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_I= DX); =20 - if (unlikely(vdev->broken)) { - return 0; - } - while (!virtio_queue_empty(vq) && vq->inuse < vq->vring.num) { /* works similar to virtqueue_pop but does not map buffers * and does not allocate any memory */ @@ -1715,6 +1707,10 @@ unsigned int virtqueue_drop_all(VirtQueue *vq) { struct VirtIODevice *vdev =3D vq->vdev; =20 + if (unlikely(vdev->broken)) { + return 0; + } + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { return virtqueue_packed_drop_all(vq); } else { --=20 2.16.5