Skip to contentSkip to conversation

cpu: smp_wmb before lauching cpus.

PATCH In review Liu Ping Fan 3 participants 8 messages Jul 5, 2012 – Jul 6, 2012 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu: smp_wmb before lauching cpus.

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kvm.h +1 -0
index 9c7b0ea..5b3c228 100644
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 13 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kvm.h +0 -0
index 9c7b0ea..5b3c228 100644

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 7 lines
kvm.h +1 -0
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real inconsistencies without this explicit one?

Jan

#2 lore raw
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 16 lines

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 13 lines
kvm.h +1 -0
index 9c7b0ea..5b3c228 100644
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real

Yeah, but what if it is non-x86?

Quoted 4 lines

inconsistencies without this explicit one?

Jan

#3 lore raw
Quoted 26 lines · liu ping fan
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 16 lines

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 13 lines
kvm.h +1 -0
index 9c7b0ea..5b3c228 100644
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real

Quoted 1 line

Yeah, but what if it is non-x86?

The locking I'm referring to is arch independent.

Quoted 1 line
Quoted 1 line

inconsistencies without this explicit one?

Again: Did you see real issues or is this based on static analysis?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
#4 lore raw
Quoted 27 lines · Jan Kiszka
Quoted 26 lines · liu ping fan
Quoted 24 lines · Jan Kiszka
Quoted 13 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kvm.h +0 -0
index 9c7b0ea..5b3c228 100644

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 7 lines
kvm.h +1 -0
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real

Quoted 8 lines
Quoted 1 line

Yeah, but what if it is non-x86?

The locking I'm referring to is arch independent.

Quoted 1 line
Quoted 1 line

inconsistencies without this explicit one?

Again: Did you see real issues or is this based on static analysis?

Just on static analysis

Regards,
pingfan

Quoted 6 lines

Jan

--
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux

#5 lore raw
Quoted 30 lines · liu ping fan
Quoted 29 lines · Jan Kiszka
Quoted 27 lines · liu ping fan
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 16 lines

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 13 lines
kvm.h +1 -0
index 9c7b0ea..5b3c228 100644
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real

Yeah, but what if it is non-x86?

Quoted 7 lines
Quoted 6 lines

The locking I'm referring to is arch independent.

Quoted 1 line
Quoted 1 line

inconsistencies without this explicit one?

Again: Did you see real issues or is this based on static analysis?

Just on static analysis

Then please describe - also for the changelog - at least one case in details where this is needed.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
#6 lore raw
Quoted 33 lines · Jan Kiszka
Quoted 32 lines · liu ping fan
Quoted 31 lines · Jan Kiszka
Quoted 26 lines · liu ping fan
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 16 lines

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 13 lines
kvm.h +1 -0
index 9c7b0ea..5b3c228 100644
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real

Quoted 1 line

Yeah, but what if it is non-x86?

The locking I'm referring to is arch independent.

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

inconsistencies without this explicit one?

Again: Did you see real issues or is this based on static analysis?

Just on static analysis

Then please describe - also for the changelog - at least one case in details where this is needed.

I dived into code. And yes, as you said, ACPI eject does involve some locking operation. So the only thing left is for starting up. There seems no potential lock operation from cpu_synchronize_all_post_init() to resume_all_vcpus().
If correct, I will update this info for the changelog

Regards,
pingfa

Quoted 8 lines

Thanks,
Jan

--
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux

#7 lore raw
Quoted 40 lines · liu ping fan
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · liu ping fan
Quoted 27 lines · Jan Kiszka
Quoted 26 lines · liu ping fan
Quoted 24 lines · Jan Kiszka
Quoted 13 lines · Liu Ping Fan

Vcpu state must be set completely before receiving INIT-IPI,SIPI

---
 kvm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kvm.h +0 -0
index 9c7b0ea..5b3c228 100644

kvm.h static inline void cpu_synchronize_post_init(CPUArchState *env) · line 204

Quoted 7 lines
kvm.h +1 -0
@@ -198,6 +198,7 @@ static inline void cpu_synchronize_post_init(CPUArchState *env)
 {
     if (kvm_enabled()) {
         kvm_cpu_synchronize_post_init(env);
+        smp_wmb();
     }
 }
 

In theory, there should be no vcpu kick-off after this without some locking operations involved that imply barriers. Did you see real

Quoted 8 lines
Quoted 1 line

Yeah, but what if it is non-x86?

The locking I'm referring to is arch independent.

Quoted 1 line
Quoted 1 line

inconsistencies without this explicit one?

Again: Did you see real issues or is this based on static analysis?

Just on static analysis

Quoted 7 lines
Quoted 3 lines

Then please describe - also for the changelog - at least one case in details where this is needed.

I dived into code. And yes, as you said, ACPI eject does involve some locking operation. So the only thing left is for starting up. There seems no potential lock operation from cpu_synchronize_all_post_init() to resume_all_vcpus().

There is no difference in this scenario as well: the vcpu is waiting on a condvar for the initial kick-off and will synchronize with the main thread via the global mutex. When in doubt, try using a debugger.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux