All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grzegorz Jaszczyk <jaz@semihalf.com>
To: linux-kernel@vger.kernel.org, alex.williamson@redhat.com
Cc: dmy@semihalf.com, tn@semihalf.com, dbehr@google.com,
	upstream@semihalf.com, dtor@google.com, jgg@ziepe.ca,
	kevin.tian@intel.com, cohuck@redhat.com, abhsahu@nvidia.com,
	yishaih@nvidia.com, yi.l.liu@intel.com, kvm@vger.kernel.org,
	Dominik Behr <dbehr@chromium.org>,
	Grzegorz Jaszczyk <jaz@semihalf.com>
Subject: [PATCH] vfio/pci: Propagate ACPI notifications to the user-space
Date: Tue,  7 Mar 2023 22:05:53 +0000	[thread overview]
Message-ID: <20230307220553.631069-1-jaz@semihalf.com> (raw)

From: Dominik Behr <dbehr@chromium.org>

Hitherto there was no support for propagating ACPI notifications to the
guest drivers. In order to provide such support, install a handler for
notifications on an ACPI device during vfio-pci device registration. The
handler role is to propagate such ACPI notifications to the user-space
via acpi netlink events, which allows VMM to receive and propagate them
further to the VMs.

Thanks to the above, the actual driver for the pass-through device,
which belongs to the guest, can receive and react to device specific
notifications.

Signed-off-by: Dominik Behr <dbehr@chromium.org>
Co-developed-by: Grzegorz Jaszczyk <jaz@semihalf.com>
Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index a5ab416cf476..92b8ed8d087c 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -10,6 +10,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/acpi.h>
 #include <linux/aperture.h>
 #include <linux/device.h>
 #include <linux/eventfd.h>
@@ -2120,10 +2121,20 @@ void vfio_pci_core_release_dev(struct vfio_device *core_vdev)
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_release_dev);
 
+static void vfio_pci_core_acpi_notify(acpi_handle handle, u32 event, void *data)
+{
+	struct vfio_pci_core_device *vdev = (struct vfio_pci_core_device *)data;
+	struct device *dev = &vdev->pdev->dev;
+
+	acpi_bus_generate_netlink_event("vfio_pci", dev_name(dev), event, 0);
+}
+
 int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
 {
+	acpi_status status;
 	struct pci_dev *pdev = vdev->pdev;
 	struct device *dev = &pdev->dev;
+	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
 	int ret;
 
 	/* Drivers must set the vfio_pci_core_device to their drvdata */
@@ -2201,8 +2212,24 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
 	ret = vfio_register_group_dev(&vdev->vdev);
 	if (ret)
 		goto out_power;
+
+	if (!adev) {
+		pci_info(pdev, "No ACPI companion");
+		return 0;
+	}
+
+	status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
+					vfio_pci_core_acpi_notify, (void *)vdev);
+
+	if (ACPI_FAILURE(status)) {
+		pci_err(pdev, "Failed to install notify handler");
+		goto out_group_register;
+	}
+
 	return 0;
 
+out_group_register:
+	vfio_unregister_group_dev(&vdev->vdev);
 out_power:
 	if (!disable_idle_d3)
 		pm_runtime_get_noresume(dev);
@@ -2216,6 +2243,12 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_register_device);
 
 void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev)
 {
+	struct acpi_device *adev = ACPI_COMPANION(&vdev->pdev->dev);
+
+	if (adev)
+		acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
+					   vfio_pci_core_acpi_notify);
+
 	vfio_pci_core_sriov_configure(vdev, 0);
 
 	vfio_unregister_group_dev(&vdev->vdev);
-- 
2.40.0.rc0.216.gc4246ad0f0-goog


             reply	other threads:[~2023-03-07 22:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 22:05 Grzegorz Jaszczyk [this message]
2023-03-07 23:41 ` [PATCH] vfio/pci: Propagate ACPI notifications to the user-space Alex Williamson
2023-03-08  8:11   ` Tian, Kevin
2023-03-08 11:41   ` Grzegorz Jaszczyk
2023-03-08 17:49     ` Alex Williamson
2023-03-08 18:45       ` Dominik Behr
2023-03-08 20:06         ` Alex Williamson
2023-03-08 22:44           ` Dominik Behr
2023-03-08 23:38             ` Alex Williamson
2023-03-09  1:51               ` Dominik Behr
2023-03-09 18:25                 ` Jason Gunthorpe
2023-03-09 13:41               ` Grzegorz Jaszczyk
2023-03-22  9:47                 ` Grzegorz Jaszczyk
2023-03-23 17:07                 ` Alex Williamson
2023-03-24 12:29                   ` Grzegorz Jaszczyk
2023-03-08 14:40 ` kernel test robot

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=20230307220553.631069-1-jaz@semihalf.com \
    --to=jaz@semihalf.com \
    --cc=abhsahu@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=dbehr@chromium.org \
    --cc=dbehr@google.com \
    --cc=dmy@semihalf.com \
    --cc=dtor@google.com \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tn@semihalf.com \
    --cc=upstream@semihalf.com \
    --cc=yi.l.liu@intel.com \
    --cc=yishaih@nvidia.com \
    /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: link
Be 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.