From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611953805; cv=none; d=zohomail.com; s=zohoarc; b=Lfg8IWbGiW2Kc8aq60U8TVJ/YPEBQ1kVvBKG68gdwBSCbujKS3FXGJCxv7SR8Q3B849GUmtyYlYaZhrep+sUdsh7CjpwoVpXXB/nWjI/WS/+Rl5NE6uU9denXpktGziTcN8S1R5z4qw7ygJGDhpxhbqvPzQ7Ht1Tvx6ImphndzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611953805; 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=FYw67uu67UeVGqqO5hsMiaJ7gjP0eH8hnGSHQzqGieE=; b=DEXlT7RDprnC5UTRK8+JTw6jb84vRcrX2wZ7hv/MZYobRfrLWXGdMrO5Qvz2rF+DC4FbjWixasvpvvkEV5OP+LR4Y2nglGGsX2zM7/cJE4fVE37Fhfk8uFsQo1fXFp8HO66XR/sk8iHYNsg7rbzhSzeIZ5+Moom0uQQE2GBSYHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611953805873390.2074098571899; Fri, 29 Jan 2021 12:56:45 -0800 (PST) Received: from localhost ([::1]:33594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5aou-0008B4-OP for importer@patchew.org; Fri, 29 Jan 2021 15:56:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5amv-0006oK-Ai for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:54:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31107) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5ams-0002bq-AH for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:54:41 -0500 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-572-SErmOgIiNSuxpQhYdp-cfA-1; Fri, 29 Jan 2021 15:54:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B8B3107AD24; Fri, 29 Jan 2021 20:54:33 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 029D519C66; Fri, 29 Jan 2021 20:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953676; 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=FYw67uu67UeVGqqO5hsMiaJ7gjP0eH8hnGSHQzqGieE=; b=al31YwSnAAcUDk4w5c0hipwC24+sQNMOJK3e/Np2He2iHPhj9+znsL7y6J3iTxfpKhg54b puS1ZVIw0PoM6OWdJvAW5yPyseLiS4BRiKrYoVnb/CQsvr0B/GS/PTDVc4PHWG1uWqLLOB nXK4uYEvJVbv5mgf1RbPLCKxpAZ1Vxg= X-MC-Unique: SErmOgIiNSuxpQhYdp-cfA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 01/10] virtio: Add virtqueue_set_handler Date: Fri, 29 Jan 2021 21:54:06 +0100 Message-Id: <20210129205415.876290-2-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This allows qemu to override vq handler. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 6 +++--- hw/virtio/virtio.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b7ece7a6a8..9b5479e256 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -47,6 +47,8 @@ size_t virtio_feature_get_config_size(VirtIOFeature *feat= ures, uint64_t host_features); =20 typedef struct VirtQueue VirtQueue; +typedef void (*VirtIOHandleOutput)(VirtIODevice *, VirtQueue *); +typedef bool (*VirtIOHandleAIOOutput)(VirtIODevice *, VirtQueue *); =20 #define VIRTQUEUE_MAX_SIZE 1024 =20 @@ -174,9 +176,6 @@ void virtio_error(VirtIODevice *vdev, const char *fmt, = ...) GCC_FMT_ATTR(2, 3); /* Set the child bus name. */ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name); =20 -typedef void (*VirtIOHandleOutput)(VirtIODevice *, VirtQueue *); -typedef bool (*VirtIOHandleAIOOutput)(VirtIODevice *, VirtQueue *); - VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, VirtIOHandleOutput handle_output); =20 @@ -184,6 +183,7 @@ void virtio_del_queue(VirtIODevice *vdev, int n); =20 void virtio_delete_queue(VirtQueue *vq); =20 +void virtqueue_set_handler(VirtQueue *vq, VirtIOHandleOutput handler); void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len); void virtqueue_flush(VirtQueue *vq, unsigned int count); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b308026596..ebb780fb42 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1796,6 +1796,20 @@ unsigned int virtqueue_drop_all(VirtQueue *vq) } } =20 +/* + * virtqueue_set_handler: + * @vq The #VirtQueue + * @handler The handler to call on vq event + * Replaces vq handler. + * + * Note: It takes no protection, so make sure no other calls to the handler + * are happening. + */ +void virtqueue_set_handler(VirtQueue *vq, VirtIOHandleOutput handler) +{ + vq->handle_output =3D handler; +} + /* 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. --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611953978; cv=none; d=zohomail.com; s=zohoarc; b=GjZUKSj+NWAdHQ/AMZJLEMzP5UySDarUYVjDEaM8iymNzx8giv0AEcY9I/U5k4q9QhePyQEXDieU8//KT2DZ1yYhs450HBzGjZnZJZioWFA4EuBSHhv6//XhK3IvCMqkdCDuKrQqyhV/CWua1uYMjepHw027wDeDHfLuexz6EEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611953978; 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=i9RnuNpZLXz2OkziKFnmRdfAX0eO1bpk6F204EzVNMg=; b=UovD9cFaMtc5qzXuk8fXCS1OjDFmKbyqVG7ML2Jgd/VdMG4EL0ZrdUJMUDTqdFL4lm+4NFD71DTMz/Vu8VISwfzJUNDOcUhsVE+DGk4Qwhun8jkq+agkI6UaJLQqPOgO0/qH3mqiSmFBNhrhrAUZJLeVRo7sIebjEmo/vWssJzk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611953978512791.5496169632511; Fri, 29 Jan 2021 12:59:38 -0800 (PST) Received: from localhost ([::1]:40718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5arh-0002jQ-Dm for importer@patchew.org; Fri, 29 Jan 2021 15:59:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5amw-0006oa-T1 for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:54:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44140) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5amv-0002d7-Ce for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:54:42 -0500 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-145-klTNv_kuO4aNTzmItSu-9A-1; Fri, 29 Jan 2021 15:54:38 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2C74107AD41; Fri, 29 Jan 2021 20:54:36 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82B9819C66; Fri, 29 Jan 2021 20:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953680; 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=i9RnuNpZLXz2OkziKFnmRdfAX0eO1bpk6F204EzVNMg=; b=TH0/qFB3BnRwmMwSymgffo2MzUKmEiYuvrRgwihqFuu5lH8z4g2j9s7bRk92C0iL9s2/2B o96rzVPSFSY3iKLioTZf5u+18i06Ey3NZeKWrs6f52socXDR7+3v5OcjkyNazAU11nru21 HVuvewaGJOJxxbTuBCWVLsQ+PNLzlZU= X-MC-Unique: klTNv_kuO4aNTzmItSu-9A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 02/10] virtio: Add set_vq_handler Date: Fri, 29 Jan 2021 21:54:07 +0100 Message-Id: <20210129205415.876290-3-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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_H3=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) So other subsystem can override vq handler and device can reset it. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 5 +++++ hw/net/virtio-net.c | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 9b5479e256..9988c6d5c9 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -149,6 +149,11 @@ struct VirtioDeviceClass { void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask); int (*start_ioeventfd)(VirtIODevice *vdev); void (*stop_ioeventfd)(VirtIODevice *vdev); + /* + * Set handler for a vq. NULL handler for reset to default. + */ + bool (*set_vq_handler)(VirtIODevice *vdev, unsigned int n, + VirtIOHandleOutput handle_output); /* Saving and loading of a device; trying to deprecate save/load * use vmsd for new devices. */ diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 5150f295e8..f7b2998fb1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2699,6 +2699,31 @@ static void virtio_net_set_multiqueue(VirtIONet *n, = int multiqueue) virtio_net_set_queues(n); } =20 +static bool virtio_net_set_vq_handler(VirtIODevice *vdev, unsigned int i, + VirtIOHandleOutput handle_output) +{ + const VirtIONet *n =3D VIRTIO_NET(vdev); + const unsigned max_queues =3D n->multiqueue ? n->max_queues : 1; + VirtQueue *vq; + + /* Reset control queue also not supported */ + assert(i < max_queues * 2); + + vq =3D virtio_get_queue(vdev, i); + if (handle_output =3D=3D NULL) { + if (i % 2) { + handle_output =3D virtio_net_handle_rx; + } else { + const VirtIONetQueue *q =3D &n->vqs[i / 2]; + handle_output =3D q->tx_timer ? virtio_net_handle_tx_timer + : virtio_net_handle_tx_bh; + } + } + + virtqueue_set_handler(vq, handle_output); + return true; +} + static int virtio_net_post_load_device(void *opaque, int version_id) { VirtIONet *n =3D opaque; @@ -3519,6 +3544,7 @@ static void virtio_net_class_init(ObjectClass *klass,= void *data) vdc->set_status =3D virtio_net_set_status; vdc->guest_notifier_mask =3D virtio_net_guest_notifier_mask; vdc->guest_notifier_pending =3D virtio_net_guest_notifier_pending; + vdc->set_vq_handler =3D virtio_net_set_vq_handler; vdc->legacy_features |=3D (0x1 << VIRTIO_NET_F_GSO); vdc->post_load =3D virtio_net_post_load_virtio; vdc->vmsd =3D &vmstate_virtio_net_device; --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611953836; cv=none; d=zohomail.com; s=zohoarc; b=FDiNHfFIBikhFAH75+YWgEc7wI5CadVZoJH7i3cP7Yq/9aC6Jsamh0M8gPxSkT0RSn0ZhMYvEwrBQfAzOjzs0kY8wYRWjzkrlnVumw7O3klqnZ35rDUC57r3uKZ1nktdlQTjXHD2Di08fPAzcVzm616ziwfHaI+6cGGpcnB1e0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611953836; 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=IWgXo8NhVeasw5ldPGasIT3otf1wmjXkeb7swtbO/Qc=; b=UKwZ8bzQBpzRA6T3g9VL8Gjis1cFwy3o/enGqm19YOS87fiexL3V4QubzZ7OudlS/e2h9VsR6JBm6ZaHrk2tlo7Lm7lz0q52vAklQHPkU0Nn64rowJOUvs0BZ5Vc0euTmTSCEncWP4psFjKN/00w/55gTMIXM90X2cnUJ7uCdg0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611953836068188.98336421089925; Fri, 29 Jan 2021 12:57:16 -0800 (PST) Received: from localhost ([::1]:34410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5apO-0008Ve-W7 for importer@patchew.org; Fri, 29 Jan 2021 15:57:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5an8-00072Y-Hj for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:54:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30917) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5an6-0002gN-TQ for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:54:54 -0500 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-265-sP-UdmAGNiabSUoTurwa9Q-1; Fri, 29 Jan 2021 15:54:50 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 131AA10054FF; Fri, 29 Jan 2021 20:54:49 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55BDA19C66; Fri, 29 Jan 2021 20:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953692; 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=IWgXo8NhVeasw5ldPGasIT3otf1wmjXkeb7swtbO/Qc=; b=FqKuYCUU7UBhLQIrKiphuUnas3KuRwPyIbYeCB+lYjDR9jLvfjzwIyz8Dj7JGl2fgqy0JG eper8CBNX4TXezA3it0uTAVWb/2vs9ZKiWlaBlOjDNrGS+lJg0qHnJaRhWvYUXgk4BCsNO /ihdy8VHngfv6Nuy3uHJNfvkXDpwd0c= X-MC-Unique: sP-UdmAGNiabSUoTurwa9Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 03/10] virtio: Add virtio_queue_get_idx Date: Fri, 29 Jan 2021 21:54:08 +0100 Message-Id: <20210129205415.876290-4-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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_H3=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 2 ++ hw/virtio/virtio.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 9988c6d5c9..9013c03424 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -399,6 +399,8 @@ static inline bool virtio_device_disabled(VirtIODevice = *vdev) return unlikely(vdev->disabled || vdev->broken); } =20 +unsigned virtio_queue_get_idx(const VirtIODevice *vdev, const VirtQueue *v= q); + bool virtio_legacy_allowed(VirtIODevice *vdev); bool virtio_legacy_check_disabled(VirtIODevice *vdev); =20 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ebb780fb42..3d14b0ef74 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -500,6 +500,11 @@ void virtio_queue_set_notification(VirtQueue *vq, int = enable) } } =20 +unsigned virtio_queue_get_idx(const VirtIODevice *vdev, const VirtQueue *v= q) +{ + return vq - vdev->vq; +} + int virtio_queue_ready(VirtQueue *vq) { return vq->vring.avail !=3D 0; --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611954161; cv=none; d=zohomail.com; s=zohoarc; b=KyGTpbAyFP9ntEs4OWIQz8p9jr20WQ4V+bCm63P1bCXeKW5bxPAxAIiZTB4jLft1rwrw80qhInSqZ+jSN53BrjGLnlfxkOuD0RexQS+zIcTpemM/yZgzXSlmLUkPLLDl6MogKnpQlV/cLdfN7UwXaxCq0cyb/gwCwZ52MG4NHp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611954161; 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=Ey7T9qoP7HlQlcZBZf+4P4GF1cv4O02zFvqOSYitM7M=; b=lIKCDAzsXpw2iUoomD529Eecp5RkpXK5zSIeIu0ru9JD+GFPH1qhdfD1mTrifML251wQnmGp29BZWrsVYzsogv0zBhZMjeafz68L4K2kiM1xzAHQ/4Z9atH2QCUgsxaGfVft7FdK0HkiVMYe0X+tx/5U36ESK+DtzXGdigHVCOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 161195416113532.40359585965052; Fri, 29 Jan 2021 13:02:41 -0800 (PST) Received: from localhost ([::1]:46496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5aud-0005Gp-NQ for importer@patchew.org; Fri, 29 Jan 2021 16:02:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anJ-0007A5-Kz for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28275) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5anD-0002ie-58 for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:05 -0500 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-393-15uPTmklMLWjpcoDRR4v9Q-1; Fri, 29 Jan 2021 15:54:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB67D8144EC; Fri, 29 Jan 2021 20:54:52 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 722B719C66; Fri, 29 Jan 2021 20:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953698; 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=Ey7T9qoP7HlQlcZBZf+4P4GF1cv4O02zFvqOSYitM7M=; b=cixdTUCVDYdQsNLC3mwpuHTYzHLwTK+dwvpVxku8+Y1g/XkG/UQu8xcOn9+cGFYJJsZG9M yIys/z0ayovsJ01nu5v4VSVqI8Zk3Dt2L+1wRM3s+IjbrhM5PVOG2o4GUzpBwrfJEClTep l9Sxjln2sdIy1CGWn1mtp4eTSK+MQ9Q= X-MC-Unique: 15uPTmklMLWjpcoDRR4v9Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 04/10] virtio: Add virtio_queue_host_notifier_status Date: Fri, 29 Jan 2021 21:54:09 +0100 Message-Id: <20210129205415.876290-5-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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_H3=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 1 + hw/virtio/virtio.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 9013c03424..c5fcd9b169 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -321,6 +321,7 @@ void virtio_device_release_ioeventfd(VirtIODevice *vdev= ); bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev); EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled); +bool virtio_queue_host_notifier_status(const VirtQueue *vq); void virtio_queue_host_notifier_read(EventNotifier *n); void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, VirtIOHandleAIOOutput hand= le_output); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3d14b0ef74..fdf37d8e48 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3613,6 +3613,11 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQu= eue *vq) return &vq->host_notifier; } =20 +bool virtio_queue_host_notifier_status(const VirtQueue *vq) +{ + return vq->host_notifier_enabled; +} + void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled) { vq->host_notifier_enabled =3D enabled; --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611953980; cv=none; d=zohomail.com; s=zohoarc; b=LmQq1aH5Cgx9uc4JgcRIl6pNa5nmlr5OSQgYFF1gx7kE3r4KyBjuvt4/E/NLPEqWrPdUvjvnryjrf+mgfVmn6elkrX2DmeJKprMkEecRxLxtReDCoXdimGfIrubnfw2LCYNuN6dKhFwIm0HmRCw/73H6CJ4qDC1O+m2LTjaxYk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611953980; 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=BeNbSiH/MHVx9FqrvgesPLa7GE7RAy1abAUIrVRnGa4=; b=Sm7B4asifOYUJ1ZeQi0CHuWnJD4twaO5vcc5hkuIV8FJunvtq558VwIJr/nN93NoNwDbBLPwPQM/qE0CXpA3v8fsO28xdqaqQiKEcV5w3SGt9wDaL328TyAIkhkqukSXDUD++YRUQblyoFUdGDFxmBBwqg2Wq7/4psmg3A4x218= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611953980390229.72127054337398; Fri, 29 Jan 2021 12:59:40 -0800 (PST) Received: from localhost ([::1]:40824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5arj-0002m0-9P for importer@patchew.org; Fri, 29 Jan 2021 15:59:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anN-0007B3-BK for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5anE-0002jb-RO for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:09 -0500 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-278-zBUJaK8hO0ChJDjOXxtmdA-1; Fri, 29 Jan 2021 15:54:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD7BC18C89C4; Fri, 29 Jan 2021 20:54:56 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DA6919D7C; Fri, 29 Jan 2021 20:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953699; 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=BeNbSiH/MHVx9FqrvgesPLa7GE7RAy1abAUIrVRnGa4=; b=TcH+N9c1xKjKkJ1fKrvuGdrC44WnR6cVbvxPdvITzS9q/2nOcnevFqr1kGrJrKOeyvRFbF JfmDNWfaydGL6xPnr/7u3ORk0sEqCRWDvECCmcweabBhYRp2pUSYqlHjmztqqWxq202mDX UlA26R9JyhH8ODVnhci68w9NrEldbb8= X-MC-Unique: zBUJaK8hO0ChJDjOXxtmdA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 05/10] vhost: Add vhost_dev_from_virtio Date: Fri, 29 Jan 2021 21:54:10 +0100 Message-Id: <20210129205415.876290-6-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost.h | 1 + hw/virtio/vhost.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4a8bc75415..fca076e3f0 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -123,6 +123,7 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, con= st int *feature_bits, void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features); bool vhost_has_free_slot(void); +struct vhost_dev *vhost_dev_from_virtio(const VirtIODevice *vdev); =20 int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 28c7d78172..8683d507f5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -61,6 +61,23 @@ bool vhost_has_free_slot(void) return slots_limit > used_memslots; } =20 +/* + * Get the vhost device associated to a VirtIO device. + */ +struct vhost_dev *vhost_dev_from_virtio(const VirtIODevice *vdev) +{ + struct vhost_dev *hdev; + + QLIST_FOREACH(hdev, &vhost_devices, entry) { + if (hdev->vdev =3D=3D vdev) { + return hdev; + } + } + + assert(hdev); + return NULL; +} + static void vhost_dev_sync_region(struct vhost_dev *dev, MemoryRegionSection *section, uint64_t mfirst, uint64_t mlast, --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611954259; cv=none; d=zohomail.com; s=zohoarc; b=kE8NUOkrqUAgXwnzfugpGfNSVvi3L62MXmGuMR7lY/0Sx0P7p993LD0QzLQxZsFpx1sRIxS0lcRAZZVogqZ5oZHUY6/ho8m853FGXBi3XdT3lLWCeaq03tAO2iZx+RIDhINv/1GP0rwm+AwYSP4gblC8m+y8kziYi7f+cnZywnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611954259; 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=00gwvgJA+llGIBdQd+EvPx5t+eKR6oOvAkUuCnrmRTE=; b=EszveguaFiUdn/AKKOKT6MskkUuZ0stSHVmaLIFO6h+8NJu9vnZ3EsgKZiAHVAHLWezAYoXC14jGyWirWao+rH6lfEjO1Q6FVb5UaXYU7jffH4vkzccj6FvSUO7X1UcG0MeWj5FkOpsg3jRnPj2odIepa/Yo0Aa6jilKZ8d3HYs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611954259149572.2588859655265; Fri, 29 Jan 2021 13:04:19 -0800 (PST) Received: from localhost ([::1]:50694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5awD-0007Cy-U5 for importer@patchew.org; Fri, 29 Jan 2021 16:04:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anT-0007FY-BJ for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41121) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5anQ-0002lx-8H for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:14 -0500 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-538-ebyRKZAHPni11PBgrSXjtg-1; Fri, 29 Jan 2021 15:55:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C9EF8144E3; Fri, 29 Jan 2021 20:55:06 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EC3319C66; Fri, 29 Jan 2021 20:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953711; 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=00gwvgJA+llGIBdQd+EvPx5t+eKR6oOvAkUuCnrmRTE=; b=Be8MRw1U0BNV9t/QsyIcUTyxyCtH4jhc8yaoQZEZwRALttRkARQh4cWlj048KDWqyPrCbD M57yiWvf+eCx3Y7VMk9VgpxYbPt7oFxQMSZjDVLJQ4YkmhXYc4iJtgf3QCF6zMcXVi01ys c/PfPS6WPSvEO8yT+VC1gySbLPNo+0Y= X-MC-Unique: ebyRKZAHPni11PBgrSXjtg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 06/10] vhost: Save masked_notifier state Date: Fri, 29 Jan 2021 21:54:11 +0100 Message-Id: <20210129205415.876290-7-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) It will be used to recover call eventfd. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost.h | 1 + hw/virtio/vhost.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index fca076e3f0..2be782cefd 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -28,6 +28,7 @@ struct vhost_virtqueue { unsigned avail_size; unsigned long long used_phys; unsigned used_size; + bool notifier_is_masked; EventNotifier masked_notifier; struct vhost_dev *dev; }; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 8683d507f5..040f68ff2e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1526,6 +1526,8 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, Vir= tIODevice *vdev, int n, /* should only be called after backend is connected */ assert(hdev->vhost_ops); =20 + hdev->vqs[index].notifier_is_masked =3D mask; + if (mask) { assert(vdev->use_guest_notifier_mask); file.fd =3D event_notifier_get_fd(&hdev->vqs[index].masked_notifie= r); --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611953990; cv=none; d=zohomail.com; s=zohoarc; b=nl4Aj6s69JBNCRHsxPVUk5v8kEmWEKb85XjTVAdoA2gnMO1xhCETdZRRgz9DPhnqXbrDjNL5OxDwi2rBJZ5y+Ut3biGX2JguWtfcqH4ZelIZNCctjssaQMg0c2e/CUEggmeLa0SCBGzPqa95SPnk8HExNn1KoakNuT5ZbKdMX1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611953990; 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=Oniwa/aRK4MFbG4ov7pO713lIswUhGp9/PJOl9xck9g=; b=MPoa2rFHy3ATU1bqFJcNv/gCyUjd3zALAkhobzFcma5sTo2KV22Y4mznhfq9KkeRK1f4IjDE7D6e7VbGRVTVggu2jRxRPhdnVr0l0FEjcQJmrEnvo+uN18LGNDbaj75qXczRFaHmRK4T0iRtOyG0AvaVegAU0zb1OQErkNLKCDI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 161195399040850.02066794079656; Fri, 29 Jan 2021 12:59:50 -0800 (PST) Received: from localhost ([::1]:41654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5art-00036i-CH for importer@patchew.org; Fri, 29 Jan 2021 15:59:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anT-0007Fj-ML for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56325) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5anR-0002me-Ns for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:15 -0500 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-312-Axb5-rR9NKWNk08wG04ddA-1; Fri, 29 Jan 2021 15:55:11 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCE7A8144E3; Fri, 29 Jan 2021 20:55:09 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 625D919C66; Fri, 29 Jan 2021 20:55:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953713; 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=Oniwa/aRK4MFbG4ov7pO713lIswUhGp9/PJOl9xck9g=; b=jAUu58brpYWf7MHcGXmkJw2r/NQob9yOFD1MGxYp/3kZm65Js0paPiRiV48SYy2FKVfEhM zM4G2R+1IiZQp9+qkMP9kPvmU6AbkJDOGdUTVGQAbyvgOHXdElh/3I4K1o41o73X+CMNin Am6v1khFnRvnwYZkISnE8b+eUeqhl9I= X-MC-Unique: Axb5-rR9NKWNk08wG04ddA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 07/10] vhost: Add VhostShadowVirtqueue Date: Fri, 29 Jan 2021 21:54:12 +0100 Message-Id: <20210129205415.876290-8-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Vhost shadow virtqueue is an intermediate jump for virtqueue notifications and buffers, allowing qemu to track them. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 24 ++++++++++++ hw/virtio/vhost-shadow-virtqueue.c | 60 ++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/vhost-shadow-virtqueue.h create mode 100644 hw/virtio/vhost-shadow-virtqueue.c diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h new file mode 100644 index 0000000000..6cc18d6acb --- /dev/null +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -0,0 +1,24 @@ +/* + * vhost software live migration ring + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 + * SPDX-FileContributor: Author: Eugenio P=C3=A9rez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef VHOST_SHADOW_VIRTQUEUE_H +#define VHOST_SHADOW_VIRTQUEUE_H + +#include "qemu/osdep.h" + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" + +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + +VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx); + +void vhost_shadow_vq_free(VhostShadowVirtqueue *vq); + +#endif diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c new file mode 100644 index 0000000000..c0c967a7c5 --- /dev/null +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -0,0 +1,60 @@ +/* + * vhost software live migration ring + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 + * SPDX-FileContributor: Author: Eugenio P=C3=A9rez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "hw/virtio/vhost-shadow-virtqueue.h" + +#include "qemu/error-report.h" +#include "qemu/event_notifier.h" + +typedef struct VhostShadowVirtqueue { + EventNotifier kick_notifier; + EventNotifier call_notifier; +} VhostShadowVirtqueue; + +/* + * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow + * methods and file descriptors. + */ +VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx) +{ + g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); + int r; + + r =3D event_notifier_init(&svq->kick_notifier, 0); + if (r !=3D 0) { + error_report("Couldn't create kick event notifier: %s", + strerror(errno)); + goto err_init_kick_notifier; + } + + r =3D event_notifier_init(&svq->call_notifier, 0); + if (r !=3D 0) { + error_report("Couldn't create call event notifier: %s", + strerror(errno)); + goto err_init_call_notifier; + } + + return svq; + +err_init_call_notifier: + event_notifier_cleanup(&svq->kick_notifier); + +err_init_kick_notifier: + return NULL; +} + +/* + * Free the resources of the shadow virtqueue. + */ +void vhost_shadow_vq_free(VhostShadowVirtqueue *vq) +{ + event_notifier_cleanup(&vq->kick_notifier); + event_notifier_cleanup(&vq->call_notifier); + g_free(vq); +} diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index fbff9bc9d4..8b5a0225fe 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-= stub.c')) =20 virtio_ss =3D ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backe= nd.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backe= nd.c', 'vhost-shadow-virtqueue.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloo= n.c')) --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611954366; cv=none; d=zohomail.com; s=zohoarc; b=JKFMwdAC+NGcvMI72rDaANX3K8olYG7HXzWH/OAlaMUBiCPzt0JHi61EU5uoYP1z5TGl9xfAxdmp31wcJiCStvevVr1VeqEF7/FTeN4DRC0GoszjDUl5YjjOoAU8PTVfcv/RVIjLgDTetarfYO4O8Wjkfz0dSD6LLbTkKD/Q7RA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611954366; 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=2wpSdDkjyWAlZskTjDdmXKJZjLeOlOlAuRgxfbF3Zhs=; b=Xx7qUSFSQAbliE8OSe2PVAEY9rINhkqWHdQDfLRyi54kb/W5u3agNcG32OkZ/FzkFezIN4nCIZ4dd1TxWYMPvaoCo7sggbwcefxzLoaYCzU2BgEJrwotN9y+MNk46BNRASckeLsfomwgSy8G/Q7NKh6hClH4coGlcd+WjieS0BE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611954366411779.5539758607016; Fri, 29 Jan 2021 13:06:06 -0800 (PST) Received: from localhost ([::1]:52796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5axw-0008BT-L2 for importer@patchew.org; Fri, 29 Jan 2021 16:06:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anc-0007J5-Sq for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5anW-0002o2-AU for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:24 -0500 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-253-VnsqSw8oNt2azPYvvXFcvw-1; Fri, 29 Jan 2021 15:55:15 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97C80107ACE3; Fri, 29 Jan 2021 20:55:13 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FB0C272CF; Fri, 29 Jan 2021 20:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953717; 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=2wpSdDkjyWAlZskTjDdmXKJZjLeOlOlAuRgxfbF3Zhs=; b=Bk/PYGzePuUf8LW68tafCIQA4uh8CWpD5+flWVI3Ii6yIpgJtQQoH6g/Io60T7jQrpJFZf 9rvmg3jYhZyS5VeRvC+UiC+FtZFFYItsph0Wjuln6zsxyVdqWA+/9IQT9JfiO3J5Ncios3 tBFo9mAuK6bvlNSb7t43l9pO2SYqFuk= X-MC-Unique: VnsqSw8oNt2azPYvvXFcvw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 08/10] vhost: Add x-vhost-enable-shadow-vq qmp Date: Fri, 29 Jan 2021 21:54:13 +0100 Message-Id: <20210129205415.876290-9-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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_H3=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Command to enable shadow virtqueue looks like: { "execute": "x-vhost-enable-shadow-vq", "arguments": { "name": "dev0", "en= able": true } } Signed-off-by: Eugenio P=C3=A9rez --- qapi/net.json | 23 +++++++++++++++++++++++ hw/virtio/vhost.c | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/qapi/net.json b/qapi/net.json index c31748c87f..6170d69798 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -77,6 +77,29 @@ ## { 'command': 'netdev_del', 'data': {'id': 'str'} } =20 +## +# @x-vhost-enable-shadow-vq: +# +# Use vhost shadow virtqueue. +# +# @name: the device name of the virtual network adapter +# +# @enable: true to use he alternate shadow VQ notification path +# +# Returns: Error if failure, or 'no error' for success +# +# Since: 5.3 +# +# Example: +# +# -> { "execute": "x-vhost_enable_shadow_vq", "arguments": {"enable": true= } } +# <- { "return": { "enabled" : true } } +# +## +{ 'command': 'x-vhost-enable-shadow-vq', + 'data': {'name': 'str', 'enable': 'bool'}, + 'if': 'defined(CONFIG_VHOST_KERNEL)' } + ## # @NetLegacyNicOptions: # diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 040f68ff2e..42836e45f3 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -15,6 +15,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qapi-commands-net.h" #include "hw/virtio/vhost.h" #include "qemu/atomic.h" #include "qemu/range.h" @@ -1841,3 +1842,8 @@ int vhost_net_set_backend(struct vhost_dev *hdev, =20 return -1; } + +void qmp_x_vhost_enable_shadow_vq(const char *name, bool enable, Error **e= rrp) +{ + error_setg(errp, "Shadow virtqueue still not implemented."); +} --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611954429; cv=none; d=zohomail.com; s=zohoarc; b=nwiRH0IRFkgdEI1P7pvDD5RNUy/QhWMzzYn/5dkuQ438kexEkobnMJo4k9BBgWM49Qssy0nz1W50jMjoeL7KMnUlraRVPObAbPduEKCihmsGRo3RmYmaYk52DNxALMr7Jz7qlynSKDkL0VABn1xIRcInv7RGi6nX6vLUQYZWDug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611954429; 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=0cPGpoRxd4fEYQvZIXJavl9w+cFdWJK9vsZiBYUG+JA=; b=G2XgiGlwYFBE0/VyZIHZqJsetjrrgc013MgSgNu2D9bSSoDQ3567kZS99q7neUWJprYyOqgGW0vwsh94v+LEISZDcObQa+vqqPXtYG6f+OcS6QLX5vfZ+IlVX11KqYeKjgbKUY6QWFQINABgYGPVL90i7eLTUusdOnz3Jbnh+tc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611954429483316.03273611909265; Fri, 29 Jan 2021 13:07:09 -0800 (PST) Received: from localhost ([::1]:54988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5ayy-0000uQ-EI for importer@patchew.org; Fri, 29 Jan 2021 16:07:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anh-0007Jk-VC for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28329) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5anc-0002pv-GQ for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:29 -0500 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-460-8peUIH-gOe29QMAyRyCXnA-1; Fri, 29 Jan 2021 15:55:21 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C2EE10054FF; Fri, 29 Jan 2021 20:55:17 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF2E619C66; Fri, 29 Jan 2021 20:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953722; 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=0cPGpoRxd4fEYQvZIXJavl9w+cFdWJK9vsZiBYUG+JA=; b=S+pE2Pghb8BZpNmZrx0dZqYXB3zCHfx0PP+xSxSHkaJ5I+4dIryAprB5CWNvpid/X+213x t8zvAOs/kFlHSWbonXqRw8mcaVkL2ojKXCBisIgS8tPeN9BJl06g8Sj2kx3YVsrvxjezsN /LbeepS79zWrGEphETl1CXXza+bRj/Q= X-MC-Unique: 8peUIH-gOe29QMAyRyCXnA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 09/10] vhost: Route guest->host notification through shadow virtqueue Date: Fri, 29 Jan 2021 21:54:14 +0100 Message-Id: <20210129205415.876290-10-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Shadow virtqueue notifications forwarding is disabled when vhost_dev stops. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 5 ++ include/hw/virtio/vhost.h | 4 + hw/virtio/vhost-shadow-virtqueue.c | 123 +++++++++++++++++++++++++- hw/virtio/vhost.c | 135 ++++++++++++++++++++++++++++- 4 files changed, 264 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 6cc18d6acb..466f8ae595 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,11 @@ =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 +bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, + VhostShadowVirtqueue *svq); +void vhost_shadow_vq_stop_rcu(struct vhost_dev *dev, + VhostShadowVirtqueue *svq); + VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx); =20 void vhost_shadow_vq_free(VhostShadowVirtqueue *vq); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 2be782cefd..732a4b2a2b 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -55,6 +55,8 @@ struct vhost_iommu { QLIST_ENTRY(vhost_iommu) iommu_next; }; =20 +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + typedef struct VhostDevConfigOps { /* Vhost device config space changed callback */ @@ -83,7 +85,9 @@ struct vhost_dev { uint64_t backend_cap; bool started; bool log_enabled; + bool sw_lm_enabled; uint64_t log_size; + VhostShadowVirtqueue **shadow_vqs; Error *migration_blocker; const VhostOps *vhost_ops; void *opaque; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index c0c967a7c5..908c36c66d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -8,15 +8,129 @@ */ =20 #include "hw/virtio/vhost-shadow-virtqueue.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/virtio-access.h" + +#include "standard-headers/linux/vhost_types.h" +#include "standard-headers/linux/virtio_ring.h" =20 #include "qemu/error-report.h" -#include "qemu/event_notifier.h" +#include "qemu/main-loop.h" =20 typedef struct VhostShadowVirtqueue { EventNotifier kick_notifier; EventNotifier call_notifier; + const struct vhost_virtqueue *hvq; + VirtIODevice *vdev; + VirtQueue *vq; } VhostShadowVirtqueue; =20 +static uint16_t vhost_shadow_vring_used_flags(VhostShadowVirtqueue *svq) +{ + const struct vring_used *used =3D svq->hvq->used; + return virtio_tswap16(svq->vdev, used->flags); +} + +static bool vhost_shadow_vring_should_kick(VhostShadowVirtqueue *vq) +{ + return !(vhost_shadow_vring_used_flags(vq) & VRING_USED_F_NO_NOTIFY); +} + +static void vhost_shadow_vring_kick(VhostShadowVirtqueue *vq) +{ + if (vhost_shadow_vring_should_kick(vq)) { + event_notifier_set(&vq->kick_notifier); + } +} + +static void handle_shadow_vq(VirtIODevice *vdev, VirtQueue *vq) +{ + struct vhost_dev *hdev =3D vhost_dev_from_virtio(vdev); + uint16_t idx =3D virtio_get_queue_index(vq); + + VhostShadowVirtqueue *svq =3D hdev->shadow_vqs[idx]; + + vhost_shadow_vring_kick(svq); +} + +/* + * Start shadow virtqueue operation. + * @dev vhost device + * @svq Shadow Virtqueue + * + * Run in RCU context + */ +bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, + VhostShadowVirtqueue *svq) +{ + const VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(dev->vdev); + EventNotifier *vq_host_notifier =3D virtio_queue_get_host_notifier(svq= ->vq); + unsigned idx =3D virtio_queue_get_idx(svq->vdev, svq->vq); + struct vhost_vring_file kick_file =3D { + .index =3D idx, + .fd =3D event_notifier_get_fd(&svq->kick_notifier), + }; + int r; + bool ok; + + /* Check that notifications are still going directly to vhost dev */ + assert(virtio_queue_host_notifier_status(svq->vq)); + + ok =3D k->set_vq_handler(dev->vdev, idx, handle_shadow_vq); + if (!ok) { + error_report("Couldn't set the vq handler"); + goto err_set_kick_handler; + } + + r =3D dev->vhost_ops->vhost_set_vring_kick(dev, &kick_file); + if (r !=3D 0) { + error_report("Couldn't set kick fd: %s", strerror(errno)); + goto err_set_vring_kick; + } + + event_notifier_set_handler(vq_host_notifier, + virtio_queue_host_notifier_read); + virtio_queue_set_host_notifier_enabled(svq->vq, false); + virtio_queue_host_notifier_read(vq_host_notifier); + + return true; + +err_set_vring_kick: + k->set_vq_handler(dev->vdev, idx, NULL); + +err_set_kick_handler: + return false; +} + +/* + * Stop shadow virtqueue operation. + * @dev vhost device + * @svq Shadow Virtqueue + * + * Run in RCU context + */ +void vhost_shadow_vq_stop_rcu(struct vhost_dev *dev, + VhostShadowVirtqueue *svq) +{ + const VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(svq->vdev); + unsigned idx =3D virtio_queue_get_idx(svq->vdev, svq->vq); + EventNotifier *vq_host_notifier =3D virtio_queue_get_host_notifier(svq= ->vq); + struct vhost_vring_file kick_file =3D { + .index =3D idx, + .fd =3D event_notifier_get_fd(vq_host_notifier), + }; + int r; + + /* Restore vhost kick */ + r =3D dev->vhost_ops->vhost_set_vring_kick(dev, &kick_file); + /* Cannot do a lot of things */ + assert(r =3D=3D 0); + + event_notifier_set_handler(vq_host_notifier, NULL); + virtio_queue_set_host_notifier_enabled(svq->vq, true); + k->set_vq_handler(svq->vdev, idx, NULL); +} + /* * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow * methods and file descriptors. @@ -24,8 +138,13 @@ typedef struct VhostShadowVirtqueue { VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx) { g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); + int vq_idx =3D dev->vhost_ops->vhost_get_vq_index(dev, dev->vq_index += idx); int r; =20 + svq->vq =3D virtio_get_queue(dev->vdev, vq_idx); + svq->hvq =3D &dev->vqs[idx]; + svq->vdev =3D dev->vdev; + r =3D event_notifier_init(&svq->kick_notifier, 0); if (r !=3D 0) { error_report("Couldn't create kick event notifier: %s", @@ -40,7 +159,7 @@ VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_d= ev *dev, int idx) goto err_init_call_notifier; } =20 - return svq; + return g_steal_pointer(&svq); =20 err_init_call_notifier: event_notifier_cleanup(&svq->kick_notifier); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 42836e45f3..bde688f278 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -25,6 +25,7 @@ #include "exec/address-spaces.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" #include "migration/blocker.h" #include "migration/qemu-file-types.h" #include "sysemu/dma.h" @@ -945,6 +946,82 @@ static void vhost_log_global_stop(MemoryListener *list= ener) } } =20 +static int vhost_sw_live_migration_stop(struct vhost_dev *dev) +{ + int idx; + + WITH_RCU_READ_LOCK_GUARD() { + dev->sw_lm_enabled =3D false; + + for (idx =3D 0; idx < dev->nvqs; ++idx) { + vhost_shadow_vq_stop_rcu(dev, dev->shadow_vqs[idx]); + } + } + + for (idx =3D 0; idx < dev->nvqs; ++idx) { + vhost_shadow_vq_free(dev->shadow_vqs[idx]); + } + + g_free(dev->shadow_vqs); + dev->shadow_vqs =3D NULL; + return 0; +} + +static int vhost_sw_live_migration_start(struct vhost_dev *dev) +{ + int idx; + + dev->shadow_vqs =3D g_new0(VhostShadowVirtqueue *, dev->nvqs); + for (idx =3D 0; idx < dev->nvqs; ++idx) { + dev->shadow_vqs[idx] =3D vhost_shadow_vq_new(dev, idx); + if (unlikely(dev->shadow_vqs[idx] =3D=3D NULL)) { + goto err; + } + } + + WITH_RCU_READ_LOCK_GUARD() { + for (idx =3D 0; idx < dev->nvqs; ++idx) { + int stop_idx =3D idx; + bool ok =3D vhost_shadow_vq_start_rcu(dev, + dev->shadow_vqs[idx]); + + if (!ok) { + while (--stop_idx >=3D 0) { + vhost_shadow_vq_stop_rcu(dev, dev->shadow_vqs[stop_idx= ]); + } + + goto err; + } + } + } + + dev->sw_lm_enabled =3D true; + return 0; + +err: + for (; idx >=3D 0; --idx) { + vhost_shadow_vq_free(dev->shadow_vqs[idx]); + } + g_free(dev->shadow_vqs[idx]); + + return -1; +} + +static int vhost_sw_live_migration_enable(struct vhost_dev *dev, + bool enable_lm) +{ + int r; + + if (enable_lm =3D=3D dev->sw_lm_enabled) { + return 0; + } + + r =3D enable_lm ? vhost_sw_live_migration_start(dev) + : vhost_sw_live_migration_stop(dev); + + return r; +} + static void vhost_log_start(MemoryListener *listener, MemoryRegionSection *section, int old, int new) @@ -1389,6 +1466,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, hdev->log =3D NULL; hdev->log_size =3D 0; hdev->log_enabled =3D false; + hdev->sw_lm_enabled =3D false; hdev->started =3D false; memory_listener_register(&hdev->memory_listener, &address_space_memory= ); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); @@ -1816,6 +1894,11 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODe= vice *vdev) hdev->vhost_ops->vhost_dev_start(hdev, false); } for (i =3D 0; i < hdev->nvqs; ++i) { + if (hdev->sw_lm_enabled) { + vhost_shadow_vq_stop_rcu(hdev, hdev->shadow_vqs[i]); + vhost_shadow_vq_free(hdev->shadow_vqs[i]); + } + vhost_virtqueue_stop(hdev, vdev, hdev->vqs + i, @@ -1829,6 +1912,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODev= ice *vdev) memory_listener_unregister(&hdev->iommu_listener); } vhost_log_put(hdev, true); + g_free(hdev->shadow_vqs); + hdev->sw_lm_enabled =3D false; hdev->started =3D false; hdev->vdev =3D NULL; } @@ -1845,5 +1930,53 @@ int vhost_net_set_backend(struct vhost_dev *hdev, =20 void qmp_x_vhost_enable_shadow_vq(const char *name, bool enable, Error **e= rrp) { - error_setg(errp, "Shadow virtqueue still not implemented."); + struct vhost_dev *hdev; + const char *err_cause =3D NULL; + const VirtioDeviceClass *k; + int r; + ErrorClass err_class =3D ERROR_CLASS_GENERIC_ERROR; + + QLIST_FOREACH(hdev, &vhost_devices, entry) { + if (hdev->vdev && 0 =3D=3D strcmp(hdev->vdev->name, name)) { + break; + } + } + + if (!hdev) { + err_class =3D ERROR_CLASS_DEVICE_NOT_FOUND; + err_cause =3D "Device not found"; + goto err; + } + + if (!hdev->started) { + err_cause =3D "Device is not started"; + goto err; + } + + if (hdev->acked_features & BIT_ULL(VIRTIO_F_RING_PACKED)) { + err_cause =3D "Use packed vq"; + goto err; + } + + if (vhost_dev_has_iommu(hdev)) { + err_cause =3D "Device use IOMMU"; + goto err; + } + + k =3D VIRTIO_DEVICE_GET_CLASS(hdev->vdev); + if (!k->set_vq_handler) { + err_cause =3D "Virtio device type does not support reset of vq han= dler"; + goto err; + } + + r =3D vhost_sw_live_migration_enable(hdev, enable); + if (unlikely(r)) { + err_cause =3D "Error enabling (see monitor)"; + } + +err: + if (err_cause) { + error_set(errp, err_class, + "Can't enable shadow vq on %s: %s", name, err_cause); + } } --=20 2.27.0 From nobody Fri Apr 19 06:30:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611954162; cv=none; d=zohomail.com; s=zohoarc; b=VDqa4Cpkesh79QUbKQicY6Fcd4jqTtjdkGpjuvK8rp/ApMq9Fj+HkUKHrw6fgEOjNvA/sNPiDhcUVfZqyMVNOrH9rRvRlEE25cyrdtvfsfToZCA+C3z8Fh//Lmwk/HJQPvTe+mtj4CJaML75iJQrWUsQP0MiOhO+VVsrIzsAmzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611954162; 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=nWKp68k969gGamZ/PvVgse5se5gbwruEO4TlMnH0TDE=; b=cPBGXp3pVWxFSDi741po5kAQoQoso0oLyFVCRliSPPgXRhEDzy6x3S3tmGVIQDJggNRpGeK0CZckWzsB9hSH4DronTGQ9YDneUqABZIeBNr8SlIj5QTI9V6rFzIyXyOeHBJ4zuTSvdiGMzopF0gFCyLBE1t8Y/g+Q3Dc9EoJmcI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1611954162017529.3426120725717; Fri, 29 Jan 2021 13:02:42 -0800 (PST) Received: from localhost ([::1]:46612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5aue-0005KX-TU for importer@patchew.org; Fri, 29 Jan 2021 16:02:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5anl-0007KO-Rt for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l5ani-0002rJ-O3 for qemu-devel@nongnu.org; Fri, 29 Jan 2021 15:55:33 -0500 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-421-2OdFKLUaOp-e8IZlx4vaWg-1; Fri, 29 Jan 2021 15:55:28 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8FEB8144E1; Fri, 29 Jan 2021 20:55:26 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id C34E419C66; Fri, 29 Jan 2021 20:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611953729; 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=nWKp68k969gGamZ/PvVgse5se5gbwruEO4TlMnH0TDE=; b=h1blpuMTXGlRFNLkgn/yCHOinsUm9LeM4BhXXhb5i9UERIZny7cqb7P40Osv6uu80mkGSo BdXoi07wJQ9WzM8dLuBSpBpnR++7ykEcr3HNF7Pn7XGLGe4PeGI/M2+/Q+i8s05dcfBeEH eL/zuFc1O5snz1w38dZt0UQZSi8Zb/Y= X-MC-Unique: 2OdFKLUaOp-e8IZlx4vaWg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC 10/10] vhost: Route host->guest notification through shadow virtqueue Date: Fri, 29 Jan 2021 21:54:15 +0100 Message-Id: <20210129205415.876290-11-eperezma@redhat.com> In-Reply-To: <20210129205415.876290-1-eperezma@redhat.com> References: <20210129205415.876290-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.249, 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_H3=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Parav Pandit , "Michael S. Tsirkin" , Jason Wang , Juan Quintela , Markus Armbruster , virtualization@lists.linux-foundation.org, Harpreet Singh Anand , Xiao W Wang , Stefan Hajnoczi , Eli Cohen , Stefano Garzarella , Michael Lilja , Jim Harford , Rob Miller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 55 ++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 5 ++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 466f8ae595..99a4e011fd 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,8 @@ =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 +EventNotifier *vhost_shadow_vq_get_call_notifier(VhostShadowVirtqueue *vq); + bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, VhostShadowVirtqueue *svq); void vhost_shadow_vq_stop_rcu(struct vhost_dev *dev, diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 908c36c66d..e2e0bfe325 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -53,6 +53,34 @@ static void handle_shadow_vq(VirtIODevice *vdev, VirtQue= ue *vq) vhost_shadow_vring_kick(svq); } =20 +static void vhost_handle_call(EventNotifier *n) +{ + VhostShadowVirtqueue *svq =3D container_of(n, VhostShadowVirtqueue, + call_notifier); + + if (event_notifier_test_and_clear(n)) { + unsigned idx =3D virtio_queue_get_idx(svq->vdev, svq->vq); + + /* + * Since QEMU has not add any descriptors, virtqueue code thinks i= ts + * not needed to signal used. QEMU shadow virtqueue will take + * descriptor forwarding soon, so just invalidate used cache for n= ow. + */ + virtio_queue_invalidate_signalled_used(svq->vdev, idx); + virtio_notify_irqfd(svq->vdev, svq->vq); + } +} + +/* + * Get the vhost call notifier of the shadow vq + * @vq Shadow virtqueue + */ +EventNotifier *vhost_shadow_vq_get_call_notifier(VhostShadowVirtqueue *vq) +{ + return &vq->call_notifier; +} + + /* * Start shadow virtqueue operation. * @dev vhost device @@ -70,6 +98,10 @@ bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, .index =3D idx, .fd =3D event_notifier_get_fd(&svq->kick_notifier), }; + struct vhost_vring_file call_file =3D { + .index =3D idx, + .fd =3D event_notifier_get_fd(&svq->call_notifier), + }; int r; bool ok; =20 @@ -88,6 +120,12 @@ bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, goto err_set_vring_kick; } =20 + r =3D dev->vhost_ops->vhost_set_vring_call(dev, &call_file); + if (r !=3D 0) { + error_report("Couldn't set call fd: %s", strerror(errno)); + goto err_set_vring_call; + } + event_notifier_set_handler(vq_host_notifier, virtio_queue_host_notifier_read); virtio_queue_set_host_notifier_enabled(svq->vq, false); @@ -95,6 +133,11 @@ bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, =20 return true; =20 +err_set_vring_call: + kick_file.fd =3D event_notifier_get_fd(vq_host_notifier); + r =3D dev->vhost_ops->vhost_set_vring_kick(dev, &kick_file); + assert(r =3D=3D 0); + err_set_vring_kick: k->set_vq_handler(dev->vdev, idx, NULL); =20 @@ -129,6 +172,17 @@ void vhost_shadow_vq_stop_rcu(struct vhost_dev *dev, event_notifier_set_handler(vq_host_notifier, NULL); virtio_queue_set_host_notifier_enabled(svq->vq, true); k->set_vq_handler(svq->vdev, idx, NULL); + + if (!dev->vqs[idx].notifier_is_masked) { + EventNotifier *e =3D vhost_shadow_vq_get_call_notifier(svq); + + /* Restore vhost call */ + vhost_virtqueue_mask(dev, svq->vdev, idx, false); + if (event_notifier_test_and_clear(e)) { + virtio_queue_invalidate_signalled_used(svq->vdev, idx); + virtio_notify_irqfd(svq->vdev, svq->vq); + } + } } =20 /* @@ -159,6 +213,7 @@ VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_= dev *dev, int idx) goto err_init_call_notifier; } =20 + event_notifier_set_handler(&svq->call_notifier, vhost_handle_call); return g_steal_pointer(&svq); =20 err_init_call_notifier: diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index bde688f278..5ad0990509 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -984,7 +984,6 @@ static int vhost_sw_live_migration_start(struct vhost_d= ev *dev) int stop_idx =3D idx; bool ok =3D vhost_shadow_vq_start_rcu(dev, dev->shadow_vqs[idx]); - if (!ok) { while (--stop_idx >=3D 0) { vhost_shadow_vq_stop_rcu(dev, dev->shadow_vqs[stop_idx= ]); @@ -1610,6 +1609,10 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, Vi= rtIODevice *vdev, int n, if (mask) { assert(vdev->use_guest_notifier_mask); file.fd =3D event_notifier_get_fd(&hdev->vqs[index].masked_notifie= r); + } else if (hdev->sw_lm_enabled) { + VhostShadowVirtqueue *svq =3D hdev->shadow_vqs[n]; + EventNotifier *e =3D vhost_shadow_vq_get_call_notifier(svq); + file.fd =3D event_notifier_get_fd(e); } else { file.fd =3D event_notifier_get_fd(virtio_queue_get_guest_notifier(= vvq)); } --=20 2.27.0