Skip to contentSkip to conversation

target/s390x: Fix broken user mode

PATCH In review Stefan Weil 5 participants 11 messages Jan 30, 2017 – Mar 22, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/s390x: Fix broken user mode

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -2
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 
Signature · 1 line
2.1.4
#1 lore raw

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 5 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

Quoted 8 lines

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

we have the "qemu" model for that (or simply drop the -cpu parameter completely). Eduardo currently proposed "max" as an alternative for x86. There is also no "any" model on x86.

Quoted 21 lines

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -1
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 

target/s390x/cpu_models.c static S390CPUModel *get_max_cpu_model(Error **errp) · line 684

Quoted 7 lines
target/s390x/cpu_models.c +0 -1
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 

Okay, the main problem is that get_max_cpu_model() doesn't return an error in this case, therefor s390_realize_cpu_model() doesn't fail correctly.

But it seems like cpu models also make sense for user mode (as you recognized, we tried to not touch it but failed). However, for now, just as for ordinary tcg, only "qemu"/z900 is supported, until proper support for tcg is implemented.

Then, also the CONFIG_USER_ONLY in apply_cpu_model() has to go.

So this makes sense to me and should fix the current problem.

Signature · 1 line
David
#2 lore raw
Quoted 10 lines · David Hildenbrand

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 9 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

Quoted 8 lines
Quoted 4 lines

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

we have the "qemu" model for that (or simply drop the -cpu parameter completely). Eduardo currently proposed "max" as an alternative for x86. There is also no "any" model on x86.

"any" isn't quite the same as the proposed "max", necessarily. For instance on ARM "any" turns on some features which in real hardware you don't ever see in combination, because for userspace they don't conflict and this lets us run the widest possible range of userspace binaries.

If "any" isn't right for s390 then you should fix the code in linux-user/main.c which picks the default CPU model (for instance on x86 it selects either "qemu64" or "qemu32").

thanks
-- PMM

Reviewed-by on v2 1/1
#3 lore raw
In reply to Stefan Weil

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 7 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

v2: Re-sent as v1 was damaged by my mailer.

Just tested your patch:

Quoted 7 lines

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

This should do the trick, will send it as an official patch:

Quoted 1 line

From e7109d1c235e463c12feeaf5d3f1d6763f34be85 Mon Sep 17 00:00:00 2001

From: David Hildenbrand <[email protected]>
Date: Mon, 30 Jan 2017 15:33:05 +0100
Subject: [PATCH] target/s390x: "qemu" is the name od the default model

"any" does not exist, therefore resulting in a misleading error message.

---
 linux-user/main.c | 2 ++
 1 file changed, 2 insertions(+)
linux-user/main.c +2 -0
index 3004958..e588f58 100644
@@ -4322,6 +4322,8 @@ int main(int argc, char **argv, char **envp)
 # endif
 #elif defined TARGET_SH4
         cpu_model = TYPE_SH7785_CPU;
+#elif defined TARGET_S390X
+        cpu_model = "qemu";
 #else
         cpu_model = "any";
 #endif
Signature · 5 lines
2.9.3

-- 

David
Acked-by on v2 1/1
#4 lore raw
In reply to Stefan Weil

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 5 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

Quoted 8 lines

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

That should then already work.

Quoted 21 lines

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -1
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 

target/s390x/cpu_models.c static S390CPUModel *get_max_cpu_model(Error **errp) · line 684

Quoted 7 lines
target/s390x/cpu_models.c +0 -1
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 

I thought this was already picked up for stable... But looks like only the "any" model fixup got.

So

Signature · 3 lines
Thanks,

David
#5 lore raw
Quoted 49 lines · David Hildenbrand

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 5 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

Quoted 8 lines

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

That should then already work.

Quoted 21 lines

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -1
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 

target/s390x/cpu_models.c static S390CPUModel *get_max_cpu_model(Error **errp) · line 684

Quoted 7 lines
target/s390x/cpu_models.c +0 -1
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 

I thought this was already picked up for stable... But looks like only the "any" model fixup got.

Quoted 4 lines

So

Ping, can somebody please pick this up?

Signature · 3 lines
Thanks,

David
#6 lore raw

Hi Stefan, Richard.

Quoted 50 lines · David Hildenbrand
Quoted 49 lines · David Hildenbrand

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 5 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

Quoted 8 lines

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

That should then already work.

Quoted 21 lines

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -1
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 

target/s390x/cpu_models.c static S390CPUModel *get_max_cpu_model(Error **errp) · line 684

