From nobody Mon Nov 25 02:54:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1718906263; cv=none; d=zohomail.com; s=zohoarc; b=kZ3ORJ3ceHKWvtIoEF6FZYzWKps7aBy3gyolHudP892hf6WlGtrCOmnnpu7JnotH5BijyBQmjuPaXRnmNL7aZD5PNfV/jNyMa4Aie+PP10a7kO5wE+WiyeS+MR9yA/EXuXZBxn5iUsVf1PJ0+ACeX8cUp/sEpTf3RoZb+lpwAdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718906263; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0Vj+BMveb2mZxDMdZQ8ep773C4avRMRPkH3UhXRCo2A=; b=J51uEi4Fcn8m6BfwLGT6UnPBZ4jQ3UrFhXSrm19bCC9iTwNCqqFHARtsrq/CveKN31oyXx+0/sdrirbVVRQZmlcnFZ1ecnW8HuDEM+aa7Vfg1TkuXpMOq2o3+XgeoeKvCzeEFLDYCfbV9t6hXnWHAeZvR7oKXDXkxCh5LX+PbFc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718906263387105.36198858372188; Thu, 20 Jun 2024 10:57:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKM1t-0008R3-Fg; Thu, 20 Jun 2024 13:57:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sKM1T-00081L-L4; Thu, 20 Jun 2024 13:56:35 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sKM1R-0005Xz-SB; Thu, 20 Jun 2024 13:56:35 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45KHBE9O009932; Thu, 20 Jun 2024 17:56:26 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yvrkj02yb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 17:56:25 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KHDpPI012753; Thu, 20 Jun 2024 17:56:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3yvrn3hnr1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 17:56:25 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 45KHuF0r018715; Thu, 20 Jun 2024 17:56:24 GMT Received: from jonah-ol8.us.oracle.com (dhcp-10-39-208-85.vpn.oracle.com [10.39.208.85]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3yvrn3hnjv-5; Thu, 20 Jun 2024 17:56:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=0 Vj+BMveb2mZxDMdZQ8ep773C4avRMRPkH3UhXRCo2A=; b=i2aOeigD1NyX3BgtQ r4Sc0wek9KjWVZ81vovrSv9Gzd4HD59HFbduwXfhy/N2kGHHu4lPmFAuwD0VCPRn hXJFQ5ca5RM/3W1ocvvihNVavWU6355Uq90hFpvzv/VoxP2jlKhcsgXlLjvxY1Gp lQNtA0tjFLysx9DyzOdf9afAT1KV0k2v5Wlfy+eGYI6/XCq1gEEN50qNpYU3C4qr wRf7GjpVNor9rMXa23iV05rCqNOW6iibMG0FoLLbE0sx3foeNFTbyNWts7dCDAhv 1LApuYb8R5a2GQsWnpqOIm7Pbg9KuHFGup3taCDUS3SYCyl6grbSbGTs1S1V8Z9o WTTsw== From: Jonah Palmer To: qemu-devel@nongnu.org Cc: mst@redhat.com, raphael@enfabrica.net, kwolf@redhat.com, hreitz@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, fam@euphon.net, eperezma@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, schalla@marvell.com, leiyang@redhat.com, virtio-fs@lists.linux.dev, si-wei.liu@oracle.com, boris.ostrovsky@oracle.com, jonah.palmer@oracle.com Subject: [PATCH v3 4/6] virtio: virtqueue_ordered_flush - VIRTIO_F_IN_ORDER support Date: Thu, 20 Jun 2024 13:56:08 -0400 Message-ID: <20240620175612.2381019-5-jonah.palmer@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175612.2381019-1-jonah.palmer@oracle.com> References: <20240620175612.2381019-1-jonah.palmer@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_08,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2406200129 X-Proofpoint-GUID: dEOoX6k4fPDIwM3GOoTmDiJFK_RYvsH_ X-Proofpoint-ORIG-GUID: dEOoX6k4fPDIwM3GOoTmDiJFK_RYvsH_ Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.165.32; envelope-from=jonah.palmer@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1718906264063100001 Content-Type: text/plain; charset="utf-8" Add VIRTIO_F_IN_ORDER feature support for the virtqueue_flush operation. The goal of the virtqueue_ordered_flush operation when the VIRTIO_F_IN_ORDER feature has been negotiated is to write elements to the used/descriptor ring in-order and then update used_idx. The function iterates through the VirtQueueElement used_elems array in-order starting at vq->used_idx. If the element is valid (filled), the element is written to the used/descriptor ring. This process continues until we find an invalid (not filled) element. For packed VQs, the first entry (at vq->used_idx) is written to the descriptor ring last so the guest doesn't see any invalid descriptors. If any elements were written, the used_idx is updated. Signed-off-by: Jonah Palmer --- hw/virtio/virtio.c | 66 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e1dfec4655..b0b1b556a2 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1024,6 +1024,68 @@ static void virtqueue_packed_flush(VirtQueue *vq, un= signed int count) } } =20 +static void virtqueue_ordered_flush(VirtQueue *vq) +{ + unsigned int i =3D vq->used_idx; + unsigned int ndescs =3D 0; + uint16_t old =3D vq->used_idx; + bool packed; + VRingUsedElem uelem; + + packed =3D virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED); + + if (packed) { + if (unlikely(!vq->vring.desc)) { + return; + } + } else if (unlikely(!vq->vring.used)) { + return; + } + + /* First expected in-order element isn't ready, nothing to do */ + if (!vq->used_elems[i].in_order_filled) { + return; + } + + /* Search for filled elements in-order */ + while (vq->used_elems[i].in_order_filled) { + /* + * First entry for packed VQs is written last so the guest + * doesn't see invalid descriptors. + */ + if (packed && i !=3D vq->used_idx) { + virtqueue_packed_fill_desc(vq, &vq->used_elems[i], ndescs, fal= se); + } else if (!packed) { + uelem.id =3D vq->used_elems[i].index; + uelem.len =3D vq->used_elems[i].len; + vring_used_write(vq, &uelem, i); + } + + vq->used_elems[i].in_order_filled =3D false; + ndescs +=3D vq->used_elems[i].ndescs; + i +=3D ndescs; + if (i >=3D vq->vring.num) { + i -=3D vq->vring.num; + } + } + + if (packed) { + virtqueue_packed_fill_desc(vq, &vq->used_elems[vq->used_idx], 0, t= rue); + 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; + vq->signalled_used_valid =3D false; + } + } else { + vring_used_idx_set(vq, i); + if (unlikely((int16_t)(i - vq->signalled_used) < (uint16_t)(i - ol= d))) { + vq->signalled_used_valid =3D false; + } + } + vq->inuse -=3D ndescs; +} + void virtqueue_flush(VirtQueue *vq, unsigned int count) { if (virtio_device_disabled(vq->vdev)) { @@ -1031,7 +1093,9 @@ void virtqueue_flush(VirtQueue *vq, unsigned int coun= t) return; } =20 - if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_IN_ORDER)) { + virtqueue_ordered_flush(vq); + } else if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { virtqueue_packed_flush(vq, count); } else { virtqueue_split_flush(vq, count); --=20 2.43.0