Check for valid ACPI _PSS object before doing the MSR read, fixes KVM brokeness 
as reported/tested by Walter Haidinger.

It could also potentially avoid a general protection fault on theoretically 
real (..yet so far not witnessed) systems.

I'm still open to doing the CPUID check, but as I explained in a previous mail 
it shouldn't be necessary.

Testers, ok's and commit welcome.
-Bryan.

Index: arch/amd64/amd64/k1x-pstate.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/k1x-pstate.c,v
retrieving revision 1.2
diff -u -p -u -r1.2 k1x-pstate.c
--- arch/amd64/amd64/k1x-pstate.c       29 May 2011 12:29:28 -0000      1.2
+++ arch/amd64/amd64/k1x-pstate.c       13 Nov 2011 18:38:25 -0000
@@ -75,7 +75,7 @@ struct k1x_cpu_state *k1x_current_state;
 void k1x_transition(struct k1x_cpu_state *, int);
 
 #if NACPICPU > 0
-void k1x_acpi_init(struct k1x_cpu_state *, u_int64_t);
+void k1x_acpi_init(struct k1x_cpu_state *);
 void k1x_acpi_states(struct k1x_cpu_state *, struct acpicpu_pss *, int,
     u_int64_t);
 #endif
@@ -154,14 +154,17 @@ k1x_acpi_states(struct k1x_cpu_state *cs
 }
 
 void
-k1x_acpi_init(struct k1x_cpu_state *cstate, u_int64_t msr)
+k1x_acpi_init(struct k1x_cpu_state *cstate)
 {
        struct acpicpu_pss *pss;
+       u_int64_t msr;
 
        cstate->n_states = acpicpu_fetch_pss(&pss);
        if (cstate->n_states == 0)
                return;
 
+       msr = rdmsr(MSR_K1X_STATUS);
+
        k1x_acpi_states(cstate, pss, cstate->n_states, msr);
 
        return;
@@ -172,12 +175,9 @@ k1x_acpi_init(struct k1x_cpu_state *csta
 void
 k1x_init(struct cpu_info *ci)
 {
-#if NACPICPU > 0
-       u_int64_t msr;
-#endif
-       u_int i;
        struct k1x_cpu_state *cstate;
        struct k1x_state *state;
+       u_int i;
 
        if (setperf_prio > 1)
                return;
@@ -189,8 +189,7 @@ k1x_init(struct cpu_info *ci)
        cstate->n_states = 0;
 
 #if NACPICPU > 0
-       msr = rdmsr(MSR_K1X_STATUS);
-       k1x_acpi_init(cstate, msr);
+       k1x_acpi_init(cstate);
 #endif
        if (cstate->n_states) {
                printf("%s: %d MHz: speeds:",
Index: arch/i386/i386/k1x-pstate.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/k1x-pstate.c,v
retrieving revision 1.2
diff -u -p -u -r1.2 k1x-pstate.c
--- arch/i386/i386/k1x-pstate.c 29 May 2011 12:29:28 -0000      1.2
+++ arch/i386/i386/k1x-pstate.c 13 Nov 2011 18:38:25 -0000
@@ -75,7 +75,7 @@ struct k1x_cpu_state *k1x_current_state;
 void k1x_transition(struct k1x_cpu_state *, int);
 
 #if NACPICPU > 0
-void k1x_acpi_init(struct k1x_cpu_state *, u_int64_t);
+void k1x_acpi_init(struct k1x_cpu_state *);
 void k1x_acpi_states(struct k1x_cpu_state *, struct acpicpu_pss *, int,
     u_int64_t);
 #endif
@@ -154,14 +154,17 @@ k1x_acpi_states(struct k1x_cpu_state *cs
 }
 
 void
-k1x_acpi_init(struct k1x_cpu_state *cstate, u_int64_t msr)
+k1x_acpi_init(struct k1x_cpu_state *cstate)
 {
        struct acpicpu_pss *pss;
+       u_int64_t msr;
 
        cstate->n_states = acpicpu_fetch_pss(&pss);
        if (cstate->n_states == 0)
                return;
 
+       msr = rdmsr(MSR_K1X_STATUS);
+
        k1x_acpi_states(cstate, pss, cstate->n_states, msr);
 
        return;
@@ -172,12 +175,9 @@ k1x_acpi_init(struct k1x_cpu_state *csta
 void
 k1x_init(struct cpu_info *ci)
 {
-#if NACPICPU > 0
-       u_int64_t msr;
-#endif
-       u_int i;
        struct k1x_cpu_state *cstate;
        struct k1x_state *state;
+       u_int i;
 
        if (setperf_prio > 1)
                return;
@@ -189,8 +189,7 @@ k1x_init(struct cpu_info *ci)
        cstate->n_states = 0;
 
 #if NACPICPU > 0
-       msr = rdmsr(MSR_K1X_STATUS);
-       k1x_acpi_init(cstate, msr);
+       k1x_acpi_init(cstate);
 #endif
        if (cstate->n_states) {
                printf("%s: %d MHz: speeds:",

Reply via email to