From patchwork Thu Feb 17 19:12:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1594469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=OfLh4T/i; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K04GW6kFsz9sFr for ; Fri, 18 Feb 2022 06:12:51 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14E4D3858D20 for ; Thu, 17 Feb 2022 19:12:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14E4D3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1645125169; bh=NJlJZM1IWiZZEueSlOm+W1gQcaqVNqO6KCo3GQpi2Y0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OfLh4T/i8l0C/fznwqi0OM2PvyI1LcaLcAbKhtwPLZU36n/5ReFTm0VNV2bC8OVQR fbjmfd04VQePbawIk8Qy4miYW0ArqkGxhpZ3FnOKwClO4tGGvyV0G2Nna69opr+FNy 4ZAkim5+HCiU5d6VW6z3unR2ov3W/p36irbfrgO8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 8A3EB3858D20 for ; Thu, 17 Feb 2022 19:12:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A3EB3858D20 Received: by mail-il1-x12a.google.com with SMTP id j5so290979ila.2 for ; Thu, 17 Feb 2022 11:12:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NJlJZM1IWiZZEueSlOm+W1gQcaqVNqO6KCo3GQpi2Y0=; b=H35o7iegADDlQG3Tz3lffFqi6rLFi/XWAs3NsgBi9bboppexO706XW7gOYmd2o28CA +2YixcQsWXCLE+3tHUtXvuE9gWreA/Qu9hjqHHizEqkfkPYUmuKUC0/zQYvF5Ry8QP4V uoOJEpBMEDPaOp14wryLTs52z70corUTfvR28I9EWHt1YMWa5pQ9RZ2kgEReku6bz6wy AxW/zjagbAYx0x6NP4AireUx54TwqLiGLWX+Eab2uZskKV7E4AYqkU5imXajxhm4e1a1 DtYi7YtgiHZqG5Oc2bIBZtNmN2KxF9UH/Nv7X8P9F4ulXL1snLOGVdIsFMwgUKUxlci7 1K5w== X-Gm-Message-State: AOAM533FrttOdxx4C6gSx0AInXchKGXhhbyswzQkTSO0YQnkm6IHfOvZ +eaP4OmdMbayMu++2EkDfLVaN8ISZ6g= X-Google-Smtp-Source: ABdhPJxf3d8nSENDqD5+JtTezyHY93zy+huVsj4uUVcInk3xRd0WPZKs9nMQW3EK+rcfvyfjxOGXnw== X-Received: by 2002:a05:6e02:184c:b0:2bf:f389:1f99 with SMTP id b12-20020a056e02184c00b002bff3891f99mr3027677ilv.22.1645125153533; Thu, 17 Feb 2022 11:12:33 -0800 (PST) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id d16sm2558106iow.13.2022.02.17.11.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 11:12:33 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v4] x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] Date: Thu, 17 Feb 2022 13:12:26 -0600 Message-Id: <20220217191226.2960676-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215162751.281955-1-goldstein.w.n@gmail.com> References: <20220215162751.281955-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "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 . */ +#include +#include #include #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"