Bug 29127 - Incomplete backport causes tst-{strncmp,wcsncmp}-rtm to fail
Summary: Incomplete backport causes tst-{strncmp,wcsncmp}-rtm to fail
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: string (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-07 01:17 UTC by Adam Sampson
Modified: 2022-05-26 03:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
Sample fix for 2.35 branch (673 bytes, patch)
2022-05-07 01:17 UTC, Adam Sampson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Sampson 2022-05-07 01:17:36 UTC
Created attachment 14093 [details]
Sample fix for 2.35 branch

The commit c6272098323153db373f2986c67786ea8c85f1cf ("x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]") was backported as fd412fff6d2bd322ec24ebd13fab196efc6c5506 to the 2.35 branch, but the backported version doesn't cover all of the fallback cases in the original commit. (Looking at #28896, maybe the original version got backported rather than the revised version that went into master?)

On my i7-9700KF, this causes string/tst-strncmp-rtm and string/tst-wcsncmp-rtm to fail with:
      
error: ../sysdeps/x86/tst-string-rtm.h:63: TSX abort rate: 100.00% (3000 out of 3000)

I've attached an example patch to fix this for 2.35 - just making the appropriate bit of sysdeps/x86_64/multiarch/strcmp-avx2.S match what's now in master - but a similar fix probably needs applying to the other release branches too.
Comment 1 Noah Goldstein 2022-05-23 15:25:56 UTC
Seems to be missing:

https://sourceware.org/git/?p=glibc.git;a=commit;h=fd412fff6d2bd322ec24ebd13fab196efc6c5506

commit c6272098323153db373f2986c67786ea8c85f1cf
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Tue Feb 15 08:18:15 2022 -0600

    x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
Comment 2 Sourceware Commits 2022-05-25 22:03:09 UTC
The release/2.35/master branch has been updated by Sunil Pandey <skpgkp2@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ac87df8d750b0734e20ffb82d1d0d0efbe4b6212

commit ac87df8d750b0734e20ffb82d1d0d0efbe4b6212
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Tue Feb 15 08:18:15 2022 -0600

    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)
Comment 3 Sourceware Commits 2022-05-25 23:08:27 UTC
The release/2.34/master branch has been updated by Sunil Pandey <skpgkp2@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=83ae8287c1c3009459ff29241b647ff61363b22c

commit 83ae8287c1c3009459ff29241b647ff61363b22c
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Tue Feb 15 08:18:15 2022 -0600

    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)
Comment 4 Sourceware Commits 2022-05-25 23:11:37 UTC
The release/2.33/master branch has been updated by Sunil Pandey <skpgkp2@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=69f16619e7119e26d70c00ac8b8750ed350147a3

commit 69f16619e7119e26d70c00ac8b8750ed350147a3
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Tue Feb 15 08:18:15 2022 -0600

    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)
Comment 5 Adam Sampson 2022-05-25 23:24:27 UTC
Excellent - I can confirm the 2.35 branch fix works for me. Thanks very much!
Comment 6 H.J. Lu 2022-05-26 03:01:48 UTC
Fixed on 2.35 branch.