[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 33/34] target-s390x: fix MVC instruction when areas o
From: |
Alexander Graf |
Subject: |
[Qemu-devel] [PULL 33/34] target-s390x: fix MVC instruction when areas overlap |
Date: |
Fri, 5 Jun 2015 01:42:03 +0200 |
From: Aurelien Jarno <address@hidden>
The MVC instruction and the memmove C funtion do not have the same
semantic when memory areas overlap:
MVC: When the operands overlap, the result is obtained as if the
operands were processed one byte at a time and each result byte were
stored immediately after fetching the necessary operand byte.
memmove: Copying takes place as though the bytes in src are first copied
into a temporary array that does not overlap src or dest, and the bytes
are then copied from the temporary array to dest.
The behaviour is therefore the same when the destination is at a lower
address than the source, but not in the other case. This is actually a
trick for propagating a value to an area. While the current code detects
that and call memset in that case, it only does for 1-byte value. This
trick can and is used for propagating two or more bytes to an area.
In the softmmu case, the call to mvc_fast_memmove is correct as the
above tests verify that source and destination are each within a page,
and both in a different page. The part doing the move 8 bytes by 8 bytes
is wrong and we need to check that if the source and destination
overlap, they do with a distance of minimum 8 bytes before copying 8
bytes at a time.
In the user code, we should check check that the destination is at a
lower address than source or than the end of the source is at a lower
address than the destination before calling memmove. In the opposite
case we fallback to the same code as the softmmu one. Note that l
represents (length - 1).
Signed-off-by: Aurelien Jarno <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Alexander Graf <address@hidden>
---
target-s390x/mem_helper.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/target-s390x/mem_helper.c b/target-s390x/mem_helper.c
index 04500ab..b4e5d44 100644
--- a/target-s390x/mem_helper.c
+++ b/target-s390x/mem_helper.c
@@ -213,21 +213,22 @@ void HELPER(mvc)(CPUS390XState *env, uint32_t l, uint64_t
dest, uint64_t src)
if (dest == (src + 1)) {
memset(g2h(dest), cpu_ldub_data(env, src), l + 1);
return;
- } else {
+ /* mvc and memmove do not behave the same when areas overlap! */
+ } else if ((dest < src) || (src + l < dest)) {
memmove(g2h(dest), g2h(src), l + 1);
return;
}
#endif
/* handle the parts that fit into 8-byte loads/stores */
- if (dest != (src + 1)) {
+ if ((dest + 8 <= src) || (src + 8 <= dest)) {
for (i = 0; i < l_64; i++) {
cpu_stq_data(env, dest + x, cpu_ldq_data(env, src + x));
x += 8;
}
}
- /* slow version crossing pages with byte accesses */
+ /* slow version with byte accesses which always work */
for (i = x; i <= l; i++) {
cpu_stb_data(env, dest + i, cpu_ldub_data(env, src + i));
}
--
1.7.12.4
- [Qemu-devel] [PULL 16/34] target-s390x: move a few instructions to the correct facility, (continued)
- [Qemu-devel] [PULL 16/34] target-s390x: move a few instructions to the correct facility, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 20/34] target-s390x: change CHRL and CGHRL format to RIL-b, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 30/34] target-s390x: add a cpu_mmu_idx_to_asc function, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 12/34] target-s390x: fix MMU index computation, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 11/34] target-s390x: fix PSW value on dynamical exception from helpers, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 15/34] target-s390x: detect tininess before rounding for FP operations, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 03/34] target-s390x: optimize (negative-) abs computation, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 01/34] target-s390x: fix CC computation for EX instruction, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 24/34] target-s390x: implement TRANSLATE AND TEST instruction, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 13/34] target-s390x: define default NaN values, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 33/34] target-s390x: fix MVC instruction when areas overlap,
Alexander Graf <=
- [Qemu-devel] [PULL 22/34] target-s390x: move SET DFP ROUNDING MODE to the correct facility, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 10/34] target-s390x: fix LOAD MULTIPLE instruction on page boundary, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 18/34] target-s390x: fix exception for invalid operation code, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 27/34] target-s390x: implement miscellaneous-instruction-extensions facility, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 23/34] target-s390x: implement LOAD FP INTEGER instructions, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 21/34] target-s390x: move STORE CLOCK FAST to the correct facility, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 32/34] target-s390x: use softmmu functions for mvcp/mvcs, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 19/34] target-s390x: fix CLGIT instruction, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 34/34] target-s390x: Only access allocated storage keys, Alexander Graf, 2015/06/04
- [Qemu-devel] [PULL 17/34] target-s390x: implement LAY and LAEY instructions, Alexander Graf, 2015/06/04