Skip to contentSkip to conversation

s390x: diag288: Improve readability

PATCH In review Nico Boehr 5 participants 9 messages Dec 17, 2021

Subsystems (2)
lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

cover s390x: diag288: Improve readability

I had a somewhat hard time figuring out what diag288 does, in particular what the number 424 is. This is an attempt to fix that by improving the naming.

While looking at the code, I also noticed we're missing a clobber for r0, addressing in this series as well.

Nico Boehr (2):
s390x: diag288: Add missing clobber
s390x: diag288: Improve readability

 s390x/diag288.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/2 s390x: diag288: Add missing clobber

We clobber r0 and thus should let the compiler know we're doing so.

Because we change from basic to extended ASM, we need to change the register names, as %r0 will be interpreted as a token in the assembler template.

For consistency, we align with the common style in kvm-unit-tests which is just 0.

---
 s390x/diag288.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
s390x/diag288.c +4 -3
index 072c04a5cbd6..da7b06c365bf 100644
@@ -94,11 +94,12 @@ static void test_bite(void)
 	/* Arm watchdog */
 	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
 	diag288(CODE_INIT, 15, ACTION_RESTART);
-	asm volatile("		larl	%r0, 1f\n"
-		     "		stg	%r0, 424\n"
+	asm volatile("		larl	0, 1f\n"
+		     "		stg	0, 424\n"
 		     "0:	nop\n"
 		     "		j	0b\n"
-		     "1:");
+		     "1:"
+		     : : : "0");
 	report_pass("restart");
 }
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH kvm-unit-tests 1/2] s390x: diag288: Add missing clobber

Quoted 19 lines · Nico Boehr

We clobber r0 and thus should let the compiler know we're doing so.

Because we change from basic to extended ASM, we need to change the register names, as %r0 will be interpreted as a token in the assembler template.

For consistency, we align with the common style in kvm-unit-tests which is just 0.

---
  s390x/diag288.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
s390x/diag288.c +0 -0
index 072c04a5cbd6..da7b06c365bf 100644

s390x/diag288.c static void test_bite(void) · line 98

Quoted 7 lines
s390x/diag288.c +2 -2
@@ -94,11 +94,12 @@ static void test_bite(void)
  	/* Arm watchdog */
  	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
  	diag288(CODE_INIT, 15, ACTION_RESTART);
-	asm volatile("		larl	%r0, 1f\n"
-		     "		stg	%r0, 424\n"
+	asm volatile("		larl	0, 1f\n"
+		     "		stg	0, 424\n"

Would it work to use %%r0 instead?

s390x/diag288.c static void test_bite(void) · line 104

Quoted 7 lines
s390x/diag288.c +2 -1
  		     "0:	nop\n"
  		     "		j	0b\n"
-		     "1:");
+		     "1:"
+		     : : : "0");
  	report_pass("restart");
  }

Anyway:

#3 lore raw

Re: [PATCH kvm-unit-tests 1/2] s390x: diag288: Add missing clobber

Quoted 15 lines · Thomas Huth
Quoted 14 lines · Nico Boehr

We clobber r0 and thus should let the compiler know we're doing so.

Because we change from basic to extended ASM, we need to change the register names, as %r0 will be interpreted as a token in the assembler template.

For consistency, we align with the common style in kvm-unit-tests which is just 0.

---
   s390x/diag288.c | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)
Quoted 14 lines

s390x/diag288.c static void test_bite(void) · line 98

Quoted 12 lines
s390x/diag288.c +2 -2
index 072c04a5cbd6..da7b06c365bf 100644
@@ -94,11 +94,12 @@ static void test_bite(void)
   	/* Arm watchdog */
   	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
   	diag288(CODE_INIT, 15, ACTION_RESTART);
-	asm volatile("		larl	%r0, 1f\n"
-		     "		stg	%r0, 424\n"
+	asm volatile("		larl	0, 1f\n"
+		     "		stg	0, 424\n"

Would it work to use %%r0 instead?

Yes, but I told him that looks weird, so that one is on me. @claudio @thomas What's your preferred way of dealing with this?

Quoted 12 lines

s390x/diag288.c static void test_bite(void) · line 104

Quoted 8 lines
s390x/diag288.c +2 -1
   		     "0:	nop\n"
   		     "		j	0b\n"
-		     "1:");
+		     "1:"
+		     : : : "0");
   	report_pass("restart");
   }

