public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
@ 2022-02-15 16:27 Noah Goldstein
  2022-02-15 16:29 ` H.J. Lu
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Noah Goldstein @ 2022-02-15 16:27 UTC (permalink / raw)
  To: libc-alpha

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all
pass. Note not tested on a machine that supports RTM (non
available).
---
 sysdeps/x86_64/multiarch/strcmp-avx2.S      | 8 ++------
 sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S | 1 +
 sysdeps/x86_64/multiarch/strncmp-avx2.S     | 1 +
 sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S | 2 +-
 sysdeps/x86_64/multiarch/wcsncmp-avx2.S     | 2 +-
 5 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 07a5a2c889..52ff5ad724 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -193,10 +193,10 @@ L(ret_zero):
 	.p2align 4,, 5
 L(one_or_less):
 	jb	L(ret_zero)
-#  ifdef USE_AS_WCSCMP
 	/* 'nbe' covers the case where length is negative (large
 	   unsigned).  */
-	jnbe	__wcscmp_avx2
+	jnbe	OVERFLOW_STRCMP
+#  ifdef USE_AS_WCSCMP
 	movl	(%rdi), %edx
 	xorl	%eax, %eax
 	cmpl	(%rsi), %edx
@@ -205,10 +205,6 @@ L(one_or_less):
 	negl	%eax
 	orl	$1, %eax
 #  else
-	/* 'nbe' covers the case where length is negative (large
-	   unsigned).  */
-
-	jnbe	__strcmp_avx2
 	movzbl	(%rdi), %eax
 	movzbl	(%rsi), %ecx
 	subl	%ecx, %eax
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
index 37d1224bb9..68bad365ba 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP	__strcmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
index 1678bcc235..f138e9f1fd 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP __strcmp_avx2
 #include "strcmp-avx2.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
index 4e88c70cc6..f467582cbe 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
index 4fa1de4d3f..e9ede522b8 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2
 #include "strcmp-avx2.S"
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:27 [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Noah Goldstein
@ 2022-02-15 16:29 ` H.J. Lu
  2022-02-15 16:51   ` Noah Goldstein
  2022-02-15 16:49 ` [PATCH v2] " Noah Goldstein
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: H.J. Lu @ 2022-02-15 16:29 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell

On Tue, Feb 15, 2022 at 8:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> not checks around vzeroupper and would trigger spurious
> aborts. This commit fixes that.

Include a testcase?

> test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all
> pass. Note not tested on a machine that supports RTM (non
> available).
> ---
>  sysdeps/x86_64/multiarch/strcmp-avx2.S      | 8 ++------
>  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S | 1 +
>  sysdeps/x86_64/multiarch/strncmp-avx2.S     | 1 +
>  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S | 2 +-
>  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     | 2 +-
>  5 files changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> index 07a5a2c889..52ff5ad724 100644
> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> @@ -193,10 +193,10 @@ L(ret_zero):
>         .p2align 4,, 5
>  L(one_or_less):
>         jb      L(ret_zero)
> -#  ifdef USE_AS_WCSCMP
>         /* 'nbe' covers the case where length is negative (large
>            unsigned).  */
> -       jnbe    __wcscmp_avx2
> +       jnbe    OVERFLOW_STRCMP
> +#  ifdef USE_AS_WCSCMP
>         movl    (%rdi), %edx
>         xorl    %eax, %eax
>         cmpl    (%rsi), %edx
> @@ -205,10 +205,6 @@ L(one_or_less):
>         negl    %eax
>         orl     $1, %eax
>  #  else
> -       /* 'nbe' covers the case where length is negative (large
> -          unsigned).  */
> -
> -       jnbe    __strcmp_avx2
>         movzbl  (%rdi), %eax
>         movzbl  (%rsi), %ecx
>         subl    %ecx, %eax
> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> index 37d1224bb9..68bad365ba 100644
> --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> @@ -1,3 +1,4 @@
>  #define STRCMP __strncmp_avx2_rtm
>  #define USE_AS_STRNCMP 1
> +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
>  #include "strcmp-avx2-rtm.S"
> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> index 1678bcc235..f138e9f1fd 100644
> --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> @@ -1,3 +1,4 @@
>  #define STRCMP __strncmp_avx2
>  #define USE_AS_STRNCMP 1
> +#define OVERFLOW_STRCMP __strcmp_avx2
>  #include "strcmp-avx2.S"
> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> index 4e88c70cc6..f467582cbe 100644
> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> @@ -1,5 +1,5 @@
>  #define STRCMP __wcsncmp_avx2_rtm
>  #define USE_AS_STRNCMP 1
>  #define USE_AS_WCSCMP 1
> -
> +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
>  #include "strcmp-avx2-rtm.S"
> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> index 4fa1de4d3f..e9ede522b8 100644
> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> @@ -1,5 +1,5 @@
>  #define STRCMP __wcsncmp_avx2
>  #define USE_AS_STRNCMP 1
>  #define USE_AS_WCSCMP 1
> -
> +#define OVERFLOW_STRCMP        __wcscmp_avx2
>  #include "strcmp-avx2.S"
> --
> 2.25.1
>


