public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Senkevich <andrew.n.senkevich@gmail.com>
To: Andreas Schwab <schwab@suse.de>
Cc: libc-alpha <libc-alpha@sourceware.org>, Max Horn <max@quendi.de>
Subject: Re: [PATCH] Fix i386 memmove issue [BZ #22644]
Date: Wed, 14 Mar 2018 14:43:00 -0000	[thread overview]
Message-ID: <CAMXFM3vqw7eiUT1XYVZWyW=eJkgEpjNc74A8mbmdKuR_hywN3w@mail.gmail.com> (raw)
In-Reply-To: <mvm606ts2w6.fsf@suse.de>

2018-02-19 11:13 GMT+01:00 Andreas Schwab <schwab@suse.de>:
> On Feb 19 2018, Andrew Senkevich <andrew.n.senkevich@gmail.com> wrote:
>
>> diff --git a/string/test-memmove.c b/string/test-memmove.c
>> index edc7a4c..8dc152b
>> --- a/string/test-memmove.c
>> +++ b/string/test-memmove.c
>> @@ -245,6 +245,49 @@ do_random_tests (void)
>>      }
>>  }
>>
>> +#if __SIZEOF_POINTER__ == 4
>> +static void
>> +do_test2 (void)
>> +{
>> +  uint32_t i;
>> +  uint32_t num = 0x20000000;
>> +  uint32_t * large_buf = mmap (0, sizeof(uint32_t) * num, PROT_READ |
>> PROT_WRITE,
>> +        MAP_PRIVATE | MAP_ANON, -1, 0);
>> +  if (large_buf == MAP_FAILED)
>> +    error (EXIT_FAILURE, errno, "large mmap failed");
>> +
>> +  if (!((uint32_t)(large_buf) < (0x80000000 - 128) && (0x80000000 +
>> 128) < (uint32_t)(&large_buf[num])))
>> +    {
>> +      error (0, 0,"allocated large memory doesn't cross 0x80000000 boundary");
>> +      ret = 1;
>> +      return;
>
> Please properly fold long lines, and remove the redundant parens.  Also,
> there is no guarantee that the address range is unallocated.

Thanks, updated patch below.  Any comment or it is Ok for trunk?

diff --git a/string/test-memmove.c b/string/test-memmove.c
index edc7a4c..a8c4af4 100644
--- a/string/test-memmove.c
+++ b/string/test-memmove.c
@@ -245,6 +245,57 @@ do_random_tests (void)
     }
 }

+#if __SIZEOF_POINTER__ == 4
+static void
+do_test2 (void)
+{
+  uint32_t i;
+  uint32_t num = 0x20000000;
+  uint32_t * large_buf = mmap (0, sizeof(uint32_t) * num,
+        PROT_READ | PROT_WRITE,
+        MAP_PRIVATE | MAP_ANON, -1, 0);
+  if (large_buf == MAP_FAILED)
+    error (EXIT_FAILURE, errno, "Large mmap failed");
+
+  if ((uint32_t)large_buf > 0x80000000 - 128
+      || (uint32_t)&large_buf[num] < 0x80000000 + 128)
+    {
+      error (0, 0,"Large mmap doesn't cross 0x80000000 boundary");
+      ret = EXIT_UNSUPPORTED;
+      munmap((void *)large_buf, sizeof(uint32_t) * num);
+      return;
+    }
+
+  int bytes_move = 0x80000000 - (uint32_t)large_buf;
+  int arr_size = bytes_move / sizeof(uint32_t);
+
+  FOR_EACH_IMPL (impl, 0)
+    {
+      for (i = 0; i < arr_size; i++)
+        large_buf[i] = i;
+
+      uint32_t * dst = &large_buf[33];
+
+      CALL (impl, (char *)dst, (char *)large_buf, bytes_move);
+
+      for (i = 0; i < arr_size; i++)
+        {
+          if (dst[i] != i)
+     {
+       error (0, 0,
+      "Wrong result in function %s dst \"%p\" src \"%p\" offset \"%d\"",
+      impl->name, dst, large_buf, i);
+       ret = 1;
+       munmap((void *)large_buf, sizeof(uint32_t) * num);
+       return;
+     }
+ }
+    }
+
+  munmap((void *)large_buf, sizeof(uint32_t) * num);
+}
+#endif
+
 int
 test_main (void)
 {
@@ -284,6 +335,11 @@ test_main (void)
     }

   do_random_tests ();
