From: Leo Yan <leo.yan@linaro.org> To: "kvm@vger.kernel.org" <kvm@vger.kernel.org>, "kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>, Will Deacon <Will.Deacon@arm.com>, Jean-Philippe Brucker <jean-philippe.brucker@arm.com>, Marc Zyngier <Marc.Zyngier@arm.com>, Eric Auger <eric.auger@redhat.com>, Robin Murphy <Robin.Murphy@arm.com> Cc: Leo Yan <leo.yan@linaro.org> Subject: [PATCH v4 2/3] vfio-pci: Add new function for INTx one-time initialisation Date: Mon, 8 Apr 2019 09:27:18 +0800 [thread overview] Message-ID: <20190408012719.16158-3-leo.yan@linaro.org> (raw) In-Reply-To: <20190408012719.16158-1-leo.yan@linaro.org> To support INTx enabling for multiple times, we need firstly to extract one-time initialisation and move the related code into a new function vfio_pci_init_intx(); if later disable and re-enable the INTx, we can skip these one-time operations. This patch move below three main operations for INTx one-time initialisation from function vfio_pci_enable_intx() into function vfio_pci_init_intx(): - Reserve 2 FDs for INTx; - Sanity check with ioctl VFIO_DEVICE_GET_IRQ_INFO; - Setup pdev->intx_gsi. Suggested-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com> Signed-off-by: Leo Yan <leo.yan@linaro.org> Reviewed-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com> --- vfio/pci.c | 67 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/vfio/pci.c b/vfio/pci.c index 5224fee..3c39844 100644 --- a/vfio/pci.c +++ b/vfio/pci.c @@ -1018,30 +1018,7 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) struct vfio_irq_eventfd trigger; struct vfio_irq_eventfd unmask; struct vfio_pci_device *pdev = &vdev->pci; - int gsi = pdev->hdr.irq_line - KVM_IRQ_OFFSET; - - struct vfio_irq_info irq_info = { - .argsz = sizeof(irq_info), - .index = VFIO_PCI_INTX_IRQ_INDEX, - }; - - vfio_pci_reserve_irq_fds(2); - - ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); - if (ret || irq_info.count == 0) { - vfio_dev_err(vdev, "no INTx reported by VFIO"); - return -ENODEV; - } - - if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { - vfio_dev_err(vdev, "interrupt not eventfd capable"); - return -EINVAL; - } - - if (!(irq_info.flags & VFIO_IRQ_INFO_AUTOMASKED)) { - vfio_dev_err(vdev, "INTx interrupt not AUTOMASKED"); - return -EINVAL; - } + int gsi = pdev->intx_gsi; /* * PCI IRQ is level-triggered, so we use two eventfds. trigger_fd @@ -1097,8 +1074,6 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) pdev->intx_fd = trigger_fd; pdev->unmask_fd = unmask_fd; - /* Guest is going to ovewrite our irq_line... */ - pdev->intx_gsi = gsi; return 0; @@ -1117,6 +1092,39 @@ err_close: return ret; } +static int vfio_pci_init_intx(struct kvm *kvm, struct vfio_device *vdev) +{ + int ret; + struct vfio_pci_device *pdev = &vdev->pci; + struct vfio_irq_info irq_info = { + .argsz = sizeof(irq_info), + .index = VFIO_PCI_INTX_IRQ_INDEX, + }; + + vfio_pci_reserve_irq_fds(2); + + ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); + if (ret || irq_info.count == 0) { + vfio_dev_err(vdev, "no INTx reported by VFIO"); + return -ENODEV; + } + + if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { + vfio_dev_err(vdev, "interrupt not eventfd capable"); + return -EINVAL; + } + + if (!(irq_info.flags & VFIO_IRQ_INFO_AUTOMASKED)) { + vfio_dev_err(vdev, "INTx interrupt not AUTOMASKED"); + return -EINVAL; + } + + /* Guest is going to ovewrite our irq_line... */ + pdev->intx_gsi = pdev->hdr.irq_line - KVM_IRQ_OFFSET; + + return 0; +} + static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev) { int ret = 0; @@ -1142,8 +1150,13 @@ static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev return ret; } - if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) + if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) { + ret = vfio_pci_init_intx(kvm, vdev); + if (ret) + return ret; + ret = vfio_pci_enable_intx(kvm, vdev); + } return ret; } -- 2.19.1
WARNING: multiple messages have this Message-ID (diff)
From: Leo Yan <leo.yan@linaro.org> To: "kvm@vger.kernel.org" <kvm@vger.kernel.org>, "kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>, Will Deacon <Will.Deacon@arm.com>, Jean-Philippe Brucker <jean-philippe.brucker@arm.com>, Marc Zyngier <Marc.Zyngier@arm.com>, Eric Auger <eric.auger@redhat.com>, Robin Murphy <Robin.Murphy@arm.com> Cc: Leo Yan <leo.yan@linaro.org> Subject: [PATCH v4 2/3] vfio-pci: Add new function for INTx one-time initialisation Date: Mon, 8 Apr 2019 09:27:18 +0800 [thread overview] Message-ID: <20190408012719.16158-3-leo.yan@linaro.org> (raw) Message-ID: <20190408012718.Aq3fNPkP2BoLZ2y_woo5nh9puTbRH0gMzYlMp2Xiv5A@z> (raw) In-Reply-To: <20190408012719.16158-1-leo.yan@linaro.org> To support INTx enabling for multiple times, we need firstly to extract one-time initialisation and move the related code into a new function vfio_pci_init_intx(); if later disable and re-enable the INTx, we can skip these one-time operations. This patch move below three main operations for INTx one-time initialisation from function vfio_pci_enable_intx() into function vfio_pci_init_intx(): - Reserve 2 FDs for INTx; - Sanity check with ioctl VFIO_DEVICE_GET_IRQ_INFO; - Setup pdev->intx_gsi. Suggested-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com> Signed-off-by: Leo Yan <leo.yan@linaro.org> Reviewed-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com> --- vfio/pci.c | 67 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/vfio/pci.c b/vfio/pci.c index 5224fee..3c39844 100644 --- a/vfio/pci.c +++ b/vfio/pci.c @@ -1018,30 +1018,7 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) struct vfio_irq_eventfd trigger; struct vfio_irq_eventfd unmask; struct vfio_pci_device *pdev = &vdev->pci; - int gsi = pdev->hdr.irq_line - KVM_IRQ_OFFSET; - - struct vfio_irq_info irq_info = { - .argsz = sizeof(irq_info), - .index = VFIO_PCI_INTX_IRQ_INDEX, - }; - - vfio_pci_reserve_irq_fds(2); - - ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); - if (ret || irq_info.count == 0) { - vfio_dev_err(vdev, "no INTx reported by VFIO"); - return -ENODEV; - } - - if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { - vfio_dev_err(vdev, "interrupt not eventfd capable"); - return -EINVAL; - } - - if (!(irq_info.flags & VFIO_IRQ_INFO_AUTOMASKED)) { - vfio_dev_err(vdev, "INTx interrupt not AUTOMASKED"); - return -EINVAL; - } + int gsi = pdev->intx_gsi; /* * PCI IRQ is level-triggered, so we use two eventfds. trigger_fd @@ -1097,8 +1074,6 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) pdev->intx_fd = trigger_fd; pdev->unmask_fd = unmask_fd; - /* Guest is going to ovewrite our irq_line... */ - pdev->intx_gsi = gsi; return 0; @@ -1117,6 +1092,39 @@ err_close: return ret; } +static int vfio_pci_init_intx(struct kvm *kvm, struct vfio_device *vdev) +{ + int ret; + struct vfio_pci_device *pdev = &vdev->pci; + struct vfio_irq_info irq_info = { + .argsz = sizeof(irq_info), + .index = VFIO_PCI_INTX_IRQ_INDEX, + }; + + vfio_pci_reserve_irq_fds(2); + + ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); + if (ret || irq_info.count == 0) { + vfio_dev_err(vdev, "no INTx reported by VFIO"); + return -ENODEV; + } + + if (!(irq_info.flags & VFIO_IRQ_INFO_EVENTFD)) { + vfio_dev_err(vdev, "interrupt not eventfd capable"); + return -EINVAL; + } + + if (!(irq_info.flags & VFIO_IRQ_INFO_AUTOMASKED)) { + vfio_dev_err(vdev, "INTx interrupt not AUTOMASKED"); + return -EINVAL; + } + + /* Guest is going to ovewrite our irq_line... */ + pdev->intx_gsi = pdev->hdr.irq_line - KVM_IRQ_OFFSET; + + return 0; +} + static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev) { int ret = 0; @@ -1142,8 +1150,13 @@ static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev return ret; } - if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) + if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) { + ret = vfio_pci_init_intx(kvm, vdev); + if (ret) + return ret; + ret = vfio_pci_enable_intx(kvm, vdev); + } return ret; } -- 2.19.1 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next prev parent reply other threads:[~2019-04-08 1:27 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-08 1:27 [PATCH v4 0/3] vfio-pci: Support INTx mode re-enabling Leo Yan 2019-04-08 1:27 ` Leo Yan 2019-04-08 1:27 ` [PATCH v4 1/3] vfio-pci: Release INTx's unmask eventfd properly Leo Yan 2019-04-08 1:27 ` Leo Yan 2019-04-08 1:27 ` Leo Yan [this message] 2019-04-08 1:27 ` [PATCH v4 2/3] vfio-pci: Add new function for INTx one-time initialisation Leo Yan 2019-04-08 1:27 ` [PATCH v4 3/3] vfio-pci: Re-enable INTx mode when disable MSI/MSIX Leo Yan 2019-04-08 1:27 ` Leo Yan 2019-04-24 14:21 ` [PATCH v4 0/3] vfio-pci: Support INTx mode re-enabling Leo Yan 2019-04-24 14:21 ` Leo Yan 2019-04-25 14:03 ` Will Deacon 2019-04-25 14:03 ` Will Deacon 2019-04-25 14:03 ` Will Deacon
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190408012719.16158-3-leo.yan@linaro.org \ --to=leo.yan@linaro.org \ --cc=Marc.Zyngier@arm.com \ --cc=Robin.Murphy@arm.com \ --cc=Will.Deacon@arm.com \ --cc=eric.auger@redhat.com \ --cc=jean-philippe.brucker@arm.com \ --cc=kvm@vger.kernel.org \ --cc=kvmarm@lists.cs.columbia.edu \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.