Skip to contentSkip to conversation

s390x: Dirty cc before executing tested instructions

PATCH In review Janosch Frank 2 participants 10 messages Jan 31, 2024 – Feb 1, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover s390x: Dirty cc before executing tested instructions

A recent s390 KVM fixpatch [1] showed us that checking the cc is not enough when emulation code forgets to set the cc. There might just be the correct cc in the PSW which would make the cc check succeed.

This series intentionally dirties the cc for sigp, uvc, some io instructions and sclp to make cc setting errors more apparent. I had a cursory look through the tested instructions and those are the most prominent ones with defined cc values.

Since the issue appeared in PQAP my AP test series is now dependent on this series.

[1] https://lore.kernel.org/kvm/[email protected]/

v2:
* Moved from spm to tmll (thanks Nina)

Janosch Frank (5):
lib: s390x: sigp: Dirty CC before sigp execution
lib: s390x: uv: Dirty CC before uvc execution
lib: s390x: css: Dirty CC before css instructions
s390x: mvpg: Dirty CC before mvpg execution
s390x: sclp: Dirty CC before sclp execution

 lib/s390x/asm/sigp.h |  6 +++++-
 lib/s390x/asm/uv.h   |  4 +++-
 lib/s390x/css.h      | 16 ++++++++++++----
 s390x/mvpg.c         |  6 ++++--
 s390x/sclp.c         |  5 ++++-
 5 files changed, 28 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 1/5 lib: s390x: sigp: Dirty CC before sigp execution

Dirtying the CC allows us to find missing CC changes when sigp is emulated.

---
 lib/s390x/asm/sigp.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/s390x/asm/sigp.h +5 -1
index 61d2c625..4eae95d0 100644
@@ -49,13 +49,17 @@ static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm,
 		       uint32_t *status)
 {
 	register unsigned long reg1 asm ("1") = parm;
+	uint64_t bogus_cc = SIGP_CC_NOT_OPERATIONAL;
 	int cc;
 
 	asm volatile(
+		"	tmll	%[bogus_cc],3\n"
 		"	sigp	%1,%2,0(%3)\n"
 		"	ipm	%0\n"
 		"	srl	%0,28\n"
-		: "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc");
+		: "=d" (cc), "+d" (reg1)
+		: "d" (addr), "a" (order), [bogus_cc] "d" (bogus_cc)
+		: "cc");
 	if (status)
 		*status = reg1;
 	return cc;
Signature · 1 line
2.40.1
#2 lore raw

Re: [kvm-unit-tests PATCH v2 1/5] lib: s390x: sigp: Dirty CC before sigp execution

Quoted 18 lines · On Wed, 31 Jan 2024 07:44:23 +0000 Janosch Frank <[email protected]> wrote:

Dirtying the CC allows us to find missing CC changes when sigp is emulated.

---
 lib/s390x/asm/sigp.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/s390x/asm/sigp.h +1 -0
index 61d2c625..4eae95d0 100644
@@ -49,13 +49,17 @@ static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm,
 		       uint32_t *status)
 {
 	register unsigned long reg1 asm ("1") = parm;
+	uint64_t bogus_cc = SIGP_CC_NOT_OPERATIONAL;
 	int cc;

lib/s390x/asm/sigp.h static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm, · line 62

Quoted 10 lines
lib/s390x/asm/sigp.h +4 -1
 
 	asm volatile(
+		"	tmll	%[bogus_cc],3\n"
 		"	sigp	%1,%2,0(%3)\n"
 		"	ipm	%0\n"
 		"	srl	%0,28\n"
-		: "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc");
+		: "=d" (cc), "+d" (reg1)
+		: "d" (addr), "a" (order), [bogus_cc] "d" (bogus_cc)
+		: "cc");

since you are doing changes in this inline asm, could you put names for all the parameters? that way it will be more consistent and readable.

also in all the other patches in the series (except patch 2)

Quoted 3 lines
lib/s390x/asm/sigp.h +0 -0
 	if (status)
 		*status = reg1;
 	return cc;
author NAK
#3 lore raw

Re: [kvm-unit-tests PATCH v2 1/5] lib: s390x: sigp: Dirty CC before sigp execution

Quoted 22 lines · Claudio Imbrenda
Quoted 19 lines · On Wed, 31 Jan 2024 07:44:23 +0000 Janosch Frank <[email protected]> wrote:

Dirtying the CC allows us to find missing CC changes when sigp is emulated.

---
  lib/s390x/asm/sigp.h | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
lib/s390x/asm/sigp.h +1 -0
index 61d2c625..4eae95d0 100644
@@ -49,13 +49,17 @@ static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm,
  		       uint32_t *status)
  {
  	register unsigned long reg1 asm ("1") = parm;
+	uint64_t bogus_cc = SIGP_CC_NOT_OPERATIONAL;
  	int cc;
 
Quoted 13 lines

lib/s390x/asm/sigp.h static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm, · line 62

Quoted 9 lines
lib/s390x/asm/sigp.h +4 -1
  	asm volatile(
+		"	tmll	%[bogus_cc],3\n"
  		"	sigp	%1,%2,0(%3)\n"
  		"	ipm	%0\n"
  		"	srl	%0,28\n"
-		: "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc");
+		: "=d" (cc), "+d" (reg1)
+		: "d" (addr), "a" (order), [bogus_cc] "d" (bogus_cc)
+		: "cc");

