From nobody Tue Nov 26 08:58:20 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=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1709581693; cv=none; d=zohomail.com; s=zohoarc; b=CSiZbMCvPwLBGvKKiaDstOP145pUAqFeXmVHctEEPx7QPfLz8DpBuUzupi/T3tgtZCPWBzDETw38WCwdm4qCieKtcxrxWP5RFH0MPgJI4xt96s+kXmQPdxPj3hLRUXWdLWkNTt2KKDR4oudcIv8S5VEoNMAYxDLHW1vA5FcImss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709581693; 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=pYsAh42//tBSLEpWQCZ5lbgKnJW+yKa5C4dXu14LSC8=; b=OMrVgXqX8lHiuheymC8PftUNZxNgYHQSfyx5D7ykLIKl1I0iWCuOA7SNZS5ThWMf2nrQPPakqCbIMAgd7IXQj0ldBF1jqGaa//37yyI0/VdsHNBT7/hBiReEuYLLAL7OwXJyliQ+qRD4wFT1ZKq//o6a7MOI8wJakznCP/Hu9r4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17095816938491019.4850148205716; Mon, 4 Mar 2024 11:48:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhEGn-0003UH-Bq; Mon, 04 Mar 2024 14:46:41 -0500 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 1rhEGi-0002yb-71; Mon, 04 Mar 2024 14:46:36 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhEGg-0007QC-9v; Mon, 04 Mar 2024 14:46:35 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 424IxI1A031676; Mon, 4 Mar 2024 19:46:18 GMT Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wkthecmug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 04 Mar 2024 19:46:17 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 424JIr72018962; Mon, 4 Mar 2024 19:46:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3wktj6ag77-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 04 Mar 2024 19:46:17 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 424JkE40038523; Mon, 4 Mar 2024 19:46:16 GMT Received: from jonah-ol8.us.oracle.com (dhcp-10-39-196-188.vpn.oracle.com [10.39.196.188]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3wktj6ag50-2; Mon, 04 Mar 2024 19:46:16 +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=pYsAh42//tBSLEpWQCZ5lbgKnJW+yKa5C4dXu14LSC8=; b=ATsurcovNWMufyo04AWEe8v9OiqCoSwb4Meh2LyW+TidXILIFecP3K+qinRypeIZprjr hD8rQssyZo0R2oLSuVZBPRp5XnnJTPVyqe/tg0UWiKZOtN/tqbgBHxfC4r0/NUrFBSJr yh8nGrcIVJXqRu5LKBhVkdSRDnGQeTe6fWIwvwBsRY+oKQkRVbQYx6eR+Io6sFl5lO/B 8UvjkQSDrK6kRymmpT7YuqNopLJxnhhb3o/ucl1xJY0GBDr7x6kCqm8+rxXfu/jS5A0O CCcKpJ89zMr8r7o9NQFAY9KXAr1JaM6E1nSHDXuU9scy5kbwOaVnrRHUgEEGkADsOvhM PA== From: Jonah Palmer To: qemu-devel@nongnu.org Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com, si-wei.liu@oracle.com, boris.ostrovsky@oracle.com, jonah.palmer@oracle.com, raphael@enfabrica.net, kwolf@redhat.com, hreitz@redhat.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, farman@linux.ibm.com, thuth@redhat.com, richard.henderson@linaro.org, david@redhat.com, iii@linux.ibm.com, cohuck@redhat.com, pbonzini@redhat.com, fam@euphon.net, stefanha@redhat.com, qemu-block@nongnu.org, qemu-s390x@nongnu.org, virtio-fs@lists.linux.dev Subject: [PATCH v1 1/8] virtio/virtio-pci: Handle extra notification data Date: Mon, 4 Mar 2024 14:46:05 -0500 Message-Id: <20240304194612.611660-2-jonah.palmer@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240304194612.611660-1-jonah.palmer@oracle.com> References: <20240304194612.611660-1-jonah.palmer@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-04_15,2024-03-04_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403040152 X-Proofpoint-ORIG-GUID: HPge5l3mwl2N1HGDE-E6vJTQ4_RHGAq4 X-Proofpoint-GUID: HPge5l3mwl2N1HGDE-E6vJTQ4_RHGAq4 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.177.32; envelope-from=jonah.palmer@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=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: 1709581694265100001 Content-Type: text/plain; charset="utf-8" Add support to virtio-pci devices for handling the extra data sent from the driver to the device when the VIRTIO_F_NOTIFICATION_DATA transport feature has been negotiated. The extra data that's passed to the virtio-pci device when this feature is enabled varies depending on the device's virtqueue layout. In a split virtqueue layout, this data includes: - upper 16 bits: shadow_avail_idx - lower 16 bits: virtqueue index In a packed virtqueue layout, this data includes: - upper 16 bits: 1-bit wrap counter & 15-bit shadow_avail_idx - lower 16 bits: virtqueue index Signed-off-by: Jonah Palmer Reviewed-by: Eugenio P=C3=A9rez --- hw/virtio/virtio-pci.c | 10 +++++++--- hw/virtio/virtio.c | 18 ++++++++++++++++++ include/hw/virtio/virtio.h | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1a7039fb0c..d12edc567f 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -384,7 +384,7 @@ static void virtio_ioport_write(void *opaque, uint32_t = addr, uint32_t val) { VirtIOPCIProxy *proxy =3D opaque; VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - uint16_t vector; + uint16_t vector, vq_idx; hwaddr pa; =20 switch (addr) { @@ -408,8 +408,12 @@ static void virtio_ioport_write(void *opaque, uint32_t= addr, uint32_t val) vdev->queue_sel =3D val; break; case VIRTIO_PCI_QUEUE_NOTIFY: - if (val < VIRTIO_QUEUE_MAX) { - virtio_queue_notify(vdev, val); + vq_idx =3D val; + if (vq_idx < VIRTIO_QUEUE_MAX) { + if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA))= { + virtio_queue_set_shadow_avail_data(vdev, val); + } + virtio_queue_notify(vdev, vq_idx); } break; case VIRTIO_PCI_STATUS: diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d229755eae..bcb9e09df0 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2255,6 +2255,24 @@ void virtio_queue_set_align(VirtIODevice *vdev, int = n, int align) } } =20 +void virtio_queue_set_shadow_avail_data(VirtIODevice *vdev, uint32_t data) +{ + /* Lower 16 bits is the virtqueue index */ + uint16_t i =3D data; + VirtQueue *vq =3D &vdev->vq[i]; + + if (!vq->vring.desc) { + return; + } + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + vq->shadow_avail_wrap_counter =3D (data >> 31) & 0x1; + vq->shadow_avail_idx =3D (data >> 16) & 0x7FFF; + } else { + vq->shadow_avail_idx =3D (data >> 16); + } +} + static void virtio_queue_notify_vq(VirtQueue *vq) { if (vq->vring.desc && vq->handle_output) { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index c8f72850bc..53915947a7 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -335,6 +335,7 @@ void virtio_queue_update_rings(VirtIODevice *vdev, int = n); void virtio_init_region_cache(VirtIODevice *vdev, int n); void virtio_queue_set_align(VirtIODevice *vdev, int n, int align); void virtio_queue_notify(VirtIODevice *vdev, int n); +void virtio_queue_set_shadow_avail_data(VirtIODevice *vdev, uint32_t data); uint16_t virtio_queue_vector(VirtIODevice *vdev, int n); void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector); int virtio_queue_set_host_notifier_mr(VirtIODevice *vdev, int n, --=20 2.39.3