public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: Stable GNU C Library <libc-stable@sourceware.org>
Subject: Re: [Backport PATCH 2/2] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
Date: Fri, 18 Feb 2022 15:26:24 -0800	[thread overview]
Message-ID: <CAMe9rOp4j7kohr_gdzn0UnvkBd4Z76zcZKcr9Sa1TuVbO+y5EA@mail.gmail.com> (raw)
In-Reply-To: <CAFUsyfJ60ahM-nPxDAL6iZQVCPxMEkUpM9jq1rNiBvNKQs_bHg@mail.gmail.com>

On Fri, Feb 18, 2022 at 3:01 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Fri, Feb 18, 2022 at 4:56 PM H.J. Lu <hjl.tools@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.
> > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> >
> > (cherry picked from commit 7835d611af0854e69a0c71e3806f8fe379282d6f)
> > ---
> >  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
>
> This is not a string
> > +#else /* !WIDE */
> > +# define CHAR char
> > +# define MEMSET memset
> > +# define STRNCMP strncmp
> > +# define TEST_NAME strncmp
>
> This is not a string
>
> Please apply:
> https://patchwork.sourceware.org/project/glibc/patch/20220218230025.3505625-1-goldstein.w.n@gmail.com/

I am backporting it now.

Thanks.

> > +#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.35.1
> >



-- 
H.J.

      reply	other threads:[~2022-02-18 23:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 22:56 H.J. Lu
2022-02-18 23:01 ` Noah Goldstein
2022-02-18 23:26   ` H.J. Lu [this message]

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=CAMe9rOp4j7kohr_gdzn0UnvkBd4Z76zcZKcr9Sa1TuVbO+y5EA@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=goldstein.w.n@gmail.com \
    --cc=libc-stable@sourceware.org \
    /path/to/YOUR_REPLY

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

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