-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:27 [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Noah Goldstein
  2022-02-15 16:29 ` H.J. Lu
@ 2022-02-15 16:49 ` Noah Goldstein
  2022-02-16  8:09 ` [PATCH v3] " Noah Goldstein
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: Noah Goldstein @ 2022-02-15 16:49 UTC (permalink / raw)
  To: libc-alpha

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all
pass. Note not tested on a machine that supports RTM (non
available).
---
Did not test the test case. I believe this will cover the bug
and is correct but do not have the hardware to check.

HJ, can you test this?        
 sysdeps/x86/tst-strncmp-rtm.c               | 11 +++++++++++
 sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
 sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
 sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
 sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
 sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
 6 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 09ed6fa0d6..20ebba319a 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -45,8 +45,19 @@ function (void)
     return 1;
 }
 
+__attribute__ ((noinline, noclone))
+static int
+function_overflow (void)
+{
+  if (strncmp (string1, string2, SIZE_MAX) == 0)
+    return 0;
+  else
+    return 1;
+}
+
 static int
 do_test (void)
 {
   return do_test_1 ("strncmp", LOOP, prepare, function);
+  return do_test_1 ("strncmp", LOOP, prepare, function_overflow);
 }
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 07a5a2c889..52ff5ad724 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -193,10 +193,10 @@ L(ret_zero):
 	.p2align 4,, 5
 L(one_or_less):
 	jb	L(ret_zero)
-#  ifdef USE_AS_WCSCMP
 	/* 'nbe' covers the case where length is negative (large
 	   unsigned).  */
-	jnbe	__wcscmp_avx2
+	jnbe	OVERFLOW_STRCMP
+#  ifdef USE_AS_WCSCMP
 	movl	(%rdi), %edx
 	xorl	%eax, %eax
 	cmpl	(%rsi), %edx
@@ -205,10 +205,6 @@ L(one_or_less):
 	negl	%eax
 	orl	$1, %eax
 #  else
-	/* 'nbe' covers the case where length is negative (large
-	   unsigned).  */
-
-	jnbe	__strcmp_avx2
 	movzbl	(%rdi), %eax
 	movzbl	(%rsi), %ecx
 	subl	%ecx, %eax
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
index 37d1224bb9..68bad365ba 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP	__strcmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
index 1678bcc235..f138e9f1fd 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP __strcmp_avx2
 #include "strcmp-avx2.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
index 4e88c70cc6..f467582cbe 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
index 4fa1de4d3f..e9ede522b8 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2
 #include "strcmp-avx2.S"
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:29 ` H.J. Lu
@ 2022-02-15 16:51   ` Noah Goldstein
  2022-02-15 16:59     ` H.J. Lu
  0 siblings, 1 reply; 18+ messages in thread
From: Noah Goldstein @ 2022-02-15 16:51 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell

On Tue, Feb 15, 2022 at 10:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Feb 15, 2022 at 8:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > not checks around vzeroupper and would trigger spurious
> > aborts. This commit fixes that.
>
> Include a testcase?
Added test case in V2. Don't have the hardware to check it though,
can you?
>
> > test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all
> > pass. Note not tested on a machine that supports RTM (non
> > available).
> > ---
> >  sysdeps/x86_64/multiarch/strcmp-avx2.S      | 8 ++------
> >  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S | 1 +
> >  sysdeps/x86_64/multiarch/strncmp-avx2.S     | 1 +
> >  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S | 2 +-
> >  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     | 2 +-
> >  5 files changed, 6 insertions(+), 8 deletions(-)
> >
> > diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > index 07a5a2c889..52ff5ad724 100644
> > --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > @@ -193,10 +193,10 @@ L(ret_zero):
> >         .p2align 4,, 5
> >  L(one_or_less):
> >         jb      L(ret_zero)
> > -#  ifdef USE_AS_WCSCMP
> >         /* 'nbe' covers the case where length is negative (large
> >            unsigned).  */
> > -       jnbe    __wcscmp_avx2
> > +       jnbe    OVERFLOW_STRCMP
> > +#  ifdef USE_AS_WCSCMP
> >         movl    (%rdi), %edx
> >         xorl    %eax, %eax
> >         cmpl    (%rsi), %edx
> > @@ -205,10 +205,6 @@ L(one_or_less):
> >         negl    %eax
> >         orl     $1, %eax
> >  #  else
> > -       /* 'nbe' covers the case where length is negative (large
> > -          unsigned).  */
> > -
> > -       jnbe    __strcmp_avx2
> >         movzbl  (%rdi), %eax
> >         movzbl  (%rsi), %ecx
> >         subl    %ecx, %eax
> > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > index 37d1224bb9..68bad365ba 100644
> > --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > @@ -1,3 +1,4 @@
> >  #define STRCMP __strncmp_avx2_rtm
> >  #define USE_AS_STRNCMP 1
> > +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> >  #include "strcmp-avx2-rtm.S"
> > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > index 1678bcc235..f138e9f1fd 100644
> > --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > @@ -1,3 +1,4 @@
> >  #define STRCMP __strncmp_avx2
> >  #define USE_AS_STRNCMP 1
> > +#define OVERFLOW_STRCMP __strcmp_avx2
> >  #include "strcmp-avx2.S"
> > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > index 4e88c70cc6..f467582cbe 100644
> > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > @@ -1,5 +1,5 @@
> >  #define STRCMP __wcsncmp_avx2_rtm
> >  #define USE_AS_STRNCMP 1
> >  #define USE_AS_WCSCMP 1
> > -
> > +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> >  #include "strcmp-avx2-rtm.S"
> > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > index 4fa1de4d3f..e9ede522b8 100644
> > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > @@ -1,5 +1,5 @@
> >  #define STRCMP __wcsncmp_avx2
> >  #define USE_AS_STRNCMP 1
> >  #define USE_AS_WCSCMP 1
> > -
> > +#define OVERFLOW_STRCMP        __wcscmp_avx2
> >  #include "strcmp-avx2.S"
> > --
> > 2.25.1
> >
>
>
> --
> H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:51   ` Noah Goldstein
@ 2022-02-15 16:59     ` H.J. Lu
  2022-02-15 17:06       ` Noah Goldstein
  0 siblings, 1 reply; 18+ messages in thread
From: H.J. Lu @ 2022-02-15 16:59 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell

On Tue, Feb 15, 2022 at 8:51 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Tue, Feb 15, 2022 at 10:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Tue, Feb 15, 2022 at 8:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >
> > > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > > not checks around vzeroupper and would trigger spurious
> > > aborts. This commit fixes that.
> >
> > Include a testcase?
> Added test case in V2. Don't have the hardware to check it though,
> can you?

Yes, I can.  Please V2 on a branch in gitlab.

Thanks.

> >
> > > test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all
> > > pass. Note not tested on a machine that supports RTM (non
> > > available).
> > > ---
> > >  sysdeps/x86_64/multiarch/strcmp-avx2.S      | 8 ++------
> > >  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S | 1 +
> > >  sysdeps/x86_64/multiarch/strncmp-avx2.S     | 1 +
> > >  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S | 2 +-
> > >  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     | 2 +-
> > >  5 files changed, 6 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > index 07a5a2c889..52ff5ad724 100644
> > > --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > @@ -193,10 +193,10 @@ L(ret_zero):
> > >         .p2align 4,, 5
> > >  L(one_or_less):
> > >         jb      L(ret_zero)
> > > -#  ifdef USE_AS_WCSCMP
> > >         /* 'nbe' covers the case where length is negative (large
> > >            unsigned).  */
> > > -       jnbe    __wcscmp_avx2
> > > +       jnbe    OVERFLOW_STRCMP
> > > +#  ifdef USE_AS_WCSCMP
> > >         movl    (%rdi), %edx
> > >         xorl    %eax, %eax
> > >         cmpl    (%rsi), %edx
> > > @@ -205,10 +205,6 @@ L(one_or_less):
> > >         negl    %eax
> > >         orl     $1, %eax
> > >  #  else
> > > -       /* 'nbe' covers the case where length is negative (large
> > > -          unsigned).  */
> > > -
> > > -       jnbe    __strcmp_avx2
> > >         movzbl  (%rdi), %eax
> > >         movzbl  (%rsi), %ecx
> > >         subl    %ecx, %eax
> > > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > index 37d1224bb9..68bad365ba 100644
> > > --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > @@ -1,3 +1,4 @@
> > >  #define STRCMP __strncmp_avx2_rtm
> > >  #define USE_AS_STRNCMP 1
> > > +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> > >  #include "strcmp-avx2-rtm.S"
> > > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > index 1678bcc235..f138e9f1fd 100644
> > > --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > @@ -1,3 +1,4 @@
> > >  #define STRCMP __strncmp_avx2
> > >  #define USE_AS_STRNCMP 1
> > > +#define OVERFLOW_STRCMP __strcmp_avx2
> > >  #include "strcmp-avx2.S"
> > > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > index 4e88c70cc6..f467582cbe 100644
> > > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > @@ -1,5 +1,5 @@
> > >  #define STRCMP __wcsncmp_avx2_rtm
> > >  #define USE_AS_STRNCMP 1
> > >  #define USE_AS_WCSCMP 1
> > > -
> > > +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> > >  #include "strcmp-avx2-rtm.S"
> > > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > index 4fa1de4d3f..e9ede522b8 100644
> > > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > @@ -1,5 +1,5 @@
> > >  #define STRCMP __wcsncmp_avx2
> > >  #define USE_AS_STRNCMP 1
> > >  #define USE_AS_WCSCMP 1
> > > -
> > > +#define OVERFLOW_STRCMP        __wcscmp_avx2
> > >  #include "strcmp-avx2.S"
> > > --
> > > 2.25.1
> > >
> >
> >
> > --
> > H.J.



-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:59     ` H.J. Lu
@ 2022-02-15 17:06       ` Noah Goldstein
  2022-02-15 18:49         ` H.J. Lu
  0 siblings, 1 reply; 18+ messages in thread
From: Noah Goldstein @ 2022-02-15 17:06 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell

On Tue, Feb 15, 2022 at 11:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Feb 15, 2022 at 8:51 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > On Tue, Feb 15, 2022 at 10:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Tue, Feb 15, 2022 at 8:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > > >
> > > > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > > > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > > > not checks around vzeroupper and would trigger spurious
> > > > aborts. This commit fixes that.
> > >
> > > Include a testcase?
> > Added test case in V2. Don't have the hardware to check it though,
> > can you?
>
> Yes, I can.  Please V2 on a branch in gitlab.

https://gitlab.com/x86-glibc/glibc/-/commits/users/goldsteinn/strncmp-rtm-test
>
> Thanks.
>
> > >
> > > > test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all
> > > > pass. Note not tested on a machine that supports RTM (non
> > > > available).
> > > > ---
> > > >  sysdeps/x86_64/multiarch/strcmp-avx2.S      | 8 ++------
> > > >  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S | 1 +
> > > >  sysdeps/x86_64/multiarch/strncmp-avx2.S     | 1 +
> > > >  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S | 2 +-
> > > >  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     | 2 +-
> > > >  5 files changed, 6 insertions(+), 8 deletions(-)
> > > >
> > > > diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > > index 07a5a2c889..52ff5ad724 100644
> > > > --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > > +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > > @@ -193,10 +193,10 @@ L(ret_zero):
> > > >         .p2align 4,, 5
> > > >  L(one_or_less):
> > > >         jb      L(ret_zero)
> > > > -#  ifdef USE_AS_WCSCMP
> > > >         /* 'nbe' covers the case where length is negative (large
> > > >            unsigned).  */
> > > > -       jnbe    __wcscmp_avx2
> > > > +       jnbe    OVERFLOW_STRCMP
> > > > +#  ifdef USE_AS_WCSCMP
> > > >         movl    (%rdi), %edx
> > > >         xorl    %eax, %eax
> > > >         cmpl    (%rsi), %edx
> > > > @@ -205,10 +205,6 @@ L(one_or_less):
> > > >         negl    %eax
> > > >         orl     $1, %eax
> > > >  #  else
> > > > -       /* 'nbe' covers the case where length is negative (large
> > > > -          unsigned).  */
> > > > -
> > > > -       jnbe    __strcmp_avx2
> > > >         movzbl  (%rdi), %eax
> > > >         movzbl  (%rsi), %ecx
> > > >         subl    %ecx, %eax
> > > > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > > index 37d1224bb9..68bad365ba 100644
> > > > --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > > @@ -1,3 +1,4 @@
> > > >  #define STRCMP __strncmp_avx2_rtm
> > > >  #define USE_AS_STRNCMP 1
> > > > +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> > > >  #include "strcmp-avx2-rtm.S"
> > > > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > > index 1678bcc235..f138e9f1fd 100644
> > > > --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > > @@ -1,3 +1,4 @@
> > > >  #define STRCMP __strncmp_avx2
> > > >  #define USE_AS_STRNCMP 1
> > > > +#define OVERFLOW_STRCMP __strcmp_avx2
> > > >  #include "strcmp-avx2.S"
> > > > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > > index 4e88c70cc6..f467582cbe 100644
> > > > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > > @@ -1,5 +1,5 @@
> > > >  #define STRCMP __wcsncmp_avx2_rtm
> > > >  #define USE_AS_STRNCMP 1
> > > >  #define USE_AS_WCSCMP 1
> > > > -
> > > > +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> > > >  #include "strcmp-avx2-rtm.S"
> > > > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > > index 4fa1de4d3f..e9ede522b8 100644
> > > > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > > @@ -1,5 +1,5 @@
> > > >  #define STRCMP __wcsncmp_avx2
> > > >  #define USE_AS_STRNCMP 1
> > > >  #define USE_AS_WCSCMP 1
> > > > -
> > > > +#define OVERFLOW_STRCMP        __wcscmp_avx2
> > > >  #include "strcmp-avx2.S"
> > > > --
> > > > 2.25.1
> > > >
> > >
> > >
> > > --
> > > H.J.
>
>
>
> --
> H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 17:06       ` Noah Goldstein
@ 2022-02-15 18:49         ` H.J. Lu
  2022-02-16  8:10           ` Noah Goldstein
  0 siblings, 1 reply; 18+ messages in thread
From: H.J. Lu @ 2022-02-15 18:49 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell

On Tue, Feb 15, 2022 at 9:06 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Tue, Feb 15, 2022 at 11:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Tue, Feb 15, 2022 at 8:51 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >
> > > On Tue, Feb 15, 2022 at 10:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > >
> > > > On Tue, Feb 15, 2022 at 8:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > > > >
> > > > > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > > > > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > > > > not checks around vzeroupper and would trigger spurious
> > > > > aborts. This commit fixes that.
> > > >
> > > > Include a testcase?
> > > Added test case in V2. Don't have the hardware to check it though,
> > > can you?
> >
> > Yes, I can.  Please V2 on a branch in gitlab.
>
> https://gitlab.com/x86-glibc/glibc/-/commits/users/goldsteinn/strncmp-rtm-test

I updated your branch with some fixes in the testcase and the commit log.
I tested it on an AVX2 machine with RTM.  The testcase fails without your
fix.

Please submit the v2 patch.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:27 [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Noah Goldstein
  2022-02-15 16:29 ` H.J. Lu
  2022-02-15 16:49 ` [PATCH v2] " Noah Goldstein
@ 2022-02-16  8:09 ` Noah Goldstein
  2022-02-16 13:17   ` H.J. Lu
  2022-02-17 19:12 ` [PATCH v4] " Noah Goldstein
  2022-02-17 19:15 ` [PATCH v5] " Noah Goldstein
  4 siblings, 1 reply; 18+ messages in thread
From: Noah Goldstein @ 2022-02-16  8:09 UTC (permalink / raw)
  To: libc-alpha

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
AVX2 machines with and without RTM.

Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
---
 sysdeps/x86/Makefile                        |  2 +-
 sysdeps/x86/tst-strncmp-rtm.c               | 14 +++++++++++++-
 sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
 sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
 sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
 sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
 sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
 7 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 6cf708335c..d110f7b7f2 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
 CFLAGS-tst-strchr-rtm.c += -mrtm
 CFLAGS-tst-strcpy-rtm.c += -mrtm
 CFLAGS-tst-strlen-rtm.c += -mrtm
-CFLAGS-tst-strncmp-rtm.c += -mrtm
+CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
 CFLAGS-tst-strrchr-rtm.c += -mrtm
 endif
 
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 09ed6fa0d6..ebc94a3a6d 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdint.h>
 #include <tst-string-rtm.h>
 
 #define LOOP 3000
@@ -45,8 +46,19 @@ function (void)
     return 1;
 }
 
+__attribute__ ((noinline, noclone))
+static int
+function_overflow (void)
+{
+  if (strncmp (string1, string2, SIZE_MAX) == 0)
+    return 0;
+  else
+    return 1;
+}
+
 static int
 do_test (void)
 {
-  return do_test_1 ("strncmp", LOOP, prepare, function);
+  return (do_test_1 ("strncmp", LOOP, prepare, function)
+	  || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
 }
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 99e5349be8..6da0e1a248 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -193,10 +193,10 @@ L(ret_zero):
 	.p2align 4,, 5
 L(one_or_less):
 	jb	L(ret_zero)
-#  ifdef USE_AS_WCSCMP
 	/* 'nbe' covers the case where length is negative (large
 	   unsigned).  */
-	jnbe	__wcscmp_avx2
+	jnbe	OVERFLOW_STRCMP
+#  ifdef USE_AS_WCSCMP
 	movl	(%rdi), %edx
 	xorl	%eax, %eax
 	cmpl	(%rsi), %edx
@@ -205,10 +205,6 @@ L(one_or_less):
 	negl	%eax
 	orl	$1, %eax
 #  else
-	/* 'nbe' covers the case where length is negative (large
-	   unsigned).  */
-
-	jnbe	__strcmp_avx2
 	movzbl	(%rdi), %eax
 	movzbl	(%rsi), %ecx
 	subl	%ecx, %eax
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
index 37d1224bb9..68bad365ba 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP	__strcmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
index 1678bcc235..f138e9f1fd 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP __strcmp_avx2
 #include "strcmp-avx2.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
index 4e88c70cc6..f467582cbe 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
index 4fa1de4d3f..e9ede522b8 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2
 #include "strcmp-avx2.S"
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 18:49         ` H.J. Lu
@ 2022-02-16  8:10           ` Noah Goldstein
  0 siblings, 0 replies; 18+ messages in thread
From: Noah Goldstein @ 2022-02-16  8:10 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell

On Tue, Feb 15, 2022 at 12:50 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Feb 15, 2022 at 9:06 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > On Tue, Feb 15, 2022 at 11:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Tue, Feb 15, 2022 at 8:51 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > > >
> > > > On Tue, Feb 15, 2022 at 10:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > >
> > > > > On Tue, Feb 15, 2022 at 8:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > > > > >
> > > > > > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > > > > > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > > > > > not checks around vzeroupper and would trigger spurious
> > > > > > aborts. This commit fixes that.
> > > > >
> > > > > Include a testcase?
> > > > Added test case in V2. Don't have the hardware to check it though,
> > > > can you?
> > >
> > > Yes, I can.  Please V2 on a branch in gitlab.
> >
> > https://gitlab.com/x86-glibc/glibc/-/commits/users/goldsteinn/strncmp-rtm-test
>
> I updated your branch with some fixes in the testcase and the commit log.
> I tested it on an AVX2 machine with RTM.  The testcase fails without your
> fix.
>
> Please submit the v2 patch.

It's up.

>
> Thanks.
>
> --
> H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-16  8:09 ` [PATCH v3] " Noah Goldstein
@ 2022-02-16 13:17   ` H.J. Lu
  2022-02-16 14:08     ` Carlos O'Donell
  0 siblings, 1 reply; 18+ messages in thread
From: H.J. Lu @ 2022-02-16 13:17 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell

On Wed, Feb 16, 2022 at 12:09 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> not checks around vzeroupper and would trigger spurious
> aborts. This commit fixes that.
>
> test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
> AVX2 machines with and without RTM.
>
> Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  sysdeps/x86/Makefile                        |  2 +-
>  sysdeps/x86/tst-strncmp-rtm.c               | 14 +++++++++++++-
>  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
>  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
>  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
>  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
>  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
>  7 files changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index 6cf708335c..d110f7b7f2 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
>  CFLAGS-tst-strchr-rtm.c += -mrtm
>  CFLAGS-tst-strcpy-rtm.c += -mrtm
>  CFLAGS-tst-strlen-rtm.c += -mrtm
> -CFLAGS-tst-strncmp-rtm.c += -mrtm
> +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
>  CFLAGS-tst-strrchr-rtm.c += -mrtm
>  endif
>
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index 09ed6fa0d6..ebc94a3a6d 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -16,6 +16,7 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>
> +#include <stdint.h>
>  #include <tst-string-rtm.h>
>
>  #define LOOP 3000
> @@ -45,8 +46,19 @@ function (void)
>      return 1;
>  }
>
> +__attribute__ ((noinline, noclone))
> +static int
> +function_overflow (void)
> +{
> +  if (strncmp (string1, string2, SIZE_MAX) == 0)
> +    return 0;
> +  else
> +    return 1;
> +}
> +
>  static int
>  do_test (void)
>  {
> -  return do_test_1 ("strncmp", LOOP, prepare, function);
> +  return (do_test_1 ("strncmp", LOOP, prepare, function)
> +         || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
>  }
> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> index 99e5349be8..6da0e1a248 100644
> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> @@ -193,10 +193,10 @@ L(ret_zero):
>         .p2align 4,, 5
>  L(one_or_less):
>         jb      L(ret_zero)
> -#  ifdef USE_AS_WCSCMP
>         /* 'nbe' covers the case where length is negative (large
>            unsigned).  */
> -       jnbe    __wcscmp_avx2
> +       jnbe    OVERFLOW_STRCMP
> +#  ifdef USE_AS_WCSCMP
>         movl    (%rdi), %edx
>         xorl    %eax, %eax
>         cmpl    (%rsi), %edx
> @@ -205,10 +205,6 @@ L(one_or_less):
>         negl    %eax
>         orl     $1, %eax
>  #  else
> -       /* 'nbe' covers the case where length is negative (large
> -          unsigned).  */
> -
> -       jnbe    __strcmp_avx2
>         movzbl  (%rdi), %eax
>         movzbl  (%rsi), %ecx
>         subl    %ecx, %eax
> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> index 37d1224bb9..68bad365ba 100644
> --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> @@ -1,3 +1,4 @@
>  #define STRCMP __strncmp_avx2_rtm
>  #define USE_AS_STRNCMP 1
> +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
>  #include "strcmp-avx2-rtm.S"
> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> index 1678bcc235..f138e9f1fd 100644
> --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> @@ -1,3 +1,4 @@
>  #define STRCMP __strncmp_avx2
>  #define USE_AS_STRNCMP 1
> +#define OVERFLOW_STRCMP __strcmp_avx2
>  #include "strcmp-avx2.S"
> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> index 4e88c70cc6..f467582cbe 100644
> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> @@ -1,5 +1,5 @@
>  #define STRCMP __wcsncmp_avx2_rtm
>  #define USE_AS_STRNCMP 1
>  #define USE_AS_WCSCMP 1
> -
> +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
>  #include "strcmp-avx2-rtm.S"
> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> index 4fa1de4d3f..e9ede522b8 100644
> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> @@ -1,5 +1,5 @@
>  #define STRCMP __wcsncmp_avx2
>  #define USE_AS_STRNCMP 1
>  #define USE_AS_WCSCMP 1
> -
> +#define OVERFLOW_STRCMP        __wcscmp_avx2
>  #include "strcmp-avx2.S"
> --
> 2.25.1
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-16 13:17   ` H.J. Lu
@ 2022-02-16 14:08     ` Carlos O'Donell
  2022-02-16 14:26       ` H.J. Lu
  0 siblings, 1 reply; 18+ messages in thread
From: Carlos O'Donell @ 2022-02-16 14:08 UTC (permalink / raw)
  To: H.J. Lu, Noah Goldstein; +Cc: GNU C Library

On 2/16/22 08:17, H.J. Lu via Libc-alpha wrote:
> On Wed, Feb 16, 2022 at 12:09 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>>
>> In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
>> call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
>> not checks around vzeroupper and would trigger spurious
>> aborts. This commit fixes that.
>>
>> test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
>> AVX2 machines with and without RTM.
>>
>> Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
>> ---
>>  sysdeps/x86/Makefile                        |  2 +-
>>  sysdeps/x86/tst-strncmp-rtm.c               | 14 +++++++++++++-
>>  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
>>  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
>>  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
>>  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
>>  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
>>  7 files changed, 20 insertions(+), 10 deletions(-)
>>
>> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
>> index 6cf708335c..d110f7b7f2 100644
>> --- a/sysdeps/x86/Makefile
>> +++ b/sysdeps/x86/Makefile
>> @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
>>  CFLAGS-tst-strchr-rtm.c += -mrtm
>>  CFLAGS-tst-strcpy-rtm.c += -mrtm
>>  CFLAGS-tst-strlen-rtm.c += -mrtm
>> -CFLAGS-tst-strncmp-rtm.c += -mrtm
>> +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
>>  CFLAGS-tst-strrchr-rtm.c += -mrtm
>>  endif
>>
>> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
>> index 09ed6fa0d6..ebc94a3a6d 100644
>> --- a/sysdeps/x86/tst-strncmp-rtm.c
>> +++ b/sysdeps/x86/tst-strncmp-rtm.c
>> @@ -16,6 +16,7 @@
>>     License along with the GNU C Library; if not, see
>>     <https://www.gnu.org/licenses/>.  */
>>
>> +#include <stdint.h>
>>  #include <tst-string-rtm.h>
>>
>>  #define LOOP 3000
>> @@ -45,8 +46,19 @@ function (void)
>>      return 1;
>>  }
>>
>> +__attribute__ ((noinline, noclone))
>> +static int
>> +function_overflow (void)
>> +{
>> +  if (strncmp (string1, string2, SIZE_MAX) == 0)
>> +    return 0;
>> +  else
>> +    return 1;
>> +}
>> +
>>  static int
>>  do_test (void)
>>  {
>> -  return do_test_1 ("strncmp", LOOP, prepare, function);
>> +  return (do_test_1 ("strncmp", LOOP, prepare, function)
>> +         || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
>>  }
>> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
>> index 99e5349be8..6da0e1a248 100644
>> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
>> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
>> @@ -193,10 +193,10 @@ L(ret_zero):
>>         .p2align 4,, 5
>>  L(one_or_less):
>>         jb      L(ret_zero)
>> -#  ifdef USE_AS_WCSCMP
>>         /* 'nbe' covers the case where length is negative (large
>>            unsigned).  */
>> -       jnbe    __wcscmp_avx2
>> +       jnbe    OVERFLOW_STRCMP
>> +#  ifdef USE_AS_WCSCMP
>>         movl    (%rdi), %edx
>>         xorl    %eax, %eax
>>         cmpl    (%rsi), %edx
>> @@ -205,10 +205,6 @@ L(one_or_less):
>>         negl    %eax
>>         orl     $1, %eax
>>  #  else
>> -       /* 'nbe' covers the case where length is negative (large
>> -          unsigned).  */
>> -
>> -       jnbe    __strcmp_avx2
>>         movzbl  (%rdi), %eax
>>         movzbl  (%rsi), %ecx
>>         subl    %ecx, %eax
>> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
>> index 37d1224bb9..68bad365ba 100644
>> --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
>> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
>> @@ -1,3 +1,4 @@
>>  #define STRCMP __strncmp_avx2_rtm
>>  #define USE_AS_STRNCMP 1
>> +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
>>  #include "strcmp-avx2-rtm.S"
>> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
>> index 1678bcc235..f138e9f1fd 100644
>> --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
>> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
>> @@ -1,3 +1,4 @@
>>  #define STRCMP __strncmp_avx2
>>  #define USE_AS_STRNCMP 1
>> +#define OVERFLOW_STRCMP __strcmp_avx2
>>  #include "strcmp-avx2.S"
>> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
>> index 4e88c70cc6..f467582cbe 100644
>> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
>> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
>> @@ -1,5 +1,5 @@
>>  #define STRCMP __wcsncmp_avx2_rtm
>>  #define USE_AS_STRNCMP 1
>>  #define USE_AS_WCSCMP 1
>> -
>> +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
>>  #include "strcmp-avx2-rtm.S"
>> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
>> index 4fa1de4d3f..e9ede522b8 100644
>> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
>> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
>> @@ -1,5 +1,5 @@
>>  #define STRCMP __wcsncmp_avx2
>>  #define USE_AS_STRNCMP 1
>>  #define USE_AS_WCSCMP 1
>> -
>> +#define OVERFLOW_STRCMP        __wcscmp_avx2
>>  #include "strcmp-avx2.S"
>> --
>> 2.25.1
>>
> 
> LGTM.
> 
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> 
> Thanks.
> 

This fails CI for i686.
https://patchwork.sourceware.org/project/glibc/patch/20220216080935.3284536-1-goldstein.w.n@gmail.com/

-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-16 14:08     ` Carlos O'Donell
@ 2022-02-16 14:26       ` H.J. Lu
  2022-02-17 19:15         ` Noah Goldstein
  0 siblings, 1 reply; 18+ messages in thread
From: H.J. Lu @ 2022-02-16 14:26 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: Noah Goldstein, GNU C Library

On Wed, Feb 16, 2022 at 6:08 AM Carlos O'Donell <carlos@redhat.com> wrote:
>
> On 2/16/22 08:17, H.J. Lu via Libc-alpha wrote:
> > On Wed, Feb 16, 2022 at 12:09 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >>
> >> In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> >> call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> >> not checks around vzeroupper and would trigger spurious
> >> aborts. This commit fixes that.
> >>
> >> test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
> >> AVX2 machines with and without RTM.
> >>
> >> Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
> >> ---
> >>  sysdeps/x86/Makefile                        |  2 +-
> >>  sysdeps/x86/tst-strncmp-rtm.c               | 14 +++++++++++++-
> >>  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
> >>  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
> >>  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
> >>  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
> >>  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
> >>  7 files changed, 20 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> >> index 6cf708335c..d110f7b7f2 100644
> >> --- a/sysdeps/x86/Makefile
> >> +++ b/sysdeps/x86/Makefile
> >> @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
> >>  CFLAGS-tst-strchr-rtm.c += -mrtm
> >>  CFLAGS-tst-strcpy-rtm.c += -mrtm
> >>  CFLAGS-tst-strlen-rtm.c += -mrtm
> >> -CFLAGS-tst-strncmp-rtm.c += -mrtm
> >> +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> >>  CFLAGS-tst-strrchr-rtm.c += -mrtm
> >>  endif
> >>
> >> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> >> index 09ed6fa0d6..ebc94a3a6d 100644
> >> --- a/sysdeps/x86/tst-strncmp-rtm.c
> >> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> >> @@ -16,6 +16,7 @@
> >>     License along with the GNU C Library; if not, see
> >>     <https://www.gnu.org/licenses/>.  */
> >>
> >> +#include <stdint.h>
> >>  #include <tst-string-rtm.h>
> >>
> >>  #define LOOP 3000
> >> @@ -45,8 +46,19 @@ function (void)
> >>      return 1;
> >>  }
> >>
> >> +__attribute__ ((noinline, noclone))
> >> +static int
> >> +function_overflow (void)
> >> +{
> >> +  if (strncmp (string1, string2, SIZE_MAX) == 0)
> >> +    return 0;
> >> +  else
> >> +    return 1;
> >> +}
> >> +
> >>  static int
> >>  do_test (void)
> >>  {
> >> -  return do_test_1 ("strncmp", LOOP, prepare, function);
> >> +  return (do_test_1 ("strncmp", LOOP, prepare, function)
> >> +         || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
> >>  }
> >> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> >> index 99e5349be8..6da0e1a248 100644
> >> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> >> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> >> @@ -193,10 +193,10 @@ L(ret_zero):
> >>         .p2align 4,, 5
> >>  L(one_or_less):
> >>         jb      L(ret_zero)
> >> -#  ifdef USE_AS_WCSCMP
> >>         /* 'nbe' covers the case where length is negative (large
> >>            unsigned).  */
> >> -       jnbe    __wcscmp_avx2
> >> +       jnbe    OVERFLOW_STRCMP
> >> +#  ifdef USE_AS_WCSCMP
> >>         movl    (%rdi), %edx
> >>         xorl    %eax, %eax
> >>         cmpl    (%rsi), %edx
> >> @@ -205,10 +205,6 @@ L(one_or_less):
> >>         negl    %eax
> >>         orl     $1, %eax
> >>  #  else
> >> -       /* 'nbe' covers the case where length is negative (large
> >> -          unsigned).  */
> >> -
> >> -       jnbe    __strcmp_avx2
> >>         movzbl  (%rdi), %eax
> >>         movzbl  (%rsi), %ecx
> >>         subl    %ecx, %eax
> >> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> >> index 37d1224bb9..68bad365ba 100644
> >> --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> >> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> >> @@ -1,3 +1,4 @@
> >>  #define STRCMP __strncmp_avx2_rtm
> >>  #define USE_AS_STRNCMP 1
> >> +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> >>  #include "strcmp-avx2-rtm.S"
> >> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> >> index 1678bcc235..f138e9f1fd 100644
> >> --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> >> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> >> @@ -1,3 +1,4 @@
> >>  #define STRCMP __strncmp_avx2
> >>  #define USE_AS_STRNCMP 1
> >> +#define OVERFLOW_STRCMP __strcmp_avx2
> >>  #include "strcmp-avx2.S"
> >> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> >> index 4e88c70cc6..f467582cbe 100644
> >> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> >> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> >> @@ -1,5 +1,5 @@
> >>  #define STRCMP __wcsncmp_avx2_rtm
> >>  #define USE_AS_STRNCMP 1
> >>  #define USE_AS_WCSCMP 1
> >> -
> >> +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> >>  #include "strcmp-avx2-rtm.S"
> >> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> >> index 4fa1de4d3f..e9ede522b8 100644
> >> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> >> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> >> @@ -1,5 +1,5 @@
> >>  #define STRCMP __wcsncmp_avx2
> >>  #define USE_AS_STRNCMP 1
> >>  #define USE_AS_WCSCMP 1
> >> -
> >> +#define OVERFLOW_STRCMP        __wcscmp_avx2
> >>  #include "strcmp-avx2.S"
> >> --
> >> 2.25.1
> >>
> >
> > LGTM.
> >
> > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> >
> > Thanks.
> >
>
> This fails CI for i686.
> https://patchwork.sourceware.org/project/glibc/patch/20220216080935.3284536-1-goldstein.w.n@gmail.com/
>
> --
> Cheers,
> Carlos.
>

Hi Noah,

We need this change on top of your patch:

diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index ebc94a3a6d..9e20abaacc 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -59,6 +59,9 @@ function_overflow (void)
 static int
 do_test (void)
 {
-  return (do_test_1 ("strncmp", LOOP, prepare, function)
-    || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
+  int status = do_test_1 ("strncmp", LOOP, prepare, function);
+  if (status != EXIT_SUCCESS)
+    return status;
+  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+  return status;
 }

-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v4] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:27 [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Noah Goldstein
                   ` (2 preceding siblings ...)
  2022-02-16  8:09 ` [PATCH v3] " Noah Goldstein
@ 2022-02-17 19:12 ` Noah Goldstein
  2022-02-17 19:15 ` [PATCH v5] " Noah Goldstein
  4 siblings, 0 replies; 18+ messages in thread
From: Noah Goldstein @ 2022-02-17 19:12 UTC (permalink / raw)
  To: libc-alpha

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
AVX2 machines with and without RTM.
---
 sysdeps/x86/Makefile                        |  2 +-
 sysdeps/x86/tst-strncmp-rtm.c               | 18 +++++++++++++++++-
 sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
 sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
 sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
 sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
 sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
 7 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 6cf708335c..d110f7b7f2 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
 CFLAGS-tst-strchr-rtm.c += -mrtm
 CFLAGS-tst-strcpy-rtm.c += -mrtm
 CFLAGS-tst-strlen-rtm.c += -mrtm
-CFLAGS-tst-strncmp-rtm.c += -mrtm
+CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
 CFLAGS-tst-strrchr-rtm.c += -mrtm
 endif
 
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 09ed6fa0d6..ba8a7ba92b 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -16,6 +16,8 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdint.h>
+#include <limits.h>
 #include <tst-string-rtm.h>
 
 #define LOOP 3000
@@ -45,8 +47,22 @@ function (void)
     return 1;
 }
 
+__attribute__ ((noinline, noclone))
+static int
+function_overflow (void)
+{
+  if (strncmp (string1, string2, SSIZE_MAX) == 0)
+    return 0;
+  else
+    return 1;
+}
+
 static int
 do_test (void)
 {
-  return do_test_1 ("strncmp", LOOP, prepare, function);
+  int status = do_test_1 ("strncmp", LOOP, prepare, function);
+  if (status != EXIT_SUCCESS)
+    return status;
+  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+  return status;
 }
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 07a5a2c889..52ff5ad724 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -193,10 +193,10 @@ L(ret_zero):
 	.p2align 4,, 5
 L(one_or_less):
 	jb	L(ret_zero)
-#  ifdef USE_AS_WCSCMP
 	/* 'nbe' covers the case where length is negative (large
 	   unsigned).  */
-	jnbe	__wcscmp_avx2
+	jnbe	OVERFLOW_STRCMP
+#  ifdef USE_AS_WCSCMP
 	movl	(%rdi), %edx
 	xorl	%eax, %eax
 	cmpl	(%rsi), %edx
@@ -205,10 +205,6 @@ L(one_or_less):
 	negl	%eax
 	orl	$1, %eax
 #  else
-	/* 'nbe' covers the case where length is negative (large
-	   unsigned).  */
-
-	jnbe	__strcmp_avx2
 	movzbl	(%rdi), %eax
 	movzbl	(%rsi), %ecx
 	subl	%ecx, %eax
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
index 37d1224bb9..68bad365ba 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP	__strcmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
index 1678bcc235..f138e9f1fd 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP __strcmp_avx2
 #include "strcmp-avx2.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
index 4e88c70cc6..f467582cbe 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
index 4fa1de4d3f..e9ede522b8 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2
 #include "strcmp-avx2.S"
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v5] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-15 16:27 [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Noah Goldstein
                   ` (3 preceding siblings ...)
  2022-02-17 19:12 ` [PATCH v4] " Noah Goldstein
@ 2022-02-17 19:15 ` Noah Goldstein
  2022-02-17 19:20   ` H.J. Lu
  4 siblings, 1 reply; 18+ messages in thread
From: Noah Goldstein @ 2022-02-17 19:15 UTC (permalink / raw)
  To: libc-alpha

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
AVX2 machines with and without RTM.

Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
---
 sysdeps/x86/Makefile                        |  2 +-
 sysdeps/x86/tst-strncmp-rtm.c               | 17 ++++++++++++++++-
 sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
 sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
 sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
 sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
 sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
 7 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 6cf708335c..d110f7b7f2 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
 CFLAGS-tst-strchr-rtm.c += -mrtm
 CFLAGS-tst-strcpy-rtm.c += -mrtm
 CFLAGS-tst-strlen-rtm.c += -mrtm
-CFLAGS-tst-strncmp-rtm.c += -mrtm
+CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
 CFLAGS-tst-strrchr-rtm.c += -mrtm
 endif
 
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 09ed6fa0d6..9e20abaacc 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdint.h>
 #include <tst-string-rtm.h>
 
 #define LOOP 3000
@@ -45,8 +46,22 @@ function (void)
     return 1;
 }
 
