From nobody Tue Feb 10 01:16:18 2026 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; 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=1572119080; cv=none; d=zoho.com; s=zohoarc; b=cWvlhmEgSOqYLG6gNMqeujeY/XUz3nXyyhXSUugteCweWtDDgI2RaSM3xgD3eUHfb6E31llaukNYpr74+5ApdJQKWANx0A45bmc6grAaisOULP2jP+SsgXeFuS3I648t3A/nHFgbRWo9G+ODevV53uPa8k/2hqxAHuArWvVyT8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572119080; 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=GIAlbc8PlpF89e3M3scUUoi5Nseo4m8yBrf1IkQW6Yg=; b=P5IsVP6COPz5LRqsnz5OnRAaGi7Q4ZMdOl5jm3zYu8nX85GM+oQkVqsUJQkcYaDgNUPjfk0lkML5eiRZ/6vQ+BhLiNKywxQVm5C1683dTQ5zEjuM2m6+x9GRs4EikTh/thzctpzeNbcWIDZ7CkCViCHrJ6wJRuW7/psg3XzEIVg= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1572119080839684.6383773682747; Sat, 26 Oct 2019 12:44:40 -0700 (PDT) Received: from localhost ([::1]:41706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iORzK-0001a2-Uz for importer@patchew.org; Sat, 26 Oct 2019 15:44:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50951) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iORuG-0000P2-Jm for qemu-devel@nongnu.org; Sat, 26 Oct 2019 15:39:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iORuF-00008o-Fs for qemu-devel@nongnu.org; Sat, 26 Oct 2019 15:39:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iORuF-00008W-7f for qemu-devel@nongnu.org; Sat, 26 Oct 2019 15:39:23 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BCA6C01D36C for ; Sat, 26 Oct 2019 19:39:22 +0000 (UTC) Received: by mail-qt1-f199.google.com with SMTP id t16so6322277qtp.11 for ; Sat, 26 Oct 2019 12:39:22 -0700 (PDT) Received: from redhat.com (bzq-79-176-10-77.red.bezeqint.net. [79.176.10.77]) by smtp.gmail.com with ESMTPSA id 14sm2991819qtb.54.2019.10.26.12.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2019 12:39:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=42QY6USANjxLIh2wuts0pVaXl5XWhZ8Sl7+dDJBp7pk=; b=jk+rFymt/Av21sBXPeawJJSSJvT0+T7OEK8VG2Lf/FnHq4RtS9910grtuEJQV7dtan AhZWVpCZgWuVs1PANESp0o1XkhHOE+K1mmYPefZGzcNDDk/Daawz5YU+3ACIeIsKkC1n xbPexFNU1xKT+tQRQ022M0n0ZM9Pd01cX1Yn94fx/nQSs9DCZFUKaG/Xx7DVcyb94rVf jJPvj1ZCnVrAjVvC4UPVC4qKYOC0linP6KI+fbAupIkovap8GCtTonwxSplDjD+UyyoO ZnFNzrTJbOEIIRI7Aipl3/md4j4CI1lqQipa94ipe8tsCSl/vxBi9hfJeFUGSYsP1MYI r28Q== X-Gm-Message-State: APjAAAWa7smCaxBJTxHcW3Slx40yC/k0w+D8VaHFcxL6t1BScv4NSOEf bRiqayA7v2RK5PVzA3Gq7w65QSliGLOxDwZ82To0N4T6iGzXMc5MGyyBZJkhOyjtiYA0EXPrUzh MS96Gh48GMmmPhmM= X-Received: by 2002:a37:383:: with SMTP id 125mr9218186qkd.482.1572118761181; Sat, 26 Oct 2019 12:39:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0xa33mrY3EfAWFFaoci3fH5N4xX4WisAKxdnr53QiZNbOUkHgEPYT5d/HKnSuHzdXibjf3g== X-Received: by 2002:a37:383:: with SMTP id 125mr9218162qkd.482.1572118760807; Sat, 26 Oct 2019 12:39:20 -0700 (PDT) Date: Sat, 26 Oct 2019 15:39:15 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 02/25] virtio: device/driver area size calculation refactor for split ring Message-ID: <20191026193824.11926-3-mst@redhat.com> References: <20191026193824.11926-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20191026193824.11926-1-mst@redhat.com> X-Mailer: git-send-email 2.22.0.678.g13338e74b8 X-Mutt-Fcc: =sent 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: 209.132.183.28 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: Peter Maydell , Jason Wang , Jens Freimann , Wei Xu , Eugenio =?utf-8?B?UMOpcmV6?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Jens Freimann Message-Id: <20191025083527.30803-3-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 MST