* [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
@ 2022-02-18 3:37 Noah Goldstein
2022-02-18 3:54 ` H.J. Lu
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 3:37 UTC (permalink / raw)
To: libc-alpha
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.
---
sysdeps/x86/Makefile | 4 +++-
sysdeps/x86/tst-strncmp-rtm.c | 33 ++++++++++++++++++++++++---------
sysdeps/x86/tst-wcsncmp-rtm.c | 20 ++++++++++++++++++++
3 files changed, 47 insertions(+), 10 deletions(-)
create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index d110f7b7f2..b13b556425 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -99,7 +99,8 @@ tests += \
tst-strcpy-rtm \
tst-strlen-rtm \
tst-strncmp-rtm \
- tst-strrchr-rtm
+ tst-strrchr-rtm \
+ tst-wcsncmp-rtm
CFLAGS-tst-memchr-rtm.c += -mrtm
CFLAGS-tst-memcmp-rtm.c += -mrtm
@@ -111,6 +112,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
CFLAGS-tst-strlen-rtm.c += -mrtm
CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
CFLAGS-tst-strrchr-rtm.c += -mrtm
+CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
endif
ifneq ($(enable-cet),no)
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 9e20abaacc..5c6f40e5aa 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -17,20 +17,35 @@
<https://www.gnu.org/licenses/>. */
#include <stdint.h>
+#include <wchar.h>
#include <tst-string-rtm.h>
+#ifdef WIDE
+# define CHAR wchar_t
+# define MEMSET wmemset
+# define STRNCMP wcsncmp
+# define TEST_NAME wcsncmp
+#else /* !WIDE */
+# define CHAR char
+# define MEMSET memset
+# define STRNCMP strncmp
+# define TEST_NAME strncmp
+#endif /* !WIDE */
+
+
+
#define LOOP 3000
#define STRING_SIZE 1024
-char string1[STRING_SIZE];
-char string2[STRING_SIZE];
+CHAR string1[STRING_SIZE];
+CHAR string2[STRING_SIZE];
__attribute__ ((noinline, noclone))
static int
prepare (void)
{
- memset (string1, 'a', STRING_SIZE - 1);
- memset (string2, 'a', STRING_SIZE - 1);
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ MEMSET (string1, 'a', STRING_SIZE - 1);
+ MEMSET (string2, 'a', STRING_SIZE - 1);
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
@@ -40,7 +55,7 @@ __attribute__ ((noinline, noclone))
static int
function (void)
{
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return 0;
else
return 1;
@@ -50,7 +65,7 @@ __attribute__ ((noinline, noclone))
static int
function_overflow (void)
{
- if (strncmp (string1, string2, SIZE_MAX) == 0)
+ if (STRNCMP (string1, string2, SIZE_MAX) == 0)
return 0;
else
return 1;
@@ -59,9 +74,9 @@ function_overflow (void)
static int
do_test (void)
{
- int status = do_test_1 ("strncmp", LOOP, prepare, function);
+ int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
if (status != EXIT_SUCCESS)
return status;
- status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+ status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
return status;
}
diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
new file mode 100644
index 0000000000..86f97e4035
--- /dev/null
+++ b/sysdeps/x86/tst-wcsncmp-rtm.c
@@ -0,0 +1,20 @@
+/* Test case for wcsncmp inside a transactionally executing RTM region.
+ Copyright (C) 2021-2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define WIDE 1
+#include "tst-strncmp-rtm.c"
--
2.25.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 3:37 [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] Noah Goldstein
@ 2022-02-18 3:54 ` H.J. Lu
2022-02-18 3:58 ` H.J. Lu
2022-02-18 5:01 ` Noah Goldstein
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: H.J. Lu @ 2022-02-18 3:54 UTC (permalink / raw)
To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell
On Thu, Feb 17, 2022 at 7:37 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> 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.
> ---
> sysdeps/x86/Makefile | 4 +++-
> sysdeps/x86/tst-strncmp-rtm.c | 33 ++++++++++++++++++++++++---------
> sysdeps/x86/tst-wcsncmp-rtm.c | 20 ++++++++++++++++++++
> 3 files changed, 47 insertions(+), 10 deletions(-)
> create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index d110f7b7f2..b13b556425 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -99,7 +99,8 @@ tests += \
> tst-strcpy-rtm \
> tst-strlen-rtm \
> tst-strncmp-rtm \
> - tst-strrchr-rtm
> + tst-strrchr-rtm \
> + tst-wcsncmp-rtm
>
> CFLAGS-tst-memchr-rtm.c += -mrtm
> CFLAGS-tst-memcmp-rtm.c += -mrtm
> @@ -111,6 +112,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> CFLAGS-tst-strlen-rtm.c += -mrtm
> CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> CFLAGS-tst-strrchr-rtm.c += -mrtm
> +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> endif
>
> ifneq ($(enable-cet),no)
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index 9e20abaacc..5c6f40e5aa 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -17,20 +17,35 @@
> <https://www.gnu.org/licenses/>. */
>
> #include <stdint.h>
> +#include <wchar.h>
> #include <tst-string-rtm.h>
>
> +#ifdef WIDE
Move #include <wchar.h> here.
> +# define CHAR wchar_t
> +# define MEMSET wmemset
> +# define STRNCMP wcsncmp
> +# define TEST_NAME wcsncmp
> +#else /* !WIDE */
> +# define CHAR char
> +# define MEMSET memset
> +# define STRNCMP strncmp
> +# define TEST_NAME strncmp
> +#endif /* !WIDE */
> +
> +
> +
> #define LOOP 3000
> #define STRING_SIZE 1024
> -char string1[STRING_SIZE];
> -char string2[STRING_SIZE];
> +CHAR string1[STRING_SIZE];
> +CHAR string2[STRING_SIZE];
>
> __attribute__ ((noinline, noclone))
> static int
> prepare (void)
> {
> - memset (string1, 'a', STRING_SIZE - 1);
> - memset (string2, 'a', STRING_SIZE - 1);
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + MEMSET (string1, 'a', STRING_SIZE - 1);
> + MEMSET (string2, 'a', STRING_SIZE - 1);
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return EXIT_SUCCESS;
> else
> return EXIT_FAILURE;
> @@ -40,7 +55,7 @@ __attribute__ ((noinline, noclone))
> static int
> function (void)
> {
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return 0;
> else
> return 1;
> @@ -50,7 +65,7 @@ __attribute__ ((noinline, noclone))
> static int
> function_overflow (void)
> {
> - if (strncmp (string1, string2, SIZE_MAX) == 0)
> + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> return 0;
> else
> return 1;
> @@ -59,9 +74,9 @@ function_overflow (void)
> static int
> do_test (void)
> {
> - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> if (status != EXIT_SUCCESS)
> return status;
> - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> return status;
> }
> diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> new file mode 100644
> index 0000000000..86f97e4035
> --- /dev/null
> +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> @@ -0,0 +1,20 @@
> +/* Test case for wcsncmp inside a transactionally executing RTM region.
> + Copyright (C) 2021-2022 Free Software Foundation, Inc.
^^^^^ Just 2022
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#define WIDE 1
> +#include "tst-strncmp-rtm.c"
> --
> 2.25.1
>
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 3:54 ` H.J. Lu
@ 2022-02-18 3:58 ` H.J. Lu
2022-02-18 5:02 ` Noah Goldstein
0 siblings, 1 reply; 13+ messages in thread
From: H.J. Lu @ 2022-02-18 3:58 UTC (permalink / raw)
To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell
On Thu, Feb 17, 2022 at 7:54 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Feb 17, 2022 at 7:37 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > 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.
> > ---
> > sysdeps/x86/Makefile | 4 +++-
> > sysdeps/x86/tst-strncmp-rtm.c | 33 ++++++++++++++++++++++++---------
> > sysdeps/x86/tst-wcsncmp-rtm.c | 20 ++++++++++++++++++++
> > 3 files changed, 47 insertions(+), 10 deletions(-)
> > create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
> >
> > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > index d110f7b7f2..b13b556425 100644
> > --- a/sysdeps/x86/Makefile
> > +++ b/sysdeps/x86/Makefile
> > @@ -99,7 +99,8 @@ tests += \
> > tst-strcpy-rtm \
> > tst-strlen-rtm \
> > tst-strncmp-rtm \
> > - tst-strrchr-rtm
> > + tst-strrchr-rtm \
> > + tst-wcsncmp-rtm
Also change it to
tst-wcsncmp-rtm \
# tests
> > CFLAGS-tst-memchr-rtm.c += -mrtm
> > CFLAGS-tst-memcmp-rtm.c += -mrtm
> > @@ -111,6 +112,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> > CFLAGS-tst-strlen-rtm.c += -mrtm
> > CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > CFLAGS-tst-strrchr-rtm.c += -mrtm
> > +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> > endif
> >
> > ifneq ($(enable-cet),no)
> > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > index 9e20abaacc..5c6f40e5aa 100644
> > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > @@ -17,20 +17,35 @@
> > <https://www.gnu.org/licenses/>. */
> >
> > #include <stdint.h>
> > +#include <wchar.h>
> > #include <tst-string-rtm.h>
> >
> > +#ifdef WIDE
>
> Move #include <wchar.h> here.
>
> > +# define CHAR wchar_t
> > +# define MEMSET wmemset
> > +# define STRNCMP wcsncmp
> > +# define TEST_NAME wcsncmp
> > +#else /* !WIDE */
> > +# define CHAR char
> > +# define MEMSET memset
> > +# define STRNCMP strncmp
> > +# define TEST_NAME strncmp
> > +#endif /* !WIDE */
> > +
> > +
> > +
> > #define LOOP 3000
> > #define STRING_SIZE 1024
> > -char string1[STRING_SIZE];
> > -char string2[STRING_SIZE];
> > +CHAR string1[STRING_SIZE];
> > +CHAR string2[STRING_SIZE];
> >
> > __attribute__ ((noinline, noclone))
> > static int
> > prepare (void)
> > {
> > - memset (string1, 'a', STRING_SIZE - 1);
> > - memset (string2, 'a', STRING_SIZE - 1);
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + MEMSET (string1, 'a', STRING_SIZE - 1);
> > + MEMSET (string2, 'a', STRING_SIZE - 1);
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return EXIT_SUCCESS;
> > else
> > return EXIT_FAILURE;
> > @@ -40,7 +55,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function (void)
> > {
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -50,7 +65,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function_overflow (void)
> > {
> > - if (strncmp (string1, string2, SIZE_MAX) == 0)
> > + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -59,9 +74,9 @@ function_overflow (void)
> > static int
> > do_test (void)
> > {
> > - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> > if (status != EXIT_SUCCESS)
> > return status;
> > - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> > return status;
> > }
> > diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> > new file mode 100644
> > index 0000000000..86f97e4035
> > --- /dev/null
> > +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> > @@ -0,0 +1,20 @@
> > +/* Test case for wcsncmp inside a transactionally executing RTM region.
> > + Copyright (C) 2021-2022 Free Software Foundation, Inc.
> ^^^^^ Just 2022
> > + This file is part of the GNU C Library.
> > +
> > + The GNU C Library is free software; you can redistribute it and/or
> > + modify it under the terms of the GNU Lesser General Public
> > + License as published by the Free Software Foundation; either
> > + version 2.1 of the License, or (at your option) any later version.
> > +
> > + The GNU C Library is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + Lesser General Public License for more details.
> > +
> > + You should have received a copy of the GNU Lesser General Public
> > + License along with the GNU C Library; if not, see
> > + <https://www.gnu.org/licenses/>. */
> > +
> > +#define WIDE 1
> > +#include "tst-strncmp-rtm.c"
> > --
> > 2.25.1
> >
>
> Thanks.
>
> --
> H.J.
--
H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 3:37 [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] Noah Goldstein
2022-02-18 3:54 ` H.J. Lu
@ 2022-02-18 5:01 ` Noah Goldstein
2022-02-18 13:13 ` H.J. Lu
2022-02-18 19:59 ` [PATCH v3] " Noah Goldstein
2022-02-18 20:19 ` [PATCH v4] " Noah Goldstein
3 siblings, 1 reply; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 5:01 UTC (permalink / raw)
To: libc-alpha
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.
---
sysdeps/x86/Makefile | 5 ++++-
sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
3 files changed, 48 insertions(+), 10 deletions(-)
create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index d110f7b7f2..c6bee981f8 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -99,7 +99,9 @@ tests += \
tst-strcpy-rtm \
tst-strlen-rtm \
tst-strncmp-rtm \
- tst-strrchr-rtm
+ tst-strrchr-rtm \
+ tst-wcsncmp-rtm \
+# tests
CFLAGS-tst-memchr-rtm.c += -mrtm
CFLAGS-tst-memcmp-rtm.c += -mrtm
@@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
CFLAGS-tst-strlen-rtm.c += -mrtm
CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
CFLAGS-tst-strrchr-rtm.c += -mrtm
+CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
endif
ifneq ($(enable-cet),no)
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 9e20abaacc..b50c11e8d4 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -19,18 +19,32 @@
#include <stdint.h>
#include <tst-string-rtm.h>
+#ifdef WIDE
+# define CHAR wchar_t
+# define MEMSET wmemset
+# define STRNCMP wcsncmp
+# define TEST_NAME wcsncmp
+#else /* !WIDE */
+# define CHAR char
+# define MEMSET memset
+# define STRNCMP strncmp
+# define TEST_NAME strncmp
+#endif /* !WIDE */
+
+
+
#define LOOP 3000
#define STRING_SIZE 1024
-char string1[STRING_SIZE];
-char string2[STRING_SIZE];
+CHAR string1[STRING_SIZE];
+CHAR string2[STRING_SIZE];
__attribute__ ((noinline, noclone))
static int
prepare (void)
{
- memset (string1, 'a', STRING_SIZE - 1);
- memset (string2, 'a', STRING_SIZE - 1);
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ MEMSET (string1, 'a', STRING_SIZE - 1);
+ MEMSET (string2, 'a', STRING_SIZE - 1);
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
@@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
static int
function (void)
{
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return 0;
else
return 1;
@@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
static int
function_overflow (void)
{
- if (strncmp (string1, string2, SIZE_MAX) == 0)
+ if (STRNCMP (string1, string2, SIZE_MAX) == 0)
return 0;
else
return 1;
@@ -59,9 +73,9 @@ function_overflow (void)
static int
do_test (void)
{
- int status = do_test_1 ("strncmp", LOOP, prepare, function);
+ int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
if (status != EXIT_SUCCESS)
return status;
- status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+ status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
return status;
}
diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
new file mode 100644
index 0000000000..3445de4bf9
--- /dev/null
+++ b/sysdeps/x86/tst-wcsncmp-rtm.c
@@ -0,0 +1,21 @@
+/* Test case for wcsncmp inside a transactionally executing RTM region.
+ Copyright (C) 2021-2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define WIDE 1
+#include <wchar.h>
+#include "tst-strncmp-rtm.c"
--
2.25.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 3:58 ` H.J. Lu
@ 2022-02-18 5:02 ` Noah Goldstein
0 siblings, 0 replies; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 5:02 UTC (permalink / raw)
To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell
On Thu, Feb 17, 2022 at 9:58 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Feb 17, 2022 at 7:54 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Thu, Feb 17, 2022 at 7:37 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >
> > > 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.
> > > ---
> > > sysdeps/x86/Makefile | 4 +++-
> > > sysdeps/x86/tst-strncmp-rtm.c | 33 ++++++++++++++++++++++++---------
> > > sysdeps/x86/tst-wcsncmp-rtm.c | 20 ++++++++++++++++++++
> > > 3 files changed, 47 insertions(+), 10 deletions(-)
> > > create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
> > >
> > > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > > index d110f7b7f2..b13b556425 100644
> > > --- a/sysdeps/x86/Makefile
> > > +++ b/sysdeps/x86/Makefile
> > > @@ -99,7 +99,8 @@ tests += \
> > > tst-strcpy-rtm \
> > > tst-strlen-rtm \
> > > tst-strncmp-rtm \
> > > - tst-strrchr-rtm
> > > + tst-strrchr-rtm \
> > > + tst-wcsncmp-rtm
>
> Also change it to
>
> tst-wcsncmp-rtm \
> # tests
Fixed in v2
>
> > > CFLAGS-tst-memchr-rtm.c += -mrtm
> > > CFLAGS-tst-memcmp-rtm.c += -mrtm
> > > @@ -111,6 +112,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> > > CFLAGS-tst-strlen-rtm.c += -mrtm
> > > CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > > CFLAGS-tst-strrchr-rtm.c += -mrtm
> > > +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> > > endif
> > >
> > > ifneq ($(enable-cet),no)
> > > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > > index 9e20abaacc..5c6f40e5aa 100644
> > > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > > @@ -17,20 +17,35 @@
> > > <https://www.gnu.org/licenses/>. */
> > >
> > > #include <stdint.h>
> > > +#include <wchar.h>
> > > #include <tst-string-rtm.h>
> > >
> > > +#ifdef WIDE
> >
> > Move #include <wchar.h> here.
> >
Fixed in v2.
> > > +# define CHAR wchar_t
> > > +# define MEMSET wmemset
> > > +# define STRNCMP wcsncmp
> > > +# define TEST_NAME wcsncmp
> > > +#else /* !WIDE */
> > > +# define CHAR char
> > > +# define MEMSET memset
> > > +# define STRNCMP strncmp
> > > +# define TEST_NAME strncmp
> > > +#endif /* !WIDE */
> > > +
> > > +
> > > +
> > > #define LOOP 3000
> > > #define STRING_SIZE 1024
> > > -char string1[STRING_SIZE];
> > > -char string2[STRING_SIZE];
> > > +CHAR string1[STRING_SIZE];
> > > +CHAR string2[STRING_SIZE];
> > >
> > > __attribute__ ((noinline, noclone))
> > > static int
> > > prepare (void)
> > > {
> > > - memset (string1, 'a', STRING_SIZE - 1);
> > > - memset (string2, 'a', STRING_SIZE - 1);
> > > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > > + MEMSET (string1, 'a', STRING_SIZE - 1);
> > > + MEMSET (string2, 'a', STRING_SIZE - 1);
> > > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > > return EXIT_SUCCESS;
> > > else
> > > return EXIT_FAILURE;
> > > @@ -40,7 +55,7 @@ __attribute__ ((noinline, noclone))
> > > static int
> > > function (void)
> > > {
> > > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > > return 0;
> > > else
> > > return 1;
> > > @@ -50,7 +65,7 @@ __attribute__ ((noinline, noclone))
> > > static int
> > > function_overflow (void)
> > > {
> > > - if (strncmp (string1, string2, SIZE_MAX) == 0)
> > > + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> > > return 0;
> > > else
> > > return 1;
> > > @@ -59,9 +74,9 @@ function_overflow (void)
> > > static int
> > > do_test (void)
> > > {
> > > - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > > + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> > > if (status != EXIT_SUCCESS)
> > > return status;
> > > - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > > + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> > > return status;
> > > }
> > > diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> > > new file mode 100644
> > > index 0000000000..86f97e4035
> > > --- /dev/null
> > > +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> > > @@ -0,0 +1,20 @@
> > > +/* Test case for wcsncmp inside a transactionally executing RTM region.
> > > + Copyright (C) 2021-2022 Free Software Foundation, Inc.
> > ^^^^^ Just 2022
> > > + This file is part of the GNU C Library.
> > > +
> > > + The GNU C Library is free software; you can redistribute it and/or
> > > + modify it under the terms of the GNU Lesser General Public
> > > + License as published by the Free Software Foundation; either
> > > + version 2.1 of the License, or (at your option) any later version.
> > > +
> > > + The GNU C Library is distributed in the hope that it will be useful,
> > > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > > + Lesser General Public License for more details.
> > > +
> > > + You should have received a copy of the GNU Lesser General Public
> > > + License along with the GNU C Library; if not, see
> > > + <https://www.gnu.org/licenses/>. */
> > > +
> > > +#define WIDE 1
> > > +#include "tst-strncmp-rtm.c"
> > > --
> > > 2.25.1
> > >
> >
> > Thanks.
> >
> > --
> > H.J.
>
>
>
> --
> H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 5:01 ` Noah Goldstein
@ 2022-02-18 13:13 ` H.J. Lu
2022-02-18 19:59 ` Noah Goldstein
0 siblings, 1 reply; 13+ messages in thread
From: H.J. Lu @ 2022-02-18 13:13 UTC (permalink / raw)
To: Noah Goldstein; +Cc: GNU C Library, Carlos O'Donell
On Thu, Feb 17, 2022 at 9:01 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> 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.
> ---
> sysdeps/x86/Makefile | 5 ++++-
> sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
> sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
> 3 files changed, 48 insertions(+), 10 deletions(-)
> create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index d110f7b7f2..c6bee981f8 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -99,7 +99,9 @@ tests += \
> tst-strcpy-rtm \
> tst-strlen-rtm \
> tst-strncmp-rtm \
> - tst-strrchr-rtm
> + tst-strrchr-rtm \
> + tst-wcsncmp-rtm \
> +# tests
>
> CFLAGS-tst-memchr-rtm.c += -mrtm
> CFLAGS-tst-memcmp-rtm.c += -mrtm
> @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> CFLAGS-tst-strlen-rtm.c += -mrtm
> CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> CFLAGS-tst-strrchr-rtm.c += -mrtm
> +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> endif
>
> ifneq ($(enable-cet),no)
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index 9e20abaacc..b50c11e8d4 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -19,18 +19,32 @@
> #include <stdint.h>
> #include <tst-string-rtm.h>
>
> +#ifdef WIDE
> +# define CHAR wchar_t
> +# define MEMSET wmemset
> +# define STRNCMP wcsncmp
> +# define TEST_NAME wcsncmp
> +#else /* !WIDE */
> +# define CHAR char
> +# define MEMSET memset
> +# define STRNCMP strncmp
> +# define TEST_NAME strncmp
> +#endif /* !WIDE */
> +
> +
> +
> #define LOOP 3000
> #define STRING_SIZE 1024
> -char string1[STRING_SIZE];
> -char string2[STRING_SIZE];
> +CHAR string1[STRING_SIZE];
> +CHAR string2[STRING_SIZE];
>
> __attribute__ ((noinline, noclone))
> static int
> prepare (void)
> {
> - memset (string1, 'a', STRING_SIZE - 1);
> - memset (string2, 'a', STRING_SIZE - 1);
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + MEMSET (string1, 'a', STRING_SIZE - 1);
> + MEMSET (string2, 'a', STRING_SIZE - 1);
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return EXIT_SUCCESS;
> else
> return EXIT_FAILURE;
> @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
> static int
> function (void)
> {
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return 0;
> else
> return 1;
> @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
> static int
> function_overflow (void)
> {
> - if (strncmp (string1, string2, SIZE_MAX) == 0)
> + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> return 0;
> else
> return 1;
> @@ -59,9 +73,9 @@ function_overflow (void)
> static int
> do_test (void)
> {
> - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> if (status != EXIT_SUCCESS)
> return status;
> - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> return status;
> }
> diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> new file mode 100644
> index 0000000000..3445de4bf9
> --- /dev/null
> +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> @@ -0,0 +1,21 @@
> +/* Test case for wcsncmp inside a transactionally executing RTM region.
> + Copyright (C) 2021-2022 Free Software Foundation, Inc.
Please remove 2021-.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#define WIDE 1
> +#include <wchar.h>
> +#include "tst-strncmp-rtm.c"
> --
> 2.25.1
>
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 3:37 [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] Noah Goldstein
2022-02-18 3:54 ` H.J. Lu
2022-02-18 5:01 ` Noah Goldstein
@ 2022-02-18 19:59 ` Noah Goldstein
2022-02-18 20:14 ` H.J. Lu
2022-02-18 20:19 ` [PATCH v4] " Noah Goldstein
3 siblings, 1 reply; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 19:59 UTC (permalink / raw)
To: libc-alpha
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.
---
sysdeps/x86/Makefile | 5 ++++-
sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
3 files changed, 48 insertions(+), 10 deletions(-)
create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index d110f7b7f2..c6bee981f8 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -99,7 +99,9 @@ tests += \
tst-strcpy-rtm \
tst-strlen-rtm \
tst-strncmp-rtm \
- tst-strrchr-rtm
+ tst-strrchr-rtm \
+ tst-wcsncmp-rtm \
+# tests
CFLAGS-tst-memchr-rtm.c += -mrtm
CFLAGS-tst-memcmp-rtm.c += -mrtm
@@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
CFLAGS-tst-strlen-rtm.c += -mrtm
CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
CFLAGS-tst-strrchr-rtm.c += -mrtm
+CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
endif
ifneq ($(enable-cet),no)
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 9e20abaacc..b50c11e8d4 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -19,18 +19,32 @@
#include <stdint.h>
#include <tst-string-rtm.h>
+#ifdef WIDE
+# define CHAR wchar_t
+# define MEMSET wmemset
+# define STRNCMP wcsncmp
+# define TEST_NAME wcsncmp
+#else /* !WIDE */
+# define CHAR char
+# define MEMSET memset
+# define STRNCMP strncmp
+# define TEST_NAME strncmp
+#endif /* !WIDE */
+
+
+
#define LOOP 3000
#define STRING_SIZE 1024
-char string1[STRING_SIZE];
-char string2[STRING_SIZE];
+CHAR string1[STRING_SIZE];
+CHAR string2[STRING_SIZE];
__attribute__ ((noinline, noclone))
static int
prepare (void)
{
- memset (string1, 'a', STRING_SIZE - 1);
- memset (string2, 'a', STRING_SIZE - 1);
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ MEMSET (string1, 'a', STRING_SIZE - 1);
+ MEMSET (string2, 'a', STRING_SIZE - 1);
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
@@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
static int
function (void)
{
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return 0;
else
return 1;
@@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
static int
function_overflow (void)
{
- if (strncmp (string1, string2, SIZE_MAX) == 0)
+ if (STRNCMP (string1, string2, SIZE_MAX) == 0)
return 0;
else
return 1;
@@ -59,9 +73,9 @@ function_overflow (void)
static int
do_test (void)
{
- int status = do_test_1 ("strncmp", LOOP, prepare, function);
+ int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
if (status != EXIT_SUCCESS)
return status;
- status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+ status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
return status;
}
diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
new file mode 100644
index 0000000000..e9ab79ba76
--- /dev/null
+++ b/sysdeps/x86/tst-wcsncmp-rtm.c
@@ -0,0 +1,21 @@
+/* Test case for wcsncmp inside a transactionally executing RTM region.
+ Copyright (C) 2022-2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define WIDE 1
+#include <wchar.h>
+#include "tst-strncmp-rtm.c"
--
2.25.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 13:13 ` H.J. Lu
@ 2022-02-18 19:59 ` Noah Goldstein
0 siblings, 0 replies; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 19:59 UTC (permalink / raw)
To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell
On Fri, Feb 18, 2022 at 7:14 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Feb 17, 2022 at 9:01 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > 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.
> > ---
> > sysdeps/x86/Makefile | 5 ++++-
> > sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
> > sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
> > 3 files changed, 48 insertions(+), 10 deletions(-)
> > create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
> >
> > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > index d110f7b7f2..c6bee981f8 100644
> > --- a/sysdeps/x86/Makefile
> > +++ b/sysdeps/x86/Makefile
> > @@ -99,7 +99,9 @@ tests += \
> > tst-strcpy-rtm \
> > tst-strlen-rtm \
> > tst-strncmp-rtm \
> > - tst-strrchr-rtm
> > + tst-strrchr-rtm \
> > + tst-wcsncmp-rtm \
> > +# tests
> >
> > CFLAGS-tst-memchr-rtm.c += -mrtm
> > CFLAGS-tst-memcmp-rtm.c += -mrtm
> > @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> > CFLAGS-tst-strlen-rtm.c += -mrtm
> > CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > CFLAGS-tst-strrchr-rtm.c += -mrtm
> > +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> > endif
> >
> > ifneq ($(enable-cet),no)
> > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > index 9e20abaacc..b50c11e8d4 100644
> > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > @@ -19,18 +19,32 @@
> > #include <stdint.h>
> > #include <tst-string-rtm.h>
> >
> > +#ifdef WIDE
> > +# define CHAR wchar_t
> > +# define MEMSET wmemset
> > +# define STRNCMP wcsncmp
> > +# define TEST_NAME wcsncmp
> > +#else /* !WIDE */
> > +# define CHAR char
> > +# define MEMSET memset
> > +# define STRNCMP strncmp
> > +# define TEST_NAME strncmp
> > +#endif /* !WIDE */
> > +
> > +
> > +
> > #define LOOP 3000
> > #define STRING_SIZE 1024
> > -char string1[STRING_SIZE];
> > -char string2[STRING_SIZE];
> > +CHAR string1[STRING_SIZE];
> > +CHAR string2[STRING_SIZE];
> >
> > __attribute__ ((noinline, noclone))
> > static int
> > prepare (void)
> > {
> > - memset (string1, 'a', STRING_SIZE - 1);
> > - memset (string2, 'a', STRING_SIZE - 1);
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + MEMSET (string1, 'a', STRING_SIZE - 1);
> > + MEMSET (string2, 'a', STRING_SIZE - 1);
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return EXIT_SUCCESS;
> > else
> > return EXIT_FAILURE;
> > @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function (void)
> > {
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function_overflow (void)
> > {
> > - if (strncmp (string1, string2, SIZE_MAX) == 0)
> > + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -59,9 +73,9 @@ function_overflow (void)
> > static int
> > do_test (void)
> > {
> > - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> > if (status != EXIT_SUCCESS)
> > return status;
> > - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> > return status;
> > }
> > diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> > new file mode 100644
> > index 0000000000..3445de4bf9
> > --- /dev/null
> > +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> > @@ -0,0 +1,21 @@
> > +/* Test case for wcsncmp inside a transactionally executing RTM region.
> > + Copyright (C) 2021-2022 Free Software Foundation, Inc.
>
> Please remove 2021-.
Fixed.
>
> > + This file is part of the GNU C Library.
> > +
> > + The GNU C Library is free software; you can redistribute it and/or
> > + modify it under the terms of the GNU Lesser General Public
> > + License as published by the Free Software Foundation; either
> > + version 2.1 of the License, or (at your option) any later version.
> > +
> > + The GNU C Library is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + Lesser General Public License for more details.
> > +
> > + You should have received a copy of the GNU Lesser General Public
> > + License along with the GNU C Library; if not, see
> > + <https://www.gnu.org/licenses/>. */
> > +
> > +#define WIDE 1
> > +#include <wchar.h>
> > +#include "tst-strncmp-rtm.c"
> > --
> > 2.25.1
> >
>
> Thanks.
>
> --
> H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 19:59 ` [PATCH v3] " Noah Goldstein
@ 2022-02-18 20:14 ` H.J. Lu
2022-02-18 20:23 ` Noah Goldstein
0 siblings, 1 reply; 13+ messages in thread
From: H.J. Lu @ 2022-02-18 20:14 UTC (permalink / raw)
To: Noah Goldstein; +Cc: libc-alpha, carlos
On Fri, Feb 18, 2022 at 11:59 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 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.
> ---
> sysdeps/x86/Makefile | 5 ++++-
> sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
> sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
> 3 files changed, 48 insertions(+), 10 deletions(-)
> create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index d110f7b7f2..c6bee981f8 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -99,7 +99,9 @@ tests += \
> tst-strcpy-rtm \
> tst-strlen-rtm \
> tst-strncmp-rtm \
> - tst-strrchr-rtm
> + tst-strrchr-rtm \
> + tst-wcsncmp-rtm \
> +# tests
>
> CFLAGS-tst-memchr-rtm.c += -mrtm
> CFLAGS-tst-memcmp-rtm.c += -mrtm
> @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> CFLAGS-tst-strlen-rtm.c += -mrtm
> CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> CFLAGS-tst-strrchr-rtm.c += -mrtm
> +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> endif
>
> ifneq ($(enable-cet),no)
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index 9e20abaacc..b50c11e8d4 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -19,18 +19,32 @@
> #include <stdint.h>
> #include <tst-string-rtm.h>
>
> +#ifdef WIDE
> +# define CHAR wchar_t
> +# define MEMSET wmemset
> +# define STRNCMP wcsncmp
> +# define TEST_NAME wcsncmp
> +#else /* !WIDE */
> +# define CHAR char
> +# define MEMSET memset
> +# define STRNCMP strncmp
> +# define TEST_NAME strncmp
> +#endif /* !WIDE */
> +
> +
> +
> #define LOOP 3000
> #define STRING_SIZE 1024
> -char string1[STRING_SIZE];
> -char string2[STRING_SIZE];
> +CHAR string1[STRING_SIZE];
> +CHAR string2[STRING_SIZE];
>
> __attribute__ ((noinline, noclone))
> static int
> prepare (void)
> {
> - memset (string1, 'a', STRING_SIZE - 1);
> - memset (string2, 'a', STRING_SIZE - 1);
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + MEMSET (string1, 'a', STRING_SIZE - 1);
> + MEMSET (string2, 'a', STRING_SIZE - 1);
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return EXIT_SUCCESS;
> else
> return EXIT_FAILURE;
> @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
> static int
> function (void)
> {
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return 0;
> else
> return 1;
> @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
> static int
> function_overflow (void)
> {
> - if (strncmp (string1, string2, SIZE_MAX) == 0)
> + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> return 0;
> else
> return 1;
> @@ -59,9 +73,9 @@ function_overflow (void)
> static int
> do_test (void)
> {
> - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> if (status != EXIT_SUCCESS)
> return status;
> - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> return status;
> }
> diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> new file mode 100644
> index 0000000000..e9ab79ba76
> --- /dev/null
> +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> @@ -0,0 +1,21 @@
> +/* Test case for wcsncmp inside a transactionally executing RTM region.
> + Copyright (C) 2022-2022 Free Software Foundation, Inc.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It should be just 2022.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#define WIDE 1
> +#include <wchar.h>
> +#include "tst-strncmp-rtm.c"
> --
> 2.25.1
>
--
H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v4] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 3:37 [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] Noah Goldstein
` (2 preceding siblings ...)
2022-02-18 19:59 ` [PATCH v3] " Noah Goldstein
@ 2022-02-18 20:19 ` Noah Goldstein
2022-02-18 20:28 ` H.J. Lu
3 siblings, 1 reply; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 20:19 UTC (permalink / raw)
To: libc-alpha
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.
---
sysdeps/x86/Makefile | 5 ++++-
sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
3 files changed, 48 insertions(+), 10 deletions(-)
create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index d110f7b7f2..c6bee981f8 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -99,7 +99,9 @@ tests += \
tst-strcpy-rtm \
tst-strlen-rtm \
tst-strncmp-rtm \
- tst-strrchr-rtm
+ tst-strrchr-rtm \
+ tst-wcsncmp-rtm \
+# tests
CFLAGS-tst-memchr-rtm.c += -mrtm
CFLAGS-tst-memcmp-rtm.c += -mrtm
@@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
CFLAGS-tst-strlen-rtm.c += -mrtm
CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
CFLAGS-tst-strrchr-rtm.c += -mrtm
+CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
endif
ifneq ($(enable-cet),no)
diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
index 9e20abaacc..b50c11e8d4 100644
--- a/sysdeps/x86/tst-strncmp-rtm.c
+++ b/sysdeps/x86/tst-strncmp-rtm.c
@@ -19,18 +19,32 @@
#include <stdint.h>
#include <tst-string-rtm.h>
+#ifdef WIDE
+# define CHAR wchar_t
+# define MEMSET wmemset
+# define STRNCMP wcsncmp
+# define TEST_NAME wcsncmp
+#else /* !WIDE */
+# define CHAR char
+# define MEMSET memset
+# define STRNCMP strncmp
+# define TEST_NAME strncmp
+#endif /* !WIDE */
+
+
+
#define LOOP 3000
#define STRING_SIZE 1024
-char string1[STRING_SIZE];
-char string2[STRING_SIZE];
+CHAR string1[STRING_SIZE];
+CHAR string2[STRING_SIZE];
__attribute__ ((noinline, noclone))
static int
prepare (void)
{
- memset (string1, 'a', STRING_SIZE - 1);
- memset (string2, 'a', STRING_SIZE - 1);
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ MEMSET (string1, 'a', STRING_SIZE - 1);
+ MEMSET (string2, 'a', STRING_SIZE - 1);
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
@@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
static int
function (void)
{
- if (strncmp (string1, string2, STRING_SIZE) == 0)
+ if (STRNCMP (string1, string2, STRING_SIZE) == 0)
return 0;
else
return 1;
@@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
static int
function_overflow (void)
{
- if (strncmp (string1, string2, SIZE_MAX) == 0)
+ if (STRNCMP (string1, string2, SIZE_MAX) == 0)
return 0;
else
return 1;
@@ -59,9 +73,9 @@ function_overflow (void)
static int
do_test (void)
{
- int status = do_test_1 ("strncmp", LOOP, prepare, function);
+ int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
if (status != EXIT_SUCCESS)
return status;
- status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
+ status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
return status;
}
diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
new file mode 100644
index 0000000000..bad3b86378
--- /dev/null
+++ b/sysdeps/x86/tst-wcsncmp-rtm.c
@@ -0,0 +1,21 @@
+/* Test case for wcsncmp inside a transactionally executing RTM region.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define WIDE 1
+#include <wchar.h>
+#include "tst-strncmp-rtm.c"
--
2.25.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 20:14 ` H.J. Lu
@ 2022-02-18 20:23 ` Noah Goldstein
0 siblings, 0 replies; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 20:23 UTC (permalink / raw)
To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell
On Fri, Feb 18, 2022 at 2:15 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Feb 18, 2022 at 11:59 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 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.
> > ---
> > sysdeps/x86/Makefile | 5 ++++-
> > sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
> > sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
> > 3 files changed, 48 insertions(+), 10 deletions(-)
> > create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
> >
> > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > index d110f7b7f2..c6bee981f8 100644
> > --- a/sysdeps/x86/Makefile
> > +++ b/sysdeps/x86/Makefile
> > @@ -99,7 +99,9 @@ tests += \
> > tst-strcpy-rtm \
> > tst-strlen-rtm \
> > tst-strncmp-rtm \
> > - tst-strrchr-rtm
> > + tst-strrchr-rtm \
> > + tst-wcsncmp-rtm \
> > +# tests
> >
> > CFLAGS-tst-memchr-rtm.c += -mrtm
> > CFLAGS-tst-memcmp-rtm.c += -mrtm
> > @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> > CFLAGS-tst-strlen-rtm.c += -mrtm
> > CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > CFLAGS-tst-strrchr-rtm.c += -mrtm
> > +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> > endif
> >
> > ifneq ($(enable-cet),no)
> > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > index 9e20abaacc..b50c11e8d4 100644
> > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > @@ -19,18 +19,32 @@
> > #include <stdint.h>
> > #include <tst-string-rtm.h>
> >
> > +#ifdef WIDE
> > +# define CHAR wchar_t
> > +# define MEMSET wmemset
> > +# define STRNCMP wcsncmp
> > +# define TEST_NAME wcsncmp
> > +#else /* !WIDE */
> > +# define CHAR char
> > +# define MEMSET memset
> > +# define STRNCMP strncmp
> > +# define TEST_NAME strncmp
> > +#endif /* !WIDE */
> > +
> > +
> > +
> > #define LOOP 3000
> > #define STRING_SIZE 1024
> > -char string1[STRING_SIZE];
> > -char string2[STRING_SIZE];
> > +CHAR string1[STRING_SIZE];
> > +CHAR string2[STRING_SIZE];
> >
> > __attribute__ ((noinline, noclone))
> > static int
> > prepare (void)
> > {
> > - memset (string1, 'a', STRING_SIZE - 1);
> > - memset (string2, 'a', STRING_SIZE - 1);
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + MEMSET (string1, 'a', STRING_SIZE - 1);
> > + MEMSET (string2, 'a', STRING_SIZE - 1);
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return EXIT_SUCCESS;
> > else
> > return EXIT_FAILURE;
> > @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function (void)
> > {
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function_overflow (void)
> > {
> > - if (strncmp (string1, string2, SIZE_MAX) == 0)
> > + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -59,9 +73,9 @@ function_overflow (void)
> > static int
> > do_test (void)
> > {
> > - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> > if (status != EXIT_SUCCESS)
> > return status;
> > - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> > return status;
> > }
> > diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> > new file mode 100644
> > index 0000000000..e9ab79ba76
> > --- /dev/null
> > +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> > @@ -0,0 +1,21 @@
> > +/* Test case for wcsncmp inside a transactionally executing RTM region.
> > + Copyright (C) 2022-2022 Free Software Foundation, Inc.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> It should be just 2022.
Sorry, fixed...
>
> > + This file is part of the GNU C Library.
> > +
> > + The GNU C Library is free software; you can redistribute it and/or
> > + modify it under the terms of the GNU Lesser General Public
> > + License as published by the Free Software Foundation; either
> > + version 2.1 of the License, or (at your option) any later version.
> > +
> > + The GNU C Library is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + Lesser General Public License for more details.
> > +
> > + You should have received a copy of the GNU Lesser General Public
> > + License along with the GNU C Library; if not, see
> > + <https://www.gnu.org/licenses/>. */
> > +
> > +#define WIDE 1
> > +#include <wchar.h>
> > +#include "tst-strncmp-rtm.c"
> > --
> > 2.25.1
> >
>
>
> --
> H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 20:19 ` [PATCH v4] " Noah Goldstein
@ 2022-02-18 20:28 ` H.J. Lu
2022-02-18 22:45 ` Noah Goldstein
0 siblings, 1 reply; 13+ messages in thread
From: H.J. Lu @ 2022-02-18 20:28 UTC (permalink / raw)
To: Noah Goldstein; +Cc: libc-alpha, carlos
On Fri, Feb 18, 2022 at 12:19 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> 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.
> ---
> sysdeps/x86/Makefile | 5 ++++-
> sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
> sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
> 3 files changed, 48 insertions(+), 10 deletions(-)
> create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index d110f7b7f2..c6bee981f8 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -99,7 +99,9 @@ tests += \
> tst-strcpy-rtm \
> tst-strlen-rtm \
> tst-strncmp-rtm \
> - tst-strrchr-rtm
> + tst-strrchr-rtm \
> + tst-wcsncmp-rtm \
> +# tests
>
> CFLAGS-tst-memchr-rtm.c += -mrtm
> CFLAGS-tst-memcmp-rtm.c += -mrtm
> @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> CFLAGS-tst-strlen-rtm.c += -mrtm
> CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> CFLAGS-tst-strrchr-rtm.c += -mrtm
> +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> endif
>
> ifneq ($(enable-cet),no)
> diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> index 9e20abaacc..b50c11e8d4 100644
> --- a/sysdeps/x86/tst-strncmp-rtm.c
> +++ b/sysdeps/x86/tst-strncmp-rtm.c
> @@ -19,18 +19,32 @@
> #include <stdint.h>
> #include <tst-string-rtm.h>
>
> +#ifdef WIDE
> +# define CHAR wchar_t
> +# define MEMSET wmemset
> +# define STRNCMP wcsncmp
> +# define TEST_NAME wcsncmp
> +#else /* !WIDE */
> +# define CHAR char
> +# define MEMSET memset
> +# define STRNCMP strncmp
> +# define TEST_NAME strncmp
> +#endif /* !WIDE */
> +
> +
> +
> #define LOOP 3000
> #define STRING_SIZE 1024
> -char string1[STRING_SIZE];
> -char string2[STRING_SIZE];
> +CHAR string1[STRING_SIZE];
> +CHAR string2[STRING_SIZE];
>
> __attribute__ ((noinline, noclone))
> static int
> prepare (void)
> {
> - memset (string1, 'a', STRING_SIZE - 1);
> - memset (string2, 'a', STRING_SIZE - 1);
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + MEMSET (string1, 'a', STRING_SIZE - 1);
> + MEMSET (string2, 'a', STRING_SIZE - 1);
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return EXIT_SUCCESS;
> else
> return EXIT_FAILURE;
> @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
> static int
> function (void)
> {
> - if (strncmp (string1, string2, STRING_SIZE) == 0)
> + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> return 0;
> else
> return 1;
> @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
> static int
> function_overflow (void)
> {
> - if (strncmp (string1, string2, SIZE_MAX) == 0)
> + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> return 0;
> else
> return 1;
> @@ -59,9 +73,9 @@ function_overflow (void)
> static int
> do_test (void)
> {
> - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> if (status != EXIT_SUCCESS)
> return status;
> - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> return status;
> }
> diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> new file mode 100644
> index 0000000000..bad3b86378
> --- /dev/null
> +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> @@ -0,0 +1,21 @@
> +/* Test case for wcsncmp inside a transactionally executing RTM region.
> + Copyright (C) 2022 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#define WIDE 1
> +#include <wchar.h>
> +#include "tst-strncmp-rtm.c"
> --
> 2.25.1
>
LGTM.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
2022-02-18 20:28 ` H.J. Lu
@ 2022-02-18 22:45 ` Noah Goldstein
0 siblings, 0 replies; 13+ messages in thread
From: Noah Goldstein @ 2022-02-18 22:45 UTC (permalink / raw)
To: H.J. Lu; +Cc: GNU C Library, Carlos O'Donell
On Fri, Feb 18, 2022 at 2:29 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Feb 18, 2022 at 12:19 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > 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.
> > ---
> > sysdeps/x86/Makefile | 5 ++++-
> > sysdeps/x86/tst-strncmp-rtm.c | 32 +++++++++++++++++++++++---------
> > sysdeps/x86/tst-wcsncmp-rtm.c | 21 +++++++++++++++++++++
> > 3 files changed, 48 insertions(+), 10 deletions(-)
> > create mode 100644 sysdeps/x86/tst-wcsncmp-rtm.c
> >
> > diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> > index d110f7b7f2..c6bee981f8 100644
> > --- a/sysdeps/x86/Makefile
> > +++ b/sysdeps/x86/Makefile
> > @@ -99,7 +99,9 @@ tests += \
> > tst-strcpy-rtm \
> > tst-strlen-rtm \
> > tst-strncmp-rtm \
> > - tst-strrchr-rtm
> > + tst-strrchr-rtm \
> > + tst-wcsncmp-rtm \
> > +# tests
> >
> > CFLAGS-tst-memchr-rtm.c += -mrtm
> > CFLAGS-tst-memcmp-rtm.c += -mrtm
> > @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm
> > CFLAGS-tst-strlen-rtm.c += -mrtm
> > CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
> > CFLAGS-tst-strrchr-rtm.c += -mrtm
> > +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error
> > endif
> >
> > ifneq ($(enable-cet),no)
> > diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c
> > index 9e20abaacc..b50c11e8d4 100644
> > --- a/sysdeps/x86/tst-strncmp-rtm.c
> > +++ b/sysdeps/x86/tst-strncmp-rtm.c
> > @@ -19,18 +19,32 @@
> > #include <stdint.h>
> > #include <tst-string-rtm.h>
> >
> > +#ifdef WIDE
> > +# define CHAR wchar_t
> > +# define MEMSET wmemset
> > +# define STRNCMP wcsncmp
> > +# define TEST_NAME wcsncmp
> > +#else /* !WIDE */
> > +# define CHAR char
> > +# define MEMSET memset
> > +# define STRNCMP strncmp
> > +# define TEST_NAME strncmp
> > +#endif /* !WIDE */
> > +
> > +
> > +
> > #define LOOP 3000
> > #define STRING_SIZE 1024
> > -char string1[STRING_SIZE];
> > -char string2[STRING_SIZE];
> > +CHAR string1[STRING_SIZE];
> > +CHAR string2[STRING_SIZE];
> >
> > __attribute__ ((noinline, noclone))
> > static int
> > prepare (void)
> > {
> > - memset (string1, 'a', STRING_SIZE - 1);
> > - memset (string2, 'a', STRING_SIZE - 1);
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + MEMSET (string1, 'a', STRING_SIZE - 1);
> > + MEMSET (string2, 'a', STRING_SIZE - 1);
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return EXIT_SUCCESS;
> > else
> > return EXIT_FAILURE;
> > @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function (void)
> > {
> > - if (strncmp (string1, string2, STRING_SIZE) == 0)
> > + if (STRNCMP (string1, string2, STRING_SIZE) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone))
> > static int
> > function_overflow (void)
> > {
> > - if (strncmp (string1, string2, SIZE_MAX) == 0)
> > + if (STRNCMP (string1, string2, SIZE_MAX) == 0)
> > return 0;
> > else
> > return 1;
> > @@ -59,9 +73,9 @@ function_overflow (void)
> > static int
> > do_test (void)
> > {
> > - int status = do_test_1 ("strncmp", LOOP, prepare, function);
> > + int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
> > if (status != EXIT_SUCCESS)
> > return status;
> > - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
> > + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
> > return status;
> > }
> > diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c
> > new file mode 100644
> > index 0000000000..bad3b86378
> > --- /dev/null
> > +++ b/sysdeps/x86/tst-wcsncmp-rtm.c
> > @@ -0,0 +1,21 @@
> > +/* Test case for wcsncmp inside a transactionally executing RTM region.
> > + Copyright (C) 2022 Free Software Foundation, Inc.
> > + This file is part of the GNU C Library.
> > +
> > + The GNU C Library is free software; you can redistribute it and/or
> > + modify it under the terms of the GNU Lesser General Public
> > + License as published by the Free Software Foundation; either
> > + version 2.1 of the License, or (at your option) any later version.
> > +
> > + The GNU C Library is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + Lesser General Public License for more details.
> > +
> > + You should have received a copy of the GNU Lesser General Public
> > + License along with the GNU C Library; if not, see
> > + <https://www.gnu.org/licenses/>. */
> > +
> > +#define WIDE 1
> > +#include <wchar.h>
> > +#include "tst-strncmp-rtm.c"
> > --
> > 2.25.1
> >
>
> LGTM.
>
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Thanks pushed.
>
> Thanks.
>
> --
> H.J.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-02-18 22:45 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-18 3:37 [PATCH v1] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] Noah Goldstein
2022-02-18 3:54 ` H.J. Lu
2022-02-18 3:58 ` H.J. Lu
2022-02-18 5:02 ` Noah Goldstein
2022-02-18 5:01 ` Noah Goldstein
2022-02-18 13:13 ` H.J. Lu
2022-02-18 19:59 ` Noah Goldstein
2022-02-18 19:59 ` [PATCH v3] " Noah Goldstein
2022-02-18 20:14 ` H.J. Lu
2022-02-18 20:23 ` Noah Goldstein
2022-02-18 20:19 ` [PATCH v4] " Noah Goldstein
2022-02-18 20:28 ` H.J. Lu
2022-02-18 22:45 ` Noah Goldstein
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).