Fixup exclusive store logic
cover Fixup exclusive store logic
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.
Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop mask
target/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/3 target/arm: Update the memops for exclusive load
Acording to the ARM ARM exclusive loads require the same allignment as exclusive stores. Let's update the memops used for the load to match that of the store. This adds the alignment requirement to the memops.
---
target/arm/translate-a64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/translate-a64.c +1 -1
@@ -1854,7 +1854,7 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2, TCGv_i64 addr, int size, bool is_pair) { TCGv_i64 tmp = tcg_temp_new_i64(); -TCGMemOp memop = s->be_data + size; +TCGMemOp memop = size |MO_ALIGN | s->be_data;g_assert (size <=3 );tcg_gen_qemu_ld_i64 (tmp, addr,get_mem_index (s), memop);
Signature · 1 line
2.11.0
Re: [Qemu-arm] [PATCH v1 1/3] target/arm: Update the memops for exclusive load
Quoted 6 lines · Alistair Francis
Acording to the ARM ARM exclusive loads require the same allignment as exclusive stores. Let's update the memops used for the load to match that of the store. This adds the alignment requirement to the memops.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Quoted 21 lines
---
target/arm/translate-a64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/translate-a64.c +1
-1@@ -1854,7 +1854,7 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2, TCGv_i64 addr, int size, bool is_pair) { TCGv_i64 tmp = tcg_temp_new_i64(); -TCGMemOp memop = s->be_data + size; +TCGMemOp memop = size |MO_ALIGN | s->be_data;g_assert (size <=3 );tcg_gen_qemu_ld_i64 (tmp, addr,get_mem_index (s), memop);Signature · 1 line
2.11.0
PATCH 2/3 tcg/tcg-op: Expose the tcg_gen_ext_i* functions
In reply to Alistair FrancisExpose the tcg_gen_ext_i32() and tcg_gen_ext_i64() functions.
---
Although I no longer am using these functions I have left this patch in as Richard thought it was a good idea.
tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
tcg/tcg-op.c +2 -2
@@ -2709,7 +2709,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)gen_ldst_i64 (INDEX_op_qemu_st_i64, val, addr, memop, idx); } -static void tcg_gen_ext_i32 (TCGv_i32 ret,TCGv_i32 val,TCGMemOp opc) +void tcg_gen_ext_i32 (TCGv_i32 ret,TCGv_i32 val,TCGMemOp opc) {switch (opc &MO_SSIZE ) {case MO_SB :
@@ -2730,7 +2730,7 @@ static void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, TCGMemOp opc) } } -static void tcg_gen_ext_i64 (TCGv_i64 ret,TCGv_i64 val,TCGMemOp opc) +void tcg_gen_ext_i64 (TCGv_i64 ret,TCGv_i64 val,TCGMemOp opc) {switch (opc &MO_SSIZE ) {case MO_SB :
tcg/tcg-op.h +2 -0
@@ -835,6 +835,8 @@ void tcg_gen_qemu_ld_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);void tcg_gen_qemu_st_i32 (TCGv_i32 ,TCGv ,TCGArg ,TCGMemOp );void tcg_gen_qemu_ld_i64 (TCGv_i64 ,TCGv ,TCGArg ,TCGMemOp );void tcg_gen_qemu_st_i64 (TCGv_i64 ,TCGv ,TCGArg ,TCGMemOp ); +void tcg_gen_ext_i32 (TCGv_i32 ret,TCGv_i32 val,TCGMemOp opc); +void tcg_gen_ext_i64 (TCGv_i64 ret,TCGv_i64 val,TCGMemOp opc);static inline void tcg_gen_qemu_ld8u (TCGv ret,TCGv addr,int mem_index) {
Signature · 1 line
2.11.0
Re: [Qemu-arm] [PATCH v1 2/3] tcg/tcg-op: Expose the tcg_gen_ext_i* functions
Quoted 4 lines · Alistair Francis
Expose the
tcg_gen_ext_i32()andtcg_gen_ext_i64()functions.Signed-off-by Alistair Francis <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Quoted 47 lines
---
Although I no longer am using these functions I have left this patch in as Richard thought it was a good idea.
tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)tcg/tcg-op.c +2
-2@@ -2709,7 +2709,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)gen_ldst_i64 (INDEX_op_qemu_st_i64, val, addr, memop, idx); } -static void tcg_gen_ext_i32 (TCGv_i32 ret,TCGv_i32 val,TCGMemOp opc) +void tcg_gen_ext_i32 (TCGv_i32 ret,TCGv_i32 val,TCGMemOp opc) {switch (opc &MO_SSIZE ) {case MO_SB :@@ -2730,7 +2730,7 @@ static void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, TCGMemOp opc) } } -static void tcg_gen_ext_i64 (TCGv_i64 ret,TCGv_i64 val,TCGMemOp opc) +void tcg_gen_ext_i64 (TCGv_i64 ret,TCGv_i64 val,TCGMemOp opc) {switch (opc &MO_SSIZE ) {case MO_SB :tcg/tcg-op.h +2
-0@@ -835,6 +835,8 @@ void tcg_gen_qemu_ld_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);void tcg_gen_qemu_st_i32 (TCGv_i32 ,TCGv ,TCGArg ,TCGMemOp );void tcg_gen_qemu_ld_i64 (TCGv_i64 ,TCGv ,TCGArg ,TCGMemOp );void tcg_gen_qemu_st_i64 (TCGv_i64 ,TCGv ,TCGArg ,TCGMemOp ); +void tcg_gen_ext_i32 (TCGv_i32 ret,TCGv_i32 val,TCGMemOp opc); +void tcg_gen_ext_i64 (TCGv_i64 ret,TCGv_i64 val,TCGMemOp opc);static inline void tcg_gen_qemu_ld8u (TCGv ret,TCGv addr,int mem_index) {Signature · 1 line
2.11.0
PATCH 3/3 target/arm: Correct exclusive store cmpxchg memop mask
In reply to Alistair FrancisWhen we perform the atomic_cmpxchg operation we want to perform the operation on a pair of 32-bit registers. Previously we were just passing the register size in which was set to MO_32. This would result in the high register to be ignored. To fix this issue we hardcode the size to be 64-bits long when operating on 32-bit pairs.
---
This was caught with an internal fuzzy tester. These patches fix the Xilinx 2.10-rc2 tree. I tested with the fuzzy tester (single CPU) and Linux boot (4 CPUs) on the Xilinx tree. I don't have a good test case to run on mainline, but am working with some internal teams to get one. Also linux-user is fully untested.
All tests were with MTTCG enabled.
target/arm/translate-a64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/translate-a64.c +1 -1
@@ -1913,7 +1913,7 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,tcg_gen_concat32_i64 (val, cpu_exclusive_val, cpu_exclusive_high);tcg_gen_atomic_cmpxchg_i64 (tmp, addr, val, tmp,get_mem_index (s), - size |MO_ALIGN | s->be_data); +MO_64 |MO_ALIGN | s->be_data);tcg_gen_setcond_i64 (TCG_COND_NE , tmp, tmp, val);tcg_temp_free_i64 (val); }else if (s->be_data ==MO_LE ) {
Signature · 1 line
2.11.0
Re: [Qemu-arm] [PATCH v1 3/3] target/arm: Correct exclusive store cmpxchg memop mask
Quoted 5 lines · Alistair Francis
When we perform the
atomic_cmpxchgoperation we want to perform the operation on a pair of 32-bit registers. Previously we were just passing the register size in which was set toMO_32. This would result in the high register to be ignored. To fix this issue we hardcode the size to be 64-bits long when operating on 32-bit pairs.
Good catch Alistair!
Quoted 31 lines
Signed-off-by Alistair Francis <[email protected]>---
This was caught with an internal fuzzy tester. These patches fix the Xilinx 2.10-rc2 tree. I tested with the fuzzy tester (single CPU) and Linux boot (4 CPUs) on the Xilinx tree. I don't have a good test case to run on mainline, but am working with some internal teams to get one. Also linux-user is fully untested.
All tests were with MTTCG enabled.
target/arm/translate-a64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/translate-a64.c +1
-1@@ -1913,7 +1913,7 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,tcg_gen_concat32_i64 (val, cpu_exclusive_val, cpu_exclusive_high);tcg_gen_atomic_cmpxchg_i64 (tmp, addr, val, tmp,get_mem_index (s), - size |MO_ALIGN | s->be_data); +MO_64 |MO_ALIGN | s->be_data);tcg_gen_setcond_i64 (TCG_COND_NE , tmp, tmp, val);tcg_temp_free_i64 (val); }else if (s->be_data ==MO_LE ) {Signature · 1 line
2.11.0
Re: [Qemu-arm] [Qemu-devel] [PATCH v1 3/3] target/arm: Correct exclusive store cmpxchg memop mask
In reply to Alistair FrancisQuoted 26 lines · Alistair Francis
When we perform the
atomic_cmpxchgoperation we want to perform the operation on a pair of 32-bit registers. Previously we were just passing the register size in which was set toMO_32. This would result in the high register to be ignored. To fix this issue we hardcode the size to be 64-bits long when operating on 32-bit pairs.Signed-off-by Alistair Francis <[email protected]>---
This was caught with an internal fuzzy tester. These patches fix the Xilinx 2.10-rc2 tree. I tested with the fuzzy tester (single CPU) and Linux boot (4 CPUs) on the Xilinx tree. I don't have a good test case to run on mainline, but am working with some internal teams to get one. Also linux-user is fully untested.
All tests were with MTTCG enabled.
target/arm/translate-a64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/translate-a64.c +0
-0
target/arm/translate-a64.c static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2, · line 1919
Quoted 8 lines
target/arm/translate-a64.c +1
-1@@ -1913,7 +1913,7 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,tcg_gen_concat32_i64 (val, cpu_exclusive_val, cpu_exclusive_high);tcg_gen_atomic_cmpxchg_i64 (tmp, addr, val, tmp,get_mem_index (s), - size |MO_ALIGN | s->be_data); +MO_64 |MO_ALIGN | s->be_data);tcg_gen_setcond_i64 (TCG_COND_NE , tmp, tmp, val);tcg_temp_free_i64 (val); }else if (s->be_data ==MO_LE ) {
Reading the ARM pseudocode again, especially wrt SetExclusiveMonitors, I think there are other bugs here wrt 32-bit LDXP/STXP.
Since SetExclusiveMonitors is invoked only with address + dsize, one should be able to write
ldxp w0, w1, [x5] stxr w3, x2, [x5] or ldxr x0, [x5] stxp w3, w1, w2, [x5]
However, the LDXR and LDXP above do not store the cpu_exclusive_* metadata in the same format. Fixing this is simply a matter of ignoring cpu_exclusive_high for 32-bit pair operations and store it all in cpu_exclusive_val, as the 64-bit single-register operation does.
In addition, 32-bit LDXP must be single-copy atomic, and we're issuing 2 loads, this is trivially fixed with the rest of the required changes, but perhaps worth noting.
I'll post a patch shortly.
r~
Quoted 9 lines · Alistair Francis
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
After working with the internal fuzzy testing team I have a test case where exclusive operations are failing on master but working on top of this patch series.
Thanks,
Alistair
Quoted 17 lines
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop masktarget/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)--
2.11.0
Quoted 11 lines · Alistair Francis
Quoted 9 lines · Alistair Francis
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
+ Portia from fuzzy testing team.
Quoted 25 lines
After working with the internal fuzzy testing team I have a test case where exclusive operations are failing on master but working on top of this patch series.
Thanks,
AlistairQuoted 17 lines
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop masktarget/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)--
2.11.0
Portia Stephens
Tested-byQuoted 18 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alistair Francis
Sent: Friday, August 11, 2017 4:23 PM
To: Alistair Francis <[email protected]>; Portia Stephens <[email protected]>
Cc: [email protected] Developers <[email protected]>; Peter Maydell <[email protected]>; Edgar Iglesias <[email protected]>; Edgar Iglesias <[email protected]>; qemu-arm <[email protected]>
Subject: Re: [PATCH v1 0/3] Fixup exclusive store logicQuoted 5 lines · Alistair Francis
Quoted 3 lines · Alistair Francis
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
+ Portia from fuzzy testing team.
Quoted 5 lines
After working with the internal fuzzy testing team I have a test case where exclusive operations are failing on master but working on top of this patch series.
This patch series fixes the failures previously seen with exclusive stores by our internal tests on AArch64.
Quoted 12 lines
Quoted 12 lines
Thanks,
AlistairQuoted 9 lines
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop mask
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
target/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)--
2.11.0
This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
Quoted 18 lines · Alistair Francis
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop mask
Quoted 4 lines
target/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)
Is this series (or at least patches 1 and 3) worth putting into 2.10 ?
thanks
-- PMM
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Alistair Francis
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop mask
Quoted 7 lines
Quoted 4 lines
target/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)Is this series (or at least patches 1 and 3) worth putting into 2.10 ?
I would vote for including it...
Cheers,
Edgar
Quoted 26 lines · Edgar E. Iglesias
Quoted 25 lines · Peter Maydell
Quoted 22 lines · Alistair Francis
I found some issues with the way exclusive store was working. This patch series seems to fix the test cases that were failing for me.
The first patch is just a simple adjustment.
The third patch fixes the main bug I was seeing.
The second patch is left over from the RFC that seems like it is still a good idea.
Changes from RFC:
- Rewrite the third patch to correctly fix the issue.Alistair Francis (3):
target/arm: Update the memops for exclusive load tcg/tcg-op: Expose the tcg_gen_ext_i* functions target/arm: Correct exclusive store cmpxchg memop masktarget/arm/translate-a64.c | 4 ++-- tcg/tcg-op.c | 4 ++-- tcg/tcg-op.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-)
Quoted 5 lines
Quoted 2 lines
Is this series (or at least patches 1 and 3) worth putting into 2.10 ?
I would vote for including it...
The only reason not to is because this bug has been in QEMU for a while, so it obviously isn't hit very often. In saying that it is a pretty big issue (32-bit pair stores are completely broken) which might become an issue during the 2.10 support window and I don't see many complications from including the series.
I agree with Edgar, probably worth including.
Thanks,
Alistair
Quoted 3 lines
Cheers,
Edgar