Anyway:

#4 lore raw

Re: [PATCH kvm-unit-tests 1/2] s390x: diag288: Add missing clobber

Quoted 31 lines · On Fri, 17 Dec 2021 15:16:34 +0100 Janosch Frank <[email protected]> wrote:
Quoted 15 lines · Thomas Huth
Quoted 14 lines · Nico Boehr

We clobber r0 and thus should let the compiler know we're doing so.

Because we change from basic to extended ASM, we need to change the register names, as %r0 will be interpreted as a token in the assembler template.

For consistency, we align with the common style in kvm-unit-tests which is just 0.

---
   s390x/diag288.c | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)
Quoted 14 lines

s390x/diag288.c static void test_bite(void) · line 98

Quoted 12 lines
s390x/diag288.c +2 -2
index 072c04a5cbd6..da7b06c365bf 100644
@@ -94,11 +94,12 @@ static void test_bite(void)
   	/* Arm watchdog */
   	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
   	diag288(CODE_INIT, 15, ACTION_RESTART);
-	asm volatile("		larl	%r0, 1f\n"
-		     "		stg	%r0, 424\n"
+	asm volatile("		larl	0, 1f\n"
+		     "		stg	0, 424\n"  

Would it work to use %%r0 instead?

Quoted 2 lines

Yes, but I told him that looks weird, so that one is on me. @claudio @thomas What's your preferred way of dealing with this?

I would prefer just 0 since that's what we use everywhere else too, but I won't oppose %%r0 if there are strong arguments for it (but then we need to decide a policy and stick to it)

Quoted 14 lines
Quoted 13 lines

s390x/diag288.c static void test_bite(void) · line 104

Quoted 9 lines
s390x/diag288.c +2 -1
   		     "0:	nop\n"
   		     "		j	0b\n"
-		     "1:");
+		     "1:"
+		     : : : "0");
   	report_pass("restart");
   }  

Anyway:

#5 lore raw

Re: [PATCH kvm-unit-tests 1/2] s390x: diag288: Add missing clobber

In reply to Janosch Frank
Quoted 31 lines · Janosch Frank
Quoted 15 lines · Thomas Huth
Quoted 14 lines · Nico Boehr

We clobber r0 and thus should let the compiler know we're doing so.

Because we change from basic to extended ASM, we need to change the register names, as %r0 will be interpreted as a token in the assembler template.

For consistency, we align with the common style in kvm-unit-tests which is just 0.

---
   s390x/diag288.c | 7 ++++---

   1 file changed, 4 insertions(+), 3 deletions(-)
Quoted 14 lines

s390x/diag288.c static void test_bite(void) · line 98

Quoted 12 lines
s390x/diag288.c +2 -2
index 072c04a5cbd6..da7b06c365bf 100644
@@ -94,11 +94,12 @@ static void test_bite(void)
        /* Arm watchdog */
        lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
        diag288(CODE_INIT, 15, ACTION_RESTART);
-    asm volatile("        larl    %r0, 1f\n"
-             "        stg    %r0, 424\n"
+    asm volatile("        larl    0, 1f\n"
+             "        stg    0, 424\n"

Would it work to use %%r0 instead?

Quoted 2 lines

Yes, but I told him that looks weird, so that one is on me. @claudio @thomas What's your preferred way of dealing with this?

I think it's mostly a matter of taste. I slightly prefer %%r0 to just 0 so that it is clear from the first sight that it is a register and not an immediate constant. Additionally, there used to be a problem with older versions of Clang that required the %%rX syntax, see:

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=052b66e7211af6

But we're not supporting those Clang versions for the kvm-unit-tests anyway, so that doesn't really count.

Thus, I don't mind too much, if everybody else prefers the bare numbers, then let's go with this.

Thomas

author
#6 lore raw

PATCH 2/2 s390x: diag288: Improve readability

In reply to Nico Boehr

Use a more descriptive name instead of the magic number 424 (address of restart new PSW in the lowcore).

In addition, add a comment to make it more obvious what the ASM snippet does.

---
 s390x/diag288.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
s390x/diag288.c +5 -2
index da7b06c365bf..a2c263e38338 100644
@@ -94,12 +94,15 @@ static void test_bite(void)
 	/* Arm watchdog */
 	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
 	diag288(CODE_INIT, 15, ACTION_RESTART);
+	/* Wait for restart interruption */
 	asm volatile("		larl	0, 1f\n"
-		     "		stg	0, 424\n"
+		     "		stg	0, %[restart_new_psw]\n"
 		     "0:	nop\n"
 		     "		j	0b\n"
 		     "1:"
-		     : : : "0");
+		     :
+		     : [restart_new_psw] "T" (lc->restart_new_psw.addr)
+		     : "0");
 	report_pass("restart");
 }
 
