Skip to contentSkip to conversation

x86: allow to notify host about guest entering s2idle

RFC In review Grzegorz Jaszczyk 2 participants 5 messages Feb 13, 2023 – Apr 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover x86: allow to notify host about guest entering s2idle

According to the mailing list discussion [1] about the preferred approach for notifying hypervisor/VMM about guest entering s2idle state this RFC was implemented.

Instead of original hypercall based approach, which involves KVM change [2] and makes it hypervisor specific, implement different mechanism, which takes advantage of MMIO/PIO trapping and makes it hypervisor independent.

For the RFCv1 [3]:
Patch #1 extends S2Idle ops by new notify handler which will be invoked as a very last command before system actually enters S2Idle states. It also allows to register and use driver specific notification hook which is used in patch #2.

Patch #2 introduces new driver for virtual PMC, which registers acpi_s2idle_dev_ops's notify handler. Its implementation is based on an ACPI _DSM evaluation, which in turn can perform MMIO access and allow to trap and therefore notify the VMM about guest entering S2Idle state.

For the RFCv2 [4]: the patch #1 was dropped as in the meantime Mario Limonciello introduced a very similar patch [5] which uses s/notify/check and invokes the callback a bit earlier just before s2idle_entry. Mentioned patch has already been merged.

This patchset is marked as RFC since patch #2 implements driver for non existing device "HYPE0001", which ACPI ID was not registered yet. Furthermore the required registration process [6] will not be started before getting positive feedback about this patchset.

[1] https://patchwork.kernel.org/project/linux-pm/patch/[email protected]/
[2] https://patchwork.kernel.org/project/linux-pm/patch/[email protected]/
[3] https://patchwork.kernel.org/project/linux-pm/cover/[email protected]/
[4] https://patchwork.kernel.org/project/linux-pm/cover/[email protected]/
[5] https://patchwork.kernel.org/project/linux-pm/patch/[email protected]
[6] https://uefi.org/PNP_ACPI_Registry

Grzegorz Jaszczyk (1):
platform/x86: Add virtual PMC driver used for S2Idle

 drivers/platform/x86/Kconfig    |  7 +++
 drivers/platform/x86/Makefile   |  3 ++
 drivers/platform/x86/virt_pmc.c | 83 +++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
#1 lore raw

RFC v3 1/1 platform/x86: Add virtual PMC driver used for S2Idle

Virtual PMC driver is meant for the guest VMs for the S2Idle notification. Its purpose is to register S2Idle dev ops check handler, which will evaluate ACPI _DSM just before the guest enters S2Idle power state.

This allows to trap on MMIO access done as a consequence of _DSM evaluation and therefore notify the VMM about the guest entering S2Idle state.

---
Changelog v1..v2:
- Take advantage of acpi_s2idle_dev_ops's check() instead of notify()

Changelog v2..v3:
- Add MODULE_LICENSE
- Remove "amd" prefixes
- Be more verbose in VIRT_PMC config description and make it HYPERVISOR_GUEST dependent
- Add extra check ensuring that DSM method supports ACPI_VIRT_PMC_NOTIFY function

---
 drivers/platform/x86/Kconfig    |  7 +++
 drivers/platform/x86/Makefile   |  3 ++
 drivers/platform/x86/virt_pmc.c | 83 +++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c
drivers/platform/x86/Kconfig +7 -0
index 5692385e2d26..837ce201b68b 100644
@@ -1099,6 +1099,13 @@ config WINMATE_FM07_KEYS
 	  buttons below the display. This module adds an input device
 	  that delivers key events when these buttons are pressed.
 
+config VIRT_PMC
+	tristate "Virtual Power Management Controller"
+	depends on ACPI && SUSPEND && HYPERVISOR_GUEST
+	help
+	  The Virtual PMC driver is meant for the guest VMs and its main
+	  purpose is to notify about guest entering s2idle state.
+
 endif # X86_PLATFORM_DEVICES
 
 config P2SB
drivers/platform/x86/Makefile +3 -0
index 1d3d1b02541b..c4d3056cf4ea 100644
@@ -129,6 +129,9 @@ obj-$(CONFIG_INTEL_SCU_WDT)		+= intel_scu_wdt.o
 obj-$(CONFIG_INTEL_SCU_IPC_UTIL)	+= intel_scu_ipcutil.o
 obj-$(CONFIG_X86_INTEL_LPSS)		+= pmc_atom.o
 