+__attribute__ ((noinline, noclone))
+static int
+function_overflow (void)
+{
+  if (strncmp (string1, string2, SIZE_MAX) == 0)
+    return 0;
+  else
+    return 1;
+}
+
 static int
 do_test (void)
 {
-  return do_test_1 ("strncmp", LOOP, prepare, function);
+  int status = do_test_1 ("strncmp", LOOP, prepare, function);
+  if (status != EXIT_SUCCESS)
+    return status;
+  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+  return status;
 }
diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 07a5a2c889..52ff5ad724 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -193,10 +193,10 @@ L(ret_zero):
 	.p2align 4,, 5
 L(one_or_less):
 	jb	L(ret_zero)
-#  ifdef USE_AS_WCSCMP
 	/* 'nbe' covers the case where length is negative (large
 	   unsigned).  */
-	jnbe	__wcscmp_avx2
+	jnbe	OVERFLOW_STRCMP
+#  ifdef USE_AS_WCSCMP
 	movl	(%rdi), %edx
 	xorl	%eax, %eax
 	cmpl	(%rsi), %edx
@@ -205,10 +205,6 @@ L(one_or_less):
 	negl	%eax
 	orl	$1, %eax
 #  else
-	/* 'nbe' covers the case where length is negative (large
-	   unsigned).  */
-
-	jnbe	__strcmp_avx2
 	movzbl	(%rdi), %eax
 	movzbl	(%rsi), %ecx
 	subl	%ecx, %eax
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
index 37d1224bb9..68bad365ba 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP	__strcmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
index 1678bcc235..f138e9f1fd 100644
--- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
@@ -1,3 +1,4 @@
 #define STRCMP	__strncmp_avx2
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP __strcmp_avx2
 #include "strcmp-avx2.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