Quoted 7 lines
target/s390x/cpu_models.c +0 -1
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 

I thought this was already picked up for stable... But looks like only the "any" model fixup got.

Quoted 6 lines
Quoted 4 lines

So

Ping, can somebody please pick this up?

I see at least two possible changes:

the nasty one to catch bug:

@@ -681,7 +681,7 @@ static S390CPUModel *get_max_cpu_model(Error **errp)

         return &max_model;
     }

#endif
- return NULL;
+ abort();
}

and the nicer one to avoid SIGSEGV:

@@ -734,8 +734,10 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)

     }

     max_model = get_max_cpu_model(errp);

- if (*errp) {
- error_prepend(errp, "CPU models are not available: ");
+ if (max_model == NULL) {
+ if (*errp) {
+ error_prepend(errp, "CPU models are not available: ");
+ } else {
+ error_setg(errp, "CPU models are not available");
+ }

         return;
     }
#7 lore raw
Quoted 79 lines · Philippe Mathieu-Daudé

Hi Stefan, Richard.

Quoted 50 lines · David Hildenbrand
Quoted 49 lines · David Hildenbrand

Am 30.01.2017 um 14:15 schrieb Stefan Weil:

Quoted 5 lines

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

Quoted 8 lines

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

That should then already work.

Quoted 21 lines

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -1
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 

target/s390x/cpu_models.c static S390CPUModel *get_max_cpu_model(Error **errp) · line 684

Quoted 7 lines
target/s390x/cpu_models.c +0 -1
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 

I thought this was already picked up for stable... But looks like only the "any" model fixup got.

Quoted 6 lines
Quoted 4 lines

So

Ping, can somebody please pick this up?

I see at least two possible changes:

the nasty one to catch bug:

target/s390x/cpu_models.c +1 -1
@@ -681,7 +681,7 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
          return &max_model;
      }
  #endif
-    return NULL;
+    abort();
  }
 

and the nicer one to avoid SIGSEGV:

(quoted diff) +0 -0
@@ -734,8 +734,10 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
      }
 
      max_model = get_max_cpu_model(errp);

Review void s390_realize_cpu_model(CPUState *cs, Error **errp)

Quoted 10 lines
(quoted diff) +6 -2
-    if (*errp) {
-        error_prepend(errp, "CPU models are not available: ");
+    if (max_model == NULL) {
+        if (*errp) {
+            error_prepend(errp, "CPU models are not available: ");
+        } else {
+            error_setg(errp, "CPU models are not available");
+        }
          return;
      }

As already discussed, user mode should behave just like tcg. No special handling. So the original patch here is just fine in my opinion.

Signature · 3 lines
Thanks,

David
#8 lore raw
In reply to Stefan Weil
Quoted 5 lines · Stefan Weil

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

Quoted 8 lines

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

applied to our tree. Do we need cc stable as well?

Quoted 27 lines

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -2
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 
#9 lore raw
Quoted 8 lines · Christian Borntraeger
Quoted 7 lines · Stefan Weil

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

v2: Re-sent as v1 was damaged by my mailer.

Quoted 8 lines
Quoted 6 lines

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

applied to our tree. Do we need cc stable as well?

Yes, I think so.

Thanks!

Signature · 3 lines
Thanks,

David
#10 lore raw
In reply to Stefan Weil
Quoted 33 lines · Stefan Weil

Returning NULL from get_max_cpu_model results in a SIGSEGV runtime error.

---

v2: Re-sent as v1 was damaged by my mailer.

This is also broken in Debian.

In addition, there is no default CPU ("any"), so binfmt and related actions currently don't work. I hacked my local installation by duplicating the "qemu" cpu definition for "any", but maybe there is a better solution.

Regards
Stefan

 target/s390x/cpu_models.c | 2 --
 1 file changed, 2 deletions(-)
target/s390x/cpu_models.c +0 -1
index 2a894ee..6e34763 100644
@@ -660,7 +660,6 @@ static void check_compatibility(const S390CPUModel *max_model,
 
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
-#ifndef CONFIG_USER_ONLY
     static S390CPUModel max_model;
     static bool cached;
 

target/s390x/cpu_models.c static S390CPUModel *get_max_cpu_model(Error **errp) · line 684

Quoted 7 lines
target/s390x/cpu_models.c +0 -1
@@ -680,7 +679,6 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
         cached = true;
         return &max_model;
     }
-#endif
     return NULL;
 }
 

applied to our tree. Do we need cc stable?