From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0GcH-00074n-92 for qemu-devel@nongnu.org; Wed, 03 Jun 2015 17:54:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0GcC-0006qx-RT for qemu-devel@nongnu.org; Wed, 03 Jun 2015 17:54:29 -0400 Received: from mail-pd0-x22b.google.com ([2607:f8b0:400e:c02::22b]:35221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0GcC-0006qY-KB for qemu-devel@nongnu.org; Wed, 03 Jun 2015 17:54:24 -0400 Received: by pdbnf5 with SMTP id nf5so16147066pdb.2 for ; Wed, 03 Jun 2015 14:54:23 -0700 (PDT) Sender: Richard Henderson Message-ID: <556F778B.7020905@twiddle.net> Date: Wed, 03 Jun 2015 14:54:19 -0700 From: Richard Henderson MIME-Version: 1.0 References: <1433365796-1118-1-git-send-email-aurelien@aurel32.net> <1433365796-1118-17-git-send-email-aurelien@aurel32.net> In-Reply-To: <1433365796-1118-17-git-send-email-aurelien@aurel32.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 16/16] target-s390x: fix MVC instruction when areas overlap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aurelien Jarno , qemu-devel@nongnu.org Cc: Alexander Graf On 06/03/2015 02:09 PM, Aurelien Jarno wrote: > 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). > > Cc: Alexander Graf > Cc: Richard Henderson > Signed-off-by: Aurelien Jarno > --- > target-s390x/mem_helper.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > Reviewed-by: Richard Henderson r~