index 4e88c70cc6..f467582cbe 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
index 4fa1de4d3f..e9ede522b8 100644
--- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP	__wcscmp_avx2
 #include "strcmp-avx2.S"
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-16 14:26       ` H.J. Lu
@ 2022-02-17 19:15         ` Noah Goldstein
  0 siblings, 0 replies; 18+ messages in thread
From: Noah Goldstein @ 2022-02-17 19:15 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Carlos O'Donell, GNU C Library

On Wed, Feb 16, 2022 at 8:27 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Wed, Feb 16, 2022 at 6:08 AM Carlos O'Donell <carlos@redhat.com> wrote:
> >
> > On 2/16/22 08:17, H.J. Lu via Libc-alpha wrote:
> > > On Wed, Feb 16, 2022 at 12:09 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >>
> > >> In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > >> call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > >> not checks around vzeroupper and would trigger spurious
> > >> aborts. This commit fixes that.
> > >>
> > >> test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
> > >> AVX2 machines with and without RTM.
> > >>
> > >> Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
> > >> ---
> > >>  sysdeps/x86/Makefile                        |  2 +-
> > >>  sysdeps/x86/tst-strncmp-rtm.c               | 14 +++++++++++++-
> > >>  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
> > >>  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
> > >>  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
> > >>  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
> > >>  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
> > >>  7 files changed, 20 insertions(+), 10 deletions(-)
> > >>
> > >> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > >> index 6cf708335c..d110f7b7f2 100644
> > >> --- a/sysdeps/x86/Makefile
> > >> +++ b/sysdeps/x86/Makefile
> > >> @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
> > >>  CFLAGS-tst-strchr-rtm.c += -mrtm
> > >>  CFLAGS-tst-strcpy-rtm.c += -mrtm
> > >>  CFLAGS-tst-strlen-rtm.c += -mrtm
> > >> -CFLAGS-tst-strncmp-rtm.c += -mrtm
> > >> +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > >>  CFLAGS-tst-strrchr-rtm.c += -mrtm
> > >>  endif
> > >>
> > >> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > >> index 09ed6fa0d6..ebc94a3a6d 100644
> > >> --- a/sysdeps/x86/tst-strncmp-rtm.c
> > >> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > >> @@ -16,6 +16,7 @@
> > >>     License along with the GNU C Library; if not, see
> > >>     <https://www.gnu.org/licenses/>.  */
> > >>
> > >> +#include <stdint.h>
> > >>  #include <tst-string-rtm.h>
> > >>
> > >>  #define LOOP 3000
> > >> @@ -45,8 +46,19 @@ function (void)
> > >>      return 1;
> > >>  }
> > >>
> > >> +__attribute__ ((noinline, noclone))
> > >> +static int
> > >> +function_overflow (void)
> > >> +{
> > >> +  if (strncmp (string1, string2, SIZE_MAX) == 0)
> > >> +    return 0;
> > >> +  else
> > >> +    return 1;
> > >> +}
> > >> +
> > >>  static int
> > >>  do_test (void)
> > >>  {
> > >> -  return do_test_1 ("strncmp", LOOP, prepare, function);
> > >> +  return (do_test_1 ("strncmp", LOOP, prepare, function)
> > >> +         || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
> > >>  }
> > >> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > >> index 99e5349be8..6da0e1a248 100644
> > >> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > >> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > >> @@ -193,10 +193,10 @@ L(ret_zero):
> > >>         .p2align 4,, 5
> > >>  L(one_or_less):
> > >>         jb      L(ret_zero)
> > >> -#  ifdef USE_AS_WCSCMP
> > >>         /* 'nbe' covers the case where length is negative (large
> > >>            unsigned).  */
> > >> -       jnbe    __wcscmp_avx2
> > >> +       jnbe    OVERFLOW_STRCMP
> > >> +#  ifdef USE_AS_WCSCMP
> > >>         movl    (%rdi), %edx
> > >>         xorl    %eax, %eax
> > >>         cmpl    (%rsi), %edx
> > >> @@ -205,10 +205,6 @@ L(one_or_less):
> > >>         negl    %eax
> > >>         orl     $1, %eax
> > >>  #  else
> > >> -       /* 'nbe' covers the case where length is negative (large
> > >> -          unsigned).  */
> > >> -
> > >> -       jnbe    __strcmp_avx2
> > >>         movzbl  (%rdi), %eax
> > >>         movzbl  (%rsi), %ecx
> > >>         subl    %ecx, %eax
> > >> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > >> index 37d1224bb9..68bad365ba 100644
> > >> --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > >> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > >> @@ -1,3 +1,4 @@
> > >>  #define STRCMP __strncmp_avx2_rtm
> > >>  #define USE_AS_STRNCMP 1
> > >> +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> > >>  #include "strcmp-avx2-rtm.S"
> > >> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > >> index 1678bcc235..f138e9f1fd 100644
> > >> --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > >> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > >> @@ -1,3 +1,4 @@
> > >>  #define STRCMP __strncmp_avx2
> > >>  #define USE_AS_STRNCMP 1
> > >> +#define OVERFLOW_STRCMP __strcmp_avx2
> > >>  #include "strcmp-avx2.S"
> > >> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > >> index 4e88c70cc6..f467582cbe 100644
> > >> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > >> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > >> @@ -1,5 +1,5 @@
> > >>  #define STRCMP __wcsncmp_avx2_rtm
> > >>  #define USE_AS_STRNCMP 1
> > >>  #define USE_AS_WCSCMP 1
> > >> -
> > >> +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> > >>  #include "strcmp-avx2-rtm.S"
> > >> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > >> index 4fa1de4d3f..e9ede522b8 100644
> > >> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > >> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > >> @@ -1,5 +1,5 @@
> > >>  #define STRCMP __wcsncmp_avx2
> > >>  #define USE_AS_STRNCMP 1
> > >>  #define USE_AS_WCSCMP 1
> > >> -
> > >> +#define OVERFLOW_STRCMP        __wcscmp_avx2
> > >>  #include "strcmp-avx2.S"
> > >> --
> > >> 2.25.1
> > >>
> > >
> > > LGTM.
> > >
> > > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> > >
> > > Thanks.
> > >
> >
> > This fails CI for i686.
> > https://patchwork.sourceware.org/project/glibc/patch/20220216080935.3284536-1-goldstein.w.n@gmail.com/
> >
> > --
> > Cheers,
> > Carlos.
> >
>
> Hi Noah,
>
> We need this change on top of your patch:
>
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index ebc94a3a6d..9e20abaacc 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -59,6 +59,9 @@ function_overflow (void)
>  static int
>  do_test (void)
>  {
> -  return (do_test_1 ("strncmp", LOOP, prepare, function)
> -    || do_test_1 ("strncmp", LOOP, prepare, function_overflow));
> +  int status = do_test_1 ("strncmp", LOOP, prepare, function);
> +  if (status != EXIT_SUCCESS)
> +    return status;
> +  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> +  return status;
>  }

Added your fix in V5.
>
> --
> H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v5] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-17 19:15 ` [PATCH v5] " Noah Goldstein
@ 2022-02-17 19:20   ` H.J. Lu
  2022-05-25 19:51     ` Sunil Pandey
  0 siblings, 1 reply; 18+ messages in thread
From: H.J. Lu @ 2022-02-17 19:20 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell

On Thu, Feb 17, 2022 at 11:15 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> not checks around vzeroupper and would trigger spurious
> aborts. This commit fixes that.
>
> test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
> AVX2 machines with and without RTM.
>
> Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  sysdeps/x86/Makefile                        |  2 +-
>  sysdeps/x86/tst-strncmp-rtm.c               | 17 ++++++++++++++++-
>  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
>  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
>  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
>  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
>  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
>  7 files changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index 6cf708335c..d110f7b7f2 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
>  CFLAGS-tst-strchr-rtm.c += -mrtm
>  CFLAGS-tst-strcpy-rtm.c += -mrtm
>  CFLAGS-tst-strlen-rtm.c += -mrtm
> -CFLAGS-tst-strncmp-rtm.c += -mrtm
> +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
>  CFLAGS-tst-strrchr-rtm.c += -mrtm
>  endif
>
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index 09ed6fa0d6..9e20abaacc 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -16,6 +16,7 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>
> +#include <stdint.h>
>  #include <tst-string-rtm.h>
>
>  #define LOOP 3000
> @@ -45,8 +46,22 @@ function (void)
>      return 1;
>  }
>
> +__attribute__ ((noinline, noclone))
> +static int
> +function_overflow (void)
> +{
> +  if (strncmp (string1, string2, SIZE_MAX) == 0)
> +    return 0;
> +  else
> +    return 1;
> +}
> +
>  static int
>  do_test (void)
>  {
> -  return do_test_1 ("strncmp", LOOP, prepare, function);
> +  int status = do_test_1 ("strncmp", LOOP, prepare, function);
> +  if (status != EXIT_SUCCESS)
> +    return status;
> +  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> +  return status;
>  }
> diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> index 07a5a2c889..52ff5ad724 100644
> --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> @@ -193,10 +193,10 @@ L(ret_zero):
>         .p2align 4,, 5
>  L(one_or_less):
>         jb      L(ret_zero)
> -#  ifdef USE_AS_WCSCMP
>         /* 'nbe' covers the case where length is negative (large
>            unsigned).  */
> -       jnbe    __wcscmp_avx2
> +       jnbe    OVERFLOW_STRCMP
> +#  ifdef USE_AS_WCSCMP
>         movl    (%rdi), %edx
>         xorl    %eax, %eax
>         cmpl    (%rsi), %edx
> @@ -205,10 +205,6 @@ L(one_or_less):
>         negl    %eax
>         orl     $1, %eax
>  #  else
> -       /* 'nbe' covers the case where length is negative (large
> -          unsigned).  */
> -
> -       jnbe    __strcmp_avx2
>         movzbl  (%rdi), %eax
>         movzbl  (%rsi), %ecx
>         subl    %ecx, %eax
> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> index 37d1224bb9..68bad365ba 100644
> --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> @@ -1,3 +1,4 @@
>  #define STRCMP __strncmp_avx2_rtm
>  #define USE_AS_STRNCMP 1
> +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
>  #include "strcmp-avx2-rtm.S"
> diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> index 1678bcc235..f138e9f1fd 100644
> --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> @@ -1,3 +1,4 @@
>  #define STRCMP __strncmp_avx2
>  #define USE_AS_STRNCMP 1
> +#define OVERFLOW_STRCMP __strcmp_avx2
>  #include "strcmp-avx2.S"
> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> index 4e88c70cc6..f467582cbe 100644
> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> @@ -1,5 +1,5 @@
>  #define STRCMP __wcsncmp_avx2_rtm
>  #define USE_AS_STRNCMP 1
>  #define USE_AS_WCSCMP 1
> -
> +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
>  #include "strcmp-avx2-rtm.S"
> diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> index 4fa1de4d3f..e9ede522b8 100644
> --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> @@ -1,5 +1,5 @@
>  #define STRCMP __wcsncmp_avx2
>  #define USE_AS_STRNCMP 1
>  #define USE_AS_WCSCMP 1
> -
> +#define OVERFLOW_STRCMP        __wcscmp_avx2
>  #include "strcmp-avx2.S"
> --
> 2.25.1
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v5] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-02-17 19:20   ` H.J. Lu
@ 2022-05-25 19:51     ` Sunil Pandey
  2022-05-25 19:56       ` H.J. Lu
  0 siblings, 1 reply; 18+ messages in thread
