From nobody Mon Feb 9 01:17:11 2026 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=1625556209; cv=none; d=zohomail.com; s=zohoarc; b=SQz825gczT5UP9dvKFtimshl020IHwckAz5OTcLCMQZq200yaYBsD2SoBF1emgsn+JEUBMpzRP7sF48DkfW6qafjcNoouuuuNX49iz8ipqEHJF0R26H/I92bclOAx6USf09d5v4RnG/+g8SpisNPsCgOT8ZMvNg7ZpnH+9jf2Y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556209; 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=txg9gBxweYaqQOs/PMaUQ8k7b338VhtiZsEXjFko1LU=; b=MB8Olk82oUYE7tDOoguiOKVJM3+OTH6azhR9hvVVolKilVHqtnTP+tYd4RM/cOeK1V8IIvXzcP2DN0RK4aEw3Af/xE1yDeA6xm/hfGDuy91ZWnrs+c91fUZZ7XgJi0pjvo5CeO+KZbPVSxaw8PK1maf1JGw8dsUXcF7E+c6j/Ng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625556209302640.014578442656; Tue, 6 Jul 2021 00:23:29 -0700 (PDT) Received: from localhost ([::1]:50588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fQW-0002zP-Aj for importer@patchew.org; Tue, 06 Jul 2021 03:23:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNp-0006Qk-5e for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40706) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNn-0003yI-8z for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:40 -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-425-UOrdpVwGNXeEiPbBXu7Mlg-1; Tue, 06 Jul 2021 03:20:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D32C510060E5 for ; Tue, 6 Jul 2021 07:20:36 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DDB05C1D0; Tue, 6 Jul 2021 07:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556038; 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=txg9gBxweYaqQOs/PMaUQ8k7b338VhtiZsEXjFko1LU=; b=CkFekHoUi46d/O+s++Er9+boBA+K0qgAmfyKaOAyfmBxqZHu/CcsVwXSeLnXs2TlzAQ864 +LuS4bpXhMU2mzNUPcqqp8NpYLT3rhAdj858dNz2oXcwkkMbbagojL9rcgs4c9T8Rido6q 7tI5Ao4elhDTIufZpGT+WQjQrEIupRc= X-MC-Unique: UOrdpVwGNXeEiPbBXu7Mlg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 1/9] virtio: introduce macro IRTIO_CONFIG_IRQ_IDX Date: Tue, 6 Jul 2021 15:20:22 +0800 Message-Id: <20210706072030.32365-2-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556212677100001 Content-Type: text/plain; charset="utf-8" In order to support configure interrupt for vhost-vdpa introduce VIRTIO_CONFIG_IRQ_IDX -1 as a queue index, then we can reuse the function guest_notifier_mask and guest_notifier_pending. we add the check of queue index, if the driver is not support configure interrupt, the function will just return Signed-off-by: Cindy Lu --- hw/display/vhost-user-gpu.c | 6 ++++++ hw/net/virtio-net.c | 10 +++++++--- hw/virtio/vhost-user-fs.c | 9 +++++++-- hw/virtio/vhost-vsock-common.c | 6 ++++++ hw/virtio/virtio-crypto.c | 6 ++++++ include/hw/virtio/virtio.h | 2 ++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 6cdaa1c73b..c232d55986 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -483,6 +483,9 @@ vhost_user_gpu_guest_notifier_pending(VirtIODevice *vde= v, int idx) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return false; + } return vhost_virtqueue_pending(&g->vhost->dev, idx); } =20 @@ -491,6 +494,9 @@ vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, = int idx, bool mask) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + 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 66b9ff4511..f50235b5d6 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3052,7 +3052,10 @@ static bool virtio_net_guest_notifier_pending(VirtIO= Device *vdev, int idx) 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 (idx !=3D VIRTIO_CONFIG_IRQ_IDX) { + 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, @@ -3061,8 +3064,9 @@ static void virtio_net_guest_notifier_mask(VirtIODevi= ce *vdev, int idx, 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 (idx !=3D VIRTIO_CONFIG_IRQ_IDX) { + 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/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 6f7f91533d..7e8ca25f71 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -156,11 +156,13 @@ static void vuf_handle_output(VirtIODevice *vdev, Vir= tQueue *vq) */ } =20 -static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, - bool mask) +static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return; + } vhost_virtqueue_mask(&fs->vhost_dev, vdev, idx, mask); } =20 @@ -168,6 +170,9 @@ static bool vuf_guest_notifier_pending(VirtIODevice *vd= ev, int idx) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + 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 4ad6e234ad..2112b44802 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -101,6 +101,9 @@ static void vhost_vsock_common_guest_notifier_mask(Virt= IODevice *vdev, int idx, { VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return; + } vhost_virtqueue_mask(&vvc->vhost_dev, vdev, idx, mask); } =20 @@ -109,6 +112,9 @@ static bool vhost_vsock_common_guest_notifier_pending(V= irtIODevice *vdev, { VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + 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..1d5192f8b4 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -948,6 +948,9 @@ static void virtio_crypto_guest_notifier_mask(VirtIODev= ice *vdev, int idx, =20 assert(vcrypto->vhost_started); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return; + } cryptodev_vhost_virtqueue_mask(vdev, queue, idx, mask); } =20 @@ -958,6 +961,9 @@ static bool virtio_crypto_guest_notifier_pending(VirtIO= Device *vdev, int idx) =20 assert(vcrypto->vhost_started); =20 + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return false; + } return cryptodev_vhost_virtqueue_pending(vdev, queue, idx); } =20 diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b7ece7a6a8..63cb9455ed 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -67,6 +67,8 @@ typedef struct VirtQueueElement =20 #define VIRTIO_NO_VECTOR 0xffff =20 +#define VIRTIO_CONFIG_IRQ_IDX -1 + #define TYPE_VIRTIO_DEVICE "virtio-device" OBJECT_DECLARE_TYPE(VirtIODevice, VirtioDeviceClass, VIRTIO_DEVICE) =20 --=20 2.21.3 From nobody Mon Feb 9 01:17:11 2026 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=1625556255; cv=none; d=zohomail.com; s=zohoarc; b=UKiHw3hR8NhlDH/lEyfBAjkhFEtKs5dShHPHpj+b0/H4fqAZ4u/gL8J2pM7V3I25mgfUZ82SLKKcCv6eX+1vB1AbTdeDBdqX2LZ4o8QJRwWU9azRZBlKzpMimM+hBlM2fWzmaarVPaYEI4uFUqAuH7PkorHb4HQ5VkdfG5oh+CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556255; 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=kTYqzuqUlw2ChN++K3OgvBbUG1krQ1JsIaU1D2UrdK8=; b=HBuVK/ReN9TTlE8OkNB0SxVR2WUcXgbBHwh9fksxJ1g2N0sdWRSUIyNoSed0+hgvByovZVJUnQj2CAFJ6Ga29dolbVuYxeaAZhVk6v1As0zmyICyxBIccGbDSqusg/A9QHhYCDCb+bASpzJZHkxNCtCUo6SB3lSKmS0edFi1FuQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625556254997255.50462914762238; Tue, 6 Jul 2021 00:24:14 -0700 (PDT) Received: from localhost ([::1]:54448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fRF-0005YW-Dv for importer@patchew.org; Tue, 06 Jul 2021 03:24:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNv-0006fK-34 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40104) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNt-00042I-6w for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20: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-207-e-g_DoWQMrqqu0fPtQn2Lg-1; Tue, 06 Jul 2021 03:20:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A5A21100C670 for ; Tue, 6 Jul 2021 07:20:42 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94A655C1D0; Tue, 6 Jul 2021 07:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556044; 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=kTYqzuqUlw2ChN++K3OgvBbUG1krQ1JsIaU1D2UrdK8=; b=DThCNmLqq9K+I+W3pxIh0nbo1ZEIUs5d9YlWJHep0ze3eL5GpMhU0XhyhVZBf4Aa47GJ7m yNhXogGEDK8hPR8F1dhrIfjtCOcf+tBou2ZVz8Orm5uSwaoPSo3PBCKxO8mVxmGHXRRwmo hAINHtQi42haQUQ9DWAQPt5JYD036j0= X-MC-Unique: e-g_DoWQMrqqu0fPtQn2Lg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 2/9] virtio-pci:decouple virtqueue from interrupt setting process Date: Tue, 6 Jul 2021 15:20:23 +0800 Message-Id: <20210706072030.32365-3-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556258602100001 Content-Type: text/plain; charset="utf-8" Decouple virtqueue from interrupt setting process to support config interru= pt Now the code for interrupt/vector are coupling with the vq number, this patch will decouple the vritqueue numbers from these functions Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 55 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b321604d9b..2fe5b1f5aa 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -693,23 +693,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 @@ -724,7 +718,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; @@ -741,7 +736,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; @@ -757,7 +754,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); } @@ -771,7 +770,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; @@ -784,21 +784,22 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIPr= oxy *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); } } =20 -static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy, +static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy, unsigned int queue_no, unsigned int vector, - MSIMessage msg) + MSIMessage msg, + 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 @@ -825,14 +826,15 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy= *proxy, 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, +static void virtio_pci_one_vector_mask(VirtIOPCIProxy *proxy, unsigned int queue_no, - unsigned int vector) + unsigned int vector, + EventNotifier *n) { VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); @@ -843,7 +845,7 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *p= roxy, if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { k->guest_notifier_mask(vdev, queue_no, true); } else { - kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); + kvm_virtio_pci_irqfd_release(proxy, n, vector); } } =20 @@ -853,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) { @@ -861,7 +864,8 @@ 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_one_vector_unmask(proxy, index, vector, msg= , n); if (ret < 0) { goto undo; } @@ -877,7 +881,8 @@ 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_one_vector_mask(proxy, index, vector, n); --unmasked; } vq =3D virtio_vector_next_queue(vq); @@ -890,15 +895,17 @@ 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_one_vector_mask(proxy, index, vector, n); } vq =3D virtio_vector_next_queue(vq); } --=20 2.21.3 From nobody Mon Feb 9 01:17:11 2026 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=1625556400; cv=none; d=zohomail.com; s=zohoarc; b=LndhwE8We4L7yBpmb+N5iI01ROQkQl7VQLbDc0efWAeTTxnfTqpumIOwqpb/j5RHxrwHLkq9/meB8E6LSclC6TE9fnbmoZ3ZbzyAhmfVXSmXkoVZxVyLR8UAX58UW0RnmyaD8cSgewFqELMWR9PE4irM4Wq5zAI8OmAvsO3JEhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556400; 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=XA8Q/0blJuFg7Ri16OWBojErzLPYGpJAKPjMN4f3h8c=; b=DknueylO6wvo5xyKNgSSoIlSCHvOlqM7BrY+sdMkGxB90oSRYFSwX+wrcj58x29tEpzx6jUBgHX63pZn+TvHuZ+C2+pz0vtA6d0VYkVkU96Kg45/DRhZBzzNFz2YjnVHN+L1JhHtiN2ozUvKq67LVwWTKXSWy7UzvNReTxbwnHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16255564005981023.5893509454613; Tue, 6 Jul 2021 00:26:40 -0700 (PDT) Received: from localhost ([::1]:60906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fTb-0001Y0-7h for importer@patchew.org; Tue, 06 Jul 2021 03:26:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNw-0006jO-Uh for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46834) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNv-00044B-Dq for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:48 -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-508-XyJueizkMZapLG6BSjlMDw-1; Tue, 06 Jul 2021 03:20:45 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3D4E100C666 for ; Tue, 6 Jul 2021 07:20:44 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 318A25C3E0; Tue, 6 Jul 2021 07:20:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556046; 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=XA8Q/0blJuFg7Ri16OWBojErzLPYGpJAKPjMN4f3h8c=; b=VGdQ3g4RMuz0g7pAscgihJFntnJsQYSNSy/hUYvr6VixxxSlIhzzqD355o7CNypaxC2k1k ycbhHifBHIpkJvtQECAd+7VI426DmlYULDVX3FNTIraEHn/wLQ8Vlzl1Y4zEOK1ihutjcA 2kwcGjz7/r1OlcrlLtbW92nEBRnK0JE= X-MC-Unique: XyJueizkMZapLG6BSjlMDw-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 3/9] vhost: add new call back function for config interrupt Date: Tue, 6 Jul 2021 15:20:24 +0800 Message-Id: <20210706072030.32365-4-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556404532100001 Content-Type: text/plain; charset="utf-8" To support configure interrupt, we need to add a new call back function for config interrupt. Signed-off-by: Cindy Lu Acked-by: Jason Wang --- include/hw/virtio/vhost-backend.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 8a6f8e2a7a..8ade8e0bd2 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 Mon Feb 9 01:17:11 2026 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=1625556137; cv=none; d=zohomail.com; s=zohoarc; b=G3+y/fZAxgxbbiTZbkqSYYe06k511TZoyqpMLIfX/0CmuYVG+DHhqOemZmOBgdNVTNr6h229dnEju312FSwffoEB1n/GGr+pIhtxTaJB/afHppMzCAWKNISwdfclqlFwTz446cHIVovFTAKAQLykqLNUzb4YFgls3+5+6RIppWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556137; 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=yDre0f3F0vl4QwFZ01Yhdqjr5hgSsuR7Jjs9M/CUJ/I=; b=dArSWrpccUQtxHt71jBmhnkebdDKO2bImKfDnsmOwQcSV6yTfGA+KJGGr5XXw4X1QQCsrNMP2UtbFoWQZAbBs8+HE8O5GLY66qGDq7q5dsFw83TEsfMI2338L72xA0ikOXxaqw9grbDvjjydZQPd/9z7HJnTt3CWBvujn7aax8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162555613762089.54839178192617; Tue, 6 Jul 2021 00:22:17 -0700 (PDT) Received: from localhost ([::1]:47742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fPM-00016L-FD for importer@patchew.org; Tue, 06 Jul 2021 03:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNz-0006qL-HV for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fNx-00045f-Q2 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:51 -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-213-HzP2FrfjPCCCBRMSW_dv0Q-1; Tue, 06 Jul 2021 03:20:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10A26100C667 for ; Tue, 6 Jul 2021 07:20:47 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 621605F714; Tue, 6 Jul 2021 07:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556049; 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=yDre0f3F0vl4QwFZ01Yhdqjr5hgSsuR7Jjs9M/CUJ/I=; b=Wt1C+21PvMoyfBouy+rDIry08uqFYKiUeAgXMITiMSzlkSjqc2/OIF4SiYwhhNNM8YcHiu WQ36h2+06ARmbzn99DPjMbkTx0RgBDHxUz9WFZmRwp+YqF13K+3QvPuFTgm5RqC70PE4kG bYCc74UsNlrO912H7ogaSauSWqYZnRA= X-MC-Unique: HzP2FrfjPCCCBRMSW_dv0Q-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 4/9] vhost-vdpa: add support for config interrupt call back Date: Tue, 6 Jul 2021 15:20:25 +0800 Message-Id: <20210706072030.32365-5-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556142357100002 Content-Type: text/plain; charset="utf-8" Add new call back function in vhost-vdpa, this call back function only supported in vhost-vdpa backend Signed-off-by: Cindy Lu Acked-by: Jason Wang --- hw/virtio/trace-events | 2 ++ hw/virtio/vhost-vdpa.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index c62727f879..152db5917d 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: %d" + =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..58075da9d9 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, }; --=20 2.21.3 From nobody Mon Feb 9 01:17:11 2026 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=1625556143; cv=none; d=zohomail.com; s=zohoarc; b=CKiLWhB6ny3YUWW6IskpgcvFNNNGEb+4Ip/rkt80ZnL5sxV2+TB4dtD4l5lUJnNxlOzZ/IkNTfWVmOZlK0QWx3duEoIzC8AdViw7ZKbkpN0Z6l4oPGpK1AeAk/NSAh0chxB0154liSun3xI8EmagrDvDpK0pkjwA9T2brdk+Paw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556143; 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=7Ucn0YtNhPI/nR/mKXayTZTffhWRtw/iMY6656SWtqk=; b=KVLaF0yJzcqN88JT0ylr0+uwSoj3swBkjtomvsF5R+DOeqOmK2xUgKBGtMxHRecAN6C4/U3ej/w6HwNfOO8n1GZaj8yNunL8IculZBBiJX8nvOQxjRkPzEXPO300wv2X4+TB7OmZXmoayvBsZJqUEp/yw4kkoX30KC7NARd0Mow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162555614353376.7955513701329; Tue, 6 Jul 2021 00:22:23 -0700 (PDT) Received: from localhost ([::1]:48184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fPR-0001OP-Up for importer@patchew.org; Tue, 06 Jul 2021 03:22:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO2-0006yo-DU for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO0-00047t-2H for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20: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-227-8_xJrDuSMkexT2rPYcoslA-1; Tue, 06 Jul 2021 03:20:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 418FF1005CBC for ; Tue, 6 Jul 2021 07:20:49 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9270F5C1D0; Tue, 6 Jul 2021 07:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556051; 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=7Ucn0YtNhPI/nR/mKXayTZTffhWRtw/iMY6656SWtqk=; b=C+blCbzqfivN+4BfzVv09bqBH9ju5WtRJ2m4YrUidNfdy9kbAOwsluz7NJj/hJW9jRd7xe rwsZCGBBBk7py1/sFn88H94rqW5sh/i0EZaS2ORM67/GrHZRVszWt6w0hDiKvWTvEX2ZIl e5hDVgKM+2DwEVcqtBWI3Kz8cSNrWLM= X-MC-Unique: 8_xJrDuSMkexT2rPYcoslA-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 5/9] vhost-net:add support for configure interrupt Date: Tue, 6 Jul 2021 15:20:26 +0800 Message-Id: <20210706072030.32365-6-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556148666100001 Content-Type: text/plain; charset="utf-8" Add configure notifier support in vhost and virtio driver When backend support VIRTIO_NET_F_STATUS,setup the configure interrupt function in vhost_net_start and release the related resource when vhost_net_stop Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 36 +++++++++++++++++++++++++++++++ hw/net/virtio-net.c | 6 ++++++ hw/virtio/vhost.c | 44 ++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio.c | 33 ++++++++++++++++++++++++++-- include/hw/virtio/vhost.h | 2 ++ include/hw/virtio/virtio.h | 5 +++++ include/net/vhost_net.h | 3 +++ 7 files changed, 127 insertions(+), 2 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 24d555e764..be453717c4 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -310,6 +310,31 @@ static void vhost_net_stop_one(struct vhost_net *net, vhost_dev_disable_notifiers(&net->dev, dev); } =20 +static void vhost_net_stop_config_intr(struct vhost_net *net) +{ + struct vhost_dev *dev =3D &net->dev; + if (dev->features & (0x1ULL << VIRTIO_NET_F_STATUS)) { + if (dev->vhost_ops->vhost_set_config_call) { + int fd =3D -1; + dev->vhost_ops->vhost_set_config_call(dev, fd); + } + } +} + +static void vhost_net_start_config_intr(struct vhost_net *net) +{ + struct vhost_dev *dev =3D &net->dev; + if (!(dev->features & (0x1ULL << VIRTIO_NET_F_STATUS))) { + return; + } + if (dev->vhost_ops->vhost_set_config_call) { + int fd =3D event_notifier_get_fd(&dev->vdev->config_notifier); + int r =3D dev->vhost_ops->vhost_set_config_call(dev, fd); + if (!r) { + event_notifier_set(&dev->vdev->config_notifier); + } + } +} int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues) { @@ -364,6 +389,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, } } =20 + vhost_net_start_config_intr(get_vhost_net(ncs[0].peer)); return 0; =20 err_start: @@ -397,6 +423,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *= ncs, fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r); fflush(stderr); } + vhost_net_stop_config_intr(get_vhost_net(ncs[0].peer)); assert(r >=3D 0); } =20 @@ -426,6 +453,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 f50235b5d6..02033be748 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3055,6 +3055,9 @@ static bool virtio_net_guest_notifier_pending(VirtIOD= evice *vdev, int idx) if (idx !=3D VIRTIO_CONFIG_IRQ_IDX) { return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx); } + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return vhost_net_config_pending(get_vhost_net(nc->peer), idx); + } return false; } =20 @@ -3067,6 +3070,9 @@ static void virtio_net_guest_notifier_mask(VirtIODevi= ce *vdev, int idx, if (idx !=3D VIRTIO_CONFIG_IRQ_IDX) { vhost_net_virtqueue_mask(get_vhost_net(nc->peer), vdev, idx, mask); } + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + 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 e2163a0d63..6716109448 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1505,6 +1505,16 @@ 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) +{ + assert(hdev->vhost_ops); + VirtIODevice *vdev =3D hdev->vdev; + if ((hdev->started =3D=3D false) || + (hdev->vhost_ops->vhost_set_config_call =3D=3D NULL)) { + return false; + } + return event_notifier_test_and_clear(&vdev->masked_config_notifier); +} /* Mask/unmask events from this vq. */ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int = n, bool mask) @@ -1529,6 +1539,30 @@ 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 &vdev->masked_config_notifier; + EventNotifier *config_notifier =3D &vdev->config_notifier; + assert(hdev->vhost_ops); + + if ((hdev->started =3D=3D false) || + (hdev->vhost_ops->vhost_set_config_call =3D=3D NULL)) { + return ; + } + 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) { + VHOST_OPS_DEBUG("vhost_set_config_call failed"); + } +} =20 uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bit= s, uint64_t features) @@ -1740,6 +1774,14 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) } } =20 + r =3D event_notifier_init(&vdev->masked_config_notifier, 0); + if (r < 0) { + return r; + } + event_notifier_test_and_clear(&vdev->masked_config_notifier); + if (!vdev->use_guest_notifier_mask) { + vhost_config_mask(hdev, vdev, true); + } if (hdev->log_enabled) { uint64_t log_base; =20 @@ -1798,6 +1840,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODev= ice *vdev) =20 /* should only be called after backend is connected */ assert(hdev->vhost_ops); + event_notifier_test_and_clear(&vdev->masked_config_notifier); + event_notifier_test_and_clear(&vdev->config_notifier); =20 if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 07f4e60b30..dbd2e36403 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3504,10 +3504,18 @@ static void virtio_queue_guest_notifier_read(EventN= otifier *n) virtio_irq(vq); } } +static void virtio_config_read(EventNotifier *n) +{ + VirtIODevice *vdev =3D container_of(n, VirtIODevice, config_notifier); =20 + 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) { + if (assign && !with_irqfd) { event_notifier_set_handler(&vq->guest_notifier, virtio_queue_guest_notifier_read); @@ -3515,12 +3523,29 @@ void virtio_queue_set_guest_notifier_fd_handler(Vir= tQueue *vq, bool assign, event_notifier_set_handler(&vq->guest_notifier, NULL); } if (!assign) { - /* Test and clear notifier before closing it, - * in case poll callback didn't have time to run. */ + /* Test and clear notifier before closing it,*/ + /* in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read(&vq->guest_notifier); } } =20 +void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign, + bool with_irqfd) +{ + EventNotifier *n; + n =3D &vdev->config_notifier; + if (assign && !with_irqfd) { + event_notifier_set_handler(n, virtio_config_read); + } else { + event_notifier_set_handler(n, NULL); + } + if (!assign) { + /* Test and clear notifier before closing it,*/ + /* in case poll callback didn't have time to run. */ + virtio_config_read(n); + } +} + EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { return &vq->guest_notifier; @@ -3594,6 +3619,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..b8814ece32 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -108,6 +108,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 ma= sk); =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 63cb9455ed..3bfd0692a4 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -110,6 +110,8 @@ struct VirtIODevice bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; + EventNotifier config_notifier; + EventNotifier masked_config_notifier; }; =20 struct VirtioDeviceClass { @@ -312,11 +314,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 assig= n, + 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 Mon Feb 9 01:17:11 2026 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=1625556325; cv=none; d=zohomail.com; s=zohoarc; b=MstEzYXVPFxkfitU7e2mv11AfniOPi8Amu3Q8z5WLbJcZHcvI3l/JeWEucCiQQDpZwYUuzw5B12hd57Hrrylpu8I+N8i18dHwNEw+0iwhyDntagpH+0FQIO6f2ysVqGtGqAq6dh1NpfTIIWT3rZiQpWAYGebdVhoPn61ueR7BL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556325; 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=fy6522q5S/GG4Oyu6DxhZ6NHSexA0c5icv6boj5RfCY=; b=CrOIps87jY9kM+0cB1sosD0IC80P1OIEc4H9slLl11dlLHrnLVzVi3XEoyHvAIcxJmN9+oyWwHrhTcbr8TDeoVfRC/eOAEtLhXnRFQLhXYYbjci+PAQb2F0zjuSdkw1s9g07Q2n8IR18Vzc5vSG9phG23wclvTz6uRmETnbZAew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625556325130473.9095359312448; Tue, 6 Jul 2021 00:25:25 -0700 (PDT) Received: from localhost ([::1]:57532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fSO-0007cK-5W for importer@patchew.org; Tue, 06 Jul 2021 03:25:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO3-00072x-NG for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53995) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO1-00048r-Sk for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:55 -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-585-CgaVFZMTNjep14As4oCZPQ-1; Tue, 06 Jul 2021 03:20:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 71FD356C35 for ; Tue, 6 Jul 2021 07:20:51 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id C375D5C1D0; Tue, 6 Jul 2021 07:20:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556053; 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=fy6522q5S/GG4Oyu6DxhZ6NHSexA0c5icv6boj5RfCY=; b=U34omFyyKApEIh69rG64FkbIwImXRn7m8EUbAPZP7snv9FcJY/6Wpo+Jr6jNj0vYSSY/F8 zBzSx4XC7RUnXU7cGZfUDG8fzXSg+yl6/TYTnR3TOWXi3WLseII7Kx/qfCfqPiZxyeB1YY NnpMBJKmlbcyjK0n8DE937Fz3gbRLfE= X-MC-Unique: CgaVFZMTNjep14As4oCZPQ-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 6/9] virtio-mmio: add support for configure interrupt Date: Tue, 6 Jul 2021 15:20:27 +0800 Message-Id: <20210706072030.32365-7-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556330642100001 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 342c918ea7..6c786db071 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -670,7 +670,29 @@ 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); + if (r < 0) { + return r; + } + 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, VIRTIO_CONFIG_IRQ_IDX, !assign); + } + return r; +} static int virtio_mmio_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) { @@ -692,6 +714,10 @@ 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 assign_error; + } =20 return 0; =20 --=20 2.21.3 From nobody Mon Feb 9 01:17:11 2026 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=1625556284; cv=none; d=zohomail.com; s=zohoarc; b=f+ke6i79/I7fZeDE+LfkHCVe8AYLxH2gw6oq+UXT0E9TRpTyQRIAY6DKU1M0gxllQ3GagXucttMUuoo+CwLYpfiQj4gS8XEivY9OBoZsGR9fCMtyaO7oSZyWfb2jDqRwofJ+pRjbirYY2gZ1rBr3W0IOWi76JMFL6ZKYKwOSxCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556284; 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=7nYgg4DsuLMUPXRxb1WtLSP8ebl8wKifegdSqR8fZmU=; b=PZA9loiwb/FfaKcnPkZPyVh03Xg+3Q0y3u/lce8xMTft0fy7RS3ReOJ0WGDSMpj9syypyNSIGL1J9CeBBM/o6KRuPGYVMwzJ4zyhFTlDOPgnednF+2ZtS5pB/HK5xz05T2ysNx77zqtx2dXJC9DJL7KZjX/OJA1JzQX24eqMLU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625556284409713.9882578528338; Tue, 6 Jul 2021 00:24:44 -0700 (PDT) Received: from localhost ([::1]:55530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fRj-0006HX-6e for importer@patchew.org; Tue, 06 Jul 2021 03:24:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO6-0007F0-VE for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35141) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO5-0004Az-2Z for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:20:58 -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-190-1tH-yPj_PQOHlA00lcoeGg-1; Tue, 06 Jul 2021 03:20:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1E815700F for ; Tue, 6 Jul 2021 07:20:54 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3AC15C22A; Tue, 6 Jul 2021 07:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556056; 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=7nYgg4DsuLMUPXRxb1WtLSP8ebl8wKifegdSqR8fZmU=; b=FGx1FKcLtdHefKSel0twaJ6O62CDPjzHBDCOIJkotFFK0wg4hOqNkiKa6cyCZsyeD11yq5 THlNnzMbOCOMMcFlgtIqOAk4/bB5CW5iAVxt9JAArsP3F2tA3RYZ7WojJHIDo3w84admbL /3f9x2vODjufojIwTvJK2aKfGyPVobk= X-MC-Unique: 1tH-yPj_PQOHlA00lcoeGg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 7/9] virtio-pci: decouple notifier from interrupt process Date: Tue, 6 Jul 2021 15:20:28 +0800 Message-Id: <20210706072030.32365-8-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556290122100001 Content-Type: text/plain; charset="utf-8" use the virtio_pci_get_notifier function to get the notifer, the input of the function will is the idx, the output is notifier and vector Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 45 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 2fe5b1f5aa..fe06847b62 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -710,6 +710,28 @@ static void kvm_virtio_pci_irqfd_release(VirtIOPCIProx= y *proxy, ret =3D kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->vir= q); assert(ret =3D=3D 0); } +static int virtio_pci_get_notifier(VirtIOPCIProxy *proxy, int queue_no, + EventNotifier **n, unsigned int *vec= tor) +{ + PCIDevice *dev =3D &proxy->pci_dev; + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + VirtQueue *vq; + + if (queue_no =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return -1; + } else { + if (!virtio_queue_get_num(vdev, queue_no)) { + return -1; + } + *vector =3D virtio_queue_vector(vdev, queue_no); + vq =3D virtio_get_queue(vdev, queue_no); + *n =3D virtio_queue_get_guest_notifier(vq); + } + if (*vector >=3D msix_nr_vectors_allocated(dev)) { + return -1; + } + return 0; +} =20 static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) { @@ -718,13 +740,15 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *= proxy, 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; } - vector =3D virtio_queue_vector(vdev, queue_no); + ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); + if (ret < 0) { + break; + } if (vector >=3D msix_nr_vectors_allocated(dev)) { continue; } @@ -736,8 +760,6 @@ 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) { - 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); @@ -754,8 +776,10 @@ undo: continue; } if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - vq =3D virtio_get_queue(vdev, queue_no); - n =3D virtio_queue_get_guest_notifier(vq); + ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); + if (ret < 0) { + break; + } kvm_virtio_pci_irqfd_release(proxy, n, vector); } kvm_virtio_pci_vq_vector_release(proxy, vector); @@ -770,13 +794,16 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIPr= oxy *proxy, int nvqs) unsigned int vector; int queue_no; VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq; EventNotifier *n; + int ret ; for (queue_no =3D 0; queue_no < nvqs; queue_no++) { if (!virtio_queue_get_num(vdev, queue_no)) { break; } - vector =3D virtio_queue_vector(vdev, queue_no); + ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); + if (ret < 0) { + break; + } if (vector >=3D msix_nr_vectors_allocated(dev)) { continue; } @@ -784,8 +811,6 @@ 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) { - 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); --=20 2.21.3 From nobody Mon Feb 9 01:17:11 2026 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=1625556445; cv=none; d=zohomail.com; s=zohoarc; b=JXkyUtu0x3ZvaxiTEcH5ROwJThqYbsSIqkF9FBzM2eWtpT4vsffM/yPrP2Guyt/Fwj0NDDXgYl4tgJlpylghAYSDawfBO440rKYMUFkD+oKSPNG/5OS3SUUiJF+Nbf61h84672eHENZ5ly62fhCX9JpXCOZVRUlRrGFOeKSXVdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556445; 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=4TdXoAjw1xd55pOqnKjw+CiAKzJsT/Bd04rkR3lpyf8=; b=lqWDnDAqAFyI9nQs600ZuYRb2YXf1Lv6DeW+1suC3Va1g6Jwv+zc1RNYcPxPnQIf3vmLUQOwty/hL1i1wN4LkFC2RUf5HWL+v/lLRiU39NEuZgFm0GHPp8aTInJyXl7fIkCQcshL753oAZTLKzqMtPA7e5ecl9akzjZh+FeRnTM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625556445872636.2746530105067; Tue, 6 Jul 2021 00:27:25 -0700 (PDT) Received: from localhost ([::1]:35770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fUK-0003ZL-P8 for importer@patchew.org; Tue, 06 Jul 2021 03:27:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO9-0007Mf-DX for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:21:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fO7-0004DQ-Da for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:21:01 -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-173-4JvNS0ysMe-mFR_yIJ9kXg-1; Tue, 06 Jul 2021 03:20:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3A9B8015C6 for ; Tue, 6 Jul 2021 07:20:56 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F9D05C1D0; Tue, 6 Jul 2021 07:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556058; 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=4TdXoAjw1xd55pOqnKjw+CiAKzJsT/Bd04rkR3lpyf8=; b=KMTUflYcZJjUV2K2UnNAVdCfK8IYNZ8qUIt7tALUnK6MhAqKAWXgI5njXyqOewvjtzs1Lr eR8YeSIEstvE6lE1YRHGeHKFbZHO6d+0CXzIgdZo2KASm7ZKgWNosumEdSpLITqQgg+p98 OD/NnvuNfb39OQqdlLYtc62XUdXyU8o= X-MC-Unique: 4JvNS0ysMe-mFR_yIJ9kXg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 8/9] virtio-pci:decouple the single vector from the interrupt process Date: Tue, 6 Jul 2021 15:20:29 +0800 Message-Id: <20210706072030.32365-9-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556449862100001 Content-Type: text/plain; charset="utf-8" use the kvm_virtio_pci_vector_use_one and _release_one these funtion is to deal with the single vector, the whole process will finish in a loop with vq number. Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 109 ++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 67 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index fe06847b62..e43d5760ee 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -666,7 +666,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]; @@ -733,87 +732,63 @@ static int virtio_pci_get_notifier(VirtIOPCIProxy *pr= oxy, int queue_no, return 0; } =20 -static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) +static int kvm_virtio_pci_vector_use_one(VirtIOPCIProxy *proxy, int queue_= no) { - PCIDevice *dev =3D &proxy->pci_dev; - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); unsigned int vector; - int ret, queue_no; + int ret; EventNotifier *n; - for (queue_no =3D 0; queue_no < nvqs; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; - } - ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); - if (ret < 0) { - break; - } - if (vector >=3D msix_nr_vectors_allocated(dev)) { - continue; - } - ret =3D kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector); - if (ret < 0) { - goto undo; - } - /* If guest supports masking, set up irqfd now. - * 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, n, vector); - if (ret < 0) { - kvm_virtio_pci_vq_vector_release(proxy, vector); - goto undo; - } - } + ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); + if (ret < 0) { + return ret; + } + 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: - while (--queue_no >=3D 0) { - vector =3D virtio_queue_vector(vdev, queue_no); - if (vector >=3D msix_nr_vectors_allocated(dev)) { - continue; - } - if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { - ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); - if (ret < 0) { - break; - } - kvm_virtio_pci_irqfd_release(proxy, n, vector); - } - kvm_virtio_pci_vq_vector_release(proxy, vector); + kvm_virtio_pci_irqfd_release(proxy, n, vector); + return ret; +} +static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) +{ + int queue_no; + int ret =3D 0; + for (queue_no =3D 0; queue_no < nvqs; queue_no++) { + ret =3D kvm_virtio_pci_vector_use_one(proxy, queue_no); } return ret; } =20 -static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) + +static void kvm_virtio_pci_vector_release_one(VirtIOPCIProxy *proxy, + int queue_no) { - PCIDevice *dev =3D &proxy->pci_dev; VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); unsigned int vector; - int queue_no; - VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); EventNotifier *n; - int ret ; + int ret; + VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); + ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); + if (ret < 0) { + return; + } + + if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { + kvm_virtio_pci_irqfd_release(proxy, n, vector); + } + kvm_virtio_pci_vq_vector_release(proxy, vector); +} +static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) +{ + int queue_no; + for (queue_no =3D 0; queue_no < nvqs; queue_no++) { - if (!virtio_queue_get_num(vdev, queue_no)) { - break; - } - ret =3D virtio_pci_get_notifier(proxy, queue_no, &n, &vector); - if (ret < 0) { - break; - } - if (vector >=3D msix_nr_vectors_allocated(dev)) { - continue; - } - /* If guest supports masking, clean up irqfd now. - * 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, n, vector); - } - kvm_virtio_pci_vq_vector_release(proxy, vector); + kvm_virtio_pci_vector_release_one(proxy, queue_no); } } =20 --=20 2.21.3 From nobody Mon Feb 9 01:17:11 2026 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=1625556416; cv=none; d=zohomail.com; s=zohoarc; b=GYav1TLzQB+MO5qtLxcka+hin2yjYEUEzkww+j//XPJJhDZxYdEnJ+5APS0sMp4aDWmeETUp8c58lWrrcGfQ2lwigE0JCrMxz5JNqhFsmLdh/7BmgUcFnBvRUVTt+YAc78bqx+Ka9GTHTGoWx4vAHBGrJo5N3kQZsIycXHGS33U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625556416; 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=H31IeVfivtg7TVCu/QypNCAglN1wFxPXF+cnDjYjwbY=; b=BdaqcO1HzY2bqopw7PDeNfhh7XuUUUoLJ8rWrN9NRgmeSwEAmHJibB0ujjAkHQrA1SWD+syVuLgpRcVWdkpskfKkCJHYTtPhmDO0fV7MYhfbYhh/TeQ3hbMtNsJhIw+l8/eY3saM1a/bW+++uXz8y/zeW3fLTCft+O+2GIo/hsw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625556416317237.7325696228737; Tue, 6 Jul 2021 00:26:56 -0700 (PDT) Received: from localhost ([::1]:33822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0fTq-0002IG-53 for importer@patchew.org; Tue, 06 Jul 2021 03:26:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fOL-0007y9-IU for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:21:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0fOJ-0004ND-JU for qemu-devel@nongnu.org; Tue, 06 Jul 2021 03:21:13 -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-139-JRuFduADNO-aeT4NHtPjZw-1; Tue, 06 Jul 2021 03:21:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69B9A192CC4F for ; Tue, 6 Jul 2021 07:21:08 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-123.pek2.redhat.com [10.72.13.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 617605C1D0; Tue, 6 Jul 2021 07:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625556071; 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=H31IeVfivtg7TVCu/QypNCAglN1wFxPXF+cnDjYjwbY=; b=BJiJK+zDOX2OY4GqvP9rIqaOewHOhJaAMEGpowyZqPaR3wJveZJJjuw/CkQLB/lRQrVfLr hNBWF7P2dGz1PEfh82lFqhaP8J5cMzbLbtBS/rif3mJR8yOpgOsMFTWeaWHywREhNyliUR xycPYmjjA3DnJyqLT2Hr5uWE4+EoTlY= X-MC-Unique: JRuFduADNO-aeT4NHtPjZw-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v8 9/9] virtio-pci: add support for configure interrupt Date: Tue, 6 Jul 2021 15:20:30 +0800 Message-Id: <20210706072030.32365-10-lulu@redhat.com> In-Reply-To: <20210706072030.32365-1-lulu@redhat.com> References: <20210706072030.32365-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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) X-ZM-MESSAGEID: 1625556419878100001 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 | 60 +++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index e43d5760ee..73b5ffd1b8 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -717,7 +717,8 @@ static int virtio_pci_get_notifier(VirtIOPCIProxy *prox= y, int queue_no, VirtQueue *vq; =20 if (queue_no =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - return -1; + *n =3D virtio_get_config_notifier(vdev); + *vector =3D vdev->config_vector; } else { if (!virtio_queue_get_num(vdev, queue_no)) { return -1; @@ -764,6 +765,10 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *p= roxy, int nvqs) return ret; } =20 +static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy) +{ + return kvm_virtio_pci_vector_use_one(proxy, VIRTIO_CONFIG_IRQ_IDX); +} =20 static void kvm_virtio_pci_vector_release_one(VirtIOPCIProxy *proxy, int queue_no) @@ -792,6 +797,30 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIPro= xy *proxy, int nvqs) } } =20 +static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy) +{ + kvm_virtio_pci_vector_release_one(proxy, VIRTIO_CONFIG_IRQ_IDX); +} +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); + if (r < 0) { + return r; + } + 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; +} static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy, unsigned int queue_no, unsigned int vector, @@ -873,7 +902,12 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, un= signed vector, } vq =3D virtio_vector_next_queue(vq); } - + n =3D virtio_get_config_notifier(vdev); + ret =3D virtio_pci_one_vector_unmask(proxy, VIRTIO_CONFIG_IRQ_IDX, + vector, msg, n); + if (ret < 0) { + goto undo; + } return 0; =20 undo: @@ -909,6 +943,8 @@ static void virtio_pci_vector_mask(PCIDevice *dev, unsi= gned vector) } vq =3D virtio_vector_next_queue(vq); } + n =3D virtio_get_config_notifier(vdev); + virtio_pci_one_vector_mask(proxy, VIRTIO_CONFIG_IRQ_IDX, vector, n); } =20 static void virtio_pci_vector_poll(PCIDevice *dev, @@ -921,19 +957,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev, int queue_no; unsigned int vector; EventNotifier *notifier; - VirtQueue *vq; - - for (queue_no =3D 0; queue_no < proxy->nvqs_with_notifiers; queue_no++= ) { - if (!virtio_queue_get_num(vdev, queue_no)) { + int ret; + for (queue_no =3D VIRTIO_CONFIG_IRQ_IDX; + queue_no < proxy->nvqs_with_notifiers; queue_no++) { + ret =3D virtio_pci_get_notifier(proxy, queue_no, ¬ifier, &vecto= r); + if (ret < 0) { break; } - vector =3D virtio_queue_vector(vdev, queue_no); if (vector < vector_start || vector >=3D vector_end || !msix_is_masked(dev, vector)) { continue; } - 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)) { msix_set_pending(dev, vector); @@ -1002,6 +1036,7 @@ static int virtio_pci_set_guest_notifiers(DeviceState= *d, int nvqs, bool assign) msix_unset_vector_notifiers(&proxy->pci_dev); if (proxy->vector_irqfd) { kvm_virtio_pci_vector_release(proxy, nvqs); + kvm_virtio_pci_vector_config_release(proxy); g_free(proxy->vector_irqfd); proxy->vector_irqfd =3D NULL; } @@ -1029,6 +1064,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, @@ -1045,7 +1084,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