+# Virtual PMC
+obj-$(CONFIG_VIRT_PMC)			+= virt_pmc.o
+
 # Siemens Simatic Industrial PCs
 obj-$(CONFIG_SIEMENS_SIMATIC_IPC)	+= simatic-ipc.o
 
drivers/platform/x86/virt_pmc.c new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
2.39.1.581.gbfd45094c4-goog
#2 lore raw

Re: [RFCv3 1/1] platform/x86: Add virtual PMC driver used for S2Idle

Hi Hans,

Do you think that this RFC is in good enough state to start the ACPI ID registration process so after it will be completed we could land this solution? Or maybe we could land it (of course if there are no other remarks) even before and adjust if needed?

Thank you in advance,
Grzegorz

pon., 13 lut 2023 o 11:11 Grzegorz Jaszczyk <[email protected]> napisał(a):

Quoted 152 lines

Virtual PMC driver is meant for the guest VMs for the S2Idle notification. Its purpose is to register S2Idle dev ops check handler, which will evaluate ACPI _DSM just before the guest enters S2Idle power state.

This allows to trap on MMIO access done as a consequence of _DSM evaluation and therefore notify the VMM about the guest entering S2Idle state.

---
Changelog v1..v2:
- Take advantage of acpi_s2idle_dev_ops's check() instead of notify()

Changelog v2..v3:
- Add MODULE_LICENSE
- Remove "amd" prefixes
- Be more verbose in VIRT_PMC config description and make it HYPERVISOR_GUEST dependent
- Add extra check ensuring that DSM method supports ACPI_VIRT_PMC_NOTIFY function

---
 drivers/platform/x86/Kconfig    |  7 +++
 drivers/platform/x86/Makefile   |  3 ++
 drivers/platform/x86/virt_pmc.c | 83 +++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c
drivers/platform/x86/Kconfig +7 -0
index 5692385e2d26..837ce201b68b 100644
@@ -1099,6 +1099,13 @@ config WINMATE_FM07_KEYS
          buttons below the display. This module adds an input device
          that delivers key events when these buttons are pressed.
 
+config VIRT_PMC
+       tristate "Virtual Power Management Controller"
+       depends on ACPI && SUSPEND && HYPERVISOR_GUEST
+       help
+         The Virtual PMC driver is meant for the guest VMs and its main
+         purpose is to notify about guest entering s2idle state.
+
 endif # X86_PLATFORM_DEVICES
 
 config P2SB
drivers/platform/x86/Makefile +3 -0
index 1d3d1b02541b..c4d3056cf4ea 100644
@@ -129,6 +129,9 @@ obj-$(CONFIG_INTEL_SCU_WDT)         += intel_scu_wdt.o
 obj-$(CONFIG_INTEL_SCU_IPC_UTIL)       += intel_scu_ipcutil.o
 obj-$(CONFIG_X86_INTEL_LPSS)           += pmc_atom.o
 
+# Virtual PMC
+obj-$(CONFIG_VIRT_PMC)                 += virt_pmc.o
+
 # Siemens Simatic Industrial PCs
 obj-$(CONFIG_SIEMENS_SIMATIC_IPC)      += simatic-ipc.o
 
drivers/platform/x86/virt_pmc.c new file +83 -1
new file mode 100644
index 000000000000..a5966bb9048f
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Virtual Power Management Controller Driver
+ *
+ * Author: Grzegorz Jaszczyk <[email protected]>
+ */
+
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+#define ACPI_VIRT_PMC_DSM_UUID "9ea49ba3-434a-49a6-be30-37cc55c4d397"
+#define ACPI_VIRT_PMC_NOTIFY 1
+
+static acpi_handle virt_pmc_handle;
+
+static void virt_pmc_s2idle_notify(void)
+{
+       union acpi_object *out_obj;
+       guid_t dsm_guid;
+
+       guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+       out_obj = acpi_evaluate_dsm(virt_pmc_handle, &dsm_guid,
+                                       0, ACPI_VIRT_PMC_NOTIFY, NULL);
+
+       acpi_handle_debug(virt_pmc_handle, "_DSM function %u evaluation %s\n",
+                         ACPI_VIRT_PMC_NOTIFY, out_obj ? "successful" : "failed");
+
+       ACPI_FREE(out_obj);
+}
+
+static struct acpi_s2idle_dev_ops pmc_s2idle_dev_ops = {
+       .check = virt_pmc_s2idle_notify,
+};
+
+static int virt_pmc_probe(struct platform_device *pdev)
+{
+       int err = 0;
+       guid_t dsm_guid;
+
+       virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
+
+       guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+       if (!acpi_check_dsm(virt_pmc_handle, &dsm_guid, 0,
+                           1 << ACPI_VIRT_PMC_NOTIFY)) {
+               dev_err(&pdev->dev, "DSM method doesn't support ACPI_VIRT_PMC_NOTIFY\n");
+               return -ENODEV;
+       }
+
+       err = acpi_register_lps0_dev(&pmc_s2idle_dev_ops);
+       if (err)
+               dev_err(&pdev->dev, "failed to register LPS0 sleep handler\n");
+
+       return err;
+}
+
+static int virt_pmc_remove(struct platform_device *pdev)
+{
+       acpi_unregister_lps0_dev(&pmc_s2idle_dev_ops);
+
+       return 0;
+}
+
+static const struct acpi_device_id virt_pmc_acpi_ids[] = {
+       {"HYPE0001", 0}, /* _HID for XXX Power Engine, _CID PNP0D80*/
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, virt_pmc_acpi_ids);
+
+static struct platform_driver virt_pmc_driver = {
+       .driver = {
+               .name = "virtual_pmc",
+               .acpi_match_table = ACPI_PTR(virt_pmc_acpi_ids),
+       },
+       .probe = virt_pmc_probe,
+       .remove = virt_pmc_remove,
+};
+
+module_platform_driver(virt_pmc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Virtual PMC Driver");
--

2.39.1.581.gbfd45094c4-goog

#3 lore raw

Re: [RFCv3 1/1] platform/x86: Add virtual PMC driver used for S2Idle

Hi Grzegorz,

Quoted 6 lines · Grzegorz Jaszczyk

Hi Hans,

Do you think that this RFC is in good enough state to start the ACPI ID registration process so after it will be completed we could land this solution? Or maybe we could land it (of course if there are no other remarks) even before and adjust if needed?

I see from the links in the cover-letter that most of the previous discussion has happened on the linux-pm list and I believe that the linux-pm folks are in a better place to answer this question then I am.

I have no objections against the suggested approach, but I don't really feel that it is my call to make if we should move forward with this.

Regards,

Hans

Quoted 154 lines

pon., 13 lut 2023 o 11:11 Grzegorz Jaszczyk <[email protected]> napisał(a):

Quoted 152 lines

Virtual PMC driver is meant for the guest VMs for the S2Idle notification. Its purpose is to register S2Idle dev ops check handler, which will evaluate ACPI _DSM just before the guest enters S2Idle power state.

This allows to trap on MMIO access done as a consequence of _DSM evaluation and therefore notify the VMM about the guest entering S2Idle state.

---
Changelog v1..v2:
- Take advantage of acpi_s2idle_dev_ops's check() instead of notify()

Changelog v2..v3:
- Add MODULE_LICENSE
- Remove "amd" prefixes
- Be more verbose in VIRT_PMC config description and make it HYPERVISOR_GUEST dependent
- Add extra check ensuring that DSM method supports ACPI_VIRT_PMC_NOTIFY function

---
 drivers/platform/x86/Kconfig    |  7 +++
 drivers/platform/x86/Makefile   |  3 ++
 drivers/platform/x86/virt_pmc.c | 83 +++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c
drivers/platform/x86/Kconfig +7 -0
index 5692385e2d26..837ce201b68b 100644
@@ -1099,6 +1099,13 @@ config WINMATE_FM07_KEYS
          buttons below the display. This module adds an input device
          that delivers key events when these buttons are pressed.
 
+config VIRT_PMC
+       tristate "Virtual Power Management Controller"
+       depends on ACPI && SUSPEND && HYPERVISOR_GUEST
+       help
+         The Virtual PMC driver is meant for the guest VMs and its main
+         purpose is to notify about guest entering s2idle state.
+
 endif # X86_PLATFORM_DEVICES
 
 config P2SB
drivers/platform/x86/Makefile +3 -0
index 1d3d1b02541b..c4d3056cf4ea 100644
@@ -129,6 +129,9 @@ obj-$(CONFIG_INTEL_SCU_WDT)         += intel_scu_wdt.o
 obj-$(CONFIG_INTEL_SCU_IPC_UTIL)       += intel_scu_ipcutil.o
 obj-$(CONFIG_X86_INTEL_LPSS)           += pmc_atom.o
 
+# Virtual PMC
+obj-$(CONFIG_VIRT_PMC)                 += virt_pmc.o
+
 # Siemens Simatic Industrial PCs
 obj-$(CONFIG_SIEMENS_SIMATIC_IPC)      += simatic-ipc.o
 
drivers/platform/x86/virt_pmc.c new file +83 -1
new file mode 100644
index 000000000000..a5966bb9048f
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Virtual Power Management Controller Driver
+ *
+ * Author: Grzegorz Jaszczyk <[email protected]>
+ */
+
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+#define ACPI_VIRT_PMC_DSM_UUID "9ea49ba3-434a-49a6-be30-37cc55c4d397"
+#define ACPI_VIRT_PMC_NOTIFY 1
+
+static acpi_handle virt_pmc_handle;
+
+static void virt_pmc_s2idle_notify(void)
+{
+       union acpi_object *out_obj;
+       guid_t dsm_guid;
+
+       guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+       out_obj = acpi_evaluate_dsm(virt_pmc_handle, &dsm_guid,
+                                       0, ACPI_VIRT_PMC_NOTIFY, NULL);
+
+       acpi_handle_debug(virt_pmc_handle, "_DSM function %u evaluation %s\n",
+                         ACPI_VIRT_PMC_NOTIFY, out_obj ? "successful" : "failed");
+
+       ACPI_FREE(out_obj);
+}
+
+static struct acpi_s2idle_dev_ops pmc_s2idle_dev_ops = {
+       .check = virt_pmc_s2idle_notify,
+};
+
+static int virt_pmc_probe(struct platform_device *pdev)
+{
+       int err = 0;
+       guid_t dsm_guid;
+
+       virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
+
+       guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+       if (!acpi_check_dsm(virt_pmc_handle, &dsm_guid, 0,
+                           1 << ACPI_VIRT_PMC_NOTIFY)) {
+               dev_err(&pdev->dev, "DSM method doesn't support ACPI_VIRT_PMC_NOTIFY\n");
+               return -ENODEV;
+       }
+
+       err = acpi_register_lps0_dev(&pmc_s2idle_dev_ops);
+       if (err)
+               dev_err(&pdev->dev, "failed to register LPS0 sleep handler\n");
+
+       return err;
+}
+
+static int virt_pmc_remove(struct platform_device *pdev)
+{
+       acpi_unregister_lps0_dev(&pmc_s2idle_dev_ops);
+
+       return 0;
+}
+
+static const struct acpi_device_id virt_pmc_acpi_ids[] = {
+       {"HYPE0001", 0}, /* _HID for XXX Power Engine, _CID PNP0D80*/
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, virt_pmc_acpi_ids);
+
+static struct platform_driver virt_pmc_driver = {
+       .driver = {
+               .name = "virtual_pmc",
+               .acpi_match_table = ACPI_PTR(virt_pmc_acpi_ids),
+       },
+       .probe = virt_pmc_probe,
+       .remove = virt_pmc_remove,
+};
+
+module_platform_driver(virt_pmc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Virtual PMC Driver");
--

2.39.1.581.gbfd45094c4-goog

#4 lore raw

Re: [RFCv3 1/1] platform/x86: Add virtual PMC driver used for S2Idle

[email protected]

Hi Hans, Rafael

czw., 6 kwi 2023 o 12:53 Hans de Goede <[email protected]> napisał(a):

Quoted 11 lines

Hi Grzegorz,

Quoted 6 lines · Grzegorz Jaszczyk

Hi Hans,

Do you think that this RFC is in good enough state to start the ACPI ID registration process so after it will be completed we could land this solution? Or maybe we could land it (of course if there are no other remarks) even before and adjust if needed?

Quoted 8 lines

I see from the links in the cover-letter that most of the previous discussion has happened on the linux-pm list and I believe that the linux-pm folks are in a better place to answer this question then I am.

I have no objections against the suggested approach, but I don't really feel that it is my call to make if we should move forward with this.

Hans: I see and thank you for your feedback.

Rafael: Could you please comment above?

Thank you in advance,
Grzegorz

Quoted 162 lines

Regards,

Hans

Quoted 154 lines

pon., 13 lut 2023 o 11:11 Grzegorz Jaszczyk <[email protected]> napisał(a):

Quoted 152 lines

Virtual PMC driver is meant for the guest VMs for the S2Idle notification. Its purpose is to register S2Idle dev ops check handler, which will evaluate ACPI _DSM just before the guest enters S2Idle power state.

This allows to trap on MMIO access done as a consequence of _DSM evaluation and therefore notify the VMM about the guest entering S2Idle state.

---
Changelog v1..v2:
- Take advantage of acpi_s2idle_dev_ops's check() instead of notify()

Changelog v2..v3:
- Add MODULE_LICENSE
- Remove "amd" prefixes
- Be more verbose in VIRT_PMC config description and make it HYPERVISOR_GUEST dependent
- Add extra check ensuring that DSM method supports ACPI_VIRT_PMC_NOTIFY function

---
 drivers/platform/x86/Kconfig    |  7 +++
 drivers/platform/x86/Makefile   |  3 ++
 drivers/platform/x86/virt_pmc.c | 83 +++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c
drivers/platform/x86/Kconfig +7 -0
index 5692385e2d26..837ce201b68b 100644
@@ -1099,6 +1099,13 @@ config WINMATE_FM07_KEYS
          buttons below the display. This module adds an input device
          that delivers key events when these buttons are pressed.
 
+config VIRT_PMC
+       tristate "Virtual Power Management Controller"
+       depends on ACPI && SUSPEND && HYPERVISOR_GUEST
+       help
+         The Virtual PMC driver is meant for the guest VMs and its main
+         purpose is to notify about guest entering s2idle state.
+
 endif # X86_PLATFORM_DEVICES
 
 config P2SB
drivers/platform/x86/Makefile +3 -0
index 1d3d1b02541b..c4d3056cf4ea 100644
@@ -129,6 +129,9 @@ obj-$(CONFIG_INTEL_SCU_WDT)         += intel_scu_wdt.o
 obj-$(CONFIG_INTEL_SCU_IPC_UTIL)       += intel_scu_ipcutil.o
 obj-$(CONFIG_X86_INTEL_LPSS)           += pmc_atom.o
 
+# Virtual PMC
+obj-$(CONFIG_VIRT_PMC)                 += virt_pmc.o
+
 # Siemens Simatic Industrial PCs
 obj-$(CONFIG_SIEMENS_SIMATIC_IPC)      += simatic-ipc.o
 
drivers/platform/x86/virt_pmc.c new file +83 -1
new file mode 100644
index 000000000000..a5966bb9048f
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Virtual Power Management Controller Driver
+ *
+ * Author: Grzegorz Jaszczyk <[email protected]>
+ */
+
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+#define ACPI_VIRT_PMC_DSM_UUID "9ea49ba3-434a-49a6-be30-37cc55c4d397"
+#define ACPI_VIRT_PMC_NOTIFY 1
+
+static acpi_handle virt_pmc_handle;
+
+static void virt_pmc_s2idle_notify(void)
+{
+       union acpi_object *out_obj;
+       guid_t dsm_guid;
+
+       guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+       out_obj = acpi_evaluate_dsm(virt_pmc_handle, &dsm_guid,
+                                       0, ACPI_VIRT_PMC_NOTIFY, NULL);
+
+       acpi_handle_debug(virt_pmc_handle, "_DSM function %u evaluation %s\n",
+                         ACPI_VIRT_PMC_NOTIFY, out_obj ? "successful" : "failed");
+
+       ACPI_FREE(out_obj);
+}
+
+static struct acpi_s2idle_dev_ops pmc_s2idle_dev_ops = {
+       .check = virt_pmc_s2idle_notify,
+};
+
+static int virt_pmc_probe(struct platform_device *pdev)
+{
+       int err = 0;
+       guid_t dsm_guid;
+
+       virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
+
+       guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+       if (!acpi_check_dsm(virt_pmc_handle, &dsm_guid, 0,
+                           1 << ACPI_VIRT_PMC_NOTIFY)) {
+               dev_err(&pdev->dev, "DSM method doesn't support ACPI_VIRT_PMC_NOTIFY\n");
+               return -ENODEV;
+       }
+
+       err = acpi_register_lps0_dev(&pmc_s2idle_dev_ops);
+       if (err)
+               dev_err(&pdev->dev, "failed to register LPS0 sleep handler\n");
+
+       return err;
+}
+
+static int virt_pmc_remove(struct platform_device *pdev)
+{
+       acpi_unregister_lps0_dev(&pmc_s2idle_dev_ops);
+
+       return 0;
+}
+
+static const struct acpi_device_id virt_pmc_acpi_ids[] = {
+       {"HYPE0001", 0}, /* _HID for XXX Power Engine, _CID PNP0D80*/
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, virt_pmc_acpi_ids);
+
+static struct platform_driver virt_pmc_driver = {
+       .driver = {
+               .name = "virtual_pmc",
+               .acpi_match_table = ACPI_PTR(virt_pmc_acpi_ids),
+       },
+       .probe = virt_pmc_probe,
+       .remove = virt_pmc_remove,
+};
+
+module_platform_driver(virt_pmc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Virtual PMC Driver");
--

2.39.1.581.gbfd45094c4-goog