Signature · 1 line
2.31.1
maintainer
#7 lore raw
Quoted 19 lines · Nico Boehr

Use a more descriptive name instead of the magic number 424 (address of restart new PSW in the lowcore).

In addition, add a comment to make it more obvious what the ASM snippet does.

---
 s390x/diag288.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
s390x/diag288.c +0 -0
index da7b06c365bf..a2c263e38338 100644
@@ -94,12 +94,15 @@ static void test_bite(void)
 	/* Arm watchdog */
 	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
 	diag288(CODE_INIT, 15, ACTION_RESTART);

s390x/diag288.c static void test_bite(void) · line 104

Quoted 10 lines
s390x/diag288.c +4 -2
+	/* Wait for restart interruption */
 	asm volatile("		larl	0, 1f\n"
-		     "		stg	0, 424\n"
+		     "		stg	0, %[restart_new_psw]\n"
 		     "0:	nop\n"
 		     "		j	0b\n"
 		     "1:"
-		     : : : "0");
+		     :
+		     : [restart_new_psw] "T" (lc->restart_new_psw.addr)

Even though it was wrong and missing before: this is an output not an input parameter. Also, older compilers might fail if only the "T" constraint is given (see gcc commit 3e4be43f69da ("S/390: Memory constraint cleanup")). Which means: "=RT" would be correct. To be on the safe side, and to avoid that gcc optimizes any potential prior C code away, I'd recommend to use "+RT" in this case.

Also there is an ordering problem here: starting the time bomb before the restart psw has been setup is racy. It is unlikely that this fails, but still...

Correct would be to setup the restart psw, and then start the time bomb. This would also allow to shorten the runtime of this test case to 1 second, instead of the 15 seconds it is running now.

It was all like that before, I know. Just some comments ;)

#8 lore raw
Quoted 29 lines · Heiko Carstens
Quoted 28 lines · Nico Boehr

Use a more descriptive name instead of the magic number 424 (address of restart new PSW in the lowcore).

In addition, add a comment to make it more obvious what the ASM snippet does.

---
  s390x/diag288.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
s390x/diag288.c +3 -2
index da7b06c365bf..a2c263e38338 100644
@@ -94,12 +94,15 @@ static void test_bite(void)
  	/* Arm watchdog */
  	lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT;
  	diag288(CODE_INIT, 15, ACTION_RESTART);
+	/* Wait for restart interruption */
  	asm volatile("		larl	0, 1f\n"
-		     "		stg	0, 424\n"
+		     "		stg	0, %[restart_new_psw]\n"
  		     "0:	nop\n"
  		     "		j	0b\n"
  		     "1:"
-		     : : : "0");
+		     :
Quoted 8 lines

s390x/diag288.c static void test_bite(void) · line 104

Quoted 1 line
s390x/diag288.c +1 -0
+		     : [restart_new_psw] "T" (lc->restart_new_psw.addr)

Even though it was wrong and missing before: this is an output not an input parameter. Also, older compilers might fail if only the "T" constraint is given (see gcc commit 3e4be43f69da ("S/390: Memory constraint cleanup")). Which means: "=RT" would be correct. To be on the safe side, and to avoid that gcc optimizes any potential prior C code away, I'd recommend to use "+RT" in this case.

Thanks for clearing that up, those intricate details are quite hard to find/remember if you only write inline assembly every few months.

Quoted 8 lines

Also there is an ordering problem here: starting the time bomb before the restart psw has been setup is racy. It is unlikely that this fails, but still...

Correct would be to setup the restart psw, and then start the time bomb. This would also allow to shorten the runtime of this test case to 1 second, instead of the 15 seconds it is running now.

While you are correct, the minimum value of the timer is 15s. Racing that will be quite hard.

@Nico but yes, while you're at it you could switch that around so I don't have to explain that a second time.

Quoted 3 lines

It was all like that before, I know. Just some comments ;)