From: Sunil Pandey @ 2022-05-25 19:51 UTC (permalink / raw)
  To: H.J. Lu, Libc-stable Mailing List; +Cc: Noah Goldstein, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 5570 bytes --]

On Thu, Feb 17, 2022 at 11:21 AM H.J. Lu via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> On Thu, Feb 17, 2022 at 11:15 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > not checks around vzeroupper and would trigger spurious
> > aborts. This commit fixes that.
> >
> > test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
> > AVX2 machines with and without RTM.
> >
> > Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
> > ---
> >  sysdeps/x86/Makefile                        |  2 +-
> >  sysdeps/x86/tst-strncmp-rtm.c               | 17 ++++++++++++++++-
> >  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
> >  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
> >  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
> >  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
> >  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
> >  7 files changed, 23 insertions(+), 10 deletions(-)
> >
> > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > index 6cf708335c..d110f7b7f2 100644
> > --- a/sysdeps/x86/Makefile
> > +++ b/sysdeps/x86/Makefile
> > @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
> >  CFLAGS-tst-strchr-rtm.c += -mrtm
> >  CFLAGS-tst-strcpy-rtm.c += -mrtm
> >  CFLAGS-tst-strlen-rtm.c += -mrtm
> > -CFLAGS-tst-strncmp-rtm.c += -mrtm
> > +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> >  CFLAGS-tst-strrchr-rtm.c += -mrtm
> >  endif
> >
> > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > index 09ed6fa0d6..9e20abaacc 100644
> > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > @@ -16,6 +16,7 @@
> >     License along with the GNU C Library; if not, see
> >     <https://www.gnu.org/licenses/>.  */
> >
> > +#include <stdint.h>
> >  #include <tst-string-rtm.h>
> >
> >  #define LOOP 3000
> > @@ -45,8 +46,22 @@ function (void)
> >      return 1;
> >  }
> >
> > +__attribute__ ((noinline, noclone))
> > +static int
> > +function_overflow (void)
> > +{
> > +  if (strncmp (string1, string2, SIZE_MAX) == 0)
> > +    return 0;
> > +  else
> > +    return 1;
> > +}
> > +
> >  static int
> >  do_test (void)
> >  {
> > -  return do_test_1 ("strncmp", LOOP, prepare, function);
> > +  int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > +  if (status != EXIT_SUCCESS)
> > +    return status;
> > +  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > +  return status;
> >  }
> > diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > index 07a5a2c889..52ff5ad724 100644
> > --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > @@ -193,10 +193,10 @@ L(ret_zero):
> >         .p2align 4,, 5
> >  L(one_or_less):
> >         jb      L(ret_zero)
> > -#  ifdef USE_AS_WCSCMP
> >         /* 'nbe' covers the case where length is negative (large
> >            unsigned).  */
> > -       jnbe    __wcscmp_avx2
> > +       jnbe    OVERFLOW_STRCMP
> > +#  ifdef USE_AS_WCSCMP
> >         movl    (%rdi), %edx
> >         xorl    %eax, %eax
> >         cmpl    (%rsi), %edx
> > @@ -205,10 +205,6 @@ L(one_or_less):
> >         negl    %eax
> >         orl     $1, %eax
> >  #  else
> > -       /* 'nbe' covers the case where length is negative (large
> > -          unsigned).  */
> > -
> > -       jnbe    __strcmp_avx2
> >         movzbl  (%rdi), %eax
> >         movzbl  (%rsi), %ecx
> >         subl    %ecx, %eax
> > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > index 37d1224bb9..68bad365ba 100644
> > --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > @@ -1,3 +1,4 @@
> >  #define STRCMP __strncmp_avx2_rtm
> >  #define USE_AS_STRNCMP 1
> > +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> >  #include "strcmp-avx2-rtm.S"
> > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > index 1678bcc235..f138e9f1fd 100644
> > --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > @@ -1,3 +1,4 @@
> >  #define STRCMP __strncmp_avx2
> >  #define USE_AS_STRNCMP 1
> > +#define OVERFLOW_STRCMP __strcmp_avx2
> >  #include "strcmp-avx2.S"
> > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > index 4e88c70cc6..f467582cbe 100644
> > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > @@ -1,5 +1,5 @@
> >  #define STRCMP __wcsncmp_avx2_rtm
> >  #define USE_AS_STRNCMP 1
> >  #define USE_AS_WCSCMP 1
> > -
> > +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> >  #include "strcmp-avx2-rtm.S"
> > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > index 4fa1de4d3f..e9ede522b8 100644
> > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > @@ -1,5 +1,5 @@
> >  #define STRCMP __wcsncmp_avx2
> >  #define USE_AS_STRNCMP 1
> >  #define USE_AS_WCSCMP 1
> > -
> > +#define OVERFLOW_STRCMP        __wcscmp_avx2
> >  #include "strcmp-avx2.S"
> > --
> > 2.25.1
> >
>
> LGTM.
>
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
>
> Thanks.
>
> --
> H.J.

