From patchwork Wed Mar 18 14:52:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11445407 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4BA013B1 for ; Wed, 18 Mar 2020 14:53:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A45920752 for ; Wed, 18 Mar 2020 14:53:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="K8eRIGx1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A45920752 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEa4G-0001jF-MN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 10:53:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46281) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEa3X-0000Tq-12 for qemu-devel@nongnu.org; Wed, 18 Mar 2020 10:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEa3V-0006ZB-OH for qemu-devel@nongnu.org; Wed, 18 Mar 2020 10:52:26 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:29564) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEa3V-0006UL-Jv for qemu-devel@nongnu.org; Wed, 18 Mar 2020 10:52:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584543145; 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=d7VCARQpa543CzI17Qh3SwV/uYby6Bu6+9e0X/pxZcw=; b=K8eRIGx1QV/oZKk4FoV8Djwpzn8m+uZNnmZ6KjK64y8HyfL/eCrbweNPJblrpJMKx9p+dG HzPJNmgOlv6Ko7gG1Kbb0pwma6oo3Cy5MiYKBccc69IxXBARdbdm/84zjznaI455RaW5AZ tIUS3gcNLhUAd+JUxEBf03xsgkLTdV4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-KILDF9pMNDmDXYUCFfFWrA-1; Wed, 18 Mar 2020 10:52:23 -0400 X-MC-Unique: KILDF9pMNDmDXYUCFfFWrA-1 Received: by mail-wm1-f70.google.com with SMTP id p18so1179528wmk.9 for ; Wed, 18 Mar 2020 07:52:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R4ymvWMCxrIfLkhgyjJ3vQ3SuCXiTnkkegIn5k6FWHQ=; b=Xcr6fItjPYGJYf6Hz34MF2GRRJYdD8JzgtjjLRoF8tDsVzuSYBUNOKP8YmjFTEitON Lzk+1k6c/Pz0UdmLyledrJkaGkyiSbtACOHYvdwb/yXg2qgjpgIYizgHkeb4aEWbI8gL T+/XKZZM8UU/b/7sis5HLb2ivs/opwRepQJ0e/lxB8QNa6lOVTkJyGt6RT+DdtmqrmFL ANsdH0pvrzVXkZ2V9uaskfqvNHleidwdG1Flc4jRIxTXcyfSBea4e992AWKa47wAAsog WUHj6sDmHvxEU4Wm3ne9sIl6f1DUMwy2oAzCj9djCyCtkOclnkC18XweF5OQc9IqP8cV J0IQ== X-Gm-Message-State: ANhLgQ3yR00lmQ0a45KXc3GDbiO9oqzbsUjUiLr5/MHFl7w4f32dbdVx EWNqClWtJ88j5E4rA+nvfzraycXHodN6NeNZstHaYQ53JD3Dh4hyz0u3+J1W0YBCpIFQA2n5PVF zBiN+5JqoTuTgqVQ= X-Received: by 2002:a1c:2e92:: with SMTP id u140mr5622803wmu.84.1584543141476; Wed, 18 Mar 2020 07:52:21 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtKnJco+TcUaI3QTwe7pmpsdrvaNbGxtpa2G8FyQoAWX0/FBt4bIUhcBOSmkrUCPYYvbZ2nwQ== X-Received: by 2002:a1c:2e92:: with SMTP id u140mr5622776wmu.84.1584543141233; Wed, 18 Mar 2020 07:52:21 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id v10sm3912401wml.44.2020.03.18.07.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 07:52:20 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 2/5] vfio/pci: Use kvm_irqchip_add_irqfd_notifier_gsi() for irqfds Date: Wed, 18 Mar 2020 10:52:01 -0400 Message-Id: <20200318145204.74483-3-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200318145204.74483-1-peterx@redhat.com> References: <20200318145204.74483-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 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: Eric Auger , Alex Williamson , Cornelia Huck , peterx@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" VFIO is currently the only one left that is not using the generic function (kvm_irqchip_add_irqfd_notifier_gsi()) to register irqfds. Let VFIO use the common framework too. Follow up patches will introduce extra features for kvm irqfd, so that VFIO can easily leverage that after the switch. Reviewed-by: Eric Auger Reviewed-by: Cornelia Huck Reviewed-by: Alex Williamson Acked-by: Alex Williamson Signed-off-by: Peter Xu --- hw/vfio/pci.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 98e0e0c994..09703362df 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -115,11 +115,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev) static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { #ifdef CONFIG_KVM - struct kvm_irqfd irqfd = { - .fd = event_notifier_get_fd(&vdev->intx.interrupt), - .gsi = vdev->intx.route.irq, - .flags = KVM_IRQFD_FLAG_RESAMPLE, - }; + int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt); Error *err = NULL; if (vdev->no_kvm_intx || !kvm_irqfds_enabled() || @@ -141,7 +137,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) } /* Get to a known interrupt state */ - qemu_set_fd_handler(irqfd.fd, NULL, NULL, vdev); + qemu_set_fd_handler(irq_fd, NULL, NULL, vdev); vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending = false; pci_irq_deassert(&vdev->pdev); @@ -152,17 +148,18 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) goto fail; } - /* KVM triggers it, VFIO listens for it */ - irqfd.resamplefd = event_notifier_get_fd(&vdev->intx.unmask); - - if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) { + if (kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, + &vdev->intx.interrupt, + &vdev->intx.unmask, + vdev->intx.route.irq)) { error_setg_errno(errp, errno, "failed to setup resample irqfd"); goto fail_irqfd; } if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0, VFIO_IRQ_SET_ACTION_UNMASK, - irqfd.resamplefd, &err)) { + event_notifier_get_fd(&vdev->intx.unmask), + &err)) { error_propagate(errp, err); goto fail_vfio; } @@ -177,12 +174,12 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) return; fail_vfio: - irqfd.flags = KVM_IRQFD_FLAG_DEASSIGN; - kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd); + kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt, + vdev->intx.route.irq); fail_irqfd: event_notifier_cleanup(&vdev->intx.unmask); fail: - qemu_set_fd_handler(irqfd.fd, vfio_intx_interrupt, NULL, vdev); + qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev); vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); #endif } @@ -190,12 +187,6 @@ fail: static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) { #ifdef CONFIG_KVM - struct kvm_irqfd irqfd = { - .fd = event_notifier_get_fd(&vdev->intx.interrupt), - .gsi = vdev->intx.route.irq, - .flags = KVM_IRQFD_FLAG_DEASSIGN, - }; - if (!vdev->intx.kvm_accel) { return; } @@ -209,7 +200,8 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) pci_irq_deassert(&vdev->pdev); /* Tell KVM to stop listening for an INTx irqfd */ - if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, &irqfd)) { + if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt, + vdev->intx.route.irq)) { error_report("vfio: Error: Failed to disable INTx irqfd: %m"); } @@ -217,7 +209,8 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) event_notifier_cleanup(&vdev->intx.unmask); /* QEMU starts listening for interrupt events. */ - qemu_set_fd_handler(irqfd.fd, vfio_intx_interrupt, NULL, vdev); + qemu_set_fd_handler(event_notifier_get_fd(&vdev->intx.interrupt), + vfio_intx_interrupt, NULL, vdev); vdev->intx.kvm_accel = false;