From nobody Tue May 21 03:53:11 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=1619494952; cv=none; d=zohomail.com; s=zohoarc; b=NlABklXp6F9kcmPfNywvAPj6jcg+lymbIud0F0uoQQlj7zk+JqF7AgSco4X8TF5wQC7ZZkDs1nbPAm0Oq6n7+XOHA6VL5Ufz0woAeF1ImwM6LE9rf7ksGj9vcp5UdqBj0cQy/5dFl+01n+D9Gzg8YXRqGPYP/kbov+tj236u4u0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619494952; 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=Q9+cvfM22Mwi6fpKnZdG+Ie0aZ0z7ddga4ndJn2CKYU=; b=Q+pG5nDkf3MKUD3dpPdDL25Z/l4qx2cz1LzFW38XIgd4pSg1dZl9TGTkSItVxwGNHoClw+9AXrFBSXRevkPkG6RfMLEZAidGuD4sg1hn4Ja3q6SNZu0e6crMws3WFNhoXuIssxkLNc0l9IFNeSRbgquJDk+0x7PJjsh8B8awqaQ= 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 1619494952653667.1768203327405; Mon, 26 Apr 2021 20:42:32 -0700 (PDT) Received: from localhost ([::1]:38346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEcJ-0007WB-Kq for importer@patchew.org; Mon, 26 Apr 2021 23:42:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaA-0005hC-0S for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEa7-0005xq-Q8 for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:17 -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-238-B24IUpsNONKoRKuVF3JBOw-1; Mon, 26 Apr 2021 23:40:11 -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 2DC4F343A9 for ; Tue, 27 Apr 2021 03:40:11 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 853A85D9C0; Tue, 27 Apr 2021 03:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494813; 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=Q9+cvfM22Mwi6fpKnZdG+Ie0aZ0z7ddga4ndJn2CKYU=; b=jCazy0aNV0murkTfKjKPV27K/NuOxSmrKlS+6ltmFWOEY5VZglnE2QceUmkRZESbKVtEuO a7wjGb0dY/JaUsMBEHxWl9vZCpacZ/1CzOXRWa7VQbcP67xKGmNj9d/z8yon/ERhrZ2JRi 5cMpPvneVCcVwzIU3+vcn5YProLFvYA= X-MC-Unique: B24IUpsNONKoRKuVF3JBOw-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 1/9] hw: Add check for queue number Date: Tue, 27 Apr 2021 11:39:43 +0800 Message-Id: <20210427033951.29805-2-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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" In order to support configure interrupt. we will use queue number -1 as configure interrupt since all these device are not support the configure interrupt So we will add an check here, if the idx is -1, the function will return; Signed-off-by: Cindy Lu --- hw/display/vhost-user-gpu.c | 8 ++++++-- hw/net/virtio-net.c | 10 +++++++--- hw/virtio/vhost-user-fs.c | 11 +++++++---- hw/virtio/vhost-vsock-common.c | 8 ++++++-- hw/virtio/virtio-crypto.c | 8 ++++++-- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 51f1747c4a..d8e26cedf1 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -490,7 +490,9 @@ static bool vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); - + if (idx =3D=3D -1) { + return false; + } return vhost_virtqueue_pending(&g->vhost->dev, idx); } =20 @@ -498,7 +500,9 @@ static void vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); - + if (idx =3D=3D -1) { + 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..78ccaa228c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3060,7 +3060,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 -1) { + 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, @@ -3069,8 +3072,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 -1) { + 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 1bc5d03a00..37424c2193 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -142,18 +142,21 @@ 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); - + if (idx =3D=3D -1) { + return; + } vhost_virtqueue_mask(&fs->vhost_dev, vdev, idx, mask); } =20 static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); - + if (idx =3D=3D -1) { + 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..0adf823d37 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -100,7 +100,9 @@ static void vhost_vsock_common_guest_notifier_mask(Virt= IODevice *vdev, int idx, bool mask) { VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); - + if (idx =3D=3D -1) { + return; + } vhost_virtqueue_mask(&vvc->vhost_dev, vdev, idx, mask); } =20 @@ -108,7 +110,9 @@ static bool vhost_vsock_common_guest_notifier_pending(V= irtIODevice *vdev, int idx) { VHostVSockCommon *vvc =3D VHOST_VSOCK_COMMON(vdev); - + if (idx =3D=3D -1) { + 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..c47f4ffb24 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -947,7 +947,9 @@ static void virtio_crypto_guest_notifier_mask(VirtIODev= ice *vdev, int idx, int queue =3D virtio_crypto_vq2q(idx); =20 assert(vcrypto->vhost_started); - + if (idx =3D=3D -1) { + return; + } cryptodev_vhost_virtqueue_mask(vdev, queue, idx, mask); } =20 @@ -957,7 +959,9 @@ static bool virtio_crypto_guest_notifier_pending(VirtIO= Device *vdev, int idx) int queue =3D virtio_crypto_vq2q(idx); =20 assert(vcrypto->vhost_started); - + if (idx =3D=3D -1) { + return false; + } return cryptodev_vhost_virtqueue_pending(vdev, queue, idx); } =20 --=20 2.21.3 From nobody Tue May 21 03:53:11 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=1619495189; cv=none; d=zohomail.com; s=zohoarc; b=E7u7dL62TcdmAKUe/oJnY4ac9GiwykJ4i5J2AD7r8BOThFJWo4WA740wAD9S7oQ4HbCsydM4AyQYxrEDG69uiHCJl5WvIi2xHUymLwLjNY7GNfXMbtT4u48zlPPKU/IJSWREp2ULK4ursxPGd1VvTaWhI7a4BaVxuU76Dy/K/qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495189; 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=1OL/n0pLYq9wUlmwQh4p0kVlL8XMv96bTIa9P7VNsC4=; b=IZAc6lLGdN7xKldO3zjHlrDCRGwDCrq3P/a6Pau6ZEen5rwqDEvvIuERZBT4BGOEGT8c4hWi6/Rxg2Gl1HpkDidz+MMDLNDMseGI2ymH3mfCPnsAhAPtO7C3H5YSrNzEG7lHuXsvXS5ekTAZNJn3UMLMVyUFMxZvo8LIKAIs2kY= 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 1619495189664227.89430337296005; Mon, 26 Apr 2021 20:46:29 -0700 (PDT) Received: from localhost ([::1]:50650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEg7-00049D-Kn for importer@patchew.org; Mon, 26 Apr 2021 23:46:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaE-0005q7-2p for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaB-00061A-Us for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:21 -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-108-iDUVssmsMSiX1bsOaVADtg-1; Mon, 26 Apr 2021 23:40:17 -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 E62451007498 for ; Tue, 27 Apr 2021 03:40:16 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 486A35D9C0; Tue, 27 Apr 2021 03:40:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494819; 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=1OL/n0pLYq9wUlmwQh4p0kVlL8XMv96bTIa9P7VNsC4=; b=ebk7JFu9OJkMOYcSktAtTq2j8jZWF3LBuxML1Y/sIALtGfPpfooW+lxO/Am2GxZ+61jtrU GQXOGXwEMKe1l06FCyC4/g9AI781RiKdk1HY+8GmFUYFiKcSjmLn8yYLvFM+PkylJYnSNn d+SRIUKSpaSqatpffUF3AsT+Kf+Fz44= X-MC-Unique: iDUVssmsMSiX1bsOaVADtg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 2/9] virtio-pci:decouple virtqueue from interrupt setting process Date: Tue, 27 Apr 2021 11:39:44 +0800 Message-Id: <20210427033951.29805-3-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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" 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 | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 36524a5728..2b7e6cc0d9 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,11 @@ 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, + 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 @@ -823,14 +824,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, 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); @@ -841,7 +843,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 @@ -851,6 +853,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 +862,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_vq_vector_unmask(proxy, index, vector, msg,= n); if (ret < 0) { goto undo; } @@ -875,7 +879,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_vq_vector_mask(proxy, index, vector, n); --unmasked; } vq =3D virtio_vector_next_queue(vq); @@ -888,15 +893,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_vq_vector_mask(proxy, index, vector, n); } vq =3D virtio_vector_next_queue(vq); } --=20 2.21.3 From nobody Tue May 21 03:53:11 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=1619495196; cv=none; d=zohomail.com; s=zohoarc; b=G4rPcHoTma2BVpYw256XHS6zIi9tfcnNTTfHQiwyg3SlaZKBPHyfBxMmykS1v9ApSrh6BjTSPfEeN/wP8jh+7jJ4Qr1NipOKuXfSxL216zIAa4r9yBkXMmmf2W7PgtJRR8sMwUdt/hpr/pLdJ2dx0iIlBqLL+y9DUdr2WWU6Bpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495196; 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=kw6z1lUROEKfKAxyZ8WCWyKpnQI1wyMhijlHPO4FqJ0=; b=Y7+BzWSUx8z5xrjmnrYMWjHOOLvO+Eri2sShE/Rz4RS1HTOkxqIClUeGLEeTw/SjG+uMRZQyRxgx6qK5mUI5WrWby4jztLf76yuTJz4mdBhyepcWOm6JYMPaXmEeT9o8ufpLkCnYaiFrUah5MOlADNp38Hcv7xPCCTXUDvglTIo= 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 1619495196570276.9645248737464; Mon, 26 Apr 2021 20:46:36 -0700 (PDT) Received: from localhost ([::1]:51110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEgF-0004Kn-HM for importer@patchew.org; Mon, 26 Apr 2021 23:46:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaF-0005tX-NP for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaE-00061r-1V for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:23 -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-376-CNJWpmAfPdSyUrjlousmjA-1; Mon, 26 Apr 2021 23:40:19 -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 1A731107ACCA for ; Tue, 27 Apr 2021 03:40:19 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 714D45D9C0; Tue, 27 Apr 2021 03:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494821; 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=kw6z1lUROEKfKAxyZ8WCWyKpnQI1wyMhijlHPO4FqJ0=; b=XZTQ12KCehGZDkb1W9KnQROMUNGEJM7TsiInR52kvDjBCki1ePgAe4RfjPmGKOtmWCRd7e Mp/V6BaICh0ystP5o3ssYZcyKiFchOcTAFbcmCorwixT7gaDz5OEvs3hhY4nxu2qpbzuwf aY0hFqUwm1bXL0CmZBsJpqFctiTRNMc= X-MC-Unique: CNJWpmAfPdSyUrjlousmjA-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 3/9] vhost: add new call back function for config interrupt Date: Tue, 27 Apr 2021 11:39:45 +0800 Message-Id: <20210427033951.29805-4-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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 a new call back function for config interrupt. Signed-off-by: Cindy Lu --- 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..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 Tue May 21 03:53:11 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=1619495279; cv=none; d=zohomail.com; s=zohoarc; b=NkZ2wQVrG3XxHYC8u9xOSGFCUffRQ1QWQib5ELaKVW99gxWJ4PRp//NoX9tO1wjclE8mGUoC77YgXe+E0c2Ql8L7Z1dtffCFxaF37n1O/zUoo6idF6XXJZvmB2NuxJKSVEDPzltvEYWh9el3MaMwz7e/liX1RNX8KIPrSmz40V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495279; 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=mWRR2KkP/ABIKUt/5lJPeJ1u8uEGOtxaFelo8I9Im98=; b=GYFp75D0ZQ1oir0Mz1XEcziApPk49IEN9RRL0OkQgAatxxcn6EHYZH3eBDvIi0o6kkOXvgouFFHOK1cX81y/uvPJCeDss929YBWXde/04WoofVejkBp0lojM0BYx3nZg7q+xIVrWn5/xoQFvbWUG7l/A/JVD4v8cL6BA6I/zkoI= 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 1619495279544916.2892279004798; Mon, 26 Apr 2021 20:47:59 -0700 (PDT) Received: from localhost ([::1]:55432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEha-00064Z-Ib for importer@patchew.org; Mon, 26 Apr 2021 23:47:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaM-00062U-Qu for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaK-00065F-QM for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:30 -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-573-GrEtp1qLOwW11XU7t7cDsg-1; Mon, 26 Apr 2021 23:40:25 -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 6B72A1007464 for ; Tue, 27 Apr 2021 03:40:24 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 993305D9C0; Tue, 27 Apr 2021 03:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494827; 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=mWRR2KkP/ABIKUt/5lJPeJ1u8uEGOtxaFelo8I9Im98=; b=L9ggglvHOTdZXduFb89b3n9RlMfPbUge9b1qWocVWwvSzSuNJUM18YaXycY5AwFJKgD4sQ lB14WjjfhNnasTjK6+A7tekS4jfio3IiIBfLy/4u98AO5HlV+3uEHnoM69vt3gReAr36yn mz+9wmFgXU1vhUGesmCr0EneRxMKtgE= X-MC-Unique: GrEtp1qLOwW11XU7t7cDsg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 4/9] vhost-vdpa: add support for config interrupt call back Date: Tue, 27 Apr 2021 11:39:46 +0800 Message-Id: <20210427033951.29805-5-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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 new call back function in vhost-vdpa, this call back function only supported in vhost-vdpa backend Signed-off-by: Cindy Lu --- 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 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, }; --=20 2.21.3 From nobody Tue May 21 03:53:11 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=1619495429; cv=none; d=zohomail.com; s=zohoarc; b=PdR+j0D/OYMz/6U+zsp5T/3sUAh27ttq4k5c/M5M2zDmq7tSgbxsV3txEdOzVNAGDbQS5TvRkZNSmPOZ/JYZu7fyMcyGQndgyGk0A2LKXXNtiziHE63ci02eSqRr/hifT8zilFg9MZuUbfsssOvqtOzyFA0vVUN8qY4OaIqtUqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495429; 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=7Z5RaOlD7rdX4XROV7V3gHNn51grnFQ52zIxx1WTXlA=; b=gDHo2+lxD7UeFwFBjrKePP0v95vOM1/AcCjthP9vw1VMSoKuRUeoTQevOfmvbAwvHHrP7F91kcTulezBR+doN53BC5DCraVPtwvCaV1EmgXhYB4GBR/+wuoDUI9NmxKKkZaoVpUQtdex5N6HL8P4miqyzpNkjR1CP3l++VkhXNM= 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 1619495429390545.844633735151; Mon, 26 Apr 2021 20:50:29 -0700 (PDT) Received: from localhost ([::1]:60226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEk0-00081H-C8 for importer@patchew.org; Mon, 26 Apr 2021 23:50:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaQ-00065G-BM for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaL-00065K-RX for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:34 -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-541-6iYJicaCPo2WU6y71BTHnQ-1; Mon, 26 Apr 2021 23:40:27 -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 964678030B5 for ; Tue, 27 Apr 2021 03:40:26 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9EBF5D9C0; Tue, 27 Apr 2021 03:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494829; 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=7Z5RaOlD7rdX4XROV7V3gHNn51grnFQ52zIxx1WTXlA=; b=ifOjlDpd5QRbyXrDVEkrkkZdtVydd3DM+TL5nFM8r7KnnUJ+WPma5JoJZ4gasafKcEhUhj wGUVpDNVVZNrr0c/QPE9tg7m4Ua4Q5mkSDWGj8fI37NLPLE8h53kspQkQ2J+Kppqpr3H95 fdkkwRw9oSsNxRFXGtsFw9ZCFXFPU/U= X-MC-Unique: 6iYJicaCPo2WU6y71BTHnQ-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 5/9] vhost:add support for configure interrupt Date: Tue, 27 Apr 2021 11:39:47 +0800 Message-Id: <20210427033951.29805-6-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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 vhost and related driver When backend support VIRTIO_NET_F_STATUS,setup the configure interrupt function in vhost_dev_start and release the related resource when vhost_dev_stop Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 9 +++++ hw/net/virtio-net.c | 6 ++++ hw/virtio/vhost.c | 70 ++++++++++++++++++++++++++++++++++++-- hw/virtio/virtio.c | 22 ++++++++++++ include/hw/virtio/vhost.h | 3 ++ include/hw/virtio/virtio.h | 4 +++ include/net/vhost_net.h | 3 ++ 7 files changed, 115 insertions(+), 2 deletions(-) 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 78ccaa228c..43b912453a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3063,6 +3063,9 @@ static bool virtio_net_guest_notifier_pending(VirtIOD= evice *vdev, int idx) if (idx !=3D -1) { return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx); } + if (idx =3D=3D -1) { + return vhost_net_config_pending(get_vhost_net(nc->peer), idx); + } return false; } =20 @@ -3075,6 +3078,9 @@ static void virtio_net_guest_notifier_mask(VirtIODevi= ce *vdev, int idx, if (idx !=3D -1) { vhost_net_virtqueue_mask(get_vhost_net(nc->peer), vdev, idx, mask); } + if (idx =3D=3D -1) { + 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..162a5dd90c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -21,6 +21,7 @@ #include "qemu/error-report.h" #include "qemu/memfd.h" #include "standard-headers/linux/vhost_types.h" +#include "standard-headers/linux/virtio_net.h" #include "exec/address-spaces.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" @@ -1313,6 +1314,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 +1410,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 +1504,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); + + if ((hdev->started =3D=3D false) || + (hdev->vhost_ops->vhost_set_config_call =3D=3D NULL)) { + return false; + } + 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 +1538,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 &hdev->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) { + 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) @@ -1701,6 +1741,7 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uin= t16_t queue_size, int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) { int i, r; + int fd =3D 0; =20 /* should only be called after backend is connected */ assert(hdev->vhost_ops); @@ -1732,7 +1773,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) goto fail_vq; } } - + event_notifier_test_and_clear(&hdev->masked_config_notifier); + if (!vdev->use_guest_notifier_mask) { + vhost_config_mask(hdev, vdev, true); + } if (hdev->log_enabled) { uint64_t log_base; =20 @@ -1749,6 +1793,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev) goto fail_log; } } + if (hdev->vhost_ops->vhost_dev_start) { r =3D hdev->vhost_ops->vhost_dev_start(hdev, true); if (r) { @@ -1766,6 +1811,19 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) vhost_device_iotlb_miss(hdev, vq->used_phys, true); } } + if (!(hdev->features & (0x1ULL << VIRTIO_NET_F_STATUS))) { + return 0; + } + if (hdev->vhost_ops->vhost_set_config_call) { + fd =3D event_notifier_get_fd(&vdev->config_notifier); + r =3D hdev->vhost_ops->vhost_set_config_call(hdev, &fd); + if (!r) { + event_notifier_set(&vdev->config_notifier); + } + if (r) { + goto fail_log; + } + } return 0; fail_log: vhost_log_put(hdev, false); @@ -1788,10 +1846,18 @@ fail_features: void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) { int i; + int fd; =20 /* should only be called after backend is connected */ assert(hdev->vhost_ops); - + event_notifier_test_and_clear(&hdev->masked_config_notifier); + event_notifier_test_and_clear(&vdev->config_notifier); + if ((hdev->features & (0x1ULL << VIRTIO_NET_F_STATUS))) { + if (hdev->vhost_ops->vhost_set_config_call) { + fd =3D -1; + hdev->vhost_ops->vhost_set_config_call(hdev, &fd); + } + } 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 ceb58fda6c..5dff29c981 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3502,6 +3502,14 @@ 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 (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 +3525,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 +3609,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 b7ece7a6a8..b0b714f6d4 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -108,6 +108,7 @@ struct VirtIODevice bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; + EventNotifier config_notifier; }; =20 struct VirtioDeviceClass { @@ -310,11 +311,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 Tue May 21 03:53:11 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=1619495526; cv=none; d=zohomail.com; s=zohoarc; b=JL9gqfJep7ANuW9OvO7kzimAIKBrha8fkX0oSqqitLiqGCqBhHfT74qbzvZOlDe0cbdPbuK4YbzVC+1QLY9P68o3CyeCZ7+W9+e08V/USLLiKdhLRSQQfoDZCXoJx1XgTF8BuZCLqhvJPQZGzXGFOxHkSm2CFL6BX4xEQnhKYC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495526; 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=I00C3iqB1b+7BcWt1JcqvSkjkrWhgvVsrJ0zhWw37TY=; b=Zc64GzWY/y+lSw5qq9CgGDrO6diOUAwfigXVEliOZWgxXx0UFL0EHutkPZHtmo8Q186XkK6C1OB4XU4v9+PXW/xvJbXxgzImjR9r5lmBnJNh1f/nGFZOg9HHzlrY25BoubQX66CAQWdk+0VOTYUKf0hKP886iVgsm/Hte8eF/iI= 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 1619495526064545.0439339971172; Mon, 26 Apr 2021 20:52:06 -0700 (PDT) Received: from localhost ([::1]:35608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbElY-0001DJ-Uo for importer@patchew.org; Mon, 26 Apr 2021 23:52:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaS-00066S-GD for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaN-00066q-Jp for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:36 -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-308-nkTsQOodNRiaKvJeAlic2g-1; Mon, 26 Apr 2021 23:40:29 -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 C740E817469 for ; Tue, 27 Apr 2021 03:40:28 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2581D5D9C0; Tue, 27 Apr 2021 03:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494831; 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=I00C3iqB1b+7BcWt1JcqvSkjkrWhgvVsrJ0zhWw37TY=; b=VzFiL2NESBqPnOZNKxmAEzT7s9j80yjo/ZQaA+3BP5vn50tR232TXE71sRroMxsi+NwL4p O2zAQZZDgN2DBNsS++YT2VvT1ShJl9lhjtkz1STq31gDYyWEDJxpvHtB2tApwOUO5WRZHg xP8BuwVOfBjlZ8jAtm8FnlrNKzD9yEU= X-MC-Unique: nkTsQOodNRiaKvJeAlic2g-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 6/9] virtio-mmio: add support for configure interrupt Date: Tue, 27 Apr 2021 11:39:48 +0800 Message-Id: <20210427033951.29805-7-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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 e1b5c3b81e..d8cb368728 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, -1, !assign); + } + 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 Tue May 21 03:53:11 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=1619495675; cv=none; d=zohomail.com; s=zohoarc; b=LFKZsiDgHumdEhmNXIlF3mhlyWijAQuFKsFiFMSrGw+cLP3rx+OOpTH+vcgbAfQ1UuLQtYDDLYKEljW4gPXeqJkeLxnn8nG9SkdU2Ae0o/f6l3Lhmg4OkWpLCrC6aXFT4pv56xklnULIGzgBMdH6kxqBRCGWbFkP8CZcYoZMS+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495675; 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=M4cmPbiEwEGftO8mrNWEPj2CgiRFKvrX7qJYFZEnNDU=; b=HVMA79OOqJDc6P9QmyFQIXmb/SDNT2lhZfx/wz0McKtVLEIuIVtFwfd3Mc9lC2VGyZTivSJXQ8S3vX41CqmME6c8ZmWBfr4zzd+qydr3SKCERkP1n/h+vFJcRt2ICtGNQIGRZN8uWV+VwZKsdnkjmWmbxh639AtzCn8AhNF2/x8= 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 1619495675205378.47850905087887; Mon, 26 Apr 2021 20:54:35 -0700 (PDT) Received: from localhost ([::1]:43294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEny-0004Kt-3a for importer@patchew.org; Mon, 26 Apr 2021 23:54:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaU-00067B-Tk for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaQ-00067V-2i for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:38 -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-44-7Q9rRR5vMVmFQyVxjy1HOA-1; Mon, 26 Apr 2021 23:40:31 -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 EFC71107ACCA for ; Tue, 27 Apr 2021 03:40:30 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 534925D9C0; Tue, 27 Apr 2021 03:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494833; 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=M4cmPbiEwEGftO8mrNWEPj2CgiRFKvrX7qJYFZEnNDU=; b=F2v/JwqXzcNiIRrmNcisEOLo8boVgF8EqcpYxgtW3fJNbs0wW0qvh3rOuIM6wNCBBbQ7Ji zq2gExW2fhUkfN2LujDD2n5Yj2DdN2vszYHSo+ZgIN7zwdrch8pGVuthUZy5UOpfbq1P64 aeM/AOdI8hepgwFbDM2gz3oWWhvPK5s= X-MC-Unique: 7Q9rRR5vMVmFQyVxjy1HOA-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 7/9] virtio-pci: add support for configure interrupt Date: Tue, 27 Apr 2021 11:39:49 +0800 Message-Id: <20210427033951.29805-8-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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 --- hw/virtio/virtio-pci.c | 186 ++++++++++++++++++++++++++--------------- 1 file changed, 120 insertions(+), 66 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 2b7e6cc0d9..07d28dd367 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -664,12 +664,10 @@ 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]; int ret; - if (irqfd->users =3D=3D 0) { ret =3D kvm_irqchip_add_msi_route(kvm_state, vector, &proxy->pci_d= ev); if (ret < 0) { @@ -708,93 +706,120 @@ static void kvm_virtio_pci_irqfd_release(VirtIOPCIPr= oxy *proxy, ret =3D kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->vir= q); assert(ret =3D=3D 0); } - -static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) + 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); - 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 (queue_no =3D=3D -1) { + *n =3D virtio_get_config_notifier(vdev); + *vector =3D vdev->config_vector; + } else { if (!virtio_queue_get_num(vdev, queue_no)) { - break; - } - vector =3D virtio_queue_vector(vdev, queue_no); - 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) { - 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; - } + 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_one(VirtIOPCIProxy *proxy, int queue_= no) +{ + unsigned int vector; + int ret; + EventNotifier *n; + 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) { - 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); + 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 int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy) +{ + return kvm_virtio_pci_vector_use_one(proxy, -1); + } + +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); - VirtQueue *vq; EventNotifier *n; + 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; - } - vector =3D virtio_queue_vector(vdev, queue_no); - 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) { - 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); + kvm_virtio_pci_vector_release_one(proxy, queue_no); } } =20 +static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy) +{ + kvm_virtio_pci_vector_release_one(proxy, -1); +} +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; +} static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy, unsigned int queue_no, unsigned int vector, MSIMessage msg, - EventNotifier *n) + EventNotifier *n) { VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); @@ -871,9 +896,16 @@ 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_vq_vector_unmask(proxy, -1, vector, msg, n); + if (ret < 0) { + goto config_undo; + } return 0; =20 + config_undo: + n =3D virtio_get_config_notifier(vdev); + virtio_pci_vq_vector_mask(proxy, -1, vector, n); undo: vq =3D virtio_vector_first_queue(vdev, vector); while (vq && unmasked >=3D 0) { @@ -907,6 +939,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_vq_vector_mask(proxy, -1, vector, n); } =20 static void virtio_pci_vector_poll(PCIDevice *dev, @@ -920,7 +954,7 @@ static void virtio_pci_vector_poll(PCIDevice *dev, unsigned int vector; EventNotifier *notifier; VirtQueue *vq; - + /*check for every queue*/ for (queue_no =3D 0; queue_no < proxy->nvqs_with_notifiers; queue_no++= ) { if (!virtio_queue_get_num(vdev, queue_no)) { break; @@ -940,6 +974,21 @@ static void virtio_pci_vector_poll(PCIDevice *dev, msix_set_pending(dev, vector); } } + /*check for config interrupt*/ + + 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, -1)) { + 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, @@ -1027,6 +1076,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, @@ -1043,7 +1096,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 From nobody Tue May 21 03:53:11 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=1619495273; cv=none; d=zohomail.com; s=zohoarc; b=Nv9G0q8DMENHWMNvN7q0NvLv40z2VlZHgpugtGoN8dGyfxuh6QnAMjMH6lcWHXxn2dQqJ7oowBME4y/6piO72SKTq6MnLlcrejvwhQQTOOL3O1rdbX0xj75SCz1En4RXyk0nGAV9cDyEZfXIKJ6eOdW6lgfr2T7WuWGmx8yJUA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495273; 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=BfmnGnKUK5degPgxbByibkUkf3YY+gi07heNJgVgNjE=; b=Avx9uz2VwK+SdRREMiiom1nl9sd5HmKiQQgjUzRJFqYfjo+L5+CmUiXIe3j1oRQ7gR/P/SBAdV28K4HwwRiTfle4iE1AYbarR4THdSwKpUywReKrIyp+zNCjI0gf5GFd6BFdS1CTLKq02Mnn+OssY649Ocu4ZV24s+bZrvj6mYo= 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 161949527395499.0842097740234; Mon, 26 Apr 2021 20:47:53 -0700 (PDT) Received: from localhost ([::1]:55022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEhU-0005uU-Kq for importer@patchew.org; Mon, 26 Apr 2021 23:47:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaa-00068m-8N for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22172) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaS-00069P-9T for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:43 -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-454-ytXt5WinPc2h42tX688nTg-1; Mon, 26 Apr 2021 23:40:33 -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 26AB98030C9 for ; Tue, 27 Apr 2021 03:40:33 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AE3C5D9C0; Tue, 27 Apr 2021 03:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494835; 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=BfmnGnKUK5degPgxbByibkUkf3YY+gi07heNJgVgNjE=; b=cqXqo9cTgDuc56g8UTRvhT6d9oM/7tFTzQdJK/+xkXIAHuaYfMGP8MMC7UnObSGBXT9Rah fPUljS/CmkWne4uxGQc/7wPxzaoK9KU6Elp7wWw7A83nxwQ/TwXaWNhBAvsk4lmM/EgSYw Ezvc2REQq9hGyhkc2YpGa08zDn61JXU= X-MC-Unique: ytXt5WinPc2h42tX688nTg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 8/9] virtio: decouple virtqueue from set notifier fd handler Date: Tue, 27 Apr 2021 11:39:50 +0800 Message-Id: <20210427033951.29805-9-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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" This patch will decouple virtqueue from virtio_queue_set_guest_notifier_fd_handler, here queue number -1 mean the configure interrupt. The funtion will set the config_notify_read as fd handler Signed-off-by: Cindy Lu --- hw/s390x/virtio-ccw.c | 6 +++--- hw/virtio/virtio-mmio.c | 8 ++++---- hw/virtio/virtio-pci.c | 9 +++++---- hw/virtio/virtio.c | 35 +++++++++++++++++------------------ include/hw/virtio/virtio.h | 4 +--- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 4582e94ae7..5d73c99d30 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -989,11 +989,11 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDev= ice *dev, int n, if (r < 0) { return r; } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); + virtio_set_notifier_fd_handler(vdev, n, true, with_irqfd); if (with_irqfd) { r =3D virtio_ccw_add_irqfd(dev, n); if (r) { - virtio_queue_set_guest_notifier_fd_handler(vq, false, + virtio_set_notifier_fd_handler(vdev, n, false, with_irqfd); return r; } @@ -1017,7 +1017,7 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDev= ice *dev, int n, if (with_irqfd) { virtio_ccw_remove_irqfd(dev, n); } - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); + virtio_set_notifier_fd_handler(vdev, n, false, with_irqfd); event_notifier_cleanup(notifier); } return 0; diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index d8cb368728..4ea55001be 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -620,9 +620,9 @@ static int virtio_mmio_set_guest_notifier(DeviceState *= d, int n, bool assign, if (r < 0) { return r; } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); + virtio_set_notifier_fd_handler(vdev, n, true, with_irqfd); } else { - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); + virtio_set_notifier_fd_handler(vdev, n, false, with_irqfd); event_notifier_cleanup(notifier); } =20 @@ -642,9 +642,9 @@ static int virtio_mmio_set_config_notifier(DeviceState = *d, bool assign) int r =3D 0; if (assign) { r =3D event_notifier_init(notifier, 0); - virtio_set_config_notifier_fd_handler(vdev, true, false); + virtio_set_notifier_fd_handler(vdev, -1, true, false); } else { - virtio_set_config_notifier_fd_handler(vdev, false, false); + virtio_set_notifier_fd_handler(vdev, -1, false, false); event_notifier_cleanup(notifier); } if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 07d28dd367..5033b3db4f 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -806,10 +806,10 @@ static int virtio_pci_set_config_notifier(DeviceState= *d, bool assign) int r =3D 0; if (assign) { r =3D event_notifier_init(notifier, 0); - virtio_set_config_notifier_fd_handler(vdev, true, true); + virtio_set_notifier_fd_handler(vdev, -1, true, true); kvm_virtio_pci_vector_config_use(proxy); } else { - virtio_set_config_notifier_fd_handler(vdev, false, true); + virtio_set_notifier_fd_handler(vdev, -1, false, true); kvm_virtio_pci_vector_config_release(proxy); event_notifier_cleanup(notifier); } @@ -1005,9 +1005,9 @@ static int virtio_pci_set_guest_notifier(DeviceState = *d, int n, bool assign, if (r < 0) { return r; } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); + virtio_set_notifier_fd_handler(vdev, n, true, with_irqfd); } else { - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); + virtio_set_notifier_fd_handler(vdev, n, false, with_irqfd); event_notifier_cleanup(notifier); } =20 @@ -1049,6 +1049,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; } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5dff29c981..8f0087deac 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3510,32 +3510,31 @@ static void virtio_config_read(EventNotifier *n) virtio_notify_config(vdev); } } -void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, - bool with_irqfd) + +void virtio_set_notifier_fd_handler(VirtIODevice *vdev, int queue_no, + bool assign, bool with_irqfd) { - if (assign && !with_irqfd) { - event_notifier_set_handler(&vq->guest_notifier, - virtio_queue_guest_notifier_read); + EventNotifier *e ; + EventNotifierHandler *handler; + if (queue_no !=3D -1) { + VirtQueue *vq =3D virtio_get_queue(vdev, queue_no); + e =3D &vq->guest_notifier; + handler =3D virtio_queue_guest_notifier_read; + } else { + e =3D &vdev->config_notifier; + handler =3D virtio_config_read; + } + if (assign && !with_irqfd) { + event_notifier_set_handler(e, handler); } else { - event_notifier_set_handler(&vq->guest_notifier, NULL); + event_notifier_set_handler(e, NULL); } if (!assign) { /* 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); + handler(e); } } -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); - } -} - EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { return &vq->guest_notifier; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b0b714f6d4..d22f5a3e7e 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -309,9 +309,7 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, i= nt n); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n); 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, +void virtio_set_notifier_fd_handler(VirtIODevice *vdev, int n, bool assign, bool with_irqfd); int virtio_device_start_ioeventfd(VirtIODevice *vdev); int virtio_device_grab_ioeventfd(VirtIODevice *vdev); --=20 2.21.3 From nobody Tue May 21 03:53:11 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=1619495066; cv=none; d=zohomail.com; s=zohoarc; b=nL1Iz6U42ocbjQNKBMXsrVmkK0mZYRNtOCeyTxV1ZBbhTZMuonEkW8Bna7+ruEN1OxchC1GA7I9BI5BkQG6PZg1SzixeKKyvoMteH74KV0WmpRHVjRyy1603R3Z3qOXax/ytUWsveuHAnTbowzB6JCZOxZwz2cWj9pfSZEB0LKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619495066; 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=luy9qUFF6YH9l21S5OyaAv3pWwDIj473IAZxR5/5crs=; b=CSau82TpzTlAMJFdZfDjEI+dZGbFjDTDcITjo3ELkZ4rRS4E+mgac3xernRm6j9Ufm1CIWekhshK+JM/mHq0O80kDWAVr39NqMnl1DZnz70ww/ZQHvQK/beP03M6Wa/xxK8/WG6ZMf7RetM2RZQudG6MV00DHOUUbvnsdqZ0WuU= 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 1619495066394430.8466886036216; Mon, 26 Apr 2021 20:44:26 -0700 (PDT) Received: from localhost ([::1]:45820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbEe9-00023j-DE for importer@patchew.org; Mon, 26 Apr 2021 23:44:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEak-0006FQ-LH for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30269) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbEaY-0006Dd-50 for qemu-devel@nongnu.org; Mon, 26 Apr 2021 23:40:52 -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-165-4IkmYt-LPkymXnFQGhqW4Q-1; Mon, 26 Apr 2021 23:40:39 -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 2A13D343A9 for ; Tue, 27 Apr 2021 03:40:38 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-211.pek2.redhat.com [10.72.13.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80CBE5D9C0; Tue, 27 Apr 2021 03:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619494840; 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=luy9qUFF6YH9l21S5OyaAv3pWwDIj473IAZxR5/5crs=; b=UvXpJlTGmRPgxC0kr/pl5/YiQmbtXZooAqQP9OZI3+DycvCvSI83lKMDT5HSP4ZUrlWxiW Bks4i9JSkRUVjXO4ktfPtbEotn3OwiWx3Jq0zgnvupnML84xIDYC2yrf+lkbRi1IXmbwN7 jNb2fuW7AMMREX8MVGx9ghAEK3mVg20= X-MC-Unique: 4IkmYt-LPkymXnFQGhqW4Q-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 9/9] virtio-net: add peer_deleted check in virtio_net_handle_rx Date: Tue, 27 Apr 2021 11:39:51 +0800 Message-Id: <20210427033951.29805-10-lulu@redhat.com> In-Reply-To: <20210427033951.29805-1-lulu@redhat.com> References: <20210427033951.29805-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: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, 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" During the test, We found this fuction will continue running while the peer is deleted, this will case the crash. so add check for this. Signed-off-by: Cindy Lu --- hw/net/virtio-net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 43b912453a..1be3f8e76f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1403,7 +1403,9 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, = VirtQueue *vq) { VirtIONet *n =3D VIRTIO_NET(vdev); int queue_index =3D vq2q(virtio_get_queue_index(vq)); - + if (n->nic->peer_deleted) { + return; + } qemu_flush_queued_packets(qemu_get_subqueue(n->nic, queue_index)); } =20 --=20 2.21.3