From nobody Thu Sep 19 00:15:25 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720046761; cv=none; d=zohomail.com; s=zohoarc; b=XDUezJB2wbDy26QZkPvljuuiD2BdfrM2/GbXcW6x97b6oz3ndDlS5KI3gBuQXH1wKq9KFptOCupYBbOwegRqXcyQLOWcS6Vp0kDXYflzkqwZUqGmVp81KduJv4TpN943jhyDzs8q+55LEHwdylJK1f/Z7OnvtFIyawLDbnYXIKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720046761; h=Content-Type: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=rU41nJqg3mDUGH1bcBpKF5g1VLC3bOtqyqIezIWqM9s=; b=Vm4jNHonc9+mrfL64ZhS/WugzPx/AzGE5fjN2t6NkNh2hddf52t+l13ko3p7UsqyU4/mCtwZ9lXp8FTvpRaX0uysiyLIcY12NS1LRN98Sm+DV0NLNtIb8ueqV0GUJeJa5r+Bh4Bh7KfQEjRL/3izHmkXsRidgsnSFhT+GaXMPCw= 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 1720046761707263.161101036761; Wed, 3 Jul 2024 15:46:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sP8iR-00022L-Ef; Wed, 03 Jul 2024 18:44:43 -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 1sP8iQ-000222-DN for qemu-devel@nongnu.org; Wed, 03 Jul 2024 18:44:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sP8iL-0000sr-OA for qemu-devel@nongnu.org; Wed, 03 Jul 2024 18:44:42 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-LYi9pBkMO0idL0PD5lrAjQ-1; Wed, 03 Jul 2024 18:44:36 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a72436378bdso1152366b.1 for ; Wed, 03 Jul 2024 15:44:35 -0700 (PDT) Received: from redhat.com ([2a0d:6fc7:441:91a8:a47d:5a9:c02f:92f2]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf1ba77sm545010666b.33.2024.07.03.15.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 15:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720046677; 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=rU41nJqg3mDUGH1bcBpKF5g1VLC3bOtqyqIezIWqM9s=; b=EmR4LJ0inU5W99aJfRYs8dQtmDsT+KteuVWQqDv6AhHj17x7QLv1fqVbPWNGfFaCfiEAhJ wH40cOc/didbvN+X28UhGhI5Nw3Jc1GrI8pyhPi9Wi6CunqCOGvqWKhBiGy1u3j8G7iJ0h XzX6tOrpEQiLY46RYb//njo9CBB/VxE= X-MC-Unique: LYi9pBkMO0idL0PD5lrAjQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720046674; x=1720651474; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rU41nJqg3mDUGH1bcBpKF5g1VLC3bOtqyqIezIWqM9s=; b=SJ9gn//d80V66eTBZyQgSloZCZSr/rVjRJxQoMz/XXdMm6zNY+6xB27tJnPiuvci15 A2VopJBbrodz6sxSNjm3WcPWPvNfDEhKcpu5ywcg3iFExVfkrX9VZZFpJkS+84kU33K/ YcCTgHdXo64HORAKsqNiBfqm2YOI09cjXYxSnue+N00raJPsvlDSfT/gqWBPvIbvNzlI KM06HOVJLNbbf7I6xB5B+9jByHg8gNnpnhszTUsauexB8YExHVAfHhXM2+ZSSJjfw7wp 9ol9OniLV7MwUAlFvSd3ZJ0UEAA5by1OrOPaJuExDEz3KqcJfwr319EVE1hcygm0J7vd jrOA== X-Gm-Message-State: AOJu0YyrrLszi10xLgZ9wTCk4T4afs9kFxBmEeGr3ViuZ4tAdO89iWPq MKJDdEYzfLSbdLAeTlyqg9pIFlxH0BaFfY/UDq9kdv3b0malTZOjqVneLrBgpbM6/q3xhU8Mp2m qkxZGszzL6dkn8BgXLNUYB3H6uXBr/1v1AiVKxPmPlG+sNHCJYB3XNr4iuG284MQdts2TyupFpH ac2N5eDYSDShHXtODRPY0zgC4qmoIeVA== X-Received: by 2002:a17:907:6e9f:b0:a6f:668b:3442 with SMTP id a640c23a62f3a-a75144de9c7mr838167966b.77.1720046674370; Wed, 03 Jul 2024 15:44:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq7GHOZ+FvW4R+yCyNqJUbyJV5EMmQwZDW8qsKuD2pWcSkK8f+BVPQfmJWbCixKkaImfdFMw== X-Received: by 2002:a17:907:6e9f:b0:a6f:668b:3442 with SMTP id a640c23a62f3a-a75144de9c7mr838165966b.77.1720046673380; Wed, 03 Jul 2024 15:44:33 -0700 (PDT) Date: Wed, 3 Jul 2024 18:44:28 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonah Palmer , Eugenio =?utf-8?B?UMOpcmV6?= Subject: [PULL v3 04/85] virtio/virtio-pci: Handle extra notification data Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @redhat.com) X-ZM-MESSAGEID: 1720046762897100001 From: Jonah Palmer 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 Message-Id: <20240315165557.26942-2-jonah.palmer@oracle.com> Reviewed-by: Eugenio P=C3=A9rez Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 2 ++ hw/virtio/virtio-pci.c | 12 +++++++++--- hw/virtio/virtio.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 7d5ffdc145..1451926a13 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -307,6 +307,8 @@ int virtio_queue_ready(VirtQueue *vq); =20 int virtio_queue_empty(VirtQueue *vq); =20 +void virtio_queue_set_shadow_avail_idx(VirtQueue *vq, uint16_t idx); + /* Host binding interface. */ =20 uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr); diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b1d02f4b3d..cffc7efcae 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,14 @@ 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 && virtio_queue_get_num(vdev, vq_idx= )) { + if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA))= { + VirtQueue *vq =3D virtio_get_queue(vdev, vq_idx); + + virtio_queue_set_shadow_avail_idx(vq, val >> 16); + } + virtio_queue_notify(vdev, vq_idx); } break; case VIRTIO_PCI_STATUS: diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 893a072c9d..f7c99e3a96 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2264,6 +2264,24 @@ void virtio_queue_set_align(VirtIODevice *vdev, int = n, int align) } } =20 +void virtio_queue_set_shadow_avail_idx(VirtQueue *vq, uint16_t shadow_avai= l_idx) +{ + if (!vq->vring.desc) { + return; + } + + /* + * 16-bit data for packed VQs include 1-bit wrap counter and + * 15-bit shadow_avail_idx. + */ + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) { + vq->shadow_avail_wrap_counter =3D (shadow_avail_idx >> 15) & 0x1; + vq->shadow_avail_idx =3D shadow_avail_idx & 0x7FFF; + } else { + vq->shadow_avail_idx =3D shadow_avail_idx; + } +} + static void virtio_queue_notify_vq(VirtQueue *vq) { if (vq->vring.desc && vq->handle_output) { --=20 MST