+
+#if __SIZEOF_POINTER__ == 4
+  do_test2 ();
+#endif
+
   return ret;
 }

diff --git a/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S
b/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S
index 9c3bbe7..9aa17de 100644
--- a/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S
+++ b/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S
@@ -72,7 +72,7 @@ ENTRY (MEMCPY)
  cmp %edx, %eax

 # ifdef USE_AS_MEMMOVE
- jg L(check_forward)
+ ja L(check_forward)

 L(mm_len_0_or_more_backward):
 /* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128]
@@ -81,7 +81,7 @@ L(mm_len_0_or_more_backward):
  jbe L(mm_len_0_16_bytes_backward)

  cmpl $32, %ecx
- jg L(mm_len_32_or_more_backward)
+ ja L(mm_len_32_or_more_backward)

 /* Copy [0..32] and return.  */
  movdqu (%eax), %xmm0
@@ -92,7 +92,7 @@ L(mm_len_0_or_more_backward):

 L(mm_len_32_or_more_backward):
  cmpl $64, %ecx
- jg L(mm_len_64_or_more_backward)
+ ja L(mm_len_64_or_more_backward)

 /* Copy [0..64] and return.  */
  movdqu (%eax), %xmm0
@@ -107,7 +107,7 @@ L(mm_len_32_or_more_backward):

 L(mm_len_64_or_more_backward):
  cmpl $128, %ecx
- jg L(mm_len_128_or_more_backward)
+ ja L(mm_len_128_or_more_backward)

 /* Copy [0..128] and return.  */
  movdqu (%eax), %xmm0
@@ -132,7 +132,7 @@ L(mm_len_128_or_more_backward):
  add %ecx, %eax
  cmp %edx, %eax
  movl SRC(%esp), %eax
- jle L(forward)
+ jbe L(forward)
  PUSH (%esi)
  PUSH (%edi)
  PUSH (%ebx)
@@ -269,7 +269,7 @@ L(check_forward):
  add %edx, %ecx
  cmp %eax, %ecx
  movl LEN(%esp), %ecx
- jle L(forward)
+ jbe L(forward)

 /* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
  separately.  */


--
WBR,
Andrew

  reply	other threads:[~2018-03-14 14:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-19 10:13 Andrew Senkevich
2018-02-19 10:31 ` Andreas Schwab
2018-03-14 14:43   ` Andrew Senkevich [this message]
2018-03-14 14:59     ` H.J. Lu
2018-03-19 12:46       ` Andrew Senkevich
2018-03-19 12:55         ` H.J. Lu
2018-03-19 13:11         ` Andreas Schwab
2018-03-19 13:17           ` Florian Weimer
2018-03-19 14:01             ` Andrew Senkevich
2018-03-19 14:25             ` Szabolcs Nagy
2018-03-19 15:33               ` Florian Weimer
2018-03-19 17:52                 ` Andrew Senkevich
2018-03-19 17:57                   ` H.J. Lu
2018-03-19 19:30                     ` Andrew Senkevich
2018-03-19 19:38                       ` H.J. Lu
2018-03-19 20:33                         ` Andrew Senkevich
2018-03-19 20:50                           ` H.J. Lu
2018-03-20  8:58                           ` Andreas Schwab
2018-03-23 17:15                             ` Andrew Senkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMXFM3vqw7eiUT1XYVZWyW=eJkgEpjNc74A8mbmdKuR_hywN3w@mail.gmail.com' \
    --to=andrew.n.senkevich@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=max@quendi.de \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).