Skip to contentSkip to conversation

cpufreq/intel_pstate: Add function to check that all MSR's are valid

PATCH Applied [email protected] 4 participants 8 messages Mar 20, 2013 – Mar 22, 2013

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

PATCH 1/1 cpufreq/intel_pstate: Add function to check that all MSR's are valid

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

---
 drivers/cpufreq/intel_pstate.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
drivers/cpufreq/intel_pstate.c +26 -0
index f6dd1e7..cd9c5f4 100644
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
 
 static int __initdata no_load;
 
+static int intel_pstate_msrs_not_valid(void)
+{
+	/* Check that all the msr's we are using are valid. */
+	u64 aperf, mperf, tmp;
+
+	rdmsrl(MSR_IA32_APERF, aperf);
+	rdmsrl(MSR_IA32_MPERF, mperf);
+
+	if (!intel_pstate_min_pstate() ||
+		!intel_pstate_max_pstate() ||
+		!intel_pstate_turbo_pstate())
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_APERF, tmp);
+	if (!(tmp - aperf))
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_MPERF, tmp);
+	if (!(tmp - mperf))
+		return -ENODEV;
+
+	return 0;
+}
 static int __init intel_pstate_init(void)
 {
 	int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
 	if (!id)
 		return -ENODEV;
 
+	if (intel_pstate_msrs_not_valid())
+		return -ENODEV;
+
 	pr_info("Intel P-state driver initializing.\n");
 
 	all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 8 lines · On Wednesday, March 20, 2013 09:17:24 AM [email protected] wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

Is this needed for v3.9? Any pointers to bug reports etc.?

Rafael

Quoted 49 lines
---
 drivers/cpufreq/intel_pstate.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
drivers/cpufreq/intel_pstate.c +26 -0
index f6dd1e7..cd9c5f4 100644
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
 
 static int __initdata no_load;
 
+static int intel_pstate_msrs_not_valid(void)
+{
+	/* Check that all the msr's we are using are valid. */
+	u64 aperf, mperf, tmp;
+
+	rdmsrl(MSR_IA32_APERF, aperf);
+	rdmsrl(MSR_IA32_MPERF, mperf);
+
+	if (!intel_pstate_min_pstate() ||
+		!intel_pstate_max_pstate() ||
+		!intel_pstate_turbo_pstate())
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_APERF, tmp);
+	if (!(tmp - aperf))
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_MPERF, tmp);
+	if (!(tmp - mperf))
+		return -ENODEV;
+
+	return 0;
+}
 static int __init intel_pstate_init(void)
 {
 	int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
 	if (!id)
 		return -ENODEV;
 
+	if (intel_pstate_msrs_not_valid())
+		return -ENODEV;
+
 	pr_info("Intel P-state driver initializing.\n");
 
 	all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw
Quoted 12 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, March 20, 2013 09:17:24 AM [email protected] wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

Is this needed for v3.9? Any pointers to bug reports etc.?

Sorry I saw right after I sent the mail that the bug report was missing

https://bugzilla.redhat.com/show_bug.cgi?id=922923

Would you like me to spin the patch?

Quoted 52 lines

Rafael

Quoted 49 lines
---
  drivers/cpufreq/intel_pstate.c |   26 ++++++++++++++++++++++++++
  1 files changed, 26 insertions(+), 0 deletions(-)
drivers/cpufreq/intel_pstate.c +26 -0
index f6dd1e7..cd9c5f4 100644
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
 
  static int __initdata no_load;
 
+static int intel_pstate_msrs_not_valid(void)
+{
+	/* Check that all the msr's we are using are valid. */
+	u64 aperf, mperf, tmp;
+
+	rdmsrl(MSR_IA32_APERF, aperf);
+	rdmsrl(MSR_IA32_MPERF, mperf);
+
+	if (!intel_pstate_min_pstate() ||
+		!intel_pstate_max_pstate() ||
+		!intel_pstate_turbo_pstate())
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_APERF, tmp);
+	if (!(tmp - aperf))
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_MPERF, tmp);
+	if (!(tmp - mperf))
+		return -ENODEV;
+
+	return 0;
+}
  static int __init intel_pstate_init(void)
  {
  	int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
  	if (!id)
  		return -ENODEV;
 
+	if (intel_pstate_msrs_not_valid())
+		return -ENODEV;
+
  	pr_info("Intel P-state driver initializing.\n");
 
  	all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());