I would like to backport this patch to release branches.
Any comments or objections?

Patch attached, it fixes BZ# 29127.

--Sunil

[-- Attachment #2: 0001-x86-Fallback-str-wcs-cmp-RTM-in-the-ncmp-overflow-ca.patch --]
[-- Type: application/octet-stream, Size: 1770 bytes --]

From 3ffb50c2fdbfabcc098289d863be13d250898acb Mon Sep 17 00:00:00 2001
From: Noah Goldstein <goldstein.w.n@gmail.com>
Date: Tue, 15 Feb 2022 08:18:15 -0600
Subject: [PATCH] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ
 #29127]

Re-cherry-pick commit c627209832 for strcmp-avx2.S change which was
omitted in intial cherry pick because at the time this bug was not
present on release branch.

Fixes BZ #29127.

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcscmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
AVX2 machines with and without RTM.

Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit c6272098323153db373f2986c67786ea8c85f1cf)
---
 sysdeps/x86_64/multiarch/strcmp-avx2.S | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
index 3366d0b083..8da09bd86d 100644
--- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
+++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
@@ -345,10 +345,10 @@ L(one_or_less):
 	movq	%LOCALE_REG, %rdx
 #  endif
 	jb	L(ret_zero)
-#  ifdef USE_AS_WCSCMP
 	/* 'nbe' covers the case where length is negative (large
 	   unsigned).  */
