Skip to contentSkip to conversation

s390x: sigp: Fix sense running reporting

PATCH Superseded Janosch Frank 3 participants 6 messages Jan 24, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x: sigp: Fix sense running reporting

The logic was inversed and reported running if the cpu was stopped. Let's fix that.

---
 target/s390x/sigp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/sigp.c +1 -1
index 727875bb4a..286c0d6c9c 100644
@@ -347,7 +347,7 @@ static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si)
     }
 
     /* If halted (which includes also STOPPED), it is not running */
-    if (CPU(dst_cpu)->halted) {
+    if (!CPU(dst_cpu)->halted) {
         si->cc = SIGP_CC_ORDER_CODE_ACCEPTED;
     } else {
         set_sigp_status(si, SIGP_STAT_NOT_RUNNING);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 1 line · On Fri, 24 Jan 2020 05:01:37 -0500 Janosch Frank <[email protected]> wrote:

The logic was inversed and reported running if the cpu was stopped.

s/inversed/inverted/ ?

Quoted 2 lines

Let's fix that.

Fixes d1b468bc8869 ("s390x/tcg: implement SIGP SENSE RUNNING STATUS")
Quoted 10 lines
---
 target/s390x/sigp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/sigp.c +0 -0
index 727875bb4a..286c0d6c9c 100644

target/s390x/sigp.c static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si) · line 353

Quoted 8 lines
target/s390x/sigp.c +1 -1
@@ -347,7 +347,7 @@ static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si)
     }
 
     /* If halted (which includes also STOPPED), it is not running */
-    if (CPU(dst_cpu)->halted) {
+    if (!CPU(dst_cpu)->halted) {
         si->cc = SIGP_CC_ORDER_CODE_ACCEPTED;
     } else {
         set_sigp_status(si, SIGP_STAT_NOT_RUNNING);

I'm wondering why nobody noticed this before...

Reviewed-by
#2 lore raw
Quoted 24 lines · Cornelia Huck
Quoted 1 line · On Fri, 24 Jan 2020 05:01:37 -0500 Janosch Frank <[email protected]> wrote:

The logic was inversed and reported running if the cpu was stopped.

s/inversed/inverted/ ?

Quoted 2 lines

Let's fix that.

Fixes d1b468bc8869 ("s390x/tcg: implement SIGP SENSE RUNNING STATUS")
Quoted 12 lines
---
 target/s390x/sigp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/sigp.c +0 -0
index 727875bb4a..286c0d6c9c 100644
@@ -347,7 +347,7 @@ static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si)
     }
 
Quoted 8 lines

target/s390x/sigp.c static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si) · line 353

Quoted 6 lines
target/s390x/sigp.c +1 -1
     /* If halted (which includes also STOPPED), it is not running */
-    if (CPU(dst_cpu)->halted) {
+    if (!CPU(dst_cpu)->halted) {
         si->cc = SIGP_CC_ORDER_CODE_ACCEPTED;
     } else {
         set_sigp_status(si, SIGP_STAT_NOT_RUNNING);

I'm wondering why nobody noticed this before...

AFAIR, it "SENSE RUNNING" allows you to test if the target CPU is scheduled by the hypervisor. So it is used for performance optimization, but correctness of a program barely depends on it.

a) You can always return "not running" and it would be totally fine

b) Return "running" would also most probably always valid (although it does not make too much sense for STOPPED CPUs).

E.g., in KVM we set CPUSTAT_RUNNING whenever we load the CPU. This can also happen (AFAIR) when the CPU state is already stopped (e.g., currently getting stopped) or still sleeping (e.g., about to wake up, or in kvm_vcpu_block()).

Long story short: There is no trusting on these values.

But yeah, the heuristic we are using is sub-optimal. :)

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
Quoted 43 lines · David Hildenbrand
Quoted 24 lines · Cornelia Huck
Quoted 1 line · On Fri, 24 Jan 2020 05:01:37 -0500 Janosch Frank <[email protected]> wrote:

The logic was inversed and reported running if the cpu was stopped.

s/inversed/inverted/ ?

Quoted 2 lines

Let's fix that.

Fixes d1b468bc8869 ("s390x/tcg: implement SIGP SENSE RUNNING STATUS")
Quoted 12 lines
---
 target/s390x/sigp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/sigp.c +0 -0
index 727875bb4a..286c0d6c9c 100644
@@ -347,7 +347,7 @@ static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si)
     }
 
Quoted 8 lines

target/s390x/sigp.c static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si) · line 353

Quoted 6 lines
target/s390x/sigp.c +1 -1
     /* If halted (which includes also STOPPED), it is not running */
-    if (CPU(dst_cpu)->halted) {
+    if (!CPU(dst_cpu)->halted) {
         si->cc = SIGP_CC_ORDER_CODE_ACCEPTED;
     } else {
         set_sigp_status(si, SIGP_STAT_NOT_RUNNING);

I'm wondering why nobody noticed this before...

AFAIR, it "SENSE RUNNING" allows you to test if the target CPU is scheduled by the hypervisor. So it is used for performance optimization, but correctness of a program barely depends on it.

a) You can always return "not running" and it would be totally fine

b) Return "running" would also most probably always valid (although it does not make too much sense for STOPPED CPUs).

Quoted 7 lines

E.g., in KVM we set CPUSTAT_RUNNING whenever we load the CPU. This can also happen (AFAIR) when the CPU state is already stopped (e.g., currently getting stopped) or still sleeping (e.g., about to wake up, or in kvm_vcpu_block()).

Long story short: There is no trusting on these values.

That answer makes me highly uncomfortable...

Quoted 5 lines

But yeah, the heuristic we are using is sub-optimal. :)

Thanks!

#4 lore raw
In reply to Cornelia Huck
Quoted 6 lines · Cornelia Huck
Quoted 1 line · On Fri, 24 Jan 2020 05:01:37 -0500 Janosch Frank <[email protected]> wrote:

The logic was inversed and reported running if the cpu was stopped.

s/inversed/inverted/ ?

Ok

Quoted 5 lines
Quoted 3 lines

Let's fix that.

Fixes d1b468bc8869 ("s390x/tcg: implement SIGP SENSE RUNNING STATUS")

Added

Quoted 13 lines
Quoted 13 lines
---
 target/s390x/sigp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/sigp.c +0 -0
index 727875bb4a..286c0d6c9c 100644
@@ -347,7 +347,7 @@ static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si)
     }
 
Quoted 8 lines

target/s390x/sigp.c static void sigp_sense_running(S390CPU *dst_cpu, SigpInfo *si) · line 353

Quoted 6 lines
target/s390x/sigp.c +1 -1
     /* If halted (which includes also STOPPED), it is not running */
-    if (CPU(dst_cpu)->halted) {
+    if (!CPU(dst_cpu)->halted) {
         si->cc = SIGP_CC_ORDER_CODE_ACCEPTED;
     } else {
         set_sigp_status(si, SIGP_STAT_NOT_RUNNING);

I'm wondering why nobody noticed this before...

No idea.
How many people use smp with tcg?

#5 lore raw
Quoted 4 lines

No idea.
How many people use smp with tcg?

The kernel uses it (pcpu_running()) to decide whether
- To send an emergency call or an external call (external calls are faster when the CPU is already running - e.g., SIE HW assist)
- In arch_vcpu_is_preempted(), for an heuristic

So nothing actually breaks (as I explained, only used for performance optimizations)

Signature · 3 lines
Thanks,

David / dhildenb