#3 lore raw
Quoted 14 lines · Dirk Brandewie
Quoted 12 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, March 20, 2013 09:17:24 AM [email protected] wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

Is this needed for v3.9? Any pointers to bug reports etc.?

Quoted 6 lines

Sorry I saw right after I sent the mail that the bug report was missing

https://bugzilla.redhat.com/show_bug.cgi?id=922923

Would you like me to spin the patch?

No, thanks, this information is sufficient.

Thanks,
Rafael

Quoted 50 lines
Quoted 49 lines
Quoted 49 lines
---
  drivers/cpufreq/intel_pstate.c |   26 ++++++++++++++++++++++++++
  1 files changed, 26 insertions(+), 0 deletions(-)
drivers/cpufreq/intel_pstate.c +26 -0
index f6dd1e7..cd9c5f4 100644
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
 
  static int __initdata no_load;
 
+static int intel_pstate_msrs_not_valid(void)
+{
+	/* Check that all the msr's we are using are valid. */
+	u64 aperf, mperf, tmp;
+
+	rdmsrl(MSR_IA32_APERF, aperf);
+	rdmsrl(MSR_IA32_MPERF, mperf);
+
+	if (!intel_pstate_min_pstate() ||
+		!intel_pstate_max_pstate() ||
+		!intel_pstate_turbo_pstate())
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_APERF, tmp);
+	if (!(tmp - aperf))
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_MPERF, tmp);
+	if (!(tmp - mperf))
+		return -ENODEV;
+
+	return 0;
+}
  static int __init intel_pstate_init(void)
  {
  	int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
  	if (!id)
  		return -ENODEV;
 
+	if (intel_pstate_msrs_not_valid())
+		return -ENODEV;
+
  	pr_info("Intel P-state driver initializing.\n");
 
  	all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#4 lore raw
Quoted 15 lines · Rafael J. Wysocki
Quoted 14 lines · Dirk Brandewie
Quoted 12 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, March 20, 2013 09:17:24 AM [email protected] wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

Is this needed for v3.9? Any pointers to bug reports etc.?

Quoted 8 lines
Quoted 6 lines

Sorry I saw right after I sent the mail that the bug report was missing

https://bugzilla.redhat.com/show_bug.cgi?id=922923

Would you like me to spin the patch?

No, thanks, this information is sufficient.

Applied to linux-pm.git/bleeding-edge and will be moved to linux-next after build testing.

Thanks,
Rafael

Quoted 51 lines
Quoted 50 lines
Quoted 49 lines
Quoted 49 lines
---
  drivers/cpufreq/intel_pstate.c |   26 ++++++++++++++++++++++++++
  1 files changed, 26 insertions(+), 0 deletions(-)
drivers/cpufreq/intel_pstate.c +26 -0
index f6dd1e7..cd9c5f4 100644
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
 
  static int __initdata no_load;
 
+static int intel_pstate_msrs_not_valid(void)
+{
+	/* Check that all the msr's we are using are valid. */
+	u64 aperf, mperf, tmp;
+
+	rdmsrl(MSR_IA32_APERF, aperf);
+	rdmsrl(MSR_IA32_MPERF, mperf);
+
+	if (!intel_pstate_min_pstate() ||
+		!intel_pstate_max_pstate() ||
+		!intel_pstate_turbo_pstate())
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_APERF, tmp);
+	if (!(tmp - aperf))
+		return -ENODEV;
+
+	rdmsrl(MSR_IA32_MPERF, tmp);
+	if (!(tmp - mperf))
+		return -ENODEV;
+
+	return 0;
+}
  static int __init intel_pstate_init(void)
  {
  	int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
  	if (!id)
  		return -ENODEV;
 
+	if (intel_pstate_msrs_not_valid())
+		return -ENODEV;
+
  	pr_info("Intel P-state driver initializing.\n");
 
  	all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#5 lore raw
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Rafael J. Wysocki
Quoted 19 lines · Dirk Brandewie
Quoted 12 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, March 20, 2013 09:17:24 AM [email protected] wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

Is this needed for v3.9? Any pointers to bug reports etc.?

Sorry I saw right after I sent the mail that the bug report was missing

https://bugzilla.redhat.com/show_bug.cgi?id=922923

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Would you like me to spin the patch?

No, thanks, this information is sufficient.

Applied to linux-pm.git/bleeding-edge and will be moved to linux-next after build testing.

'next' seems to be imply you're targetting this for 3.10 ? In case it wasn't clear, this is needed for 3.9.

Dave

#6 lore raw
Quoted 24 lines · Dave Jones
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 20 lines · Dirk Brandewie
Quoted 12 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, March 20, 2013 09:17:24 AM [email protected] wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

Is this needed for v3.9? Any pointers to bug reports etc.?

Sorry I saw right after I sent the mail that the bug report was missing

https://bugzilla.redhat.com/show_bug.cgi?id=922923

Would you like me to spin the patch?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

No, thanks, this information is sufficient.

Applied to linux-pm.git/bleeding-edge and will be moved to linux-next after build testing.

'next' seems to be imply you're targetting this for 3.10 ? In case it wasn't clear, this is needed for 3.9.

I'm going to push this for 3.9 after it has spent a couple of days in linux-next just in case. So 3.9-rc5 is the target.

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
maintainer Acked-by on v1 1/1
#7 lore raw
In reply to [email protected]
Quoted 33 lines · On Wed, Mar 20, 2013 at 9:47 PM, <[email protected]> wrote:

From: Dirk Brandewie <[email protected]>

Some VMs seem to try to implement some MSRs but not all the registers the driver needs. Check to make sure all the MSR that we need are available. If any of the required MSRs are not available refuse to load.

---
 drivers/cpufreq/intel_pstate.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
drivers/cpufreq/intel_pstate.c +13 -0
index f6dd1e7..cd9c5f4 100644
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
 
 static int __initdata no_load;
 
+static int intel_pstate_msrs_not_valid(void)
+{
+       /* Check that all the msr's we are using are valid. */
+       u64 aperf, mperf, tmp;
+
+       rdmsrl(MSR_IA32_APERF, aperf);
+       rdmsrl(MSR_IA32_MPERF, mperf);
+
+       if (!intel_pstate_min_pstate() ||
+               !intel_pstate_max_pstate() ||
+               !intel_pstate_turbo_pstate())
+               return -ENODEV;
+

drivers/cpufreq/intel_pstate.c static struct cpufreq_driver intel_pstate_driver = { · line 777

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +10 -0
+       rdmsrl(MSR_IA32_APERF, tmp);
+       if (!(tmp - aperf))
+               return -ENODEV;
+
+       rdmsrl(MSR_IA32_MPERF, tmp);
+       if (!(tmp - mperf))
+               return -ENODEV;
+
+       return 0;
+}

Add blank line here.

drivers/cpufreq/intel_pstate.c static int __init intel_pstate_init(void) · line 795

Quoted 13 lines
drivers/cpufreq/intel_pstate.c +3 -0
 static int __init intel_pstate_init(void)
 {
        int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
        if (!id)
                return -ENODEV;
 
+       if (intel_pstate_msrs_not_valid())
+               return -ENODEV;
+
        pr_info("Intel P-state driver initializing.\n");
 
        all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());