From nobody Mon Feb 9 02:38:43 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=1611647292; cv=none; d=zohomail.com; s=zohoarc; b=czgpuBJrVOaHU6Xo/PJ2Qg5SSD8dNbkyziFpydCpkT6cHdB6zl9A0Wk+v6fDM1DlTU6kA6Z89cvztlnDB7CColj4IT+IUcOk8+uX6uL4SbsY7qc7cA436hWBzArgu1tZkqsw+WZPYbluD6mauZmQoKrKpuA9qBHQ4qSDop6fMps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611647292; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MhA0b+K+hM/2YH6ae4S4KY5ATy6h938EicWWmfTmS6s=; b=GTEhxjSehmoKiVuhp9iRJjlLlgMECAZVSAXrAePqXlZEejQYkt5rmNN2ARF4pxfkitsanmdA2YYWPz99HbEJrMVXchm1aMAjv8CB8TXQxq6p/WxuscfNfQ8dqQqYkPKPh+OXNlcUy/5hobvmdUHgF1SkIspGQDn23DFhGOj9Tew= 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 1611647292226740.8209869497914; Mon, 25 Jan 2021 23:48:12 -0800 (PST) Received: from localhost ([::1]:32812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4J59-0003F3-5n for importer@patchew.org; Tue, 26 Jan 2021 02:48:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4J0H-0006tM-2c for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l4J0F-0001gH-5x for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:08 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-it06015zPyOuU5P-ddSWOw-1; Tue, 26 Jan 2021 02:43:04 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91CB1E75F for ; Tue, 26 Jan 2021 07:43:03 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-115.pek2.redhat.com [10.72.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C53A5D74E; Tue, 26 Jan 2021 07:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611646986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MhA0b+K+hM/2YH6ae4S4KY5ATy6h938EicWWmfTmS6s=; b=aO3CPWJ7ARcwd297pnc/CyM0eo8tJxD2XveET/7vJ4+8gIhcnl+8+s5oEA5yzuBECFd1os +MfgzWJGIJVuFbeqLrfHZGX/Pt+FPuLyHF6yULxHbCOkVExhxv5aYO7HTa9iQ5ltM54aiI TFQsVvS8ySZLoNt9Uh3DnCr7kq9yUv8= X-MC-Unique: it06015zPyOuU5P-ddSWOw-1 From: Cindy Lu To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 1/5] virtio: add support for configure interrupt Date: Tue, 26 Jan 2021 15:42:50 +0800 Message-Id: <20210126074254.3225-2-lulu@redhat.com> In-Reply-To: <20210126074254.3225-1-lulu@redhat.com> References: <20210126074254.3225-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.255, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lulu@redhat.com 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 and virtio_set_config_notifier_fd_handler in virtio Signed-off-by: Cindy Lu --- hw/virtio/virtio.c | 26 ++++++++++++++++++++++++++ include/hw/virtio/virtio-bus.h | 2 ++ include/hw/virtio/virtio.h | 6 ++++++ 3 files changed, 34 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ceb58fda6c..25e164cf8a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3502,6 +3502,16 @@ static void virtio_queue_guest_notifier_read(EventNo= tifier *n) } } =20 +static void virtio_config_read(EventNotifier *n) +{ + VirtIODevice *vdev =3D container_of(n, VirtIODevice, config_notifier); + if (!vdev->use_config_notifier) { + return; + } + if (event_notifier_test_and_clear(n)) { + virtio_notify_config(vdev); + } +} void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, bool with_irqfd) { @@ -3518,6 +3528,17 @@ void virtio_queue_set_guest_notifier_fd_handler(Virt= Queue *vq, bool assign, } } =20 +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; @@ -3591,6 +3612,11 @@ 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/virtio-bus.h b/include/hw/virtio/virtio-bus.h index ef8abe49c5..97e13ec484 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -93,6 +93,8 @@ struct VirtioBusClass { */ bool has_variable_vring_alignment; AddressSpace *(*get_dma_as)(DeviceState *d); + int (*set_config_notifiers)(DeviceState *d, bool assign); + }; =20 struct VirtioBusState { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b7ece7a6a8..79f2f78625 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -108,6 +108,8 @@ struct VirtIODevice bool use_guest_notifier_mask; AddressSpace *dma_as; QLIST_HEAD(, VirtQueue) *vector_queues; + EventNotifier config_notifier; + bool use_config_notifier; }; =20 struct VirtioDeviceClass { @@ -310,11 +312,15 @@ 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, --=20 2.21.3 From nobody Mon Feb 9 02:38:43 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=1611647094; cv=none; d=zohomail.com; s=zohoarc; b=fqmuoDQ8Ek8L2jev3zYYi3p6VC0ugjGWWddYLRCPI7hTG1zTtaLGQJpJjxzIDtFLSdp2YnMCglgmb7dbn7P5JgqVLk7bXOtYeRJPmFMLWRRBb5+ytuxzJZiVNfRtQ2NC0JwAbpni1walOFgMg6ii/yc1CFsSHXH+kj7ntpzP8fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611647094; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WJcUJHvBjXsnwfyTHfgl/jj1ddgQ0Itnc9egQ+dJRPQ=; b=Mj7w8H7X7J/JORUwUbpsFMDdM0D3j865FpDd+JZLVNHuBKOoDlpipR3e2bUIHWh/8KuI7uNO3j4l1nsN9kOLhOuxkGjXCQO5W4vbY89MdwwOSu5hDAb+aKJb6K6yTFXjvJQoLrJCeEysmG8WCw787OIGgsHJI37gP1qjzmbx+k4= 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 16116470941221012.7778351300013; Mon, 25 Jan 2021 23:44:54 -0800 (PST) Received: from localhost ([::1]:53126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4J1w-0008Et-SB for importer@patchew.org; Tue, 26 Jan 2021 02:44:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4J0I-0006v0-4P for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l4J0G-0001gV-Hy for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:09 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-2KI1A4jqPfC8IW3cDF45MQ-1; Tue, 26 Jan 2021 02:43:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 997F5806674 for ; Tue, 26 Jan 2021 07:43:05 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-115.pek2.redhat.com [10.72.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15E9A5D76F; Tue, 26 Jan 2021 07:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611646987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WJcUJHvBjXsnwfyTHfgl/jj1ddgQ0Itnc9egQ+dJRPQ=; b=AQIiLiFeolelmOEh3fn+cZyrJ+G9FRqgxo5WQFIrDJs/E3Ej/BK2GAvYx5/HXdbfo6QWL2 V5W7RmCsUkm4u/mcw8Y/6FMXdDwGttT3aITPKp4GvRa95skwXNUvyj+zaz0ul2EvuCw+Vu 68WUR2ilpv+Jv1rVB8XpUtLu0kVN1hQ= X-MC-Unique: 2KI1A4jqPfC8IW3cDF45MQ-1 From: Cindy Lu To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 2/5] vhost_net: enable configure interrupt when vhost_net start Date: Tue, 26 Jan 2021 15:42:51 +0800 Message-Id: <20210126074254.3225-3-lulu@redhat.com> In-Reply-To: <20210126074254.3225-1-lulu@redhat.com> References: <20210126074254.3225-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.255, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lulu@redhat.com 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" While peer is vhost vdpa, setup the configure interrupt function vhost_net_start and release the resource when vhost_net_stop Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 24d555e764..0660da474a 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -345,6 +345,15 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, error_report("Error binding guest notifier: %d", -r); goto err; } + if (ncs->peer && ncs->peer->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_= VDPA) { + if (k->set_config_notifiers) { + r =3D k->set_config_notifiers(qbus->parent, true); + if (r < 0) { + error_report("Error binding config notifier: %d", -r); + goto err; + } + } + } =20 for (i =3D 0; i < total_queues; i++) { peer =3D qemu_get_peer(ncs, i); @@ -391,7 +400,15 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState = *ncs, for (i =3D 0; i < total_queues; i++) { vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); } - + if (ncs->peer && ncs->peer->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_V= DPA) { + if (k->set_config_notifiers) { + r =3D k->set_config_notifiers(qbus->parent, false); + if (r < 0) { + error_report("Error unbinding config notifier: %d", -r); + } + assert(r >=3D 0); + } + } r =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (r < 0) { fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r); --=20 2.21.3 From nobody Mon Feb 9 02:38:43 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=1611647151; cv=none; d=zohomail.com; s=zohoarc; b=gSBc3eqqXrSVd4rsc8tbi5b6rORU2rU6J/WXgwa3YTfSNjV8/EKyshQ/urJWHieCqYBzOtiSPd6q3HChI2bOzMp05aqXgrSiWqD5rEsXdPjhHvw1M6rP84NDz9+DMwTNqXoiYxlUF+ShDkpFsz55zOKPuNCT7K4sxY2X/FUalvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611647151; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uycYLpeUBZ55HNoDRJJJs0rpK+pMXKThZ71uvoV2WKo=; b=IGgUQmK84nL9sGvEP6827Sy7A/rbYP1vfYAO5Gg6ZPE/gTXQY2lCR8PHvom1Mp+2yn5uU3GuJIUlIYKtmCAj/KBOKQ1TOpW+RTwcFgcrbmnZls0Gr/7Wb+V6T6LMKrLX5oGpyWlvd4H6iAkptEQS6LNTrNLrYMBGyKQjT2CMTy8= 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 1611647151365600.8329630253579; Mon, 25 Jan 2021 23:45:51 -0800 (PST) Received: from localhost ([::1]:55252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4J2s-0000iG-77 for importer@patchew.org; Tue, 26 Jan 2021 02:45:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4J0Q-00079p-15 for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20256) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l4J0O-0001j4-3z for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-HCku6kVRPAeI7Wn0pvIMlQ-1; Tue, 26 Jan 2021 02:43:13 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA2C91922023 for ; Tue, 26 Jan 2021 07:43:12 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-115.pek2.redhat.com [10.72.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 779BB62950; Tue, 26 Jan 2021 07:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611646995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uycYLpeUBZ55HNoDRJJJs0rpK+pMXKThZ71uvoV2WKo=; b=DJptHFjYDdrHKdfDjydzgv9nC/5kyAODPm0+T55L7C83IzggyeLpRBhXtYqqt8SWeMUIiD lkTobwe3lTOKmSxHnsehvoSq2YSGmq46CbaHjxSJyuyK3Vgrs5h63K1c7iHvojgO304cPY wEup+uy46f2XiSM07jJP4ZJjs4eTLEs= X-MC-Unique: HCku6kVRPAeI7Wn0pvIMlQ-1 From: Cindy Lu To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 3/5] virtio-pci: add support for configure interrupt Date: Tue, 26 Jan 2021 15:42:52 +0800 Message-Id: <20210126074254.3225-4-lulu@redhat.com> In-Reply-To: <20210126074254.3225-1-lulu@redhat.com> References: <20210126074254.3225-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.255, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lulu@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add support for configure interrupt, use kvm_irqfd_assign and set the gsi to kernel. When the configure notifier was eventfd_signal by host kernel, this will finally inject an msix interrupt to guest Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 92 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 17 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 36524a5728..8e192600b8 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -664,7 +664,6 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev, } =20 static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy, - unsigned int queue_no, unsigned int vector) { VirtIOIRQFD *irqfd =3D &proxy->vector_irqfd[vector]; @@ -691,23 +690,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 +715,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; @@ -731,7 +725,7 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *pr= oxy, int nvqs) if (vector >=3D msix_nr_vectors_allocated(dev)) { continue; } - ret =3D kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector); + ret =3D kvm_virtio_pci_vq_vector_use(proxy, vector); if (ret < 0) { goto undo; } @@ -739,7 +733,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,13 +751,69 @@ 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); } return ret; } =20 +static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy) +{ + + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + unsigned int vector; + int ret; + EventNotifier *n =3D virtio_get_config_notifier(vdev); + + vector =3D vdev->config_vector ; + ret =3D kvm_virtio_pci_vq_vector_use(proxy, vector); + if (ret < 0) { + goto undo; + } + ret =3D kvm_virtio_pci_irqfd_use(proxy, n, vector); + if (ret < 0) { + goto undo; + } + return 0; +undo: + kvm_virtio_pci_irqfd_release(proxy, n, vector); + return ret; +} +static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy) +{ + PCIDevice *dev =3D &proxy->pci_dev; + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + unsigned int vector; + EventNotifier *n =3D virtio_get_config_notifier(vdev); + vector =3D vdev->config_vector ; + if (vector >=3D msix_nr_vectors_allocated(dev)) { + return; + } + kvm_virtio_pci_irqfd_release(proxy, n, vector); + kvm_virtio_pci_vq_vector_release(proxy, vector); +} + +static int virtio_pci_set_config_notifier(DeviceState *d, bool assign) +{ + VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + EventNotifier *notifier =3D virtio_get_config_notifier(vdev); + int r =3D 0; + if (assign) { + r =3D event_notifier_init(notifier, 0); + virtio_set_config_notifier_fd_handler(vdev, true, true); + kvm_virtio_pci_vector_config_use(proxy); + } else { + virtio_set_config_notifier_fd_handler(vdev, false, true); + kvm_virtio_pci_vector_config_release(proxy); + event_notifier_cleanup(notifier); + } + return r; +} + static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) { PCIDevice *dev =3D &proxy->pci_dev; @@ -769,7 +821,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 +835,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); } @@ -823,7 +878,7 @@ 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; } @@ -835,13 +890,15 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy = *proxy, VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 + VirtQueue *vq =3D virtio_get_queue(vdev, queue_no); + EventNotifier *n =3D virtio_queue_get_guest_notifier(vq); /* If guest supports masking, keep irqfd but mask it. * Otherwise, clean it up now. */=20 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 @@ -2137,6 +2194,7 @@ static void virtio_pci_bus_class_init(ObjectClass *kl= ass, void *data) k->ioeventfd_assign =3D virtio_pci_ioeventfd_assign; k->get_dma_as =3D virtio_pci_get_dma_as; k->queue_enabled =3D virtio_pci_queue_enabled; + k->set_config_notifiers =3D virtio_pci_set_config_notifier; } =20 static const TypeInfo virtio_pci_bus_info =3D { --=20 2.21.3 From nobody Mon Feb 9 02:38:43 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=1611647369; cv=none; d=zohomail.com; s=zohoarc; b=VWSH6EeCm2aDSoHzEzAwuZvhQW9dyj8QIuRO0u4jMIrMXPsnVlqBO1lcwPdYV9RdZSxv4rNuOdgRuYImyHTv0eUGdXxtP6ZmSApW/nuilOXBfGbl/8fds/qYrpX6HJMIOLC/FlCp4HdfqP21DCkggmlr16NzPhSgnw0yBLQfS8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611647369; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ua2MJPKyhckrhznbF0TFlcdA8jGgaynNIN8wY0tzrgw=; b=iPhaD8wMovTPA43ll45prZcyiEUDo3WPh3rLPMzRafsmRexA5w9RC0aCGnPfzPE/ipmgw/kSgKreudQ2W4DPZrdsrD39WWoh4yQFB4t8OMFQrkHEWjEu193l1FgtixcdmKlKTHO8B6/qj6xo4oGPdprwkiboq/i6teRNJTxT/C0= 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 1611647369490192.68681649246207; Mon, 25 Jan 2021 23:49:29 -0800 (PST) Received: from localhost ([::1]:35730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4J6N-0004Sh-1y for importer@patchew.org; Tue, 26 Jan 2021 02:49:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4J0R-0007EB-EH for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l4J0P-0001jG-SR for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-a5wUNJvBPruuUQ2a5FjJUg-1; Tue, 26 Jan 2021 02:43:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D32C010054FF for ; Tue, 26 Jan 2021 07:43:14 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-115.pek2.redhat.com [10.72.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FFAD5D74E; Tue, 26 Jan 2021 07:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611646997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ua2MJPKyhckrhznbF0TFlcdA8jGgaynNIN8wY0tzrgw=; b=OVIgQqfA3fNc7G3lxmGhymGH+tizhSfA4JoArn5YMDXVvGnEX8Y/UHfIRprFjNzXBClxma Qji2vSXvlnS5bEw8FCOl31U7dz9pAGGcMcQtyiWKSdQNNWGEfFPuIuPc2L7kBdvbp2XDKy VlREaWvGHJI9D4/tKlCfuoWMVuB/Gog= X-MC-Unique: a5wUNJvBPruuUQ2a5FjJUg-1 From: Cindy Lu To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 4/5] virtio-mmio: add support for configure interrupt Date: Tue, 26 Jan 2021 15:42:53 +0800 Message-Id: <20210126074254.3225-5-lulu@redhat.com> In-Reply-To: <20210126074254.3225-1-lulu@redhat.com> References: <20210126074254.3225-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.255, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lulu@redhat.com 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index e1b5c3b81e..d580f1ea9a 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -666,6 +666,21 @@ assign_error: return r; } =20 +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); + 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); + } + return r; +} static void virtio_mmio_pre_plugged(DeviceState *d, Error **errp) { VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); @@ -780,6 +795,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *kla= ss, void *data) k->ioeventfd_assign =3D virtio_mmio_ioeventfd_assign; k->pre_plugged =3D virtio_mmio_pre_plugged; k->has_variable_vring_alignment =3D true; + k->set_config_notifiers =3D virtio_mmio_set_config_notifier; bus_class->max_dev =3D 1; bus_class->get_dev_path =3D virtio_mmio_bus_get_dev_path; } --=20 2.21.3 From nobody Mon Feb 9 02:38:43 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=1611647434; cv=none; d=zohomail.com; s=zohoarc; b=eIjQoM9puKBuvrkebqMjV2vG5DrI5piBxNeHa5pHvR94EKJqkycnAfSnfPK29YTE0E/3ztYmc8YQeyCTNP5Y4gsIRqGw6PIH9fxiqMLUvkjEz85AHarGtBUsSmhUJsKZqDoHgkw8Vtzaushr2Prk09Jedqrkg9DpPMzdQv+AnNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611647434; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FsOHWShvamlumGGTuRsSaT+aiFR+zTUmun2b5qLe5qY=; b=XyFqUcmZoLcT40oeNXyEV82xOk1/8YyezZQupaVJIx3YissPNk+fh/zbwi6RTiu/KgmYh0igk4Qa75e1L4Z3wydP64iLFN+b9R0Kwcg+33GBUb2bjnHVQRjQiahIx6tGMv7I+Eu+gQ+1PaiTJhGbC7aJDJ7dMLoFZeJuu9L+aMg= 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 1611647434966300.6718513533334; Mon, 25 Jan 2021 23:50:34 -0800 (PST) Received: from localhost ([::1]:41022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4J7R-0006hp-VY for importer@patchew.org; Tue, 26 Jan 2021 02:50:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4J0a-0007PP-Gu for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l4J0V-0001l9-UD for qemu-devel@nongnu.org; Tue, 26 Jan 2021 02:43:28 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-290-H2sIXi0-M8mB60MAbnjEww-1; Tue, 26 Jan 2021 02:43:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B95471005513 for ; Tue, 26 Jan 2021 07:43:19 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-115.pek2.redhat.com [10.72.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 352755D74E; Tue, 26 Jan 2021 07:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611647003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FsOHWShvamlumGGTuRsSaT+aiFR+zTUmun2b5qLe5qY=; b=LQgUPe9qkVj+b4e9m3yRXcaqnPieFbW0r19WPSfEQk/hUUV6fHCKK7nOO0QWivyRirvliF PQbvR11c/Y8gocB4R0C9qb9bhpDonBr6IiQrx+Mc4oWD0o0Ecq7vOBN/qjBH3kTwn0tya3 aOvgcgMlglSoveRBS5Q8R8qS4Fnp4nU= X-MC-Unique: H2sIXi0-M8mB60MAbnjEww-1 From: Cindy Lu To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 5/5] vhost-vdpa: add callback function for configure interrupt Date: Tue, 26 Jan 2021 15:42:54 +0800 Message-Id: <20210126074254.3225-6-lulu@redhat.com> In-Reply-To: <20210126074254.3225-1-lulu@redhat.com> References: <20210126074254.3225-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.255, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lulu@redhat.com 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 call back function for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource Signed-off-by: Cindy Lu --- hw/virtio/trace-events | 2 ++ hw/virtio/vhost-vdpa.c | 37 ++++++++++++++++++++++++++++++- include/hw/virtio/vhost-backend.h | 4 ++++ 3 files changed, 42 insertions(+), 1 deletion(-) 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..cc1d39d663 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev *de= v, uint8_t *config, } return ret; } +static void vhost_vdpa_config_notify_start(struct vhost_dev *dev, + struct VirtIODevice *vdev, bool start) +{ + int fd, r; + if (start) { + fd =3D event_notifier_get_fd(&vdev->config_notifier); + vdev->use_config_notifier =3D true; + } else { + fd =3D -1; + vdev->use_config_notifier =3D false; + } + /*set the fd call back to vdpa driver*/ + r =3D dev->vhost_ops->vhost_set_config_call(dev, &fd); + if (r) { + vdev->use_config_notifier =3D false; + info_report("vhost_vdpa_config_notify not started!"); + } + /*active the config_notifier when vdev->use_config_notifier is true*/ + if ((vdev->use_config_notifier) && (start)) { + event_notifier_set(&vdev->config_notifier); + } + return; =20 +} static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; trace_vhost_vdpa_dev_start(dev, started); + VirtIODevice *vdev =3D dev->vdev; + if (started) { uint8_t status =3D 0; memory_listener_register(&v->listener, &address_space_memory); vhost_vdpa_set_vring_ready(dev); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); - + /*set the configure interrupt call back*/ + vhost_vdpa_config_notify_start(dev, vdev, true); return !(status & VIRTIO_CONFIG_S_DRIVER_OK); } else { + vhost_vdpa_config_notify_start(dev, vdev, false); vhost_vdpa_reset_device(dev); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); @@ -546,6 +573,13 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev = *dev, return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); } =20 +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); +} + static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features) { @@ -611,4 +645,5 @@ const VhostOps vdpa_ops =3D { .vhost_get_device_id =3D vhost_vdpa_get_device_id, .vhost_vq_get_addr =3D vhost_vdpa_vq_get_addr, .vhost_force_iommu =3D vhost_vdpa_force_iommu, + .vhost_set_config_call =3D vhost_vdpa_set_config_call, }; diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 8a6f8e2a7a..1a2fee8994 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -125,6 +125,9 @@ 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 +173,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