From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50081.outbound.protection.outlook.com [40.107.5.81]) by sourceware.org (Postfix) with ESMTPS id 6031138515C5 for ; Fri, 20 May 2022 10:35:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6031138515C5 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=BjQZCGY8dWpXh9Kge7B15coR83WkPCo+U5kntxUZDjJgJZqCA8W+wl4SzV0CtJ8Fil+Myfrcx7rxAB4AHopnbxV/8RgRKsG68WKagz8VKU35gp7bYKgIarvG+kkZ9i4pJPkDXAA3KT1wm3QJtFLrQk+T7keDzKVDKvvSzSGuBZJ+a3tQ8vPtuLwc1ro/oVyGFKrdC1j2k8lC9GGI3ZdQnFsaKQjlIPiyQOY8AFD0+xN3xurv0qpB6+RNs0Xy/8fk7JNt4P8h3sw2qTVkfDADKvEeYDzRIKI+Jbr+RnTyzgGGC5ugV5jJGv+fACd4M4J0hozO+hsehqYeNUFPEqXtuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I4pL/7ZMpgxZekWmkrSTm92mK6vPjW3NXcLZI/iOh/k=; b=MdNbfBBrknEF4kXoTg9tcaOuzGgLvp3Uck9jBAQWs5WlYtbEyn0tbxEWo5rKhHRWf+nOd3/y8aqM/2skwbstOLjMLjOYn8xmqxu3XcSz29bWxxkeDJy7PE509EyNZghoR7MJpAqXj1hjRNl0Mkh4ja6ghCmlkLZ1jNrbUX/8/TnaumzQNBGBRhy4LXL7NNfjXGQ/GACu5DSjsBYpJODbpg/55R9Ha5P6N+lW4SAk8lecQ7Xv5E8GY3VdLR3fX03PLsNFGiI2pYeH6sx7BsSGUWsO08fK9M3+RXYKTvtvbM9Dg5i9Wbc4TBIQh7+Kk96BwTP9ji+T7kTr4fbK7zEnrQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AS9PR06CA0290.eurprd06.prod.outlook.com (2603:10a6:20b:45a::8) by AM0PR08MB3331.eurprd08.prod.outlook.com (2603:10a6:208:5b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Fri, 20 May 2022 10:35:09 +0000 Received: from AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45a:cafe::4b) by AS9PR06CA0290.outlook.office365.com (2603:10a6:20b:45a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.15 via Frontend Transport; Fri, 20 May 2022 10:35:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT038.mail.protection.outlook.com (10.152.17.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14 via Frontend Transport; Fri, 20 May 2022 10:35:09 +0000 Received: ("Tessian outbound 42cead292588:v119"); Fri, 20 May 2022 10:35:08 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 77efd4425bc609bc X-CR-MTA-TID: 64aa7808 Received: from 3cd36e4c5466.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0D9F4CE6-1DC1-47C6-9F1F-2893F416DEB1.1; Fri, 20 May 2022 10:35:02 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3cd36e4c5466.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 20 May 2022 10:35:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WZeMQW6hO/Bazf8VYPKL9UINBK7pvfjkLUgMMvLGdSPs/BFFao2ASdNwACj+Xm9iyjMtbnoOPU9WixOqRHtnzO92rSpI9pGZWGACT4e/34Dg2vkFYrxOLgDXQ/pzGMmPYdBt0AqF4I0Za3RwGgx1aC0hLIBdacc5qHsnZrYoAk65WCtTSFBkrESNxdnI9aRAsu8rXV9jXJtcLKhumWr9zM+KCcMquey671jfyOKUwsXOPTIKh6Kmwm/dB+ewhUZjPaFN9RMpxgTpZ7RACZODZaUW4/IbC+1w6PF0Ej/sOWuz5cojblMmZJ9i4DnY47dM0hhGt4oPxRhjKxYgmNircA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I4pL/7ZMpgxZekWmkrSTm92mK6vPjW3NXcLZI/iOh/k=; b=N6Q11xLoL6ataXlNmv023TIpLEvo9lb0wQq4mTZhzDoqU0o0aKLxSj+GMUC315+kmVxMvCrZnuAkVaxgRU3GjbxfAJha/oeC1seCDwFzGKsYV250jG5T8Yau3STy1YBvpqfvUwE9pc7g9EH7baU5eNtk4HVq6BdGnip70chevSh2ZmFirXlq1YA0vxN78qvJcpyVYuFSae7503F3t15Pj425M+AyAGiX9u3vmKQURc9upZH+QFx4WT9Q45M+wvFVvb6NwjlL1eE3fJqhIkIACnvYPPi5oXh9Zzs/T2t2gKtLfgds68qtahjV2t2pMRFQa0G9tpWkZJh2T8KLqAVuwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from DB6PR0801MB1879.eurprd08.prod.outlook.com (2603:10a6:4:73::9) by DB8PR08MB5020.eurprd08.prod.outlook.com (2603:10a6:10:e3::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.17; Fri, 20 May 2022 10:34:59 +0000 Received: from DB6PR0801MB1879.eurprd08.prod.outlook.com ([fe80::4c79:5ff3:ff33:7ee1]) by DB6PR0801MB1879.eurprd08.prod.outlook.com ([fe80::4c79:5ff3:ff33:7ee1%11]) with mapi id 15.20.5273.016; Fri, 20 May 2022 10:34:58 +0000 From: Wilco Dijkstra To: Adhemerval Zanella CC: 'GNU C Library' Subject: Re: [PATCH] Avoid RMW of flags2 outside lock (BZ #27842) Thread-Topic: [PATCH] Avoid RMW of flags2 outside lock (BZ #27842) Thread-Index: AQHYa5JSAJa6BcYBU0GjgjmKmoALd60mWGSAgAAGLkOAAA01AIABHlqn Date: Fri, 20 May 2022 10:34:58 +0000 Message-ID: References: <7d120257-c779-ee56-932d-17738067f0ea@linaro.org> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-MS-Office365-Filtering-Correlation-Id: bf12f787-f808-4d40-fe0c-08da3a4c69af x-ms-traffictypediagnostic: DB8PR08MB5020:EE_|AM5EUR03FT038:EE_|AM0PR08MB3331:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: N9Neu6YTZiZUym9+0qfkE2XVXbo6k2JzWfmivsgIky8vyV+KoGHJoQd/CVhj1dUqutE1B+9YhArcNlEMMjvhQkDaz37kzXQj4aKAYVEMRhVDXM2zb4xoAtEyaZqaezUyR9QwgZp4dwN83vdHfIiw3FqzfPxyql1fhoI9X3IAGFe8cwtDyjcBQrxG351+hArDjcRqJqXxFwOK1E9J9uNjyCNTQfZt6tPoaovvbAY7GQt7Jzh13C6d/6nunnyYDUZ4cxz3ur4xFGGeasQvcRbefaTKHoMsZYYd4cf/XeMfPEDrhivZU25DJhVzO0o2+9rvCDxANQ05tOhP3QxFHUb4IbLV/GagN6c0BHHfGhtSlVOeC3w5BuXlt1Qd74uIAuohTYqDB+gP5jIM9zxM9/B9s4CBgAelQ0+MANjUeQ96kxVAzpTEavjH6lsaNVRsogVwvkPy62CZIJXG7/glAbi3WaMEAhNsDciGqoDuTza9QWxaSvqFqbru4Wm/Yjdkq2OTVHRFjpwwPEA6NFb0lnf2/2gEdFmE+a5EDmdlLJFYo5tb8YEdX5AGO4u/HbqWsea4cCHnlb6QVUoc1myToTEkxX0wF0zTYX3EyBwk97AQYltuJ5lBIEhEBF14judUoV6ZR/OERsCoz6pMb4xJD3C6SDDCgzkBVd6tX2boBWLOa0kaMAWpH5G9dPWSoQmgLOyXnluDIYj9Ft69h2bNeUpQjA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0801MB1879.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(4326008)(76116006)(66946007)(66556008)(66446008)(2906002)(8676002)(33656002)(91956017)(66476007)(26005)(9686003)(6916009)(64756008)(316002)(71200400001)(6506007)(186003)(8936002)(7696005)(55016003)(38100700002)(86362001)(5660300002)(38070700005)(83380400001)(122000001)(52536014)(508600001); DIR:OUT; SFP:1101; Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5020 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7f3d9264-d4a8-490b-5b9c-08da3a4c6376 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /l4GYwyDciVFaqYjnf0AwWKDP7irqbS1+k9Ca86AcgTEW4oEhGhKIeKx/ljfsKiHAniQ730OybN/d+rigWYbZAStXh/lpd5BijGNBttWUT2MLHC7mYqcVNPk9u/l8B+1Riwx7zSRbKTIfQAmVtpXVPKW4gvPJZanUi3Cc3MgXOMoJVjSz/JZCy52SXK5/v9COz+AaKtGrEIW2fOLaLW12JcOAfaFAAqa+6ElIVYYtN+k9OEXQ4Ox9c1QHtZK7XVzAz+ar/p7ubBu7KZGbuiuAN0224Plo+alHdhrLOADhZDNpu991D2Nl5tv9Evucg7kTG/85hWFsrZUXeaxwCv4sn0qiML7GnrUio2znBS5tE+TaxGhoG87GqBEORjDTFM5CotyFVfmWZZtrbv/fPuK6+LxZkBwI3isv1xkTRq5Vgipg4pc7bvtaRzEXSkxWUIhtf11UcfVMKp8C5yvNyWQ2Jwk6jUG+Vgv4NPj2K9TxrBqSCQl4LOx5QbsekGPzNs8ZuQEb/xQ1nZq3UV4rNiGLF2FSBEFVJWVkE3v5robFXWU07XmG0MvdtRQWEuca8k7n5grjOaHB8lUVpwjXvpjS2kgUiFKPhTjK25Lk9JU6OojpIpNnKO3ZkMB1CS5O4pClxkCIjGD3xAyw9SamfBJuAiWEiGzHvaeqGKT4WYbb3VMGJXa1g1ZGkxTdW+BOZ3S X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(508600001)(8936002)(316002)(26005)(9686003)(36860700001)(82310400005)(33656002)(40460700003)(186003)(6862004)(86362001)(55016003)(81166007)(83380400001)(70586007)(8676002)(6506007)(4326008)(5660300002)(356005)(7696005)(70206006)(47076005)(2906002)(336012)(52536014); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2022 10:35:09.0944 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf12f787-f808-4d40-fe0c-08da3a4c69af X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3331 X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-List-Received-Date: Fri, 20 May 2022 10:35:18 -0000 Hi Adhemerval,=0A= =0A= > I am trying to see why exactly we need to disable single-thread optimizat= ion=0A= > on flockfile, since there is no FILE operation that takes a callback wher= e=0A= > pthread_create might be called beween _IO_acquire_lock.=A0 Can't we just = remove=0A= > the _IO_FLAGS2_NEED_LOCK set on flockfile?=0A= =0A= Yes we could. I don't believe you could actually notice the difference - re= cursion=0A= or starting a thread before funlockfile would work fine.=0A= =0A= >> Right so you mean moving NEED_LOCK bit into the lock variable?=0A= >=0A= > Yes, and making the lock smaller on linux (just a word plus the recursive= counter).=0A= =0A= OK, it will be interesting to see how that works out. Any lock speedup will= be=0A= good, however I guess that recursive locks will remain quite expensive. By = design=0A= the single-thread optimization does not need to support things like trylock= ,=0A= recursion or starting a new thread, and that is a huge advantage.=0A= =0A= > You mean as it is now? It is a real bug since various functions update fl= ags2=0A= > behind a lock, so it is possible for this RMW to cause corruption (but on= ly if=0A= > you are already multithreaded, which the update is pointless anyway and w= e=0A= > can just skip it).=0A= =0A= > I don't think it would be possible to corrupt because once pthread_create= =0A= > is called, _IO_FLAGS2_NEED_LOCK will be always set (so RMW won't see a=0A= > __flags2 without _IO_FLAGS2_NEED_LOCK being set).=0A= =0A= The issue is not corruption of _IO_FLAGS2_NEED_LOCK but of a different flag= .=0A= Several IO functions may set or clear bits in flag2. So we could get a race= =0A= between RMW sequences setting/clearing different bits - if there is any ove= rlap=0A= one of the updates may be lost.=0A= =0A= Cheers,=0A= Wilco=0A=