since you are doing changes in this inline asm, could you put names for all the parameters? that way it will be more consistent and readable.

NACK, not in this series.

#4 lore raw

PATCH v2 2/5 lib: s390x: uv: Dirty CC before uvc execution

In reply to Janosch Frank

Dirtying the CC allows us to find missing CC changes.

---
 lib/s390x/asm/uv.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/s390x/asm/uv.h +3 -1
index e9fb19af..611dcd3f 100644
@@ -216,14 +216,16 @@ struct uv_cb_ssc {
 
 static inline int uv_call_once(unsigned long r1, unsigned long r2)
 {
+	uint64_t bogus_cc = 1;
 	int cc;
 
 	asm volatile(
+		"	tmll    %[bogus_cc],3\n"
 		"0:	.insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
 		"		ipm	%[cc]\n"
 		"		srl	%[cc],28\n"
 		: [cc] "=d" (cc)
-		: [r1] "a" (r1), [r2] "a" (r2)
+		: [r1] "a" (r1), [r2] "a" (r2), [bogus_cc] "d" (bogus_cc)
 		: "memory", "cc");
 
 	if (UVC_ERR_DEBUG && cc == 1)
Signature · 1 line
2.40.1
Reviewed-by on v2 2/5
#5 lore raw

Re: [kvm-unit-tests PATCH v2 2/5] lib: s390x: uv: Dirty CC before uvc execution

Quoted 3 lines · On Wed, 31 Jan 2024 07:44:24 +0000 Janosch Frank <[email protected]> wrote:

Dirtying the CC allows us to find missing CC changes.

Quoted 26 lines
---
 lib/s390x/asm/uv.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/s390x/asm/uv.h +3 -1
index e9fb19af..611dcd3f 100644
@@ -216,14 +216,16 @@ struct uv_cb_ssc {
 
 static inline int uv_call_once(unsigned long r1, unsigned long r2)
 {
+	uint64_t bogus_cc = 1;
 	int cc;
 
 	asm volatile(
+		"	tmll    %[bogus_cc],3\n"
 		"0:	.insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
 		"		ipm	%[cc]\n"
 		"		srl	%[cc],28\n"
 		: [cc] "=d" (cc)
-		: [r1] "a" (r1), [r2] "a" (r2)
+		: [r1] "a" (r1), [r2] "a" (r2), [bogus_cc] "d" (bogus_cc)
 		: "memory", "cc");
 
 	if (UVC_ERR_DEBUG && cc == 1)
#6 lore raw

PATCH v2 3/5 lib: s390x: css: Dirty CC before css instructions

In reply to Janosch Frank

Dirtying the CC allows us to find missing CC changes when css instructions are emulated.

---
 lib/s390x/css.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
lib/s390x/css.h +12 -4
index 0a19324b..504b3f14 100644
@@ -147,14 +147,16 @@ static inline int ssch(unsigned long schid, struct orb *addr)
 static inline int stsch(unsigned long schid, struct schib *addr)
 {
 	register unsigned long reg1 asm ("1") = schid;
+	uint64_t bogus_cc = 1;
 	int cc;
 
 	asm volatile(
+		"       tmll    %[bogus_cc],3\n"
 		"	stsch	0(%3)\n"
 		"	ipm	%0\n"
 		"	srl	%0,28"
 		: "=d" (cc), "=m" (*addr)
-		: "d" (reg1), "a" (addr)
+		: "d" (reg1), "a" (addr), [bogus_cc] "d" (bogus_cc)
 		: "cc");
 	return cc;
 }
@@ -177,14 +179,16 @@ static inline int msch(unsigned long schid, struct schib *addr)
 static inline int tsch(unsigned long schid, struct irb *addr)
 {
 	register unsigned long reg1 asm ("1") = schid;
+	uint64_t bogus_cc = 2;
 	int cc;
 
 	asm volatile(
+		"       tmll    %[bogus_cc],3\n"
 		"	tsch	0(%3)\n"
 		"	ipm	%0\n"
 		"	srl	%0,28"
 		: "=d" (cc), "=m" (*addr)
-		: "d" (reg1), "a" (addr)
+		: "d" (reg1), "a" (addr), [bogus_cc] "d" (bogus_cc)
 		: "cc");
 	return cc;
 }
@@ -252,28 +256,32 @@ static inline int rsch(unsigned long schid)
 static inline int rchp(unsigned long chpid)
 {
 	register unsigned long reg1 asm("1") = chpid;
+	uint64_t bogus_cc = 1;
 	int cc;
 
 	asm volatile(
+		"       tmll    %[bogus_cc],3\n"
 		"	rchp\n"
 		"	ipm	%0\n"
 		"	srl	%0,28"
 		: "=d" (cc)
-		: "d" (reg1)
+		: "d" (reg1), [bogus_cc] "d" (bogus_cc)
 		: "cc");
 	return cc;
 }
 
 static inline int stcrw(uint32_t *crw)
 {
+	uint64_t bogus_cc = 1;
 	int cc;
 
 	asm volatile(
+		"       tmll    %[bogus_cc],3\n"
 		"	stcrw	%[crw]\n"
 		"	ipm	%[cc]\n"
 		"	srl	%[cc],28"
 		: [cc] "=d" (cc)
-		: [crw] "Q" (*crw)
+		: [crw] "Q" (*crw), [bogus_cc] "d" (bogus_cc)
 		: "cc", "memory");
 	return cc;
 }
Signature · 1 line
2.40.1
#7 lore raw

PATCH v2 4/5 s390x: mvpg: Dirty CC before mvpg execution

In reply to Janosch Frank

Dirtying the CC allows us to find missing CC changes when mvpg is emulated.

---
 s390x/mvpg.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
s390x/mvpg.c +4 -2
index 296338d4..62d42e36 100644
@@ -40,12 +40,14 @@ static uint8_t *fresh;
 static inline int mvpg(unsigned long r0, void *dest, void *src)
 {
 	register unsigned long reg0 asm ("0") = r0;
+	uint64_t bogus_cc = 3;
 	int cc;
 
-	asm volatile("	mvpg    %1,%2\n"
+	asm volatile("	tmll	%[bogus_cc],3\n"
+		     "	mvpg    %1,%2\n"
 		     "	ipm     %0\n"
 		     "	srl     %0,28"
-		: "=&d" (cc) : "a" (dest), "a" (src), "d" (reg0)
+		: "=&d" (cc) : "a" (dest), "a" (src), "d" (reg0), [bogus_cc] "d" (bogus_cc)
 		: "memory", "cc");
 	return cc;
 }
Signature · 1 line
2.40.1
#8 lore raw

PATCH v2 5/5 s390x: sclp: Dirty CC before sclp execution

In reply to Janosch Frank

Dirtying the CC allows us to find missing CC changes when sclp is emulated.

---
 s390x/sclp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
s390x/sclp.c +4 -1
index ccbaa913..53fce0cf 100644
@@ -399,6 +399,7 @@ out:
 static void test_instbits(void)
 {
 	SCCBHeader *h = (SCCBHeader *)pagebuf;
+	uint64_t bogus_cc = 1;
 	int cc;
 
 	sclp_mark_busy();
@@ -406,10 +407,12 @@ static void test_instbits(void)
 	sclp_setup_int();
 
 	asm volatile(
+		"	tmll	%[bogus_cc],3\n"
 		"       .insn   rre,0xb2204200,%1,%2\n"  /* servc %1,%2 */
 		"       ipm     %0\n"
 		"       srl     %0,28"
-		: "=&d" (cc) : "d" (valid_code), "a" (__pa(pagebuf))
+		: "=&d" (cc)
+		: "d" (valid_code), "a" (__pa(pagebuf)), [bogus_cc] "d" (bogus_cc)
 		: "cc", "memory");
 	/* No exception, but also no command accepted, so no interrupt is
 	 * expected. We need to clear the flag manually otherwise we will
Signature · 1 line
2.40.1
Reviewed-by on the v2 series
#9 lore raw
In reply to Janosch Frank
Quoted 9 lines · On Wed, 31 Jan 2024 07:44:22 +0000 Janosch Frank <[email protected]> wrote:

A recent s390 KVM fixpatch [1] showed us that checking the cc is not enough when emulation code forgets to set the cc. There might just be the correct cc in the PSW which would make the cc check succeed.

This series intentionally dirties the cc for sigp, uvc, some io instructions and sclp to make cc setting errors more apparent. I had a cursory look through the tested instructions and those are the most prominent ones with defined cc values.

Quoted 4 lines

Since the issue appeared in PQAP my AP test series is now dependent on this series.

[1] https://lore.kernel.org/kvm/[email protected]/

whole series:

Quoted 18 lines

v2:
* Moved from spm to tmll (thanks Nina)

Janosch Frank (5):
lib: s390x: sigp: Dirty CC before sigp execution
lib: s390x: uv: Dirty CC before uvc execution
lib: s390x: css: Dirty CC before css instructions
s390x: mvpg: Dirty CC before mvpg execution
s390x: sclp: Dirty CC before sclp execution

 lib/s390x/asm/sigp.h |  6 +++++-
 lib/s390x/asm/uv.h   |  4 +++-
 lib/s390x/css.h      | 16 ++++++++++++----
 s390x/mvpg.c         |  6 ++++--
 s390x/sclp.c         |  5 ++++-
 5 files changed, 28 insertions(+), 9 deletions(-)