linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND RFCv2 0/1] x86: allow to notify host about guest entering s2idle
@ 2023-02-09 15:21 Grzegorz Jaszczyk
  2023-02-09 15:21 ` [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle Grzegorz Jaszczyk
  0 siblings, 1 reply; 8+ messages in thread
From: Grzegorz Jaszczyk @ 2023-02-09 15:21 UTC (permalink / raw)
  To: linux-kernel, rafael
  Cc: dmy, tn, dbehr, zide.chen, seanjc, upstream, hdegoede, markgross,
	dtor, mario.limonciello, linux-pm, x86, platform-driver-x86,
	Grzegorz Jaszczyk

<Resend with some extra lists added to the Cc>

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: the patch #1 was dropped as in the meantime Mario Limonciello
introduced a very similar patch [4] 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 [5] will not be started
before getting positive feedback about this patchset.

[1] https://patchwork.kernel.org/project/linux-pm/patch/20220609110337.1238762-2-jaz@semihalf.com/
[2] https://patchwork.kernel.org/project/linux-pm/patch/20220609110337.1238762-3-jaz@semihalf.com/
[3] https://patchwork.kernel.org/project/linux-pm/cover/20220707125329.378277-1-jaz@semihalf.com/
[4] https://patchwork.kernel.org/project/linux-pm/patch/20220829162953.5947-2-mario.limonciello@amd.com
[5] 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 | 73 +++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c

-- 
2.39.1.519.gcb327c4b5f-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 15:21 [RESEND RFCv2 0/1] x86: allow to notify host about guest entering s2idle Grzegorz Jaszczyk
@ 2023-02-09 15:21 ` Grzegorz Jaszczyk
  2023-02-09 18:05   ` Thomas Gleixner
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Grzegorz Jaszczyk @ 2023-02-09 15:21 UTC (permalink / raw)
  To: linux-kernel, rafael
  Cc: dmy, tn, dbehr, zide.chen, seanjc, upstream, hdegoede, markgross,
	dtor, mario.limonciello, linux-pm, x86, platform-driver-x86,
	Grzegorz Jaszczyk

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.

Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
---
Changelog v1..v2:
- Take advantage of acpi_s2idle_dev_ops's check() instead of notify()
---
 drivers/platform/x86/Kconfig    |  7 ++++
 drivers/platform/x86/Makefile   |  3 ++
 drivers/platform/x86/virt_pmc.c | 73 +++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 drivers/platform/x86/virt_pmc.c

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 5692385e2d26..b7c3f98031d7 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -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 "Virt PMC"
+	depends on ACPI && SUSPEND
+	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
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 1d3d1b02541b..c4d3056cf4ea 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -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
 
diff --git a/drivers/platform/x86/virt_pmc.c b/drivers/platform/x86/virt_pmc.c
new file mode 100644
index 000000000000..daf9c9ed86e5
--- /dev/null
+++ b/drivers/platform/x86/virt_pmc.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Virtual Power Management Controller Driver
+ *
+ * Author: Grzegorz Jaszczyk <jaz@semihalf.com>
+ */
+
+#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;
+	static 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 amd_pmc_s2idle_dev_ops = {
+	.check = virt_pmc_s2idle_notify,
+};
+
+static int virt_pmc_probe(struct platform_device *pdev)
+{
+	int err = 0;
+
+	virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
+
+	err = acpi_register_lps0_dev(&amd_pmc_s2idle_dev_ops);
+	if (err)
+		dev_warn(&pdev->dev, "failed to register LPS0 sleep handler\n");
+
+	return err;
+}
+
+static int virt_pmc_remove(struct platform_device *pdev)
+{
+	acpi_unregister_lps0_dev(&amd_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_DESCRIPTION("Virtual PMC Driver");
-- 
2.39.1.519.gcb327c4b5f-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 15:21 ` [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle Grzegorz Jaszczyk
@ 2023-02-09 18:05   ` Thomas Gleixner
  2023-02-10 10:51     ` Grzegorz Jaszczyk
  2023-02-09 18:25   ` Limonciello, Mario
  2023-02-09 21:26   ` Sean Christopherson
  2 siblings, 1 reply; 8+ messages in thread
From: Thomas Gleixner @ 2023-02-09 18:05 UTC (permalink / raw)
  To: Grzegorz Jaszczyk, linux-kernel, rafael
  Cc: dmy, tn, dbehr, zide.chen, seanjc, upstream, hdegoede, markgross,
	dtor, mario.limonciello, linux-pm, x86, platform-driver-x86,
	Grzegorz Jaszczyk

On Thu, Feb 09 2023 at 15:21, Grzegorz Jaszczyk wrote:
> +
> +static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = {

What is AMD specific about this?

> +	.check = virt_pmc_s2idle_notify,
> +};

...

> +
> +MODULE_DESCRIPTION("Virtual PMC Driver");

Lacks MODULE_LICENSE("GPL")

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 15:21 ` [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle Grzegorz Jaszczyk
  2023-02-09 18:05   ` Thomas Gleixner
@ 2023-02-09 18:25   ` Limonciello, Mario
  2023-02-10 10:56     ` Grzegorz Jaszczyk
  2023-02-09 21:26   ` Sean Christopherson
  2 siblings, 1 reply; 8+ messages in thread
From: Limonciello, Mario @ 2023-02-09 18:25 UTC (permalink / raw)
  To: Grzegorz Jaszczyk, linux-kernel, rafael
  Cc: dmy, tn, dbehr, zide.chen, seanjc, upstream, hdegoede, markgross,
	dtor, linux-pm, x86, platform-driver-x86

[AMD Official Use Only - General]



> -----Original Message-----
> From: Grzegorz Jaszczyk <jaz@semihalf.com>
> Sent: Thursday, February 9, 2023 09:21
> To: linux-kernel@vger.kernel.org; rafael@kernel.org
> Cc: dmy@semihalf.com; tn@semihalf.com; dbehr@google.com;
> zide.chen@intel.corp-partner.google.com; seanjc@google.com;
> upstream@semihalf.com; hdegoede@redhat.com; markgross@kernel.org;
> dtor@google.com; Limonciello, Mario <Mario.Limonciello@amd.com>; linux-
> pm@vger.kernel.org; x86@kernel.org; platform-driver-x86@vger.kernel.org;
> Grzegorz Jaszczyk <jaz@semihalf.com>
> Subject: [RESEND RFCv2 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.
> 
> Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
> ---
> Changelog v1..v2:
> - Take advantage of acpi_s2idle_dev_ops's check() instead of notify()
> ---
>  drivers/platform/x86/Kconfig    |  7 ++++
>  drivers/platform/x86/Makefile   |  3 ++
>  drivers/platform/x86/virt_pmc.c | 73
> +++++++++++++++++++++++++++++++++
>  3 files changed, 83 insertions(+)
>  create mode 100644 drivers/platform/x86/virt_pmc.c
> 
> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index 5692385e2d26..b7c3f98031d7 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -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 "Virt PMC"
> +	depends on ACPI && SUSPEND
> +	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
> diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
> index 1d3d1b02541b..c4d3056cf4ea 100644
> --- a/drivers/platform/x86/Makefile
> +++ b/drivers/platform/x86/Makefile
> @@ -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
> 
> diff --git a/drivers/platform/x86/virt_pmc.c
> b/drivers/platform/x86/virt_pmc.c
> new file mode 100644
> index 000000000000..daf9c9ed86e5
> --- /dev/null
> +++ b/drivers/platform/x86/virt_pmc.c
> @@ -0,0 +1,73 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Virtual Power Management Controller Driver
> + *
> + * Author: Grzegorz Jaszczyk <jaz@semihalf.com>
> + */
> +
> +#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;
> +	static 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 amd_pmc_s2idle_dev_ops = {
> +	.check = virt_pmc_s2idle_notify,
> +};
> +
> +static int virt_pmc_probe(struct platform_device *pdev)
> +{
> +	int err = 0;
> +
> +	virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
> +
> +	err = acpi_register_lps0_dev(&amd_pmc_s2idle_dev_ops);
> +	if (err)
> +		dev_warn(&pdev->dev, "failed to register LPS0 sleep
> handler\n");
> +

Besides registering, I would think you also want to have a query to the
_DSM to determine what functions are available.  It could allow this to
scale better if you're going to need to introduce a new function again
later for a different reason.

> +	return err;
> +}
> +
> +static int virt_pmc_remove(struct platform_device *pdev)
> +{
> +	acpi_unregister_lps0_dev(&amd_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_DESCRIPTION("Virtual PMC Driver");
> --
> 2.39.1.519.gcb327c4b5f-goog

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 15:21 ` [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle Grzegorz Jaszczyk
  2023-02-09 18:05   ` Thomas Gleixner
  2023-02-09 18:25   ` Limonciello, Mario
@ 2023-02-09 21:26   ` Sean Christopherson
  2023-02-10 10:58     ` Grzegorz Jaszczyk
  2 siblings, 1 reply; 8+ messages in thread
From: Sean Christopherson @ 2023-02-09 21:26 UTC (permalink / raw)
  To: Grzegorz Jaszczyk
  Cc: linux-kernel, rafael, dmy, tn, dbehr, zide.chen, upstream,
	hdegoede, markgross, dtor, mario.limonciello, linux-pm, x86,
	platform-driver-x86

On Thu, Feb 09, 2023, Grzegorz Jaszczyk wrote:
> 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.
> 
> Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
> ---
> Changelog v1..v2:
> - Take advantage of acpi_s2idle_dev_ops's check() instead of notify()
> ---
>  drivers/platform/x86/Kconfig    |  7 ++++
>  drivers/platform/x86/Makefile   |  3 ++
>  drivers/platform/x86/virt_pmc.c | 73 +++++++++++++++++++++++++++++++++
>  3 files changed, 83 insertions(+)
>  create mode 100644 drivers/platform/x86/virt_pmc.c
> 
> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index 5692385e2d26..b7c3f98031d7 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -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 "Virt PMC"

Maybe spell out "Virtual Power Management Controller"?  See below.

> +	depends on ACPI && SUSPEND

I think it makes sense to take a dependency on HYPERVISOR_GUEST.  It's not strictly
required, but taking that dependency helps clarify that this is a guest-side thing,
e.g. "virtual PMC" in KVM-land means "virtual performance monitoring counter".

And IMO, disabling HYPERVISOR_GUEST should disable these type of guest-specific
features.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 18:05   ` Thomas Gleixner
@ 2023-02-10 10:51     ` Grzegorz Jaszczyk
  0 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Jaszczyk @ 2023-02-10 10:51 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, rafael, dmy, tn, dbehr, zide.chen, seanjc,
	upstream, hdegoede, markgross, dtor, mario.limonciello, linux-pm,
	x86, platform-driver-x86

czw., 9 lut 2023 o 19:05 Thomas Gleixner <tglx@linutronix.de> napisał(a):
>
> On Thu, Feb 09 2023 at 15:21, Grzegorz Jaszczyk wrote:
> > +
> > +static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = {
>
> What is AMD specific about this?

Nothing, my bad - I will remove the 'amd' prefix.

>
> > +     .check = virt_pmc_s2idle_notify,
> > +};
>
> ...
>
> > +
> > +MODULE_DESCRIPTION("Virtual PMC Driver");
>
> Lacks MODULE_LICENSE("GPL")

Sure,
Thank you

>
> Thanks,
>
>         tglx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 18:25   ` Limonciello, Mario
@ 2023-02-10 10:56     ` Grzegorz Jaszczyk
  0 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Jaszczyk @ 2023-02-10 10:56 UTC (permalink / raw)
  To: Limonciello, Mario
  Cc: linux-kernel, rafael, dmy, tn, dbehr, zide.chen, seanjc,
	upstream, hdegoede, markgross, dtor, linux-pm, x86,
	platform-driver-x86

czw., 9 lut 2023 o 19:25 Limonciello, Mario
<Mario.Limonciello@amd.com> napisał(a):
>
> [AMD Official Use Only - General]
>
>
>
> > -----Original Message-----
> > From: Grzegorz Jaszczyk <jaz@semihalf.com>
> > Sent: Thursday, February 9, 2023 09:21
> > To: linux-kernel@vger.kernel.org; rafael@kernel.org
> > Cc: dmy@semihalf.com; tn@semihalf.com; dbehr@google.com;
> > zide.chen@intel.corp-partner.google.com; seanjc@google.com;
> > upstream@semihalf.com; hdegoede@redhat.com; markgross@kernel.org;
> > dtor@google.com; Limonciello, Mario <Mario.Limonciello@amd.com>; linux-
> > pm@vger.kernel.org; x86@kernel.org; platform-driver-x86@vger.kernel.org;
> > Grzegorz Jaszczyk <jaz@semihalf.com>
> > Subject: [RESEND RFCv2 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.
> >
> > Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
> > ---
> > Changelog v1..v2:
> > - Take advantage of acpi_s2idle_dev_ops's check() instead of notify()
> > ---
> >  drivers/platform/x86/Kconfig    |  7 ++++
> >  drivers/platform/x86/Makefile   |  3 ++
> >  drivers/platform/x86/virt_pmc.c | 73
> > +++++++++++++++++++++++++++++++++
> >  3 files changed, 83 insertions(+)
> >  create mode 100644 drivers/platform/x86/virt_pmc.c
> >
> > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> > index 5692385e2d26..b7c3f98031d7 100644
> > --- a/drivers/platform/x86/Kconfig
> > +++ b/drivers/platform/x86/Kconfig
> > @@ -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 "Virt PMC"
> > +     depends on ACPI && SUSPEND
> > +     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
> > diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
> > index 1d3d1b02541b..c4d3056cf4ea 100644
> > --- a/drivers/platform/x86/Makefile
> > +++ b/drivers/platform/x86/Makefile
> > @@ -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
> >
> > diff --git a/drivers/platform/x86/virt_pmc.c
> > b/drivers/platform/x86/virt_pmc.c
> > new file mode 100644
> > index 000000000000..daf9c9ed86e5
> > --- /dev/null
> > +++ b/drivers/platform/x86/virt_pmc.c
> > @@ -0,0 +1,73 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Virtual Power Management Controller Driver
> > + *
> > + * Author: Grzegorz Jaszczyk <jaz@semihalf.com>
> > + */
> > +
> > +#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;
> > +     static 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 amd_pmc_s2idle_dev_ops = {
> > +     .check = virt_pmc_s2idle_notify,
> > +};
> > +
> > +static int virt_pmc_probe(struct platform_device *pdev)
> > +{
> > +     int err = 0;
> > +
> > +     virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
> > +
> > +     err = acpi_register_lps0_dev(&amd_pmc_s2idle_dev_ops);
> > +     if (err)
> > +             dev_warn(&pdev->dev, "failed to register LPS0 sleep
> > handler\n");
> > +
>
> Besides registering, I would think you also want to have a query to the
> _DSM to determine what functions are available.  It could allow this to
> scale better if you're going to need to introduce a new function again
> later for a different reason.
>

Ok, I will add such a query. Thanks

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle
  2023-02-09 21:26   ` Sean Christopherson
@ 2023-02-10 10:58     ` Grzegorz Jaszczyk
  0 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Jaszczyk @ 2023-02-10 10:58 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: linux-kernel, rafael, dmy, tn, dbehr, zide.chen, upstream,
	hdegoede, markgross, dtor, mario.limonciello, linux-pm, x86,
	platform-driver-x86

czw., 9 lut 2023 o 22:26 Sean Christopherson <seanjc@google.com> napisał(a):
>
> On Thu, Feb 09, 2023, Grzegorz Jaszczyk wrote:
> > 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.
> >
> > Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
> > ---
> > Changelog v1..v2:
> > - Take advantage of acpi_s2idle_dev_ops's check() instead of notify()
> > ---
> >  drivers/platform/x86/Kconfig    |  7 ++++
> >  drivers/platform/x86/Makefile   |  3 ++
> >  drivers/platform/x86/virt_pmc.c | 73 +++++++++++++++++++++++++++++++++
> >  3 files changed, 83 insertions(+)
> >  create mode 100644 drivers/platform/x86/virt_pmc.c
> >
> > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> > index 5692385e2d26..b7c3f98031d7 100644
> > --- a/drivers/platform/x86/Kconfig
> > +++ b/drivers/platform/x86/Kconfig
> > @@ -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 "Virt PMC"
>
> Maybe spell out "Virtual Power Management Controller"?  See below.

Sure, it makes sense to be more verbose here.

>
> > +     depends on ACPI && SUSPEND
>
> I think it makes sense to take a dependency on HYPERVISOR_GUEST.  It's not strictly
> required, but taking that dependency helps clarify that this is a guest-side thing,
> e.g. "virtual PMC" in KVM-land means "virtual performance monitoring counter".
>
> And IMO, disabling HYPERVISOR_GUEST should disable these type of guest-specific
> features.

Ok, thank you

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-02-10 10:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 15:21 [RESEND RFCv2 0/1] x86: allow to notify host about guest entering s2idle Grzegorz Jaszczyk
2023-02-09 15:21 ` [RESEND RFCv2 1/1] platform/x86: Add virtual PMC driver used for S2Idle Grzegorz Jaszczyk
2023-02-09 18:05   ` Thomas Gleixner
2023-02-10 10:51     ` Grzegorz Jaszczyk
2023-02-09 18:25   ` Limonciello, Mario
2023-02-10 10:56     ` Grzegorz Jaszczyk
2023-02-09 21:26   ` Sean Christopherson
2023-02-10 10:58     ` Grzegorz Jaszczyk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).