-	jnbe	__wcscmp_avx2
+	jnbe	OVERFLOW_STRCMP
+#  ifdef USE_AS_WCSCMP
 	movl	(%rdi), %edx
 	xorl	%eax, %eax
 	cmpl	(%rsi), %edx
@@ -357,10 +357,6 @@ L(one_or_less):
 	negl	%eax
 	orl	$1, %eax
 #  else
-	/* 'nbe' covers the case where length is negative (large
-	   unsigned).  */
-
-	jnbe	__strcmp_avx2
 	movzbl	(%rdi), %eax
 	movzbl	(%rsi), %ecx
 	TOLOWER_gpr (%rax, %eax)
-- 
2.35.3


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v5] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
  2022-05-25 19:51     ` Sunil Pandey
@ 2022-05-25 19:56       ` H.J. Lu
  0 siblings, 0 replies; 18+ messages in thread
From: H.J. Lu @ 2022-05-25 19:56 UTC (permalink / raw)
  To: Sunil Pandey; +Cc: Libc-stable Mailing List, Noah Goldstein, GNU C Library

On Wed, May 25, 2022 at 12:52 PM Sunil Pandey <skpgkp2@gmail.com> wrote:
>
> On Thu, Feb 17, 2022 at 11:21 AM H.J. Lu via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> >
> > On Thu, Feb 17, 2022 at 11:15 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >
> > > In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
> > > call strcmp-avx2 and wcsncmp-avx2 respectively. This would have
> > > not checks around vzeroupper and would trigger spurious
> > > aborts. This commit fixes that.
> > >
> > > test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
> > > AVX2 machines with and without RTM.
> > >
> > > Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
> > > ---
> > >  sysdeps/x86/Makefile                        |  2 +-
> > >  sysdeps/x86/tst-strncmp-rtm.c               | 17 ++++++++++++++++-
> > >  sysdeps/x86_64/multiarch/strcmp-avx2.S      |  8 ++------
> > >  sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S |  1 +
> > >  sysdeps/x86_64/multiarch/strncmp-avx2.S     |  1 +
> > >  sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S |  2 +-
> > >  sysdeps/x86_64/multiarch/wcsncmp-avx2.S     |  2 +-
> > >  7 files changed, 23 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > > index 6cf708335c..d110f7b7f2 100644
> > > --- a/sysdeps/x86/Makefile
> > > +++ b/sysdeps/x86/Makefile
> > > @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
> > >  CFLAGS-tst-strchr-rtm.c += -mrtm
> > >  CFLAGS-tst-strcpy-rtm.c += -mrtm
> > >  CFLAGS-tst-strlen-rtm.c += -mrtm
> > > -CFLAGS-tst-strncmp-rtm.c += -mrtm
> > > +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > >  CFLAGS-tst-strrchr-rtm.c += -mrtm
> > >  endif
> > >
> > > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > > index 09ed6fa0d6..9e20abaacc 100644
> > > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > > @@ -16,6 +16,7 @@
> > >     License along with the GNU C Library; if not, see
> > >     <https://www.gnu.org/licenses/>.  */
> > >
> > > +#include <stdint.h>
> > >  #include <tst-string-rtm.h>
> > >
> > >  #define LOOP 3000
> > > @@ -45,8 +46,22 @@ function (void)
> > >      return 1;
> > >  }
> > >
> > > +__attribute__ ((noinline, noclone))
> > > +static int
> > > +function_overflow (void)
> > > +{
> > > +  if (strncmp (string1, string2, SIZE_MAX) == 0)
> > > +    return 0;
> > > +  else
> > > +    return 1;
> > > +}
> > > +
> > >  static int
> > >  do_test (void)
> > >  {
> > > -  return do_test_1 ("strncmp", LOOP, prepare, function);
> > > +  int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > > +  if (status != EXIT_SUCCESS)
> > > +    return status;
> > > +  status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > > +  return status;
> > >  }
> > > diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > index 07a5a2c889..52ff5ad724 100644
> > > --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S
> > > @@ -193,10 +193,10 @@ L(ret_zero):
> > >         .p2align 4,, 5
> > >  L(one_or_less):
> > >         jb      L(ret_zero)
> > > -#  ifdef USE_AS_WCSCMP
> > >         /* 'nbe' covers the case where length is negative (large
> > >            unsigned).  */
> > > -       jnbe    __wcscmp_avx2
> > > +       jnbe    OVERFLOW_STRCMP
> > > +#  ifdef USE_AS_WCSCMP
> > >         movl    (%rdi), %edx
> > >         xorl    %eax, %eax
> > >         cmpl    (%rsi), %edx
> > > @@ -205,10 +205,6 @@ L(one_or_less):
> > >         negl    %eax
> > >         orl     $1, %eax
> > >  #  else
> > > -       /* 'nbe' covers the case where length is negative (large
> > > -          unsigned).  */
> > > -
> > > -       jnbe    __strcmp_avx2
> > >         movzbl  (%rdi), %eax
> > >         movzbl  (%rsi), %ecx
> > >         subl    %ecx, %eax
> > > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > index 37d1224bb9..68bad365ba 100644
> > > --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
> > > @@ -1,3 +1,4 @@
> > >  #define STRCMP __strncmp_avx2_rtm
> > >  #define USE_AS_STRNCMP 1
> > > +#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
> > >  #include "strcmp-avx2-rtm.S"
> > > diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > index 1678bcc235..f138e9f1fd 100644
> > > --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S
> > > @@ -1,3 +1,4 @@
> > >  #define STRCMP __strncmp_avx2
> > >  #define USE_AS_STRNCMP 1
> > > +#define OVERFLOW_STRCMP __strcmp_avx2
> > >  #include "strcmp-avx2.S"
> > > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > index 4e88c70cc6..f467582cbe 100644
> > > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
> > > @@ -1,5 +1,5 @@
> > >  #define STRCMP __wcsncmp_avx2_rtm
> > >  #define USE_AS_STRNCMP 1
> > >  #define USE_AS_WCSCMP 1
> > > -
> > > +#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
> > >  #include "strcmp-avx2-rtm.S"
> > > diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > index 4fa1de4d3f..e9ede522b8 100644
> > > --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S
> > > @@ -1,5 +1,5 @@
> > >  #define STRCMP __wcsncmp_avx2
> > >  #define USE_AS_STRNCMP 1
> > >  #define USE_AS_WCSCMP 1
> > > -
> > > +#define OVERFLOW_STRCMP        __wcscmp_avx2
> > >  #include "strcmp-avx2.S"
> > > --
> > > 2.25.1
> > >
> >
> > LGTM.
> >
> > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> >
> > Thanks.
> >
> > --
> > H.J.
>
> I would like to backport this patch to release branches.
> Any comments or objections?
>
> Patch attached, it fixes BZ# 29127.
>
> --Sunil

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-05-25 19:57 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 16:27 [PATCH v1] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Noah Goldstein
2022-02-15 16:29 ` H.J. Lu
2022-02-15 16:51   ` Noah Goldstein
2022-02-15 16:59     ` H.J. Lu
2022-02-15 17:06       ` Noah Goldstein
2022-02-15 18:49         ` H.J. Lu
2022-02-16  8:10           ` Noah Goldstein
2022-02-15 16:49 ` [PATCH v2] " Noah Goldstein
2022-02-16  8:09 ` [PATCH v3] " Noah Goldstein
2022-02-16 13:17   ` H.J. Lu
2022-02-16 14:08     ` Carlos O'Donell
2022-02-16 14:26       ` H.J. Lu
2022-02-17 19:15         ` Noah Goldstein
2022-02-17 19:12 ` [PATCH v4] " Noah Goldstein
2022-02-17 19:15 ` [PATCH v5] " Noah Goldstein
2022-02-17 19:20   ` H.J. Lu
2022-05-25 19:51     ` Sunil Pandey
2022-05-25 19:56       ` H.J. Lu

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).