From nobody Sat Apr 20 01:09:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617875321; cv=none; d=zohomail.com; s=zohoarc; b=g1NdKWLy6A2p3iOsnWcA6sjJMBfNXr3LhjA/uYfGednlbxtKpC7S9xCXzRzkgDI7bqEC/3zUa+PehBRuMB7hMl/mB4yjOcsAXJxiyMj0b46l+T+pBb7qJpaFKRF0kGUUftYzhM5UqH1qY1mnE9PnmCWkKIvNNFcdxEr8/i5PD5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617875321; h=Content-Type:Content-Transfer-Encoding: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=vdfJALUU1ndnIHB6UX7DZ4cd7BeUr76SuJcCpi6sRuI=; b=PwHtt6LqWuKKNQEaVZURE4oGzp1+KS3FZROeMyzPHiMJA9kD59KJAfN+FIBKr+v2ezX21gN4gfJexSGjwJ1shEzmUAiOXLfWSubu2U2eD2sj+NVMIMlCF/Vt6d70YgWObcPDfWBAUF4pWHERc61jzXM+9ERDCJ6PtpfAZIPe/hY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617875321642783.0345987321464; Thu, 8 Apr 2021 02:48:41 -0700 (PDT) Received: from localhost ([::1]:43106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lURHE-0007gC-Gs for importer@patchew.org; Thu, 08 Apr 2021 05:48:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7e-0006du-OR for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59093) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7X-0004J2-Kr for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:46 -0400 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-36-0112pvmYPZuo1V309EL8Rw-1; Thu, 08 Apr 2021 05:38:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92495814337 for ; Thu, 8 Apr 2021 09:38:36 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-72.pek2.redhat.com [10.72.13.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2CFD5D9DC; Thu, 8 Apr 2021 09:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617874718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vdfJALUU1ndnIHB6UX7DZ4cd7BeUr76SuJcCpi6sRuI=; b=LmG0iWgkWerqsMG3jVR0bxcK5EooYYGCg6lH4Hz1urqOHTLDXBQJSPOAcRA1h6INkPoTee MIi7oFgFdj8n8qVC9h9sdI35ZNQthnF3/0pyb4rM1Ol1ESK40iGCpJt5BSIwhyeTZ5mOcX d3PXvBxvjXKYwO9TRE2LW4VLcYNzFOI= X-MC-Unique: 0112pvmYPZuo1V309EL8Rw-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v5 1/6] virtio: introduce new type in interrupt process Date: Thu, 8 Apr 2021 17:38:19 +0800 Message-Id: <20210408093824.14985-2-lulu@redhat.com> In-Reply-To: <20210408093824.14985-1-lulu@redhat.com> References: <20210408093824.14985-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=170.10.133.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_CHARSET_FARAWAY=2.45, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" To support config interrupt we need to add a new type of interrupt process. So we introduce the vector type enum virtio_vector_type { =E8=81=BD =E8=81=BD =E8=81=BD =E8=81=BD VIRTIO_VQ_VECTOR, =E8=81=BD =E8=81=BD =E8=81=BD =E8=81=BD VIRTIO_CONFIG_VECTOR, =E8=81=BD =E8=81=BD =E8=81=BD =E8=81=BD VIRTIO_VECTOR_UNKNOWN, =E8=81=BD =E8=81=BD }; =E8=81=BD =E8=81=BD Now the bus which support configure interrupt is virtio-mmio and vritio-pci. For other drivers, the function will only check if the interrupt type is the VIRTIO_CONFIG_VQ. If not the function will fail. Signed-off-by: Cindy Lu --- hw/display/vhost-user-gpu.c | 14 +++++--- hw/net/virtio-net.c | 15 +++++--- hw/s390x/virtio-ccw.c | 6 ++-- hw/virtio/vhost-user-fs.c | 12 ++++--- hw/virtio/vhost-vsock-common.c | 12 ++++--- hw/virtio/virtio-crypto.c | 13 ++++--- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 66 ++++++++++++++++++++-------------- include/hw/virtio/virtio.h | 9 +++-- 9 files changed, 95 insertions(+), 54 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 51f1747c4a..959ad115b6 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -487,18 +487,24 @@ vhost_user_gpu_set_status(VirtIODevice *vdev, uint8_t= val) } =20 static bool -vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx) +vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx, + int type) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return false; + } return vhost_virtqueue_pending(&g->vhost->dev, idx); } =20 static void -vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) +vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask, + int type) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return; + } vhost_virtqueue_mask(&g->vhost->dev, vdev, idx, mask); } =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9179013ac4..00d95e6615 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3055,22 +3055,27 @@ static NetClientInfo net_virtio_info =3D { .announce =3D virtio_net_announce, }; =20 -static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx) +static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx, + int type) { VirtIONet *n =3D VIRTIO_NET(vdev); NetClientState *nc =3D qemu_get_subqueue(n->nic, vq2q(idx)); assert(n->vhost_started); - return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx); + if (type =3D=3D VIRTIO_VQ_VECTOR) { + return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx); + } + return false; } =20 static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx, - bool mask) + bool mask, int type) { VirtIONet *n =3D VIRTIO_NET(vdev); NetClientState *nc =3D qemu_get_subqueue(n->nic, vq2q(idx)); assert(n->vhost_started); - vhost_net_virtqueue_mask(get_vhost_net(nc->peer), - vdev, idx, mask); + if (type =3D=3D VIRTIO_VQ_VECTOR) { + vhost_net_virtqueue_mask(get_vhost_net(nc->peer), vdev, idx, mask); + } } =20 static void virtio_net_set_config_size(VirtIONet *n, uint64_t host_feature= s) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 4582e94ae7..234f749548 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -1003,16 +1003,16 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwD= evice *dev, int n, * need to manually trigger any guest masking callbacks here. */ if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { - k->guest_notifier_mask(vdev, n, false); + k->guest_notifier_mask(vdev, n, false, VIRTIO_VQ_VECTOR); } /* get lost events and re-inject */ if (k->guest_notifier_pending && - k->guest_notifier_pending(vdev, n)) { + k->guest_notifier_pending(vdev, n, VIRTIO_VQ_VECTOR)) { event_notifier_set(notifier); } } else { if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { - k->guest_notifier_mask(vdev, n, true); + k->guest_notifier_mask(vdev, n, true, VIRTIO_VQ_VECTOR); } if (with_irqfd) { virtio_ccw_remove_irqfd(dev, n); diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 1bc5d03a00..22358767f1 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -143,17 +143,21 @@ static void vuf_handle_output(VirtIODevice *vdev, Vir= tQueue *vq) } =20 static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, - bool mask) + bool mask, int type) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return; + } vhost_virtqueue_mask(&fs->vhost_dev, vdev, idx, mask); } =20 -static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx) +static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx, int ty= pe) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return false; + } return vhost_virtqueue_pending(&fs->vhost_dev, idx); } =20 diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index 5b2ebf3496..92c133c54c 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -97,18 +97,22 @@ static void vhost_vsock_common_handle_output(VirtIODevi= ce *vdev, VirtQueue *vq) } =20 static void vhost_vsock_common_guest_notifier_mask(VirtIODevice *vdev, int= idx, - bool mask) + bool mask, int type) { VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return; + } vhost_virtqueue_mask(&vvc->vhost_dev, vdev, idx, mask); } =20 static bool vhost_vsock_common_guest_notifier_pending(VirtIODevice *vdev, - int idx) + int idx, int type) { VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return false; + } return vhost_virtqueue_pending(&vvc->vhost_dev, idx); } =20 diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 54f9bbb789..ab7958465c 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -941,23 +941,28 @@ static void virtio_crypto_set_status(VirtIODevice *vd= ev, uint8_t status) } =20 static void virtio_crypto_guest_notifier_mask(VirtIODevice *vdev, int idx, - bool mask) + bool mask, int type) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(vdev); int queue =3D virtio_crypto_vq2q(idx); =20 assert(vcrypto->vhost_started); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return; + } cryptodev_vhost_virtqueue_mask(vdev, queue, idx, mask); } =20 -static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int i= dx) +static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int i= dx, + int type) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(vdev); int queue =3D virtio_crypto_vq2q(idx); =20 assert(vcrypto->vhost_started); - + if (type !=3D VIRTIO_VQ_VECTOR) { + return false; + } return cryptodev_vhost_virtqueue_pending(vdev, queue, idx); } =20 diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index e1b5c3b81e..1aa1aaeca4 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -627,7 +627,7 @@ static int virtio_mmio_set_guest_notifier(DeviceState *= d, int n, bool assign, } =20 if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { - vdc->guest_notifier_mask(vdev, n, !assign); + vdc->guest_notifier_mask(vdev, n, !assign, VIRTIO_VQ_VECTOR); } =20 return 0; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 36524a5728..481f6e7505 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -691,23 +691,17 @@ static void kvm_virtio_pci_vq_vector_release(VirtIOPC= IProxy *proxy, } =20 static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy, - unsigned int queue_no, + EventNotifier *n, unsigned int vector) { VirtIOIRQFD *irqfd =3D &proxy->vector_irqfd[vector]; - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - VirtQueue *vq =3D virtio_get_queue(vdev, queue_no); - EventNotifier *n =3D virtio_queue_get_guest_notifier(vq); return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->v= irq); } =20 static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy, - unsigned int queue_no, + EventNotifier *n , unsigned int vector) { - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - VirtQueue *vq =3D virtio_get_queue(vdev, queue_no); - EventNotifier *n =3D virtio_queue_get_guest_notifier(vq); VirtIOIRQFD *irqfd =3D &proxy->vector_irqfd[vector]; int ret; =20 @@ -722,7 +716,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *pr= oxy, int nvqs) VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); unsigned int vector; int ret, queue_no; - + VirtQueue *vq; + EventNotifier *n; for (queue_no =3D 0; queue_no < nvqs; queue_no++) { if (!virtio_queue_get_num(vdev, queue_no)) { break; @@ -739,7 +734,9 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *pr= oxy, int nvqs) * Otherwise, delay until unmasked in the frontend. */ if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - ret =3D kvm_virtio_pci_irqfd_use(proxy, queue_no, vector); + vq =3D virtio_get_queue(vdev, queue_no); + n =3D virtio_queue_get_guest_notifier(vq); + ret =3D kvm_virtio_pci_irqfd_use(proxy, n, vector); if (ret < 0) { kvm_virtio_pci_vq_vector_release(proxy, vector); goto undo; @@ -755,7 +752,9 @@ undo: continue; } if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); + vq =3D virtio_get_queue(vdev, queue_no); + n =3D virtio_queue_get_guest_notifier(vq); + kvm_virtio_pci_irqfd_release(proxy, n, vector); } kvm_virtio_pci_vq_vector_release(proxy, vector); } @@ -769,7 +768,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProx= y *proxy, int nvqs) unsigned int vector; int queue_no; VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); - + VirtQueue *vq; + EventNotifier *n; for (queue_no =3D 0; queue_no < nvqs; queue_no++) { if (!virtio_queue_get_num(vdev, queue_no)) { break; @@ -782,7 +782,9 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProx= y *proxy, int nvqs) * Otherwise, it was cleaned when masked in the frontend. */ if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); + vq =3D virtio_get_queue(vdev, queue_no); + n =3D virtio_queue_get_guest_notifier(vq); + kvm_virtio_pci_irqfd_release(proxy, n, vector); } kvm_virtio_pci_vq_vector_release(proxy, vector); } @@ -791,12 +793,12 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIPr= oxy *proxy, int nvqs) static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy, unsigned int queue_no, unsigned int vector, - MSIMessage msg) + MSIMessage msg, + int type, + EventNotifier *n) { VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D virtio_get_queue(vdev, queue_no); - EventNotifier *n =3D virtio_queue_get_guest_notifier(vq); VirtIOIRQFD *irqfd; int ret =3D 0; =20 @@ -816,21 +818,23 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy= *proxy, * Otherwise, set it up now. */ if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - k->guest_notifier_mask(vdev, queue_no, false); + k->guest_notifier_mask(vdev, queue_no, false, type); /* Test after unmasking to avoid losing events. */ if (k->guest_notifier_pending && - k->guest_notifier_pending(vdev, queue_no)) { + k->guest_notifier_pending(vdev, queue_no, type)) { event_notifier_set(n); } } else { - ret =3D kvm_virtio_pci_irqfd_use(proxy, queue_no, vector); + ret =3D kvm_virtio_pci_irqfd_use(proxy, n, vector); } return ret; } =20 static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy, unsigned int queue_no, - unsigned int vector) + unsigned int vector, + int type, + EventNotifier *n) { VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); @@ -839,9 +843,9 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *p= roxy, * Otherwise, clean it up now. */=20 if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - k->guest_notifier_mask(vdev, queue_no, true); + k->guest_notifier_mask(vdev, queue_no, true, type); } else { - kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); + kvm_virtio_pci_irqfd_release(proxy, n, vector); } } =20 @@ -851,6 +855,7 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, uns= igned vector, VirtIOPCIProxy *proxy =3D container_of(dev, VirtIOPCIProxy, pci_dev); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtQueue *vq =3D virtio_vector_first_queue(vdev, vector); + EventNotifier *n; int ret, index, unmasked =3D 0; =20 while (vq) { @@ -859,7 +864,9 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, uns= igned vector, break; } if (index < proxy->nvqs_with_notifiers) { - ret =3D virtio_pci_vq_vector_unmask(proxy, index, vector, msg); + n =3D virtio_queue_get_guest_notifier(vq); + ret =3D virtio_pci_vq_vector_unmask(proxy, index, vector, msg, + VIRTIO_VQ_VECTOR, n); if (ret < 0) { goto undo; } @@ -875,7 +882,9 @@ undo: while (vq && unmasked >=3D 0) { index =3D virtio_get_queue_index(vq); if (index < proxy->nvqs_with_notifiers) { - virtio_pci_vq_vector_mask(proxy, index, vector); + n =3D virtio_queue_get_guest_notifier(vq); + virtio_pci_vq_vector_mask(proxy, index, vector, + VIRTIO_VQ_VECTOR, n); --unmasked; } vq =3D virtio_vector_next_queue(vq); @@ -888,15 +897,18 @@ static void virtio_pci_vector_mask(PCIDevice *dev, un= signed vector) VirtIOPCIProxy *proxy =3D container_of(dev, VirtIOPCIProxy, pci_dev); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtQueue *vq =3D virtio_vector_first_queue(vdev, vector); + EventNotifier *n; int index; =20 while (vq) { index =3D virtio_get_queue_index(vq); + n =3D virtio_queue_get_guest_notifier(vq); if (!virtio_queue_get_num(vdev, index)) { break; } if (index < proxy->nvqs_with_notifiers) { - virtio_pci_vq_vector_mask(proxy, index, vector); + virtio_pci_vq_vector_mask(proxy, index, vector, + VIRTIO_VQ_VECTOR, n); } vq =3D virtio_vector_next_queue(vq); } @@ -926,7 +938,7 @@ static void virtio_pci_vector_poll(PCIDevice *dev, vq =3D virtio_get_queue(vdev, queue_no); notifier =3D virtio_queue_get_guest_notifier(vq); if (k->guest_notifier_pending) { - if (k->guest_notifier_pending(vdev, queue_no)) { + if (k->guest_notifier_pending(vdev, queue_no, VIRTIO_VQ_VECTOR= )) { msix_set_pending(dev, vector); } } else if (event_notifier_test_and_clear(notifier)) { @@ -958,7 +970,7 @@ static int virtio_pci_set_guest_notifier(DeviceState *d= , int n, bool assign, if (!msix_enabled(&proxy->pci_dev) && vdev->use_guest_notifier_mask && vdc->guest_notifier_mask) { - vdc->guest_notifier_mask(vdev, n, !assign); + vdc->guest_notifier_mask(vdev, n, !assign, VIRTIO_VQ_VECTOR); } =20 return 0; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b7ece7a6a8..5a1940fe70 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -67,6 +67,11 @@ typedef struct VirtQueueElement =20 #define VIRTIO_NO_VECTOR 0xffff =20 +enum virtio_vector_type { + VIRTIO_VQ_VECTOR, + VIRTIO_CONFIG_VECTOR, + VIRTIO_VECTOR_UNKNOWN, +}; #define TYPE_VIRTIO_DEVICE "virtio-device" OBJECT_DECLARE_TYPE(VirtIODevice, VirtioDeviceClass, VIRTIO_DEVICE) =20 @@ -138,13 +143,13 @@ struct VirtioDeviceClass { * If backend does not support masking, * must check in frontend instead. */ - bool (*guest_notifier_pending)(VirtIODevice *vdev, int n); + bool (*guest_notifier_pending)(VirtIODevice *vdev, int n, int type); /* Mask/unmask events from this vq. Any events reported * while masked will become pending. * If backend does not support masking, * must mask in frontend instead. */ - void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask); + void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask, int = type); int (*start_ioeventfd)(VirtIODevice *vdev); void (*stop_ioeventfd)(VirtIODevice *vdev); /* Saving and loading of a device; trying to deprecate save/load --=20 2.21.3 From nobody Sat Apr 20 01:09:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617875177; cv=none; d=zohomail.com; s=zohoarc; b=I31GLU0G/Rk02VsIz10joNVl80V0PrwHSM8rw9R1SW2jA4xgMizoYd3H4Z4SAaU2ZJjOwLlRcgHrh9KIhlb5US9BLlMg4XPIEGopydf1YOgvO4w/BELZs5d2bcj84hRyLUj0j5nKTdiapkXF1t2zru/aGlN5+n9qHOOyPENxgRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617875177; h=Content-Type:Content-Transfer-Encoding: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=UL3R7GXkmABb4jQovcZo9CLNzO+V++NsFPsFRSgDL+c=; b=gwLCquW12fCE1ZupQ94O9bxcH7t19uvB9iMnvibAvZI2gYPQ78uCKE8sQRxPB6YFvjVwldJOXqnxNhsc6sMk4v8W7V1Rh9AKv9Hq0igKN1+Buc7fjY8L6Ueu9/tXGJtZDh9beRA2eOAfZsB6hkMRqAyouraSQlcWqodQqm/JTj8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617875177990947.6870947607796; Thu, 8 Apr 2021 02:46:17 -0700 (PDT) Received: from localhost ([::1]:34460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUREu-00048O-OH for importer@patchew.org; Thu, 08 Apr 2021 05:46:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7c-0006dG-Ue for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33706) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7a-0004L1-Ol for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:44 -0400 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-594-qcxFtmssOImTEGUDjK3jew-1; Thu, 08 Apr 2021 05:38:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F6FA107ACCD for ; Thu, 8 Apr 2021 09:38:40 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-72.pek2.redhat.com [10.72.13.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91AB95D9DC; Thu, 8 Apr 2021 09:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617874722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UL3R7GXkmABb4jQovcZo9CLNzO+V++NsFPsFRSgDL+c=; b=R4ZkHsuGOEjEGePJX6Z8q5Odm1iua8xpvEilm3mC5HH3/eB+wrarsezy7tuGRQ32/Or1/L fJrbyeLLYSyJ5tabhio334QXtIYcLAKGlsZwp5PV2tQCasiH+OVbuePjoqIMCFoavdncG2 dcZ44Lv0uqU3QyMHOk7dwkpafRZd1f8= X-MC-Unique: qcxFtmssOImTEGUDjK3jew-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v5 2/6] vhost: add new call back function for config interrupt Date: Thu, 8 Apr 2021 17:38:20 +0800 Message-Id: <20210408093824.14985-3-lulu@redhat.com> In-Reply-To: <20210408093824.14985-1-lulu@redhat.com> References: <20210408093824.14985-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" to support configure interrupt, we need to Add new call back function for config interrupt. now=E8=81=BDthis call back function only used in vhost-vdpa driver Signed-off-by: Cindy Lu --- hw/virtio/trace-events | 2 ++ hw/virtio/vhost-vdpa.c | 7 +++++++ include/hw/virtio/vhost-backend.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 2060a144a2..6710835b46 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, = int fd) "dev: %p index: vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0= x%"PRIx64 vhost_vdpa_set_owner(void *dev) "dev: %p" vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint6= 4_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_add= r: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64 +vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p" + =20 # virtio.c virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned o= ut_num) "elem %p size %zd in_num %u out_num %u" diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 01d2101d09..9ba2a2bed4 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -545,6 +545,12 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev = *dev, trace_vhost_vdpa_set_vring_call(dev, file->index, file->fd); return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); } +static int vhost_vdpa_set_config_call(struct vhost_dev *dev, + int *fd) +{ + trace_vhost_vdpa_set_config_call(dev, fd); + return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd); +} =20 static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features) @@ -611,4 +617,5 @@ const VhostOps vdpa_ops =3D { .vhost_get_device_id =3D vhost_vdpa_get_device_id, .vhost_vq_get_addr =3D vhost_vdpa_vq_get_addr, .vhost_force_iommu =3D vhost_vdpa_force_iommu, + .vhost_set_config_call =3D vhost_vdpa_set_config_call, }; diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 8a6f8e2a7a..adaf6982d2 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -125,6 +125,8 @@ typedef int (*vhost_get_device_id_op)(struct vhost_dev = *dev, uint32_t *dev_id); =20 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev); =20 +typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev, + int *fd); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -170,6 +172,7 @@ typedef struct VhostOps { vhost_vq_get_addr_op vhost_vq_get_addr; vhost_get_device_id_op vhost_get_device_id; vhost_force_iommu_op vhost_force_iommu; + vhost_set_config_call_op vhost_set_config_call; } VhostOps; =20 extern const VhostOps user_ops; --=20 2.21.3 From nobody Sat Apr 20 01:09:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617874872; cv=none; d=zohomail.com; s=zohoarc; b=B4LspSdogJSdv8i+nqAPjI8GBCVprQ9ZvVcp0Z1nBVAmpySD6fyxd3g17ZEwFUerbcEwbDEfOVcm5MBcRoviTJUa6uEcunCCeWWI/YqCeqhhXzx0MZCGWWk7JguPyIU+BLx+6RG67fXS9XxgqeRYl4cWTFZwoPH9K6xTL2REKww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617874872; h=Content-Type:Content-Transfer-Encoding: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=fJ8spgiXxRL21jFYdGtiDV2PeoVTdhWZavoFwhiJGXA=; b=kH1XkFfgkDfEa9WyLEyZQuJI085PgdFmKhiQyxNXisTOBpJ8zqzUYQMkiJOX9aPnXad1ZYBl98bOvAzbozzHI/mFZ76ywuidou6HTFNQRalNR0O9MBDorbOP+A2tHHIa6O6pssGcJappJ7ZI4Tueu3s2U3MlhKFQQ6TyurDo5rk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617874872134148.57544649784916; Thu, 8 Apr 2021 02:41:12 -0700 (PDT) Received: from localhost ([::1]:51980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUR9z-0008Cx-0I for importer@patchew.org; Thu, 08 Apr 2021 05:41:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7m-0006mi-Ct for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7e-0004MX-9a for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:54 -0400 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-40rmjVVWMHyHhPXz5lXj5w-1; Thu, 08 Apr 2021 05:38:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DB97C7400 for ; Thu, 8 Apr 2021 09:38:43 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-72.pek2.redhat.com [10.72.13.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFA2D5D9DC; Thu, 8 Apr 2021 09:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617874725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fJ8spgiXxRL21jFYdGtiDV2PeoVTdhWZavoFwhiJGXA=; b=BxOl4N8gjlSly7REdtBMwQpBA5qknnUfUPKt0+4oW0UVCzs380oDugpbQ9ROoJuRJ9vX1e ChMnOq4l+IK0rvhJGwt56q9S30UUzJd9qvMBvmTPD1c+n32otLX4Cak0YEWXXG9b20Akpu PvFqZ0zH1MKG+lAFVq7YXFDnbTnTUOA= X-MC-Unique: 40rmjVVWMHyHhPXz5lXj5w-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v5 3/6] virtio:add support in configure interrupt Date: Thu, 8 Apr 2021 17:38:21 +0800 Message-Id: <20210408093824.14985-4-lulu@redhat.com> In-Reply-To: <20210408093824.14985-1-lulu@redhat.com> References: <20210408093824.14985-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add configure notifier support in virtio and related driver When peer is vhost vdpa, setup the configure interrupt function vhost_net_start and release the resource when vhost_net_stop Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 9 +++++++++ hw/net/virtio-net.c | 6 ++++++ hw/virtio/vhost.c | 38 +++++++++++++++++++++++++++++++++++++- hw/virtio/virtio.c | 25 +++++++++++++++++++++++++ include/hw/virtio/vhost.h | 3 +++ include/hw/virtio/virtio.h | 5 +++++ include/net/vhost_net.h | 3 +++ 7 files changed, 88 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 24d555e764..12e30dc25e 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -426,6 +426,15 @@ void vhost_net_virtqueue_mask(VHostNetState *net, Virt= IODevice *dev, vhost_virtqueue_mask(&net->dev, dev, idx, mask); } =20 +bool vhost_net_config_pending(VHostNetState *net, int idx) +{ + return vhost_config_pending(&net->dev, idx); +} +void vhost_net_config_mask(VHostNetState *net, VirtIODevice *dev, + bool mask) +{ + vhost_config_mask(&net->dev, dev, mask); +} VHostNetState *get_vhost_net(NetClientState *nc) { VHostNetState *vhost_net =3D 0; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 00d95e6615..e30a7d9835 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3064,6 +3064,9 @@ static bool virtio_net_guest_notifier_pending(VirtIOD= evice *vdev, int idx, if (type =3D=3D VIRTIO_VQ_VECTOR) { return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx); } + if (type =3D=3D VIRTIO_CONFIG_VECTOR) { + return vhost_net_config_pending(get_vhost_net(nc->peer), idx); + } return false; } =20 @@ -3076,6 +3079,9 @@ static void virtio_net_guest_notifier_mask(VirtIODevi= ce *vdev, int idx, if (type =3D=3D VIRTIO_VQ_VECTOR) { vhost_net_virtqueue_mask(get_vhost_net(nc->peer), vdev, idx, mask); } + if (type =3D=3D VIRTIO_CONFIG_VECTOR) { + vhost_net_config_mask(get_vhost_net(nc->peer), vdev, mask); + } } =20 static void virtio_net_set_config_size(VirtIONet *n, uint64_t host_feature= s) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 614ccc2bcb..b5e915d5cf 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1313,6 +1313,10 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, goto fail; } } + r =3D event_notifier_init(&hdev->masked_config_notifier, 0); + if (r < 0) { + return r; + } =20 if (busyloop_timeout) { for (i =3D 0; i < hdev->nvqs; ++i) { @@ -1405,6 +1409,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev) for (i =3D 0; i < hdev->nvqs; ++i) { vhost_virtqueue_cleanup(hdev->vqs + i); } + event_notifier_cleanup(&hdev->masked_config_notifier); if (hdev->mem) { /* those are only safe after successful init */ memory_listener_unregister(&hdev->memory_listener); @@ -1498,6 +1503,10 @@ bool vhost_virtqueue_pending(struct vhost_dev *hdev,= int n) return event_notifier_test_and_clear(&vq->masked_notifier); } =20 +bool vhost_config_pending(struct vhost_dev *hdev, int n) +{ + return event_notifier_test_and_clear(&hdev->masked_config_notifier); +} /* Mask/unmask events from this vq. */ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int = n, bool mask) @@ -1522,6 +1531,28 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, Vi= rtIODevice *vdev, int n, VHOST_OPS_DEBUG("vhost_set_vring_call failed"); } } +void vhost_config_mask(struct vhost_dev *hdev, VirtIODevice *vdev, + bool mask) +{ + int fd; + int r; + EventNotifier *masked_config_notifier =3D &hdev->masked_config_notifier; + EventNotifier *config_notifier =3D &vdev->config_notifier; + if (vdev->use_config_notifier !=3D true) { + return; + } + assert(hdev->vhost_ops); + if (mask) { + assert(vdev->use_guest_notifier_mask); + fd =3D event_notifier_get_fd(masked_config_notifier); + } else { + fd =3D event_notifier_get_fd(config_notifier); + } + r =3D hdev->vhost_ops->vhost_set_config_call(hdev, &fd); + if (r < 0) { + error_report("vhost_set_config_call failed"); + } +} =20 uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bit= s, uint64_t features) @@ -1732,7 +1763,12 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) goto fail_vq; } } - + if (vdev->use_config_notifier =3D=3D true) { + event_notifier_test_and_clear(&hdev->masked_config_notifier); + if (!vdev->use_guest_notifier_mask) { + vhost_config_mask(hdev, vdev, false); + } + } if (hdev->log_enabled) { uint64_t log_base; =20 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ceb58fda6c..774ac3893b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3278,6 +3278,7 @@ void virtio_init(VirtIODevice *vdev, const char *name, virtio_vmstate_change, vdev); vdev->device_endian =3D virtio_default_endian(); vdev->use_guest_notifier_mask =3D true; + vdev->use_config_notifier =3D false; } =20 /* @@ -3502,6 +3503,16 @@ static void virtio_queue_guest_notifier_read(EventNo= tifier *n) } } =20 +static void virtio_config_read(EventNotifier *n) +{ + VirtIODevice *vdev =3D container_of(n, VirtIODevice, config_notifier); + if (vdev->use_config_notifier =3D=3D false) { + return; + } + if (event_notifier_test_and_clear(n)) { + virtio_notify_config(vdev); + } +} void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, bool with_irqfd) { @@ -3517,6 +3528,16 @@ void virtio_queue_set_guest_notifier_fd_handler(Virt= Queue *vq, bool assign, virtio_queue_guest_notifier_read(&vq->guest_notifier); } } +void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign, + bool with_irqfd) +{ + if (assign && !with_irqfd) { + event_notifier_set_handler(&vdev->config_notifier, + virtio_config_read); + } else { + event_notifier_set_handler(&vdev->config_notifier, NULL); + } +} =20 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { @@ -3591,6 +3612,10 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQu= eue *vq) return &vq->host_notifier; } =20 +EventNotifier *virtio_get_config_notifier(VirtIODevice *vdev) +{ + return &vdev->config_notifier; +} void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled) { vq->host_notifier_enabled =3D enabled; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4a8bc75415..22efa7008e 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -91,6 +91,7 @@ struct vhost_dev { QLIST_HEAD(, vhost_iommu) iommu_list; IOMMUNotifier n; const VhostDevConfigOps *config_ops; + EventNotifier masked_config_notifier; }; =20 struct vhost_net { @@ -108,6 +109,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevic= e *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vde= v); +bool vhost_config_pending(struct vhost_dev *hdev, int n); +void vhost_config_mask(struct vhost_dev *hdev, VirtIODevice *vdev, bool m= ask); =20 /* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 5a1940fe70..fd17dbb097 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -113,6 +113,8 @@ struct VirtIODevice bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; + EventNotifier config_notifier; + bool use_config_notifier; }; =20 struct VirtioDeviceClass { @@ -315,11 +317,14 @@ uint16_t virtio_get_queue_index(VirtQueue *vq); EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq); void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, bool with_irqfd); +void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign, + bool with_irqfd); int virtio_device_start_ioeventfd(VirtIODevice *vdev); int virtio_device_grab_ioeventfd(VirtIODevice *vdev); void virtio_device_release_ioeventfd(VirtIODevice *vdev); bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev); EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); +EventNotifier *virtio_get_config_notifier(VirtIODevice *vdev); void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled); void virtio_queue_host_notifier_read(EventNotifier *n); void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 172b0051d8..0d38c97c94 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -36,6 +36,9 @@ int vhost_net_set_config(struct vhost_net *net, const uin= t8_t *data, bool vhost_net_virtqueue_pending(VHostNetState *net, int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, int idx, bool mask); +bool vhost_net_config_pending(VHostNetState *net, int n); +void vhost_net_config_mask(VHostNetState *net, VirtIODevice *dev, + bool mask); int vhost_net_notify_migration_done(VHostNetState *net, char* mac_addr); VHostNetState *get_vhost_net(NetClientState *nc); =20 --=20 2.21.3 From nobody Sat Apr 20 01:09:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617875082; cv=none; d=zohomail.com; s=zohoarc; b=gsRwGNW1Mv1qhm3rOaCfdnS0zetpwaLaDLInPokPQ8ReDNTKTDcnVGYkv3dQVODwmWv79tfuFWqo12MvpLCQBAxL93YP+uxYCqOUXRoPerrU0kIFUAYFg4694tpAFz/8y8h8wnc24dwCr5nPxfQe3eDefmoC0wPYC6+sYQ+q9nc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617875082; h=Content-Type:Content-Transfer-Encoding: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=PEcKC2Yko0rz3J3ciQK5MVymGM2xuxXf9mgN9ZYEUaE=; b=SYVFBVzAhZF/hU7mg0eufmoNHiK0g3LAiZPV85XmRZ7GY6frLTA/cGl2dnpSns+GP4GwBjjY98FrG7V9imApAjHfzt9yfvpTspTA0qi6UTixpyu3PO/olELmPh9VBtj0YktCBDFsfzwkhetDajKdFH6Ov27paBJa0KYLCG0TidQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161787508230986.97653124025919; Thu, 8 Apr 2021 02:44:42 -0700 (PDT) Received: from localhost ([::1]:59736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lURDM-0002wA-NA for importer@patchew.org; Thu, 08 Apr 2021 05:44:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7j-0006hS-3y for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7g-0004NG-L4 for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:50 -0400 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-409-g8Oj3hVpNnOH9ISDabVC2Q-1; Thu, 08 Apr 2021 05:38:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B7EAC7403 for ; Thu, 8 Apr 2021 09:38:45 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-72.pek2.redhat.com [10.72.13.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED6865D9DC; Thu, 8 Apr 2021 09:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617874727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PEcKC2Yko0rz3J3ciQK5MVymGM2xuxXf9mgN9ZYEUaE=; b=YvZP6Jy/XJxh5Pf/OwzoWCWSU4UYj/acYy2sawxFH8h3wBJlNsIwPxynDrr9e+ltGQw+3h ueSeCs6Z+4+wNL5CNDV5KMJrea4jjxAFqA3OiHsVN5esbUunMtW6Qy4gXoj1T6ndk2mw0o X/JMuEDMzVFWA2Lk7QLovGDsiaACeks= X-MC-Unique: g8Oj3hVpNnOH9ISDabVC2Q-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v5 4/6] vhost-vdpa: add support for configure interrupt Date: Thu, 8 Apr 2021 17:38:22 +0800 Message-Id: <20210408093824.14985-5-lulu@redhat.com> In-Reply-To: <20210408093824.14985-1-lulu@redhat.com> References: <20210408093824.14985-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add support for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource Signed-off-by: Cindy Lu --- hw/virtio/vhost-vdpa.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 9ba2a2bed4..7825366f64 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -467,11 +467,33 @@ static int vhost_vdpa_get_config(struct vhost_dev *de= v, uint8_t *config, } return ret; } - +static void vhost_vdpa_config_notify_start(struct vhost_dev *dev, + struct VirtIODevice *vdev, bool start) +{ + int fd =3D 0; + int r =3D 0; + if (!(dev->features & (0x1ULL << VIRTIO_NET_F_STATUS))) { + return; + } + if (start) { + fd =3D event_notifier_get_fd(&vdev->config_notifier); + r =3D dev->vhost_ops->vhost_set_config_call(dev, &fd); + if (!r) { + vdev->use_config_notifier =3D true; + event_notifier_set(&vdev->config_notifier); + } + } else { + fd =3D -1; + vdev->use_config_notifier =3D false; + r =3D dev->vhost_ops->vhost_set_config_call(dev, &fd); + } + return; +} static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; trace_vhost_vdpa_dev_start(dev, started); + VirtIODevice *vdev =3D dev->vdev; if (started) { uint8_t status =3D 0; memory_listener_register(&v->listener, &address_space_memory); @@ -479,8 +501,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev,= bool started) vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); =20 + vhost_vdpa_config_notify_start(dev, vdev, true); return !(status & VIRTIO_CONFIG_S_DRIVER_OK); } else { + vhost_vdpa_config_notify_start(dev, vdev, false); vhost_vdpa_reset_device(dev); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); --=20 2.21.3 From nobody Sat Apr 20 01:09:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617875450; cv=none; d=zohomail.com; s=zohoarc; b=eitNKRqIKx93FuLI4WRTypzUvWEFR7khiQRSNW/sZmk/0C/gIU9+luNrUMHrw7uZamq9D+zYMakWN3HRJ1Kg82cbuBkYdVkLhc3VSGBdHyYbOyYgaGGxliLQhDI4ZTge29TuJUu56WaEKHgktMBXoemOVKztegYhoNG7eHWUivk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617875450; h=Content-Type:Content-Transfer-Encoding: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=X4395TULP4UEzOtfdoBXCLrd58NQvBygiKuU38WheVc=; b=Q9u2GZp67qqod0RbWCsGm8Qpek1V0zXjTTKSJrY+XeHwDvsfcCOPib55XYdqxbQfzUN05CHq09ZLtEaAl0qbIlvnZweaqMJBUyyvt9EG+68p3BNftSdAkS6qeWF2DxQkBGZKiwtbE0s+7lGj07ArAaW6GagLYjcwcZ6vMDTGWXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161787545021182.74563414048191; Thu, 8 Apr 2021 02:50:50 -0700 (PDT) Received: from localhost ([::1]:50342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lURJI-0002A8-RP for importer@patchew.org; Thu, 08 Apr 2021 05:50:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7o-0006r5-SL for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7i-0004OD-Pj for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:56 -0400 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-419-owKV9fKoPNGtJVTQ2TSSFw-1; Thu, 08 Apr 2021 05:38:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDEE7C7400 for ; Thu, 8 Apr 2021 09:38:47 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-72.pek2.redhat.com [10.72.13.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C8145D9DC; Thu, 8 Apr 2021 09:38:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617874730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X4395TULP4UEzOtfdoBXCLrd58NQvBygiKuU38WheVc=; b=LpDCKrl20mxQq7J+wPdPr5kp4PP5pGbnyt94SS20PFEcvTDDKnSuXwmV6TgP6OJejsE90i tJmBfkVezYv4nXI5ezbwsP0efl4uPbpj/fAY+Gs4FecPuAUxol4oq5jDzUfhYMmcob5RlM vGsf7DLiELiDUEC6VsR8U/7bHDACHCo= X-MC-Unique: owKV9fKoPNGtJVTQ2TSSFw-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v5 5/6] virtio-mmio: add support for configure interrupt Date: Thu, 8 Apr 2021 17:38:23 +0800 Message-Id: <20210408093824.14985-6-lulu@redhat.com> In-Reply-To: <20210408093824.14985-1-lulu@redhat.com> References: <20210408093824.14985-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" add configure interrupt support for virtio-mmio bus. This interrupt will working while backend is vhost-vdpa Signed-off-by: Cindy Lu --- hw/virtio/virtio-mmio.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 1aa1aaeca4..64b347421b 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -632,7 +632,26 @@ static int virtio_mmio_set_guest_notifier(DeviceState = *d, int n, bool assign, =20 return 0; } +static int virtio_mmio_set_config_notifier(DeviceState *d, bool assign) +{ + VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 + EventNotifier *notifier =3D virtio_get_config_notifier(vdev); + int r =3D 0; + if (assign) { + r =3D event_notifier_init(notifier, 0); + virtio_set_config_notifier_fd_handler(vdev, true, false); + } else { + virtio_set_config_notifier_fd_handler(vdev, false, false); + event_notifier_cleanup(notifier); + } + if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { + vdc->guest_notifier_mask(vdev, 0, !assign, VIRTIO_CONFIG_VECTO= R); + } + return r; +} static int virtio_mmio_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) { @@ -654,8 +673,15 @@ static int virtio_mmio_set_guest_notifiers(DeviceState= *d, int nvqs, goto assign_error; } } + r =3D virtio_mmio_set_config_notifier(d, assign); + if (r < 0) { + goto config_assign_error; + } =20 return 0; +config_assign_error: + assert(assign); + r =3D virtio_mmio_set_config_notifier(d, false); =20 assign_error: /* We get here on assignment failure. Recover by undoing for VQs 0 .. = n. */ --=20 2.21.3 From nobody Sat Apr 20 01:09:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617875249; cv=none; d=zohomail.com; s=zohoarc; b=A3mYc0W3+ONJudE0WlDwmITKM7ixzvjZWtsWncRBxYEflvLPoJNcYB7AN/LEHKmAIjJUFKuTCkE8ELifHdsFKX1zHOqUz48AyJsmIlOsGJKNA0qGfi1wKILKTncEjRnUSGFj/hGhKCvvNMVNE+rB4N0IzzMVXmf53ACDDbn2pas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617875249; h=Content-Type:Content-Transfer-Encoding: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=3D5QWsXrt8U2q7hGTy+r4bnjPeVicLH5vwZ7t4sdQw4=; b=niMT5cP7OLlFaZrs+uCQ1eKeaNGP57FpEIWkGP4JfALZu2/iknUivoKCjXkJ+i4qpqZqt7AbcZ7++Lps9w/tE7wEc9Mv2EFouB1XQ5TKR+Ld54COavl1M9BLNrtrUfIqhOzdAucb1V4zE5v3zU8tRhTk38DCVNzuUe5jRynfhig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617875249916727.0196178237337; Thu, 8 Apr 2021 02:47:29 -0700 (PDT) Received: from localhost ([::1]:40008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lURG4-0006Rj-GI for importer@patchew.org; Thu, 08 Apr 2021 05:47:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7r-0006wf-8q for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41195) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUR7p-0004Si-HN for qemu-devel@nongnu.org; Thu, 08 Apr 2021 05:38:59 -0400 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-351-LnEoei9lPOCk_OT3WNkxtw-1; Thu, 08 Apr 2021 05:38:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1EAF1006C87 for ; Thu, 8 Apr 2021 09:38:54 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-72.pek2.redhat.com [10.72.13.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AA825D9DC; Thu, 8 Apr 2021 09:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617874737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3D5QWsXrt8U2q7hGTy+r4bnjPeVicLH5vwZ7t4sdQw4=; b=FWoTSHrrTAV9NKb3oOvCv889z3U0HephAg7Gu+cBAd+UuRoNVz5kZvIJ6+zx39nymbUHQd CGrT6fY7ZUIedx2EzAZL6ptOmCJ9YqIJ3+9eufaiGV1PNua7rX3pEHs1Xc6vEqyY7i64O4 xzgvcO8b5Uf6QMcifT786vWLwtdqe00= X-MC-Unique: LnEoei9lPOCk_OT3WNkxtw-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v5 6/6] virtio-pci: add support for configure interrupt Date: Thu, 8 Apr 2021 17:38:24 +0800 Message-Id: <20210408093824.14985-7-lulu@redhat.com> In-Reply-To: <20210408093824.14985-1-lulu@redhat.com> References: <20210408093824.14985-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add support for configure interrupt, use kvm_irqfd_assign and set the gsi to kernel. When the configure notifier was eventfd_signal by host kernel, this will finally inject an msix interrupt to guest Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 91 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 481f6e7505..7b02f42c06 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -664,7 +664,6 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev, } =20 static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy, - unsigned int queue_no, unsigned int vector) { VirtIOIRQFD *irqfd =3D &proxy->vector_irqfd[vector]; @@ -726,7 +725,7 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *pr= oxy, int nvqs) if (vector >=3D msix_nr_vectors_allocated(dev)) { continue; } - ret =3D kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector); + ret =3D kvm_virtio_pci_vq_vector_use(proxy, vector); if (ret < 0) { goto undo; } @@ -760,6 +759,56 @@ undo: } return ret; } +static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy) +{ + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + unsigned int vector; + int ret; + EventNotifier *n =3D virtio_get_config_notifier(vdev); + vector =3D vdev->config_vector ; + ret =3D kvm_virtio_pci_vq_vector_use(proxy, vector); + if (ret < 0) { + goto undo; + } + ret =3D kvm_virtio_pci_irqfd_use(proxy, n, vector); + if (ret < 0) { + goto undo; + } + return 0; +undo: + kvm_virtio_pci_irqfd_release(proxy, n, vector); + return ret; +} +static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy) +{ + PCIDevice *dev =3D &proxy->pci_dev; + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + unsigned int vector; + EventNotifier *n =3D virtio_get_config_notifier(vdev); + vector =3D vdev->config_vector ; + if (vector >=3D msix_nr_vectors_allocated(dev)) { + return; + } + kvm_virtio_pci_irqfd_release(proxy, n, vector); + kvm_virtio_pci_vq_vector_release(proxy, vector); +} +static int virtio_pci_set_config_notifier(DeviceState *d, bool assign) +{ + VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + EventNotifier *notifier =3D virtio_get_config_notifier(vdev); + int r =3D 0; + if (assign) { + r =3D event_notifier_init(notifier, 0); + virtio_set_config_notifier_fd_handler(vdev, true, true); + kvm_virtio_pci_vector_config_use(proxy); + } else { + virtio_set_config_notifier_fd_handler(vdev, false, true); + kvm_virtio_pci_vector_config_release(proxy); + event_notifier_cleanup(notifier); + } + return r; +} =20 static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) { @@ -858,6 +907,14 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, un= signed vector, EventNotifier *n; int ret, index, unmasked =3D 0; =20 + if (vdev->use_config_notifier =3D=3D true) { + n =3D virtio_get_config_notifier(vdev); + ret =3D virtio_pci_vq_vector_unmask(proxy, 0, vector, msg, + VIRTIO_CONFIG_VECTOR, n); + if (ret < 0) { + goto config_undo; + } + } while (vq) { index =3D virtio_get_queue_index(vq); if (!virtio_queue_get_num(vdev, index)) { @@ -889,6 +946,10 @@ undo: } vq =3D virtio_vector_next_queue(vq); } + config_undo: + n =3D virtio_get_config_notifier(vdev); + virtio_pci_vq_vector_mask(proxy, 0, vector, + VIRTIO_CONFIG_VECTOR, n); return ret; } =20 @@ -900,6 +961,10 @@ static void virtio_pci_vector_mask(PCIDevice *dev, uns= igned vector) EventNotifier *n; int index; =20 + if (vdev->use_config_notifier =3D=3D true) { + n =3D virtio_get_config_notifier(vdev); + virtio_pci_vq_vector_mask(proxy, 0, vector, VIRTIO_CONFIG_VECTOR, = n); + } while (vq) { index =3D virtio_get_queue_index(vq); n =3D virtio_queue_get_guest_notifier(vq); @@ -945,6 +1010,21 @@ static void virtio_pci_vector_poll(PCIDevice *dev, msix_set_pending(dev, vector); } } + if (vdev->use_config_notifier =3D=3D true) { + vector =3D vdev->config_vector; + notifier =3D virtio_get_config_notifier(vdev); + if (vector < vector_start || vector >=3D vector_end || + !msix_is_masked(dev, vector)) { + return; + } + if (k->guest_notifier_pending) { + if (k->guest_notifier_pending(vdev, 0, VIRTIO_CONFIG_VECTOR))= { + msix_set_pending(dev, vector); + } + } else if (event_notifier_test_and_clear(notifier)) { + msix_set_pending(dev, vector); + } + } } =20 static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assig= n, @@ -1032,6 +1112,10 @@ static int virtio_pci_set_guest_notifiers(DeviceStat= e *d, int nvqs, bool assign) goto assign_error; } } + r =3D virtio_pci_set_config_notifier(d, assign); + if (r < 0) { + goto config_error; + } r =3D msix_set_vector_notifiers(&proxy->pci_dev, virtio_pci_vector_unmask, virtio_pci_vector_mask, @@ -1048,7 +1132,8 @@ notifiers_error: assert(assign); kvm_virtio_pci_vector_release(proxy, nvqs); } - + config_error: + kvm_virtio_pci_vector_config_release(proxy); assign_error: /* We get here on assignment failure. Recover by undoing for VQs 0 .. = n. */ assert(assign); --=20 2.21.3