From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id A231C3858402 for ; Fri, 18 Feb 2022 22:56:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A231C3858402 Received: by mail-pl1-x62d.google.com with SMTP id u5so8277704ple.3 for ; Fri, 18 Feb 2022 14:56:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=3ld1VrSWUHoMH8dBiVbPQ9ywz313QMGOpBxRIsXJ5KU=; b=mE1LqkF17a2nyYIYTjB1e2JQ26QDVRFsooBKqsyJJ7dECtLRs5LWui8KWgqpMV2C/B PiyyOqhPvxDzh2UzIGKQu7SZTiufqPY76wuhEtLS0unpPpvoRmg5qmvjNDHSs/I7wy8H 6Pb76OxUB4ToUVNjDt/Vl2QjLokUYfiLPAR01AtIrjXCo8V978sRUPcUYnxShBKui5gD x2YNjz49Ypt/sI2FYBlZI+ovgW9eJe5rBtR8k3fiL1058uaMvQj0u9opJuxPyk3wkKj6 Y1ZOMCmiCOU0kIkf4YTYCPI9hJMA2aW5cMoNaJ0ZovnfDiYqF1xh0Snfu0O/XTYu7P4t vzmw== X-Gm-Message-State: AOAM530zIik21b/d5nADYThbhzGwIIdKvORPYV834Mq57pczWnagH6cV 2NBm6j9wZVbyF9sdO3UJLCFCxjbhlyI= X-Google-Smtp-Source: ABdhPJwmVSLyHDuR7TU9zVO9vZAx2N7B7YrHwL8x40JnbINYGG8akmWigkesvY4/eeA4ILO5jZH4zQ== X-Received: by 2002:a17:902:ef4c:b0:14f:7548:dae3 with SMTP id e12-20020a170902ef4c00b0014f7548dae3mr5551838plx.92.1645224976300; Fri, 18 Feb 2022 14:56:16 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id l16sm368887pjy.14.2022.02.18.14.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 14:56:15 -0800 (PST) Received: by gnu-tgl-3.localdomain (Postfix, from userid 1000) id ED136C03A8; Fri, 18 Feb 2022 14:56:14 -0800 (PST) Date: Fri, 18 Feb 2022 14:56:14 -0800 From: "H.J. Lu" To: Stable GNU C Library Subject: [Backport PATCH 2/2] x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3029.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Feb 2022 22:56:21 -0000 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 (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 #include +#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 + . */ + +#define WIDE 1 +#include +#include "tst-strncmp-rtm.c" -- 2.35.1