s390x: Dirty cc before executing tested instructions
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
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
@@ -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; asmvolatile ( +" 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
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.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/asm/sigp.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/s390x/asm/sigp.h +1
-0@@ -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
-1asmvolatile ( +" 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
-0if (status) *status = reg1;return cc;
Janosch Frank
NAKRe: [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.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/asm/sigp.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/s390x/asm/sigp.h +1
-0@@ -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
-1asmvolatile ( +" 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.
PATCH v2 2/5 lib: s390x: uv: Dirty CC before uvc execution
In reply to Janosch FrankDirtying 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
@@ -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; asmvolatile ( +" 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
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.
Signed-off-by Janosch Frank <[email protected]>
Quoted 26 lines
--- lib/s390x/asm/uv.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/s390x/asm/uv.h +3
-1@@ -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; asmvolatile ( +" 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 )
PATCH v2 3/5 lib: s390x: css: Dirty CC before css instructions
In reply to Janosch FrankDirtying 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
@@ -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; asmvolatile ( +" 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; asmvolatile ( +" 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; asmvolatile ( +" 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; asmvolatile ( +" 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
PATCH v2 4/5 s390x: mvpg: Dirty CC before mvpg execution
In reply to Janosch FrankDirtying 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
@@ -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; - asmvolatile (" mvpg %1,%2\n" + asmvolatile (" 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
PATCH v2 5/5 s390x: sclp: Dirty CC before sclp execution
In reply to Janosch FrankDirtying 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
@@ -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 (); asmvolatile ( +" 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
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.
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 executionlib/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(-)