Skip to contentSkip to conversation

s390x/spec_ex: Use PSW macro

PATCH Superseded Nina Schoetterl-Glausch 3 participants 11 messages Feb 21, 2023 – Mar 15, 2023 1 message not in the archive

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/3 s390x/spec_ex: Use PSW macro

Replace explicit psw definition by PSW macro.
No functional change intended.

---
 s390x/spec_ex.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
s390x/spec_ex.c +2 -8
index 42ecaed3..2adc5996 100644
@@ -105,10 +105,7 @@ static int check_invalid_psw(void)
 /* For normal PSWs bit 12 has to be 0 to be a valid PSW*/
 static int psw_bit_12_is_1(void)
 {
-	struct psw invalid = {
-		.mask = BIT(63 - 12),
-		.addr = 0x00000000deadbeee
-	};
+	struct psw invalid = PSW(BIT(63 - 12), 0x00000000deadbeee);
 
 	expect_invalid_psw(invalid);
 	load_psw(invalid);
@@ -118,10 +115,7 @@ static int psw_bit_12_is_1(void)
 /* A short PSW needs to have bit 12 set to be valid. */
 static int short_psw_bit_12_is_0(void)
 {
-	struct psw invalid = {
-		.mask = BIT(63 - 12),
-		.addr = 0x00000000deadbeee
-	};
+	struct psw invalid = PSW(BIT(63 - 12), 0x00000000deadbeee);
 	struct short_psw short_invalid = {
 		.mask = 0x0,
 		.addr = 0xdeadbeee
Signature · 1 line
2.36.1
#2 lore raw

Messed up the recipients on the cover letter...

Instructions on s390 must be halfword aligned.
Add two tests for that.
These currently fail when using TCG.

v1 -> v2:
* rebase
* use PSW macros
* simplify odd psw test (thanks Claudio)
* rename some identifiers
* pick up R-b (thanks Claudio)

Nina Schoetterl-Glausch (3):
s390x/spec_ex: Use PSW macro
s390x/spec_ex: Add test introducing odd address into PSW s390x/spec_ex: Add test of EXECUTE with odd target address

 s390x/spec_ex.c | 85 +++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 76 insertions(+), 9 deletions(-)

Range-diff against v1:

-:  -------- > 1:  d82f4fb6 s390x/spec_ex: Use PSW macro
1:  62f61c07 ! 2:  e537797f s390x/spec_ex: Add test introducing odd address into PSW
    @@ Commit message
         Signed-off-by: Nina Schoetterl-Glausch <[email protected]>
     
      ## s390x/spec_ex.c ##
    -@@ s390x/spec_ex.c: static void fixup_invalid_psw(struct stack_frame_int *stack)
    - /*
    -  * Load possibly invalid psw, but setup fixup_psw before,
    -  * so that fixup_invalid_psw() can bring us back onto the right track.
    -+ * The provided argument is loaded into register 1.
    -  * Also acts as compiler barrier, -> none required in expect/check_invalid_psw
    -  */
    --static void load_psw(struct psw psw)
    -+static void load_psw_with_arg(struct psw psw, uint64_t arg)
    - {
    - 	uint64_t scratch;
    - 
    -@@ s390x/spec_ex.c: static void load_psw(struct psw psw)
    - 	fixup_psw.mask = extract_psw_mask();
    - 	asm volatile ( "larl	%[scratch],0f\n"
    - 		"	stg	%[scratch],%[fixup_addr]\n"
    -+		"	lgr	%%r1,%[arg]\n"
    - 		"	lpswe	%[psw]\n"
    - 		"0:	nop\n"
    - 		: [scratch] "=&d" (scratch),
    - 		  [fixup_addr] "=&T" (fixup_psw.addr)
    --		: [psw] "Q" (psw)
    --		: "cc", "memory"
    -+		: [psw] "Q" (psw),
    -+		  [arg] "d" (arg)
    -+		: "cc", "memory", "%r1"
    - 	);
    - }
    - 
    -+static void load_psw(struct psw psw)
    -+{
    -+	load_psw_with_arg(psw, 0);
    -+}
    -+
    - static void load_short_psw(struct short_psw psw)
    - {
    - 	uint64_t scratch;
     @@ s390x/spec_ex.c: static void expect_invalid_psw(struct psw psw)
      	invalid_psw_expected = true;
      }
      
     +static void clear_invalid_psw(void)
     +{
    -+	expected_psw = (struct psw){0};
    ++	expected_psw = PSW(0, 0);
     +	invalid_psw_expected = false;
     +}
     +
    @@ s390x/spec_ex.c: static void expect_invalid_psw(struct psw psw)
      {
      	/* Since the fixup sets this to false we check for false here. */
      	if (!invalid_psw_expected) {
    ++		/*
    ++		 * Early exception recognition: pgm_int_id == 0.
    ++		 * Late exception recognition: psw address has been
    ++		 *	incremented by pgm_int_id (unpredictable value)
    ++		 */
      		if (expected_psw.mask == invalid_psw.mask &&
     -		    expected_psw.addr == invalid_psw.addr)
     +		    expected_psw.addr == invalid_psw.addr - lowcore.pgm_int_id)
    @@ s390x/spec_ex.c: static int psw_bit_12_is_1(void)
      	return check_invalid_psw();
      }
      
    ++extern char misaligned_code[];
    ++asm (  ".balign	2\n"
    ++"	. = . + 1\n"
    ++"misaligned_code:\n"
    ++"	larl	%r0,0\n"
    ++"	bcr	0xf,%r1\n"
    ++);
    ++
     +static int psw_odd_address(void)
     +{
    -+	struct psw odd = {
    -+		.mask = extract_psw_mask(),
    -+	};
    -+	uint64_t regs[16];
    -+	int r;
    ++	struct psw odd = PSW_WITH_CUR_MASK((uint64_t)&misaligned_code);
    ++	uint64_t executed_addr;
     +
    -+	/*
    -+	 * This asm is reentered at an odd address, which should cause a specification
    -+	 * exception before the first unaligned instruction is executed.
    -+	 * In this case, the interrupt handler fixes the address and the test succeeds.
    -+	 * If, however, unaligned instructions *are* executed, they are jumped to
    -+	 * from somewhere, with unknown registers, so save and restore those before.
    -+	 */
    -+	asm volatile ( "stmg	%%r0,%%r15,%[regs]\n"
    -+		//can only offset by even number when using larl -> increment by one
    -+		"	larl	%[r],0f\n"
    -+		"	aghi	%[r],1\n"
    -+		"	stg	%[r],%[addr]\n"
    -+		"	xr	%[r],%[r]\n"
    -+		"	brc	0xf,1f\n"
    -+		"0:	. = . + 1\n"
    -+		"	lmg	%%r0,%%r15,0(%%r1)\n"
    -+		//address of the instruction itself, should be odd, store for assert
    -+		"	larl	%[r],0\n"
    -+		"	stg	%[r],%[addr]\n"
    -+		"	larl	%[r],0f\n"
    -+		"	aghi	%[r],1\n"
    -+		"	bcr	0xf,%[r]\n"
    -+		"0:	. = . + 1\n"
    -+		"1:\n"
    -+	: [addr] "=T" (odd.addr),
    -+	  [regs] "=Q" (regs),
    -+	  [r] "=d" (r)
    -+	: : "cc", "memory"
    ++	expect_invalid_psw(odd);
    ++	fixup_psw.mask = extract_psw_mask();
    ++	asm volatile ( "xr	%%r0,%%r0\n"
    ++		"	larl	%%r1,0f\n"
    ++		"	stg	%%r1,%[fixup_addr]\n"
    ++		"	lpswe	%[odd_psw]\n"
    ++		"0:	lr	%[executed_addr],%%r0\n"
    ++	: [fixup_addr] "=&T" (fixup_psw.addr),
    ++	  [executed_addr] "=d" (executed_addr)
    ++	: [odd_psw] "Q" (odd)
    ++	: "cc", "%r0", "%r1"
     +	);
     +
    -+	if (!r) {
    -+		expect_invalid_psw(odd);
    -+		load_psw_with_arg(odd, (uint64_t)&regs);
    ++	if (!executed_addr) {
     +		return check_invalid_psw();
     +	} else {
    -+		assert(odd.addr & 1);
    ++		assert(executed_addr == odd.addr);
     +		clear_invalid_psw();
    -+		report_fail("executed unaligned instructions");
    ++		report_fail("did not execute unaligned instructions");
     +		return 1;
     +	}
     +}
2:  30075863 ! 3:  dc552880 s390x/spec_ex: Add test of EXECUTE with odd target address
    @@ s390x/spec_ex.c: static int short_psw_bit_12_is_0(void)
      
     +static int odd_ex_target(void)
     +{
    -+	uint64_t target_addr_pre;
    ++	uint64_t pre_target_addr;
     +	int to = 0, from = 0x0dd;
     +
     +	asm volatile ( ".pushsection .rodata\n"
    -+		"odd_ex_target_pre_insn:\n"
    -+		"	.balign 2\n"
    ++		"pre_odd_ex_target:\n"
    ++		"	.balign	2\n"
     +		"	. = . + 1\n"
     +		"	lr	%[to],%[from]\n"
     +		"	.popsection\n"
     +
    -+		"	larl	%[target_addr_pre],odd_ex_target_pre_insn\n"
    -+		"	ex	0,1(%[target_addr_pre])\n"
    -+		: [target_addr_pre] "=&a" (target_addr_pre),
    ++		"	larl	%[pre_target_addr],pre_odd_ex_target\n"
    ++		"	ex	0,1(%[pre_target_addr])\n"
    ++		: [pre_target_addr] "=&a" (pre_target_addr),
     +		  [to] "+d" (to)
     +		: [from] "d" (from)
     +	);
     +
    -+	assert((target_addr_pre + 1) & 1);
    ++	assert((pre_target_addr + 1) & 1);
     +	report(to != from, "did not perform ex with odd target");
     +	return 0;
     +}

base-commit: e3c5c3ef2524c58023073c0fadde2e8ae3c04ec6

Signature · 1 line
2.36.1
Reviewed-by on v2 1/3
#3 lore raw
In reply to Nina Schoetterl-Glausch
Quoted 13 lines · Nina Schoetterl-Glausch

Replace explicit psw definition by PSW macro.
No functional change intended.

---
  s390x/spec_ex.c | 10 ++--------
  1 file changed, 2 insertions(+), 8 deletions(-)
s390x/spec_ex.c +0 -0
index 42ecaed3..2adc5996 100644

s390x/spec_ex.c static int check_invalid_psw(void) · line 108

Quoted 8 lines
s390x/spec_ex.c +1 -4
@@ -105,10 +105,7 @@ static int check_invalid_psw(void)
  /* For normal PSWs bit 12 has to be 0 to be a valid PSW*/
  static int psw_bit_12_is_1(void)
  {
-	struct psw invalid = {
-		.mask = BIT(63 - 12),
-		.addr = 0x00000000deadbeee
-	};
+	struct psw invalid = PSW(BIT(63 - 12), 0x00000000deadbeee);

I think we've passed the point where we can use a constant for the short psw. But we can convert that at a later time, I'll add it to the TODO list, so:

#4 lore raw

PATCH v2 2/3 s390x/spec_ex: Add test introducing odd address into PSW

In reply to a message not in the archive

Instructions on s390 must be halfword aligned.
Introducing an odd instruction address into the PSW leads to a specification exception when attempting to execute the instruction at the odd address.
Add a test for this.

---
 s390x/spec_ex.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
s390x/spec_ex.c +49 -1
index 2adc5996..a26c56aa 100644
@@ -88,12 +88,23 @@ static void expect_invalid_psw(struct psw psw)
 	invalid_psw_expected = true;
 }
 
+static void clear_invalid_psw(void)
+{
+	expected_psw = PSW(0, 0);
+	invalid_psw_expected = false;
+}
+
 static int check_invalid_psw(void)
 {
 	/* Since the fixup sets this to false we check for false here. */
 	if (!invalid_psw_expected) {
+		/*
+		 * Early exception recognition: pgm_int_id == 0.
+		 * Late exception recognition: psw address has been
+		 *	incremented by pgm_int_id (unpredictable value)
+		 */
 		if (expected_psw.mask == invalid_psw.mask &&
-		    expected_psw.addr == invalid_psw.addr)
+		    expected_psw.addr == invalid_psw.addr - lowcore.pgm_int_id)
 			return 0;
 		report_fail("Wrong invalid PSW");
 	} else {
@@ -112,6 +123,42 @@ static int psw_bit_12_is_1(void)
 	return check_invalid_psw();
 }
 
+extern char misaligned_code[];
+asm (  ".balign	2\n"
+"	. = . + 1\n"
+"misaligned_code:\n"
+"	larl	%r0,0\n"
+"	bcr	0xf,%r1\n"
+);
+
+static int psw_odd_address(void)
+{
+	struct psw odd = PSW_WITH_CUR_MASK((uint64_t)&misaligned_code);
+	uint64_t executed_addr;
+
+	expect_invalid_psw(odd);
+	fixup_psw.mask = extract_psw_mask();
+	asm volatile ( "xr	%%r0,%%r0\n"
+		"	larl	%%r1,0f\n"
+		"	stg	%%r1,%[fixup_addr]\n"
+		"	lpswe	%[odd_psw]\n"
+		"0:	lr	%[executed_addr],%%r0\n"
+	: [fixup_addr] "=&T" (fixup_psw.addr),
+	  [executed_addr] "=d" (executed_addr)
+	: [odd_psw] "Q" (odd)
+	: "cc", "%r0", "%r1"
+	);
+
+	if (!executed_addr) {
+		return check_invalid_psw();
+	} else {
+		assert(executed_addr == odd.addr);
+		clear_invalid_psw();
+		report_fail("did not execute unaligned instructions");
+		return 1;
+	}
+}
+
 /* A short PSW needs to have bit 12 set to be valid. */
 static int short_psw_bit_12_is_0(void)
 {
@@ -170,6 +217,7 @@ struct spec_ex_trigger {
 static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
+	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
Signature · 1 line
2.36.1
#5 lore raw

Re: [kvm-unit-tests PATCH v2 2/3] s390x/spec_ex: Add test introducing odd address into PSW

Quoted 41 lines · On Tue, 21 Feb 2023 18:48:21 +0100 Nina Schoetterl-Glausch <[email protected]>…

Instructions on s390 must be halfword aligned.
Introducing an odd instruction address into the PSW leads to a specification exception when attempting to execute the instruction at the odd address.
Add a test for this.

---
 s390x/spec_ex.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
s390x/spec_ex.c +12 -1
index 2adc5996..a26c56aa 100644
@@ -88,12 +88,23 @@ static void expect_invalid_psw(struct psw psw)
 	invalid_psw_expected = true;
 }
 
+static void clear_invalid_psw(void)
+{
+	expected_psw = PSW(0, 0);
+	invalid_psw_expected = false;
+}
+
 static int check_invalid_psw(void)
 {
 	/* Since the fixup sets this to false we check for false here. */
 	if (!invalid_psw_expected) {
+		/*
+		 * Early exception recognition: pgm_int_id == 0.
+		 * Late exception recognition: psw address has been
+		 *	incremented by pgm_int_id (unpredictable value)
+		 */
 		if (expected_psw.mask == invalid_psw.mask &&
-		    expected_psw.addr == invalid_psw.addr)
+		    expected_psw.addr == invalid_psw.addr - lowcore.pgm_int_id)
 			return 0;
 		report_fail("Wrong invalid PSW");
 	} else {

s390x/spec_ex.c static int psw_bit_12_is_1(void) · line 127

Quoted 5 lines
s390x/spec_ex.c +2 -0
@@ -112,6 +123,42 @@ static int psw_bit_12_is_1(void)
 	return check_invalid_psw();
 }
 
+extern char misaligned_code[];
+asm (  ".balign	2\n"

which section will this end up in?

s390x/spec_ex.c static int psw_bit_12_is_1(void) · line 131

Quoted 4 lines
s390x/spec_ex.c +4 -0
+"	. = . + 1\n"
+"misaligned_code:\n"
+"	larl	%r0,0\n"
+"	bcr	0xf,%r1\n"

you should just use

        br %r1

it's shorter and easier to understand

Quoted 41 lines
s390x/spec_ex.c +31 -0
+);
+
+static int psw_odd_address(void)
+{
+	struct psw odd = PSW_WITH_CUR_MASK((uint64_t)&misaligned_code);
+	uint64_t executed_addr;
+
+	expect_invalid_psw(odd);
+	fixup_psw.mask = extract_psw_mask();
+	asm volatile ( "xr	%%r0,%%r0\n"
+		"	larl	%%r1,0f\n"
+		"	stg	%%r1,%[fixup_addr]\n"
+		"	lpswe	%[odd_psw]\n"
+		"0:	lr	%[executed_addr],%%r0\n"
+	: [fixup_addr] "=&T" (fixup_psw.addr),
+	  [executed_addr] "=d" (executed_addr)
+	: [odd_psw] "Q" (odd)
+	: "cc", "%r0", "%r1"
+	);
+
+	if (!executed_addr) {
+		return check_invalid_psw();
+	} else {
+		assert(executed_addr == odd.addr);
+		clear_invalid_psw();
+		report_fail("did not execute unaligned instructions");
+		return 1;
+	}
+}
+
 /* A short PSW needs to have bit 12 set to be valid. */
 static int short_psw_bit_12_is_0(void)
 {
@@ -170,6 +217,7 @@ struct spec_ex_trigger {
 static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
+	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
#6 lore raw

Re: [kvm-unit-tests PATCH v2 2/3] s390x/spec_ex: Add test introducing odd address into PSW

Quoted 47 lines · Claudio Imbrenda
Quoted 44 lines · On Tue, 21 Feb 2023 18:48:21 +0100 Nina Schoetterl-Glausch <[email protected]>…

Instructions on s390 must be halfword aligned.
Introducing an odd instruction address into the PSW leads to a specification exception when attempting to execute the instruction at the odd address.
Add a test for this.

---
 s390x/spec_ex.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
s390x/spec_ex.c +12 -1
index 2adc5996..a26c56aa 100644
@@ -88,12 +88,23 @@ static void expect_invalid_psw(struct psw psw)
 	invalid_psw_expected = true;
 }
 
+static void clear_invalid_psw(void)
+{
+	expected_psw = PSW(0, 0);
+	invalid_psw_expected = false;
+}
+
 static int check_invalid_psw(void)
 {
 	/* Since the fixup sets this to false we check for false here. */
 	if (!invalid_psw_expected) {
+		/*
+		 * Early exception recognition: pgm_int_id == 0.
+		 * Late exception recognition: psw address has been
+		 *	incremented by pgm_int_id (unpredictable value)
+		 */
 		if (expected_psw.mask == invalid_psw.mask &&
-		    expected_psw.addr == invalid_psw.addr)
+		    expected_psw.addr == invalid_psw.addr - lowcore.pgm_int_id)
 			return 0;
 		report_fail("Wrong invalid PSW");
 	} else {
@@ -112,6 +123,42 @@ static int psw_bit_12_is_1(void)
 	return check_invalid_psw();
 }
 
Quoted 4 lines

s390x/spec_ex.c static int psw_bit_12_is_1(void) · line 127

Quoted 2 lines
s390x/spec_ex.c +2 -0
+extern char misaligned_code[];
+asm (  ".balign	2\n"

which section will this end up in?

.text

Quoted 9 lines

s390x/spec_ex.c static int psw_bit_12_is_1(void) · line 131

Quoted 5 lines
s390x/spec_ex.c +4 -0
+"	. = . + 1\n"
+"misaligned_code:\n"
+"	larl	%r0,0\n"
+"	bcr	0xf,%r1\n"

you should just use

        br %r1

it's shorter and easier to understand

Yes.

Quoted 43 lines
Quoted 42 lines
s390x/spec_ex.c +31 -0
+);
+
+static int psw_odd_address(void)
+{
+	struct psw odd = PSW_WITH_CUR_MASK((uint64_t)&misaligned_code);
+	uint64_t executed_addr;
+
+	expect_invalid_psw(odd);
+	fixup_psw.mask = extract_psw_mask();
+	asm volatile ( "xr	%%r0,%%r0\n"
+		"	larl	%%r1,0f\n"
+		"	stg	%%r1,%[fixup_addr]\n"
+		"	lpswe	%[odd_psw]\n"
+		"0:	lr	%[executed_addr],%%r0\n"
+	: [fixup_addr] "=&T" (fixup_psw.addr),
+	  [executed_addr] "=d" (executed_addr)
+	: [odd_psw] "Q" (odd)
+	: "cc", "%r0", "%r1"
+	);
+
+	if (!executed_addr) {
+		return check_invalid_psw();
+	} else {
+		assert(executed_addr == odd.addr);
+		clear_invalid_psw();
+		report_fail("did not execute unaligned instructions");
+		return 1;
+	}
+}
+
 /* A short PSW needs to have bit 12 set to be valid. */
 static int short_psw_bit_12_is_0(void)
 {
@@ -170,6 +217,7 @@ struct spec_ex_trigger {
 static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
+	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
#7 lore raw

PATCH v2 3/3 s390x/spec_ex: Add test of EXECUTE with odd target address

In reply to a message not in the archive

The EXECUTE instruction executes the instruction at the given target address. This address must be halfword aligned, otherwise a specification exception occurs.
Add a test for this.

---
 s390x/spec_ex.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
s390x/spec_ex.c +25 -0
index a26c56aa..dd097f9b 100644
@@ -177,6 +177,30 @@ static int short_psw_bit_12_is_0(void)
 	return 0;
 }
 
+static int odd_ex_target(void)
+{
+	uint64_t pre_target_addr;
+	int to = 0, from = 0x0dd;
+
+	asm volatile ( ".pushsection .rodata\n"
+		"pre_odd_ex_target:\n"
+		"	.balign	2\n"
+		"	. = . + 1\n"
+		"	lr	%[to],%[from]\n"
+		"	.popsection\n"
+
+		"	larl	%[pre_target_addr],pre_odd_ex_target\n"
+		"	ex	0,1(%[pre_target_addr])\n"
+		: [pre_target_addr] "=&a" (pre_target_addr),
+		  [to] "+d" (to)
+		: [from] "d" (from)
+	);
+
+	assert((pre_target_addr + 1) & 1);
+	report(to != from, "did not perform ex with odd target");
+	return 0;
+}
+
 static int bad_alignment(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
@@ -218,6 +242,7 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
+	{ "odd_ex_target", &odd_ex_target, true, NULL },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
Signature · 1 line
2.36.1
#8 lore raw

Re: [kvm-unit-tests PATCH v2 3/3] s390x/spec_ex: Add test of EXECUTE with odd target address

Quoted 15 lines · On Tue, 21 Feb 2023 18:48:22 +0100 Nina Schoetterl-Glausch <[email protected]>…

The EXECUTE instruction executes the instruction at the given target address. This address must be halfword aligned, otherwise a specification exception occurs.
Add a test for this.

---
 s390x/spec_ex.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
s390x/spec_ex.c +0 -0
index a26c56aa..dd097f9b 100644

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 185

Quoted 9 lines
s390x/spec_ex.c +6 -0
@@ -177,6 +177,30 @@ static int short_psw_bit_12_is_0(void)
 	return 0;
 }
 
+static int odd_ex_target(void)
+{
+	uint64_t pre_target_addr;
+	int to = 0, from = 0x0dd;
+
+	asm volatile ( ".pushsection .rodata\n"

and this should go in a .text.something subsection, as we discussed offline

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 186

Quoted 1 line
s390x/spec_ex.c +1 -0
+		"pre_odd_ex_target:\n"

shouldn't the label be after the align?

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 187

Quoted 1 line
s390x/spec_ex.c +1 -0
+		"	.balign	2\n"

(i.e. here)

Quoted 27 lines
s390x/spec_ex.c +17 -0
+		"	. = . + 1\n"
+		"	lr	%[to],%[from]\n"
+		"	.popsection\n"
+
+		"	larl	%[pre_target_addr],pre_odd_ex_target\n"
+		"	ex	0,1(%[pre_target_addr])\n"
+		: [pre_target_addr] "=&a" (pre_target_addr),
+		  [to] "+d" (to)
+		: [from] "d" (from)
+	);
+
+	assert((pre_target_addr + 1) & 1);
+	report(to != from, "did not perform ex with odd target");
+	return 0;
+}
+
 static int bad_alignment(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
@@ -218,6 +242,7 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
+	{ "odd_ex_target", &odd_ex_target, true, NULL },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
#9 lore raw

Re: [kvm-unit-tests PATCH v2 3/3] s390x/spec_ex: Add test of EXECUTE with odd target address

Quoted 21 lines · Claudio Imbrenda
Quoted 18 lines · On Tue, 21 Feb 2023 18:48:22 +0100 Nina Schoetterl-Glausch <[email protected]>…

The EXECUTE instruction executes the instruction at the given target address. This address must be halfword aligned, otherwise a specification exception occurs.
Add a test for this.

---
 s390x/spec_ex.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
s390x/spec_ex.c +0 -0
index a26c56aa..dd097f9b 100644
@@ -177,6 +177,30 @@ static int short_psw_bit_12_is_0(void)
 	return 0;
 }
 
Quoted 9 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 185

Quoted 6 lines
s390x/spec_ex.c +6 -0
+static int odd_ex_target(void)
+{
+	uint64_t pre_target_addr;
+	int to = 0, from = 0x0dd;
+
+	asm volatile ( ".pushsection .rodata\n"

and this should go in a .text.something subsection, as we discussed offline

Yes.

Quoted 4 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 186

Quoted 2 lines
s390x/spec_ex.c +1 -0
+		"pre_odd_ex_target:\n"

shouldn't the label be after the align?

No, larl needs an aligned address, and the ex below adds 1. That's why it has the pre_ prefix, it's not the ex target itself.

Quoted 33 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 187

Quoted 2 lines
s390x/spec_ex.c +1 -0
+		"	.balign	2\n"

(i.e. here)

Quoted 27 lines
s390x/spec_ex.c +17 -0
+		"	. = . + 1\n"
+		"	lr	%[to],%[from]\n"
+		"	.popsection\n"
+
+		"	larl	%[pre_target_addr],pre_odd_ex_target\n"
+		"	ex	0,1(%[pre_target_addr])\n"
+		: [pre_target_addr] "=&a" (pre_target_addr),
+		  [to] "+d" (to)
+		: [from] "d" (from)
+	);
+
+	assert((pre_target_addr + 1) & 1);
+	report(to != from, "did not perform ex with odd target");
+	return 0;
+}
+
 static int bad_alignment(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
@@ -218,6 +242,7 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
+	{ "odd_ex_target", &odd_ex_target, true, NULL },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
#10 lore raw

Re: [kvm-unit-tests PATCH v2 3/3] s390x/spec_ex: Add test of EXECUTE with odd target address

Quoted 32 lines · On Tue, 14 Mar 2023 17:41:24 +0100 Nina Schoetterl-Glausch <[email protected]>…
Quoted 21 lines · Claudio Imbrenda
Quoted 18 lines · On Tue, 21 Feb 2023 18:48:22 +0100 Nina Schoetterl-Glausch <[email protected]>…

The EXECUTE instruction executes the instruction at the given target address. This address must be halfword aligned, otherwise a specification exception occurs.
Add a test for this.

---
 s390x/spec_ex.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
s390x/spec_ex.c +0 -0
index a26c56aa..dd097f9b 100644
@@ -177,6 +177,30 @@ static int short_psw_bit_12_is_0(void)
 	return 0;
 }
 
Quoted 9 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 185

Quoted 6 lines
s390x/spec_ex.c +6 -0
+static int odd_ex_target(void)
+{
+	uint64_t pre_target_addr;
+	int to = 0, from = 0x0dd;
+
+	asm volatile ( ".pushsection .rodata\n"  

and this should go in a .text.something subsection, as we discussed offline

Quoted 8 lines

Yes.

Quoted 4 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 186

Quoted 2 lines
s390x/spec_ex.c +1 -0
+		"pre_odd_ex_target:\n"  

shouldn't the label be after the align?

No, larl needs an aligned address, and the ex below adds 1. That's why it has the pre_ prefix, it's not the ex target itself.

I understand that, but

Quoted 2 lines
Quoted 2 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 187

Quoted 2 lines
s390x/spec_ex.c +1 -0
+		"	.balign	2\n"  

doesn't the address get aligned here?
so the label here would be aligned to 2

Quoted 4 lines
Quoted 4 lines

(i.e. here)

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 188

Quoted 1 line
s390x/spec_ex.c +1 -0
+		"	. = . + 1\n"

and here it gets the +1?

Quoted 28 lines
Quoted 27 lines
Quoted 26 lines
s390x/spec_ex.c +16 -0
+		"	lr	%[to],%[from]\n"
+		"	.popsection\n"
+
+		"	larl	%[pre_target_addr],pre_odd_ex_target\n"
+		"	ex	0,1(%[pre_target_addr])\n"
+		: [pre_target_addr] "=&a" (pre_target_addr),
+		  [to] "+d" (to)
+		: [from] "d" (from)
+	);
+
+	assert((pre_target_addr + 1) & 1);
+	report(to != from, "did not perform ex with odd target");
+	return 0;
+}
+
 static int bad_alignment(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
@@ -218,6 +242,7 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
+	{ "odd_ex_target", &odd_ex_target, true, NULL },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },  
#11 lore raw

Re: [kvm-unit-tests PATCH v2 3/3] s390x/spec_ex: Add test of EXECUTE with odd target address

Quoted 44 lines · Claudio Imbrenda
Quoted 32 lines · On Tue, 14 Mar 2023 17:41:24 +0100 Nina Schoetterl-Glausch <[email protected]>…
Quoted 21 lines · Claudio Imbrenda
Quoted 18 lines · On Tue, 21 Feb 2023 18:48:22 +0100 Nina Schoetterl-Glausch <[email protected]>…

The EXECUTE instruction executes the instruction at the given target address. This address must be halfword aligned, otherwise a specification exception occurs.
Add a test for this.

---
 s390x/spec_ex.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
s390x/spec_ex.c +0 -0
index a26c56aa..dd097f9b 100644
@@ -177,6 +177,30 @@ static int short_psw_bit_12_is_0(void)
 	return 0;
 }
 
Quoted 9 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 185

Quoted 6 lines
s390x/spec_ex.c +6 -0
+static int odd_ex_target(void)
+{
+	uint64_t pre_target_addr;
+	int to = 0, from = 0x0dd;
+
+	asm volatile ( ".pushsection .rodata\n"  

and this should go in a .text.something subsection, as we discussed offline

Quoted 8 lines

Yes.

Quoted 4 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 186

Quoted 2 lines
s390x/spec_ex.c +1 -0
+		"pre_odd_ex_target:\n"  

shouldn't the label be after the align?

No, larl needs an aligned address, and the ex below adds 1. That's why it has the pre_ prefix, it's not the ex target itself.

Quoted 6 lines

I understand that, but

Quoted 2 lines
Quoted 2 lines

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 187

Quoted 2 lines
s390x/spec_ex.c +1 -0
+		"	.balign	2\n"  

doesn't the address get aligned here?
so the label here would be aligned to 2

Uh, yeah, sorry.

Quoted 37 lines
Quoted 5 lines
Quoted 5 lines

(i.e. here)

s390x/spec_ex.c static int short_psw_bit_12_is_0(void) · line 188

Quoted 1 line
s390x/spec_ex.c +1 -0
+		"	. = . + 1\n"

and here it gets the +1?

Quoted 28 lines
Quoted 27 lines
Quoted 26 lines
s390x/spec_ex.c +16 -0
+		"	lr	%[to],%[from]\n"
+		"	.popsection\n"
+
+		"	larl	%[pre_target_addr],pre_odd_ex_target\n"
+		"	ex	0,1(%[pre_target_addr])\n"
+		: [pre_target_addr] "=&a" (pre_target_addr),
+		  [to] "+d" (to)
+		: [from] "d" (from)
+	);
+
+	assert((pre_target_addr + 1) & 1);
+	report(to != from, "did not perform ex with odd target");
+	return 0;
+}
+
 static int bad_alignment(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
@@ -218,6 +242,7 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
+	{ "odd_ex_target", &odd_ex_target, true, NULL },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },