From patchwork Fri Jan 29 20:54:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61E8FC433E0 for ; Fri, 29 Jan 2021 20:56:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B955C64DEC for ; Fri, 29 Jan 2021 20:56:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B955C64DEC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5aor-0008B4-Jt for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 15:56:41 -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 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= 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 X-MC-Unique: SErmOgIiNSuxpQhYdp-cfA-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This allows qemu to override vq handler. Signed-off-by: Eugenio Pérez --- 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 *features, uint64_t host_features); typedef struct VirtQueue VirtQueue; +typedef void (*VirtIOHandleOutput)(VirtIODevice *, VirtQueue *); +typedef bool (*VirtIOHandleAIOOutput)(VirtIODevice *, VirtQueue *); #define VIRTQUEUE_MAX_SIZE 1024 @@ -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); -typedef void (*VirtIOHandleOutput)(VirtIODevice *, VirtQueue *); -typedef bool (*VirtIOHandleAIOOutput)(VirtIODevice *, VirtQueue *); - VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, VirtIOHandleOutput handle_output); @@ -184,6 +183,7 @@ void virtio_del_queue(VirtIODevice *vdev, int n); void virtio_delete_queue(VirtQueue *vq); +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) } } +/* + * 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 = 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. From patchwork Fri Jan 29 20:54:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0A9FC433E0 for ; Fri, 29 Jan 2021 20:59:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C4A364E04 for ; Fri, 29 Jan 2021 20:59:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C4A364E04 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5are-0002jQ-4M for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 15:59:34 -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 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= 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 X-MC-Unique: klTNv_kuO4aNTzmItSu-9A-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" So other subsystem can override vq handler and device can reset it. Signed-off-by: Eugenio Pérez --- 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); } +static bool virtio_net_set_vq_handler(VirtIODevice *vdev, unsigned int i, + VirtIOHandleOutput handle_output) +{ + const VirtIONet *n = VIRTIO_NET(vdev); + const unsigned max_queues = n->multiqueue ? n->max_queues : 1; + VirtQueue *vq; + + /* Reset control queue also not supported */ + assert(i < max_queues * 2); + + vq = virtio_get_queue(vdev, i); + if (handle_output == NULL) { + if (i % 2) { + handle_output = virtio_net_handle_rx; + } else { + const VirtIONetQueue *q = &n->vqs[i / 2]; + handle_output = 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 = opaque; @@ -3519,6 +3544,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data) vdc->set_status = virtio_net_set_status; vdc->guest_notifier_mask = virtio_net_guest_notifier_mask; vdc->guest_notifier_pending = virtio_net_guest_notifier_pending; + vdc->set_vq_handler = virtio_net_set_vq_handler; vdc->legacy_features |= (0x1 << VIRTIO_NET_F_GSO); vdc->post_load = virtio_net_post_load_virtio; vdc->vmsd = &vmstate_virtio_net_device; From patchwork Fri Jan 29 20:54:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 014BCC433E6 for ; Fri, 29 Jan 2021 20:56:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64DCB64DEC for ; Fri, 29 Jan 2021 20:56:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64DCB64DEC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5ap5-0008Ve-4R for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 15:56:55 -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 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= 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 X-MC-Unique: sP-UdmAGNiabSUoTurwa9Q-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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); } +unsigned virtio_queue_get_idx(const VirtIODevice *vdev, const VirtQueue *vq); + bool virtio_legacy_allowed(VirtIODevice *vdev); bool virtio_legacy_check_disabled(VirtIODevice *vdev); 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) } } +unsigned virtio_queue_get_idx(const VirtIODevice *vdev, const VirtQueue *vq) +{ + return vq - vdev->vq; +} + int virtio_queue_ready(VirtQueue *vq) { return vq->vring.avail != 0; From patchwork Fri Jan 29 20:54:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A77B1C433E6 for ; Fri, 29 Jan 2021 21:02:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA71164E09 for ; Fri, 29 Jan 2021 21:02:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA71164E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5aua-0005Gp-T2 for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 16:02:36 -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 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= 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 X-MC-Unique: 15uPTmklMLWjpcoDRR4v9Q-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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 handle_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(VirtQueue *vq) return &vq->host_notifier; } +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 = enabled; From patchwork Fri Jan 29 20:54:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 946E6C433DB for ; Fri, 29 Jan 2021 20:59:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 01F3264E06 for ; Fri, 29 Jan 2021 20:59:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01F3264E06 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5arf-0002m0-UQ for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 15:59:35 -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 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= 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 X-MC-Unique: zBUJaK8hO0ChJDjOXxtmdA-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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, const 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); 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; } +/* + * 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 == 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, From patchwork Fri Jan 29 20:54:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24E28C433E0 for ; Fri, 29 Jan 2021 21:04:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8653764E0A for ; Fri, 29 Jan 2021 21:04:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8653764E0A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5awB-0007Cy-Ly for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 16:04:15 -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 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= 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 X-MC-Unique: ebyRKZAHPni11PBgrSXjtg-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It will be used to recover call eventfd. Signed-off-by: Eugenio Pérez --- 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, VirtIODevice *vdev, int n, /* should only be called after backend is connected */ assert(hdev->vhost_ops); + hdev->vqs[index].notifier_is_masked = mask; + if (mask) { assert(vdev->use_guest_notifier_mask); file.fd = event_notifier_get_fd(&hdev->vqs[index].masked_notifier); From patchwork Fri Jan 29 20:54:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B028C433DB for ; Fri, 29 Jan 2021 20:59:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EADEE64E06 for ; Fri, 29 Jan 2021 20:59:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EADEE64E06 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5arq-00036i-2e for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 15:59:46 -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 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= 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 X-MC-Unique: Axb5-rR9NKWNk08wG04ddA-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Vhost shadow virtqueue is an intermediate jump for virtqueue notifications and buffers, allowing qemu to track them. Signed-off-by: Eugenio Pérez --- 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-virtqueue.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érez + * + * 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-virtqueue.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érez + * + * 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 shadow + * methods and file descriptors. + */ +VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx) +{ + g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1); + int r; + + r = event_notifier_init(&svq->kick_notifier, 0); + if (r != 0) { + error_report("Couldn't create kick event notifier: %s", + strerror(errno)); + goto err_init_kick_notifier; + } + + r = event_notifier_init(&svq->call_notifier, 0); + if (r != 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')) virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.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-balloon.c')) From patchwork Fri Jan 29 20:54:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AC9FC433E0 for ; Fri, 29 Jan 2021 21:06:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C0B564E09 for ; Fri, 29 Jan 2021 21:06:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C0B564E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5axu-0008BT-4q for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 16:06:02 -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 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= 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 X-MC-Unique: VnsqSw8oNt2azPYvvXFcvw-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Command to enable shadow virtqueue looks like: { "execute": "x-vhost-enable-shadow-vq", "arguments": { "name": "dev0", "enable": true } } Signed-off-by: Eugenio Pérez --- 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'} } +## +# @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 @@ #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, return -1; } + +void qmp_x_vhost_enable_shadow_vq(const char *name, bool enable, Error **errp) +{ + error_setg(errp, "Shadow virtqueue still not implemented."); +} From patchwork Fri Jan 29 20:54:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5067C433DB for ; Fri, 29 Jan 2021 21:07:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0778164E09 for ; Fri, 29 Jan 2021 21:07:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0778164E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5ayw-0000uQ-1i for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 16:07:06 -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 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= 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 X-MC-Unique: 8peUIH-gOe29QMAyRyCXnA-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Shadow virtqueue notifications forwarding is disabled when vhost_dev stops. Signed-off-by: Eugenio Pérez --- 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-virtqueue.h index 6cc18d6acb..466f8ae595 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,11 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; +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); 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; }; +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-virtqueue.c index c0c967a7c5..908c36c66d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -8,15 +8,129 @@ */ #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" #include "qemu/error-report.h" -#include "qemu/event_notifier.h" +#include "qemu/main-loop.h" typedef struct VhostShadowVirtqueue { EventNotifier kick_notifier; EventNotifier call_notifier; + const struct vhost_virtqueue *hvq; + VirtIODevice *vdev; + VirtQueue *vq; } VhostShadowVirtqueue; +static uint16_t vhost_shadow_vring_used_flags(VhostShadowVirtqueue *svq) +{ + const struct vring_used *used = 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 = vhost_dev_from_virtio(vdev); + uint16_t idx = virtio_get_queue_index(vq); + + VhostShadowVirtqueue *svq = 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 = VIRTIO_DEVICE_GET_CLASS(dev->vdev); + EventNotifier *vq_host_notifier = virtio_queue_get_host_notifier(svq->vq); + unsigned idx = virtio_queue_get_idx(svq->vdev, svq->vq); + struct vhost_vring_file kick_file = { + .index = idx, + .fd = 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 = 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 = dev->vhost_ops->vhost_set_vring_kick(dev, &kick_file); + if (r != 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 = VIRTIO_DEVICE_GET_CLASS(svq->vdev); + unsigned idx = virtio_queue_get_idx(svq->vdev, svq->vq); + EventNotifier *vq_host_notifier = virtio_queue_get_host_notifier(svq->vq); + struct vhost_vring_file kick_file = { + .index = idx, + .fd = event_notifier_get_fd(vq_host_notifier), + }; + int r; + + /* Restore vhost kick */ + r = dev->vhost_ops->vhost_set_vring_kick(dev, &kick_file); + /* Cannot do a lot of things */ + assert(r == 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 shadow * 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 = g_new0(VhostShadowVirtqueue, 1); + int vq_idx = dev->vhost_ops->vhost_get_vq_index(dev, dev->vq_index + idx); int r; + svq->vq = virtio_get_queue(dev->vdev, vq_idx); + svq->hvq = &dev->vqs[idx]; + svq->vdev = dev->vdev; + r = event_notifier_init(&svq->kick_notifier, 0); if (r != 0) { error_report("Couldn't create kick event notifier: %s", @@ -40,7 +159,7 @@ VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx) goto err_init_call_notifier; } - return svq; + return g_steal_pointer(&svq); 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 *listener) } } +static int vhost_sw_live_migration_stop(struct vhost_dev *dev) +{ + int idx; + + WITH_RCU_READ_LOCK_GUARD() { + dev->sw_lm_enabled = false; + + for (idx = 0; idx < dev->nvqs; ++idx) { + vhost_shadow_vq_stop_rcu(dev, dev->shadow_vqs[idx]); + } + } + + for (idx = 0; idx < dev->nvqs; ++idx) { + vhost_shadow_vq_free(dev->shadow_vqs[idx]); + } + + g_free(dev->shadow_vqs); + dev->shadow_vqs = NULL; + return 0; +} + +static int vhost_sw_live_migration_start(struct vhost_dev *dev) +{ + int idx; + + dev->shadow_vqs = g_new0(VhostShadowVirtqueue *, dev->nvqs); + for (idx = 0; idx < dev->nvqs; ++idx) { + dev->shadow_vqs[idx] = vhost_shadow_vq_new(dev, idx); + if (unlikely(dev->shadow_vqs[idx] == NULL)) { + goto err; + } + } + + WITH_RCU_READ_LOCK_GUARD() { + for (idx = 0; idx < dev->nvqs; ++idx) { + int stop_idx = idx; + bool ok = vhost_shadow_vq_start_rcu(dev, + dev->shadow_vqs[idx]); + + if (!ok) { + while (--stop_idx >= 0) { + vhost_shadow_vq_stop_rcu(dev, dev->shadow_vqs[stop_idx]); + } + + goto err; + } + } + } + + dev->sw_lm_enabled = true; + return 0; + +err: + for (; idx >= 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 == dev->sw_lm_enabled) { + return 0; + } + + r = 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 *opaque, hdev->log = NULL; hdev->log_size = 0; hdev->log_enabled = false; + hdev->sw_lm_enabled = false; hdev->started = 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, VirtIODevice *vdev) hdev->vhost_ops->vhost_dev_start(hdev, false); } for (i = 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, VirtIODevice *vdev) memory_listener_unregister(&hdev->iommu_listener); } vhost_log_put(hdev, true); + g_free(hdev->shadow_vqs); + hdev->sw_lm_enabled = false; hdev->started = false; hdev->vdev = NULL; } @@ -1845,5 +1930,53 @@ int vhost_net_set_backend(struct vhost_dev *hdev, void qmp_x_vhost_enable_shadow_vq(const char *name, bool enable, Error **errp) { - error_setg(errp, "Shadow virtqueue still not implemented."); + struct vhost_dev *hdev; + const char *err_cause = NULL; + const VirtioDeviceClass *k; + int r; + ErrorClass err_class = ERROR_CLASS_GENERIC_ERROR; + + QLIST_FOREACH(hdev, &vhost_devices, entry) { + if (hdev->vdev && 0 == strcmp(hdev->vdev->name, name)) { + break; + } + } + + if (!hdev) { + err_class = ERROR_CLASS_DEVICE_NOT_FOUND; + err_cause = "Device not found"; + goto err; + } + + if (!hdev->started) { + err_cause = "Device is not started"; + goto err; + } + + if (hdev->acked_features & BIT_ULL(VIRTIO_F_RING_PACKED)) { + err_cause = "Use packed vq"; + goto err; + } + + if (vhost_dev_has_iommu(hdev)) { + err_cause = "Device use IOMMU"; + goto err; + } + + k = VIRTIO_DEVICE_GET_CLASS(hdev->vdev); + if (!k->set_vq_handler) { + err_cause = "Virtio device type does not support reset of vq handler"; + goto err; + } + + r = vhost_sw_live_migration_enable(hdev, enable); + if (unlikely(r)) { + err_cause = "Error enabling (see monitor)"; + } + +err: + if (err_cause) { + error_set(errp, err_class, + "Can't enable shadow vq on %s: %s", name, err_cause); + } } From patchwork Fri Jan 29 20:54:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 12056561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3AACC433E0 for ; Fri, 29 Jan 2021 21:02:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 308CC64E0A for ; Fri, 29 Jan 2021 21:02:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 308CC64E0A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5auc-0005KX-0y for qemu-devel@archiver.kernel.org; Fri, 29 Jan 2021 16:02:38 -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 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= 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 X-MC-Unique: 2OdFKLUaOp-e8IZlx4vaWg-1 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) From: =?utf-8?q?Eugenio_P=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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-virtqueue.h index 466f8ae595..99a4e011fd 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,8 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; +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-virtqueue.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, VirtQueue *vq) vhost_shadow_vring_kick(svq); } +static void vhost_handle_call(EventNotifier *n) +{ + VhostShadowVirtqueue *svq = container_of(n, VhostShadowVirtqueue, + call_notifier); + + if (event_notifier_test_and_clear(n)) { + unsigned idx = virtio_queue_get_idx(svq->vdev, svq->vq); + + /* + * Since QEMU has not add any descriptors, virtqueue code thinks its + * not needed to signal used. QEMU shadow virtqueue will take + * descriptor forwarding soon, so just invalidate used cache for now. + */ + 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 = idx, .fd = event_notifier_get_fd(&svq->kick_notifier), }; + struct vhost_vring_file call_file = { + .index = idx, + .fd = event_notifier_get_fd(&svq->call_notifier), + }; int r; bool ok; @@ -88,6 +120,12 @@ bool vhost_shadow_vq_start_rcu(struct vhost_dev *dev, goto err_set_vring_kick; } + r = dev->vhost_ops->vhost_set_vring_call(dev, &call_file); + if (r != 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, return true; +err_set_vring_call: + kick_file.fd = event_notifier_get_fd(vq_host_notifier); + r = dev->vhost_ops->vhost_set_vring_kick(dev, &kick_file); + assert(r == 0); + err_set_vring_kick: k->set_vq_handler(dev->vdev, idx, NULL); @@ -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 = 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); + } + } } /* @@ -159,6 +213,7 @@ VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx) goto err_init_call_notifier; } + event_notifier_set_handler(&svq->call_notifier, vhost_handle_call); return g_steal_pointer(&svq); 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_dev *dev) int stop_idx = idx; bool ok = vhost_shadow_vq_start_rcu(dev, dev->shadow_vqs[idx]); - if (!ok) { while (--stop_idx >= 0) { vhost_shadow_vq_stop_rcu(dev, dev->shadow_vqs[stop_idx]); @@ -1610,6 +1609,10 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, if (mask) { assert(vdev->use_guest_notifier_mask); file.fd = event_notifier_get_fd(&hdev->vqs[index].masked_notifier); + } else if (hdev->sw_lm_enabled) { + VhostShadowVirtqueue *svq = hdev->shadow_vqs[n]; + EventNotifier *e = vhost_shadow_vq_get_call_notifier(svq); + file.fd = event_notifier_get_fd(e); } else { file.fd = event_notifier_get_fd(virtio_queue_get_guest_notifier(vvq)); }