target-s390x: Implement mvcos instruction
RFC PATCH 1/1 target-s390x: Implement mvcos instruction
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)
target/s390x/helper.h +1 -0
@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)
target/s390x/insn-data.def +2 -0
@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */
target/s390x/mem_helper.c +80 -0
86 lines not on this page · raw message
target/s390x/translate.c +12 -0
@@ -1194,6 +1194,7 @@ typedef enum DisasFacility {FAC_SCF ,/* store clock fast */ FAC_SFLE ,/* store facility list extended */ FAC_ILA ,/* interlocked access facility 1 */ +FAC_MVCOS ,/* move-with-optional-specification */ } DisasFacility; struct DisasInsn {
@@ -2877,6 +2878,17 @@ static ExitStatus op_mvcs(DisasContext *s, DisasOps *o)set_cc_static (s); return NO_EXIT; } + +static ExitStatus op_mvcos (DisasContext *s,DisasOps *o) +{ +int r3 =get_field (s->fields, r3); + +check_privileged (s); +potential_page_fault (s); +gen_helper_mvcos (cc_op, cpu_env, regs[0 ], o->addr1, o->in2, regs[r3]); +set_cc_static (s); +return NO_EXIT ; +}#endif static ExitStatus op_mvpg (DisasContext *s,DisasOps *o)
Signature · 1 line
2.12.0
Quoted 9 lines · Miroslav Benes
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
Signed-off-by Miroslav Benes <[email protected]>---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.
Quoted 5 lines
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used
fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).
I'm not aware of a function that could deal with two address spaces already (but that does not mean that there is no such function already) ... still, I guess, you likely need to write your own memmove helper function that can deal with two different address spaces.
Quoted 42 lines
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)target/s390x/helper.h +1
-0@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)target/s390x/insn-data.def +2
-0@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */target/s390x/mem_helper.c +3
-0@@ -1089,6 +1089,86 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)return cc; } +uint32_t HELPER (mvcos )(CPUS390XState *env,uint64_t r0,uint64_t dest, +uint64_t src,uint64_t len) +{
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1104
Quoted 10 lines
target/s390x/mem_helper.c +10
-0+int cc; +int key1, as1, abit1, kbit1; +int key2, as2, abit2, kbit2; + +HELPER_LOG ("%s dest %" PRIx64", src %" PRIx64", len %" PRIx64"\n" , + __func__, dest, src, len); + +/* check DAT */ +if (!(env->psw.mask &PSW_MASK_DAT )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );
Length of the opcode is 6 bytes, not 2.
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1114
Quoted 10 lines
target/s390x/mem_helper.c +10
-0+ } + +/* access control for the first operand */ + abit1 = (r0 &0x0010000ULL ) >>16 ; + kbit1 = (r0 &0x0020000ULL ) >>17 ; + as1 = (r0 &0x00c00000ULL ) >>22 ; + key1 = (r0 &0xf0000000ULL ) >>28 ; + +if (!kbit1) { + key1 = (env->psw.mask &PSW_MASK_KEY ) >> (PSW_SHIFT_KEY -4 );
I wonder whether it would make sense to define PSW_SHIFT_KEY directly to 52 instead ... I can't see the reason for 56 here. The only other spot that uses it also subtracts 4.
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1124
Quoted 10 lines
target/s390x/mem_helper.c +10
-0+ } + +if (!abit1) { + as1 = (env->psw.mask &PSW_MASK_ASC ) >>46 ; + } + +/* +* abit1 is set, as1 designates the home-space mode, psw is in the problem +* state. +* */
Cosmetic nit: Make the closing comment just "*/" instead of "* */".
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1126
Quoted 2 lines
target/s390x/mem_helper.c +2
-0+if (abit1 && (as1 ==3 ) && (env->psw.mask &PSW_MASK_PSTATE )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );
set instruction length = 6 again
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1133
Quoted 7 lines
target/s390x/mem_helper.c +7
-0+ } + +/* access control for the second operand */ + abit2 = (r0 &0x0010000ULL ); + kbit2 = (r0 &0x0020000ULL ) >>1 ; + as2 = (r0 &0x00c00000ULL ) >>6 ; + key2 = (r0 &0xf0000000ULL ) >>12 ;
The above four lines look wrong ... are you sure that you've got the masks right? If I read the POP correctly, the values should be in the lowest two bytes instead?
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1147
Quoted 13 lines
target/s390x/mem_helper.c +13
-0+if (!kbit2) { + key2 = (env->psw.mask &PSW_MASK_KEY ) >> (PSW_SHIFT_KEY -4 ); + } + +if (!abit2) { + as2 = (env->psw.mask &PSW_MASK_ASC ) >>46 ; + } + +/* +* Secondary-space control bit is zero (bit 37 of r0) and either as +* designates secondary-space mode. +*/ +if (!(r0 &0x2000000000ULL ) && (as1 ==2 || as2 ==2 )) {
You mixed up "control register 0" with "general purpose register 0" here, i.e. you must not use r0 but rather env->cregs[0] here.
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1147
Quoted 1 line
target/s390x/mem_helper.c +1
-0+program_interrupt (env,PGM_SPECIAL_OP ,2 );
s/2/6/
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1155
Quoted 7 lines
target/s390x/mem_helper.c +7
-0+ } + +/* psw is in the problem state and either key is invalid */ +if ((env->psw.mask &PSW_MASK_PSTATE ) && + (!(env->cregs[3 ] & (1 << (31 - key1))) || + !(env->cregs[3 ] & (1 << (31 - key2))))) { +program_interrupt (env,PGM_PRIVILEGED ,2 );
s/2/6/
Quoted 32 lines
target/s390x/mem_helper.c +16
-0+ } + +if (len <=4096 ) { + cc =0 ; + }else { + cc =3 ; + len =4096 ; + } + +/* move */ +/* XXX use keys and as during the move */ +fast_memmove (env, dest, src, len); + +return cc; +} +/* invalidate pte */ void HELPER (ipte )(CPUS390XState *env,uint64_t pte_addr,uint64_t vaddr) {target/s390x/translate.c +1
-0@@ -1194,6 +1194,7 @@ typedef enum DisasFacility {FAC_SCF ,/* store clock fast */ FAC_SFLE ,/* store facility list extended */ FAC_ILA ,/* interlocked access facility 1 */ +FAC_MVCOS ,/* move-with-optional-specification */ } DisasFacility; struct DisasInsn {
target/s390x/translate.c static ExitStatus op_mvcs(DisasContext *s, DisasOps *o) · line 2886
Quoted 9 lines
target/s390x/translate.c +6
-0@@ -2877,6 +2878,17 @@ static ExitStatus op_mvcs(DisasContext *s, DisasOps *o)set_cc_static (s);return NO_EXIT ; } + +static ExitStatus op_mvcos (DisasContext *s,DisasOps *o) +{ +int r3 =get_field (s->fields, r3); + +check_privileged (s);
I think it is possible to use this instruction in PRoblem state, so the general check_privileged() check seems to be wrong here. The instruction only generates a PRIVILEGE exception if the keys are invalid.
Quoted 9 lines
target/s390x/translate.c +5
-0+potential_page_fault (s); +gen_helper_mvcos (cc_op, cpu_env, regs[0 ], o->addr1, o->in2, regs[r3]); +set_cc_static (s); + return NO_EXIT; +}#endif static ExitStatus op_mvpg (DisasContext *s,DisasOps *o)
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Miroslav Benes
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
Signed-off-by Miroslav Benes <[email protected]>---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.Quoted 5 lines
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used
fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).
Quoted 4 lines
I'm not aware of a function that could deal with two address spaces already (but that does not mean that there is no such function already) ... still, I guess, you likely need to write your own memmove helper function that can deal with two different address spaces.
Ok, I thought that was the case. I'll try to come up with something.
Quoted 39 lines
Quoted 39 lines
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)target/s390x/helper.h +1
-0@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)target/s390x/insn-data.def +2
-0@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */target/s390x/mem_helper.c +0
-0@@ -1089,6 +1089,86 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)return cc; }
Quoted 15 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1104
Quoted 13 lines
target/s390x/mem_helper.c +13
-0+uint32_t HELPER (mvcos )(CPUS390XState *env,uint64_t r0,uint64_t dest, +uint64_t src,uint64_t len) +{ +int cc; +int key1, as1, abit1, kbit1; +int key2, as2, abit2, kbit2; + +HELPER_LOG ("%s dest %" PRIx64", src %" PRIx64", len %" PRIx64"\n" , + __func__, dest, src, len); + +/* check DAT */ +if (!(env->psw.mask &PSW_MASK_DAT )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );Length of the opcode is 6 bytes, not 2.
True. Sorry, I don't know where 2 came from. It does not make sense.
Quoted 6 lines
Quoted 6 lines
target/s390x/mem_helper.c +6
-0+ } + +/* access control for the first operand */ + abit1 = (r0 &0x0010000ULL ) >>16 ; + kbit1 = (r0 &0x0020000ULL ) >>17 ; + as1 = (r0 &0x00c00000ULL ) >>22 ;
Quoted 8 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1114
Quoted 4 lines
target/s390x/mem_helper.c +4
-0+ key1 = (r0 &0xf0000000ULL ) >>28 ; + +if (!kbit1) { + key1 = (env->psw.mask &PSW_MASK_KEY ) >> (PSW_SHIFT_KEY -4 );I wonder whether it would make sense to define
PSW_SHIFT_KEYdirectly to 52 instead ... I can't see the reason for 56 here. The only other spot that uses it also subtracts 4.
Right, I'll make a patch to change that.
Quoted 4 lines
Quoted 4 lines
target/s390x/mem_helper.c +4
-0+ } + +if (!abit1) { + as1 = (env->psw.mask &PSW_MASK_ASC ) >>46 ;
Quoted 8 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1124
Quoted 6 lines
target/s390x/mem_helper.c +6
-0+ } + +/* +* abit1 is set, as1 designates the home-space mode, psw is in the problem +* state. +* */ Cosmetic nit: Make the closing comment just "*/" instead of "* */".
Oh, sure.
Quoted 13 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1126
Quoted 2 lines
target/s390x/mem_helper.c +2
-0+if (abit1 && (as1 ==3 ) && (env->psw.mask &PSW_MASK_PSTATE )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );set instruction length = 6 again
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1133
Quoted 7 lines
target/s390x/mem_helper.c +7
-0+ } + +/* access control for the second operand */ + abit2 = (r0 &0x0010000ULL ); + kbit2 = (r0 &0x0020000ULL ) >>1 ; + as2 = (r0 &0x00c00000ULL ) >>6 ; + key2 = (r0 &0xf0000000ULL ) >>12 ;
Quoted 3 lines
The above four lines look wrong ... are you sure that you've got the masks right? If I read the POP correctly, the values should be in the lowest two bytes instead?
You're right. Stupid copy-paste error, I only changed shift constants. Sorry for that.
Quoted 8 lines
Quoted 8 lines
target/s390x/mem_helper.c +8
-0+if (!kbit2) { + key2 = (env->psw.mask &PSW_MASK_KEY ) >> (PSW_SHIFT_KEY -4 ); + } + +if (!abit2) { + as2 = (env->psw.mask &PSW_MASK_ASC ) >>46 ; + } +
Quoted 8 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1147
Quoted 5 lines
target/s390x/mem_helper.c +5
-0+/* +* Secondary-space control bit is zero (bit 37 of r0) and either as +* designates secondary-space mode. +*/ +if (!(r0 &0x2000000000ULL ) && (as1 ==2 || as2 ==2 )) {You mixed up "control register 0" with "general purpose register 0" here, i.e. you must not use r0 but rather env->cregs[0] here.
Correct. Will fix it.
Quoted 44 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1147
Quoted 1 line
target/s390x/mem_helper.c +1
-0+program_interrupt (env,PGM_SPECIAL_OP ,2 );s/2/6/
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1155
Quoted 7 lines
target/s390x/mem_helper.c +7
-0+ } + +/* psw is in the problem state and either key is invalid */ +if ((env->psw.mask &PSW_MASK_PSTATE ) && + (!(env->cregs[3 ] & (1 << (31 - key1))) || + !(env->cregs[3 ] & (1 << (31 - key2))))) { +program_interrupt (env,PGM_PRIVILEGED ,2 );s/2/6/
Quoted 30 lines
target/s390x/mem_helper.c +16
-0+ } + +if (len <=4096 ) { + cc =0 ; + }else { + cc =3 ; + len =4096 ; + } + +/* move */ +/* XXX use keys and as during the move */ +fast_memmove (env, dest, src, len); + +return cc; +} +/* invalidate pte */ void HELPER (ipte )(CPUS390XState *env,uint64_t pte_addr,uint64_t vaddr) {target/s390x/translate.c +1
-0@@ -1194,6 +1194,7 @@ typedef enum DisasFacility {FAC_SCF ,/* store clock fast */ FAC_SFLE ,/* store facility list extended */ FAC_ILA ,/* interlocked access facility 1 */ +FAC_MVCOS ,/* move-with-optional-specification */ } DisasFacility;
Quoted 15 lines
target/s390x/translate.c static ExitStatus op_mvcs(DisasContext *s, DisasOps *o) · line 2886
Quoted 11 lines
target/s390x/translate.c +6
-0struct DisasInsn {@@ -2877,6 +2878,17 @@ static ExitStatus op_mvcs(DisasContext *s, DisasOps *o)set_cc_static (s);return NO_EXIT ; } + +static ExitStatus op_mvcos (DisasContext *s,DisasOps *o) +{ +int r3 =get_field (s->fields, r3); + +check_privileged (s);I think it is possible to use this instruction in PRoblem state, so the general
check_privileged()check seems to be wrong here. The instruction only generates a PRIVILEGE exception if the keys are invalid.
Ok.
Thanks for the feedback! I'm new to qemu, so everything is more than useful.
Miroslav
Quoted 80 lines · Miroslav Benes
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Miroslav Benes
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
Signed-off-by Miroslav Benes <[email protected]>---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.Quoted 5 lines
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used
fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).Quoted 4 lines
I'm not aware of a function that could deal with two address spaces already (but that does not mean that there is no such function already) ... still, I guess, you likely need to write your own memmove helper function that can deal with two different address spaces.
Ok, I thought that was the case. I'll try to come up with something.
Quoted 39 lines
Quoted 39 lines
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)target/s390x/helper.h +1
-0@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)target/s390x/insn-data.def +2
-0@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */target/s390x/mem_helper.c +0
-0@@ -1089,6 +1089,86 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)return cc; }Quoted 15 lines
target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1104
Quoted 13 lines
target/s390x/mem_helper.c +13
-0+uint32_t HELPER (mvcos )(CPUS390XState *env,uint64_t r0,uint64_t dest, +uint64_t src,uint64_t len) +{ +int cc; +int key1, as1, abit1, kbit1; +int key2, as2, abit2, kbit2; + +HELPER_LOG ("%s dest %" PRIx64", src %" PRIx64", len %" PRIx64"\n" , + __func__, dest, src, len); + +/* check DAT */ +if (!(env->psw.mask &PSW_MASK_DAT )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );Length of the opcode is 6 bytes, not 2.
Quoted 1 line
True. Sorry, I don't know where 2 came from. It does not make sense.
As I recently had to learn it the hard way (while implementing the TEST BLOCK instruction), you should use ILEN_LATER_INC here instead of 2 (or 6), since the Special operation exception is suppressing, too, i.e. the program counter should be increased afterwards to the next instruction.
BTW, are you still working on a new version of this patch?
Thomas
Quoted 81 lines · Thomas Huth
Quoted 80 lines · Miroslav Benes
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Miroslav Benes
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
Signed-off-by Miroslav Benes <[email protected]>---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.Quoted 5 lines
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used
fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).Quoted 4 lines
I'm not aware of a function that could deal with two address spaces already (but that does not mean that there is no such function already) ... still, I guess, you likely need to write your own memmove helper function that can deal with two different address spaces.
Ok, I thought that was the case. I'll try to come up with something.
Quoted 54 lines
Quoted 42 lines
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)target/s390x/helper.h +1
-0@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)target/s390x/insn-data.def +2
-0@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */target/s390x/mem_helper.c +3
-0@@ -1089,6 +1089,86 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)return cc; } +uint32_t HELPER (mvcos )(CPUS390XState *env,uint64_t r0,uint64_t dest, +uint64_t src,uint64_t len) +{target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1104
Quoted 10 lines
target/s390x/mem_helper.c +10
-0+int cc; +int key1, as1, abit1, kbit1; +int key2, as2, abit2, kbit2; + +HELPER_LOG ("%s dest %" PRIx64", src %" PRIx64", len %" PRIx64"\n" , + __func__, dest, src, len); + +/* check DAT */ +if (!(env->psw.mask &PSW_MASK_DAT )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );Length of the opcode is 6 bytes, not 2.
Quoted 7 lines
Quoted 1 line
True. Sorry, I don't know where 2 came from. It does not make sense.
As I recently had to learn it the hard way (while implementing the TEST BLOCK instruction), you should use
ILEN_LATER_INChere instead of 2 (or 6), since the Special operation exception is suppressing, too, i.e. the program counter should be increased afterwards to the next instruction.
This is no longer needed with
https://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg02631.html
You can either use 6 or ILEN_AUTO here, suppression will be handled internally.
Quoted 4 lines
BTW, are you still working on a new version of this patch?
Thomas
Signature · 3 lines
Thanks, David
Quoted 90 lines · David Hildenbrand
Quoted 81 lines · Thomas Huth
Quoted 80 lines · Miroslav Benes
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Miroslav Benes
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
Signed-off-by Miroslav Benes <[email protected]>---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.Quoted 5 lines
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used
fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).Quoted 4 lines
I'm not aware of a function that could deal with two address spaces already (but that does not mean that there is no such function already) ... still, I guess, you likely need to write your own memmove helper function that can deal with two different address spaces.
Ok, I thought that was the case. I'll try to come up with something.
Quoted 54 lines
Quoted 42 lines
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)target/s390x/helper.h +1
-0@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)target/s390x/insn-data.def +2
-0@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */target/s390x/mem_helper.c +3
-0@@ -1089,6 +1089,86 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)return cc; } +uint32_t HELPER (mvcos )(CPUS390XState *env,uint64_t r0,uint64_t dest, +uint64_t src,uint64_t len) +{target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1104
Quoted 10 lines
target/s390x/mem_helper.c +10
-0+int cc; +int key1, as1, abit1, kbit1; +int key2, as2, abit2, kbit2; + +HELPER_LOG ("%s dest %" PRIx64", src %" PRIx64", len %" PRIx64"\n" , + __func__, dest, src, len); + +/* check DAT */ +if (!(env->psw.mask &PSW_MASK_DAT )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );Length of the opcode is 6 bytes, not 2.
Quoted 7 lines
Quoted 1 line
True. Sorry, I don't know where 2 came from. It does not make sense.
As I recently had to learn it the hard way (while implementing the TEST BLOCK instruction), you should use
ILEN_LATER_INChere instead of 2 (or 6), since the Special operation exception is suppressing, too, i.e. the program counter should be increased afterwards to the next instruction.
Quoted 5 lines
This is no longer needed with
https://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg02631.htmlYou can either use 6 or
ILEN_AUTOhere, suppression will be handled internally.
ok, good to know.
Quoted 1 line
Quoted 1 line
BTW, are you still working on a new version of this patch?
Unfortunately, I haven't touched it since the submission. It is only a side project at work and I only started reading about s390x address spaces to implement a proper memmove helper. No implementation yet so far :/
So if anyone wants to work on this, they can of course take my patch as a basis.
Thanks,
Miroslav
Quoted 100 lines · Miroslav Benes
Quoted 90 lines · David Hildenbrand
Quoted 81 lines · Thomas Huth
Quoted 80 lines · Miroslav Benes
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Miroslav Benes
Implement MVCOS instruction, which the Linux kernel uses in user access functions.
Signed-off-by Miroslav Benes <[email protected]>---
I tried to do my best to follow the specification but it is quite possible that I got something wrong because of my lack of understanding. Especially I am not sure about all those bit ops :/.Quoted 5 lines
Anyway, there is one piece missing. The actual use of keys and address-space-control during the move. I used
fast_memmove, but it is not correct. Is there a helper which I could use? I looked at other instructions which should implement access control, but there were silently ignore it :).Quoted 4 lines
I'm not aware of a function that could deal with two address spaces already (but that does not mean that there is no such function already) ... still, I guess, you likely need to write your own memmove helper function that can deal with two different address spaces.
Ok, I thought that was the case. I'll try to come up with something.
Quoted 54 lines
Quoted 42 lines
target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 12 +++++++ 4 files changed, 95 insertions(+)target/s390x/helper.h +1
-0@@ -104,6 +104,7 @@ DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) DEF_HELPER_3(csp, i32, env, i32, i64) +DEF_HELPER_5(mvcos, i32, env, i64, i64, i64, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)DEF_HELPER_4 (sigp, i32, env, i64, i32, i64)target/s390x/insn-data.def +2
-0@@ -854,6 +854,8 @@ /* LOAD USING REAL ADDRESS */ C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) +/* MOVE WITH OPTIONAL SPECIFICATION */ + C(0xc800, MVCOS, SSF, MVCOS, la1, a2, 0, 0, mvcos, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */target/s390x/mem_helper.c +3
-0@@ -1089,6 +1089,86 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)return cc; } +uint32_t HELPER (mvcos )(CPUS390XState *env,uint64_t r0,uint64_t dest, +uint64_t src,uint64_t len) +{target/s390x/mem_helper.c uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2) · line 1104
Quoted 10 lines
target/s390x/mem_helper.c +10
-0+int cc; +int key1, as1, abit1, kbit1; +int key2, as2, abit2, kbit2; + +HELPER_LOG ("%s dest %" PRIx64", src %" PRIx64", len %" PRIx64"\n" , + __func__, dest, src, len); + +/* check DAT */ +if (!(env->psw.mask &PSW_MASK_DAT )) { +program_interrupt (env,PGM_SPECIAL_OP ,2 );Length of the opcode is 6 bytes, not 2.
Quoted 7 lines
Quoted 1 line
True. Sorry, I don't know where 2 came from. It does not make sense.
As I recently had to learn it the hard way (while implementing the TEST BLOCK instruction), you should use
ILEN_LATER_INChere instead of 2 (or 6), since the Special operation exception is suppressing, too, i.e. the program counter should be increased afterwards to the next instruction.Quoted 5 lines
This is no longer needed with
https://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg02631.htmlYou can either use 6 or
ILEN_AUTOhere, suppression will be handled internally.ok, good to know.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
BTW, are you still working on a new version of this patch?
Unfortunately, I haven't touched it since the submission. It is only a side project at work and I only started reading about s390x address spaces to implement a proper memmove helper. No implementation yet so far :/
So if anyone wants to work on this, they can of course take my patch as a basis.
I will look into it. I already have something running that almost works.
For some reason, when I trick my upstream linux kernel in using mvcos for uaccess, I get my /init killed at some point, like it would be receiving some unexpected page fault. hmmm....
Thanks!
Quoted 4 lines
Thanks,
Miroslav
Signature · 3 lines
Thanks, David