Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3877420pxv; Mon, 5 Jul 2021 07:54:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyd5F1kw3RKx3ofrPxh+FswFEu+8AWKIrZik6h1CGxStUULea5jAsAy9nb6uveE2V79/hnd X-Received: by 2002:a02:b60b:: with SMTP id h11mr12834398jam.46.1625496870143; Mon, 05 Jul 2021 07:54:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1625496870; cv=pass; d=google.com; s=arc-20160816; b=QzVzBYGszGflZciWkdPO1xcjUcIeVohF4p5X7HBkKc+opMW6eUy8Roq49PewQvRotV CUJLXq/5gXT+Zz2fs5jpAgIiwz+DZ/rInhDi57skNbVKH8UlpJugojZbWtjFOOAUc50i uWltitVysOla6mTn5tSeMHRW1dB8cUe3KDq6cMvbsGUbGf3fWL8JQVL7loI7nmHwqRK2 rhZx/nfq7XsbQlJJJYpiko2cWzBly307wtkgBXq+n4TaUTOZ9yRmvBmkoRXogfQOXkzU HPxg0mFpMxjO6DWEsSCyGSwVBxntU0Ani3Yl3HysdNZweZu2ebwADGRHPHgscNCvBuK2 9Dvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=RfSxz9/wyMS7GyWbZcN2o621C2pBNci3c0dTiugA6h0=; b=OGznfQu2yg5Bw4voGZCTJb3f8RARn1VL3qpl6yU0OR4DR4LVyn9XBWcxSDk6bpigSg e/t16rfljro2+0i5c9HawHXpCgjIhqGhiYL5r5RrqI5Jgn2p0IFXOBdSf9/nLaWp75X9 aqzEyHXJoAlaOgt0I9dEUFHjB3rkPZZYx7YIBqBD1vZaH4FjgbgYexovh/iW/4PQwHun ntzcg0BNcfr0OBc8JIQc0CmRC29/4lJ981jLpEhLIG9krKdNTAhU5i4YWXnxRxbe/atD 1lq+7BYyHqo9+tyBXXUspRemt/2DhVS0wUL5e1tZZnZWxQZ35yJ993tfk6nBgQDGvKk3 NiGA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=SUasgrgA; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=windriver.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si13504902ioh.93.2021.07.05.07.54.17; Mon, 05 Jul 2021 07:54:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=SUasgrgA; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=windriver.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231475AbhGEOz2 (ORCPT + 99 others); Mon, 5 Jul 2021 10:55:28 -0400 Received: from mx0b-0064b401.pphosted.com ([205.220.178.238]:14972 "EHLO mx0b-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbhGEOz1 (ORCPT ); Mon, 5 Jul 2021 10:55:27 -0400 Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 165ElruN025347; Mon, 5 Jul 2021 14:52:44 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by mx0a-0064b401.pphosted.com with ESMTP id 39kyka85cd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jul 2021 14:52:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WS0pP7l1s+ZvrkgqrHMQ13fO2Ppa4s/nri1pK5EFGswbInhv2bu4njqLksD7KFnSxGVq0OLe0Vyb2LU0sGBXffY4NqDSBdykdxid4fXCCznoxudY6b/KPR5oKG/zlPZFs3cphFzEAzg79+Tu/jseTH46vkWeN8c3NWbvDrKknf8gtQXjKhvuO9hQznQfSZycLtlu5jeW1wEVyqAJauDILSTQ4TIvwIsm2eio4WRzpZS0D2F4Dn5aoynh7AFBWkcmERkgEUTy2A4sA5DUCPrE4p9qtg2++JroEeN44hivHcfHMjDS04SEKE5hu/hJmIrhOMKmGMptNZqz58sqynOWug== 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-SenderADCheck; bh=RfSxz9/wyMS7GyWbZcN2o621C2pBNci3c0dTiugA6h0=; b=d0HHGZU0blns8ki16xawYpnIPpGxTdIbLJ2YKJnNSf2lbxAr/LY7+ek0M20Vp1nULMCiIyMeOnXV/YnzACZEcgjGdnoIo0eVwAGtKxgMMA2k9/c3RSEeYymq0NsJLBTDS4uIloNC6+qv//V5OJ4DLYakRozmJy3Sj/3YEnFi7WYZX46kNV5jrKBh2XWcHvEnyu4fJYvuN4WltKpUKS6J8V17doWszDwCdQaFTWw5zNsGO/jSVZ3mqVSOIKFT3fNoO2xw7d5UnIrs72xZgZeHI1xwtxoqI9m33QpVU0e5re1GCMekw1UuUoc1LGy5AllEOXbgfDd25AopcjzDLVSfyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RfSxz9/wyMS7GyWbZcN2o621C2pBNci3c0dTiugA6h0=; b=SUasgrgARzLUHVToveERTjlXvyeNdVN/qI20MvU/obB7dNvMwUYx/qX5vZkcoRsq0Nf8+LMbPZ/T4mmEkt4vxOpa8lomkcyuxW8PvAGOcVWW2+EMJeuqxqENoSHOLOaMWSb6rflCB3HPcVQ/CjjclZoM4OGbYzrP5psBkraMFY8= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=windriver.com; Received: from DM8PR11MB5734.namprd11.prod.outlook.com (2603:10b6:8:31::22) by DM6PR11MB4201.namprd11.prod.outlook.com (2603:10b6:5:200::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Mon, 5 Jul 2021 14:52:42 +0000 Received: from DM8PR11MB5734.namprd11.prod.outlook.com ([fe80::bce8:81f7:f5a1:af19]) by DM8PR11MB5734.namprd11.prod.outlook.com ([fe80::bce8:81f7:f5a1:af19%6]) with mapi id 15.20.4287.033; Mon, 5 Jul 2021 14:52:42 +0000 Subject: Re: [RFC][PATCH 1/4] locking/mutex: Use try_cmpxchg() To: Peter Zijlstra Cc: mingo@redhat.com, longman@redhat.com, boqun.feng@gmail.com, will@kernel.org, linux-kernel@vger.kernel.org References: <20210630153516.832731403@infradead.org> <20210630154114.834438545@infradead.org> From: "Xu, Yanfei" Message-ID: <320cf54f-719c-8aa5-17af-455a53db4478@windriver.com> Date: Mon, 5 Jul 2021 22:52:34 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR0302CA0002.apcprd03.prod.outlook.com (2603:1096:202::12) To DM8PR11MB5734.namprd11.prod.outlook.com (2603:10b6:8:31::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [128.224.162.160] (60.247.85.82) by HK2PR0302CA0002.apcprd03.prod.outlook.com (2603:1096:202::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.8 via Frontend Transport; Mon, 5 Jul 2021 14:52:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cd08e231-6104-4074-d43f-08d93fc48a8f X-MS-TrafficTypeDiagnostic: DM6PR11MB4201: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1YzkcgrczaeTVWYPxJLtAEAdchmzi4NJO4LBapCCYfBO2o+3GTG7rdmHXC+kURhOV3DQIoLEZSaC/OF5PrdoWOGVd/Y6IxH8nQHhbxV6uR3EYt9T0R7r5dd/uDZNYgJpErCjxYpkM4JJBQ9w0eS7x3dvEJdWpiHxyhBGRTVbw8TMOfqK6KQ0Ge4lg/F/DLmRSNxdqHw/3qkBysAS3IlJh036fsPTFQABi4FY85RMbZiSlBgqofyPhcADKdEWXB3Jou5LjpLMhApzono63AUrHTxYQFWqqUlO/UDHdegIsANpAiu5vpa7CzpcE9XIC+G5kC/8Brj/IFyNwdWw9s6frbepAs5DTvzU4Wi1BN1Zp0AO81CpdQSnry1374Hdd5I29yGWeDCVJ/DXYe4HR7pyW+WhvWHrXO8GDIsBVnZnjD2eTV/dvQsBfZ5rAJm/jkfjFMhUs9StZGATE2+UdriNPsy+BKxxi54rWiO09VGZSf0VjiISxNyrZfAD0mCzSOy6aaoPOEac4qDWPc6eBl59gBjDgQgioCe85SG6cHxX7R2cDWw7ROo58scIss1d1VFTWWvn8Be837XdxYOKoaTaz64PiusTbLd8syYB6uTjM95VzjzJWvfecTLh5dBlRsXzaM5YrLhNiasjpM9lihGE8cYFV72pzh0O2DyzbORz1Hd6TiGdGNOol6TkACVUPq8jREh9+4X6DIN7Xj7edJiBP6eD2ShkJXtwHesRy9iR1kedt/421QT1EItdP9ZPnuhR1efijerE7JVpv42mPLv9tULiraCxl3LaOl8vUOBY5P8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM8PR11MB5734.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(39850400004)(396003)(366004)(346002)(36756003)(16526019)(6916009)(26005)(8676002)(66476007)(2616005)(53546011)(66556008)(956004)(478600001)(66946007)(8936002)(83380400001)(186003)(38100700002)(38350700002)(6486002)(4326008)(2906002)(16576012)(316002)(52116002)(6666004)(31696002)(5660300002)(86362001)(31686004)(6706004)(78286007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RHNvR2JTYWdja0owVmhodmxTM3JjMjhpeVdQY3lRVE9penBVMktDK3VrQkZp?= =?utf-8?B?OUdyNnUvZGRoZjR0UDdYdVFHbjFZd2ZoMkp6RGxlU3gzZHBjRUVZeGpWQTlR?= =?utf-8?B?WnBwaWJxYklDN2d6cVdTYW5tenlUV2RBN1lYaFZVcitUYlVFWmx4bUYwR0RC?= =?utf-8?B?dTNCMFFLRm1vdmtTUlg2eDNhZUM2TWF0ODNxT3BKTGxka1lRWmNna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Wi9La1BHRkx6L1lIeFBHenF0QkpD?= =?utf-8?B?ODBpVUo4MHhpSCtKbTlKMXVPcHNueE1GV2pPelE3NXVZdnVXR3YvTmlSTXRR?= =?utf-8?B?SVpIMnVESU5sQW5yWVhwZkhOczBtNHk3dEtZQUJQbGdJanNYT2tDZkc0YTRz?= =?utf-8?B?eDhQK2VCRTBOS3dtSGt2MEFRK0V5ZG83c3MzUXhJWnBaSzlCNUVJY21PWmti?= =?utf-8?B?Qi9mOE5IcUJrSkRzRHhYQ2szclcxbUhXZ01qNWhLRzFwNEVtamsrQlBiZmM4?= =?utf-8?B?bVprVGRUL0hYa0NjQ1k3UHpHYmlWSzZMQTNWaVRyRm5Dc0N5SGJlamxWc0ZU?= =?utf-8?B?bmVYRGRhN2lQZCttU0U3aTVTUk5GSk5sSnBVcDRSaDdHTGFHa1dRNUF2VU9w?= =?utf-8?B?U2ZDVG5La2tjUllmWGFWUGVNalhmU2p2di93Vlp0U1p4UHhXVGZYVkRZb1Zm?= =?utf-8?B?NTVjbENocEdVTVA4bTRHd2lMT29UdjNxM2dKTjFHVythSDNvMHhaVXRoZVAv?= =?utf-8?B?QmtCeTN4dEFFRlFJWEp4aEd6YVhRcEN6THo5Q1l0QjdQeWNFUU9vSGxYZkIz?= =?utf-8?B?MmpJTXdWcmRmY0RicGdRRTJ3U0E3emFYWlljNkJIN1h6bTFZUFNycWtSc2g3?= =?utf-8?Q?3HZhAfTakoZ0EaGyucYGs8unro8Rl0IY+Bu9DBG?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd08e231-6104-4074-d43f-08d93fc48a8f X-MS-Exchange-CrossTenant-AuthSource: DM8PR11MB5734.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2021 14:52:42.3822 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rCyc3JeBKiua46z9WKwX8Ncx648QwYR4CTeZydZ10mfAhxD75b26vOJObf75rzmWincTJx4HXP34Vv+lT49Dtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4201 X-Proofpoint-GUID: l6ER9bM3d-KI-FGYX_RWGyd-bqyba_ZR X-Proofpoint-ORIG-GUID: l6ER9bM3d-KI-FGYX_RWGyd-bqyba_ZR X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-05_08:2021-07-02,2021-07-05 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=997 suspectscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 spamscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107050079 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/5/21 10:00 PM, Peter Zijlstra wrote: > [Please note: This e-mail is from an EXTERNAL e-mail address] > > On Mon, Jul 05, 2021 at 07:59:12PM +0800, Xu, Yanfei wrote: >> >> >> On 6/30/21 11:35 PM, Peter Zijlstra wrote: >>> For simpler and better code. >>> >>> Signed-off-by: Peter Zijlstra (Intel) >>> --- >>> kernel/locking/mutex.c | 27 ++++++--------------------- >>> 1 file changed, 6 insertions(+), 21 deletions(-) >> >> Hi Peter, >> >> I read the mutex codes today, and find there seems something wrong for the >> patch. Should we consider the race condition as blow? >> >> From 4035f50c96e17cbe3febab768b64da5c000e5b76 Mon Sep 17 00:00:00 2001 >> From: Yanfei Xu >> Date: Mon, 5 Jul 2021 17:56:58 +0800 >> Subject: [PATCH] locking/mutex: fix the endless loop when racing against >> mutex.owner >> >> if a race condition happened on mutex.owner after we fetch its value, >> atomic_long_try_cmpxchg_acquire/release invoked on &mutex.owner will >> return false. Then we need to reassign the temporary variable which >> saves mutex.owner value if in loop, or it will lead an endless loop. > > No, when try_cmpxchg() fails it will update oldp. This is the reason old > is now a pointer too. Got it. Thanks! Yanfei >