Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp180389pxv; Wed, 30 Jun 2021 03:07:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQfwWCtcLM0W8GfUl2k3i4aI1YjH/9TjxtVybdPskY4zHe0EWaLZkJD4RE6qwtbN0aQnmx X-Received: by 2002:a05:6638:c2:: with SMTP id w2mr8318652jao.38.1625047636272; Wed, 30 Jun 2021 03:07:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1625047636; cv=pass; d=google.com; s=arc-20160816; b=oMYZIKUlErJa6Had26sKYUIKF3lUH3uHMV6jBCoQ33VJ03ASh41AkVbQPoK7wX1+7/ 9QQcjep5LqY70tTCEcPePCV8CMUq0d58fwRIqVCWFf07B1g5HaGvGWKzeRLnG4kQo8k1 93qGPIxR62huCHrHoCba+uD4njjDdrOAUq7+ViBMnFCbaoq+DO06fqG45+40IB6fvctJ vKOAB5KyIStz1kzg/BxfX2AvRARyIKE/Nv0g+TbgvML1yoQ0DR01UKFmBqcjo7pFP0Uq dpKa1Tmn7uLjXFRpV3Ti/omJOiYj06Kl2CVpFXdkoeWRNEnNju9OR0mMG410SzNt2zYM JY2g== 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:references :cc:to:from:subject:dkim-signature; bh=J1riiS8zWUd/9fMZZmOCTEpLFmG4P6XOWDWmH3WIfpY=; b=tF/rrE1vMO5abNnzz18+tokv00v4wIVNgtZF7clL9/Yonuzg06ThBqJuucaGsRV56X Sf5kME7xWeVWHq/7hs+92rYxUyyoBuFqxYkytTswq2mo65SHGby9fvFf8VFkqIUX41NL 2nniyhoMeRn9MbEBCZHcI6QqWnuLTKMKKqaaYl1IYDddjw96CV0quJB0g3nDHYsbZynS hW9XzdxFDnV52wpnRWotbIOLa5eOG5lDOQDv/WITHhnz2D/yt3j4BaYVgk0V53tsIueM Js0S6yDggkCoHinfsgwIO+lhZmwjFaQFIZpuO5OiAMjQBCz6GJfCXS75O0sjllWnfsaD sdBA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=j9Qj+UTn; 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 a14si27291831jat.22.2021.06.30.03.07.03; Wed, 30 Jun 2021 03:07:16 -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=j9Qj+UTn; 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 S234168AbhF3KIw (ORCPT + 99 others); Wed, 30 Jun 2021 06:08:52 -0400 Received: from mx0a-0064b401.pphosted.com ([205.220.166.238]:48438 "EHLO mx0a-0064b401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234101AbhF3KIt (ORCPT ); Wed, 30 Jun 2021 06:08:49 -0400 Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15UA4E1l017385; Wed, 30 Jun 2021 03:06:14 -0700 Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by mx0a-0064b401.pphosted.com with ESMTP id 39g5a80qq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Jun 2021 03:06:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dputcS/IX6XsmM/clZjmuxIrnqIkDdZrLmWQpuZr+HU/N+UUhvOdXUwL9hz+bYDv4SHiNNpDPMn/MRfoyH0+uhY1b5C25p1ITDkf5ZXCz/++D6y08To11b+j+rukRf42Jloyeg9Hdf+sXyO6P76YzXSdARc1F3mDKQqXwz10zSN5fL7CwOi2F1Gcq44h/p9shJ5K8Kac1dZdGeH5Qc+HRWzazxUUH9E+kOluVNmEQZnJ+Pn62mZ3cRAsyug4vzrMLeKC3Cl6XvRHhC3qLE3guz/pVDeosECFGB2SaLphincgVt6FqbJOGjk51yuuZKLcQmE9l5xvfkq2aPV2uRW57A== 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=J1riiS8zWUd/9fMZZmOCTEpLFmG4P6XOWDWmH3WIfpY=; b=dtApKAcT1uKdYyQXA2G34nQjFBx/bTZc+zss94S43kcol8OpyN1g+GMIgT55EpQKeliK3OO/fbMJjILG0OdVxj7hKDLW6rTbrk4HoMQkZBuDVTu75NELqctSPPANJ+9d0vr4NmuP3p5/ol7PXZiXodhNC6T+17fFiSiSjXgC8W+zawMfEs/XCWIEPs42OZfskVxMxHUMLzC4VibBKtl6rzeQXBXdVTRQjdEqkAVRhGHog/G/4GQMwM14WAYmZ6Oog7/LLdk9j0VObXQ9UDD3NcOw5ane50tG50BCkFvPjl+bsPFfLxJDX0z1FQmw5Y4A5H6vGc6diOellKB1mzl8Zw== 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=J1riiS8zWUd/9fMZZmOCTEpLFmG4P6XOWDWmH3WIfpY=; b=j9Qj+UTnfgydM60oKZx9594ix0RhDw18tIxnIl4iMIs+t8Fptpb5qnD5pHVdH9xutvArQ+RkXF8QKE2nAQVp2dPxGMRGTJ2o5BZOX6jO3Ro5z+juK/KxozntkX+QoUU8R0CZTw0UErm4do7hMpAzxRQglxaUPULMN7yE3KaxMWI= 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 DM6PR11MB4252.namprd11.prod.outlook.com (2603:10b6:5:201::26) by DM6PR11MB4185.namprd11.prod.outlook.com (2603:10b6:5:195::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23; Wed, 30 Jun 2021 10:06:12 +0000 Received: from DM6PR11MB4252.namprd11.prod.outlook.com ([fe80::c0f2:cf50:3404:90ac]) by DM6PR11MB4252.namprd11.prod.outlook.com ([fe80::c0f2:cf50:3404:90ac%3]) with mapi id 15.20.4264.026; Wed, 30 Jun 2021 10:06:12 +0000 Subject: Re: [PATCH] locking/mutex: fix the MUTEX_FLAG_HANDOFF bit is cleared unexpected From: "Xu, Yanfei" To: Waiman Long , peterz@infradead.org, mingo@redhat.com, boqun.feng@gmail.com Cc: linux-kernel@vger.kernel.org References: <20210628155155.11623-1-yanfei.xu@windriver.com> <02691c73-6ba8-241c-6ec8-486d9d549c23@windriver.com> <78f45c3c-191b-bd14-3b38-522907d0e24f@redhat.com> <8241576e-ac92-1a0b-b1ad-2372b61759ea@windriver.com> Message-ID: <945cc291-7057-389c-faf8-a30bde605654@windriver.com> Date: Wed, 30 Jun 2021 18:06:05 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <8241576e-ac92-1a0b-b1ad-2372b61759ea@windriver.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: BYAPR03CA0017.namprd03.prod.outlook.com (2603:10b6:a02:a8::30) To DM6PR11MB4252.namprd11.prod.outlook.com (2603:10b6:5:201::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [128.224.162.160] (60.247.85.82) by BYAPR03CA0017.namprd03.prod.outlook.com (2603:10b6:a02:a8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22 via Frontend Transport; Wed, 30 Jun 2021 10:06:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a25f235e-d911-46d1-cb5e-08d93baeb04d X-MS-TrafficTypeDiagnostic: DM6PR11MB4185: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yp8SvUAOFSxgyaCwUuSdbYznjrXyKq6uEPFc7yOPG5OWwFKn+Cis4C0BBVBE0vljn0b+zhwNpBNnuLZnH/vV1tduUZnBA9ldl85rcFwPrrUYzlVAgjTtWsQjZzKMOVPS05H520d7oPiY+0AVprb7DBIjp+O3FzaKHqXldOZr9yF7MLpynMQ7HTeSzQD2KsrGfhh70DeJNy19vA19UFGcYcXbY4XzofbOX/w6HDXEIPHMvKneptdVBfqQFyXLF3y3hk+IvmGveAY6FBfF/TYOFDay2ExcvQIKHluKwe6kGS1kh7w7vO4cIuNe//bbpAtJsvZFXonRy78I5cDMv+LBcWQTRotLupd710qClJg+uGg08zoJAn7SvZFyH150+4JX6h89Ou12K39SmBmtb3JfD/FOnYtENF84DyKBLAcYexR7z2mbv9j9qgeKk8RK90n17gr+wNC6ZbQ3sbEnfz9wG2wbqxCpOcKSfrgBV7MOH9X8PURzYXKbQGJnMZGyeJLtjtQG+sd/M/Mprdzp1RkINq/i13FS4dt+8bjAUJOK31G5fMFUFXguS1dq7Mz+4r1q3Oq8n2+niMqEc+T9JuTWQVGKkph3j23uhHRaF7v1ZM9J2meevKAkZp70evaQN30+JiHhcLhS+gkqfZHms56ZgPfi2Aj/3bhPXOAcHE+hzdbD9106AGX9jgzxqyT+S/WpTv7LTa55IIakIt1g+vV2Cp+CSval4cFQrw6KgimS3q5toiMe0BKctAgJvN2uKe6wt9nne2vhhtpxKw5wUiRGKMxp4Cg0ztPznf3zG2MSba0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4252.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(396003)(376002)(136003)(39840400004)(366004)(6706004)(4326008)(6486002)(956004)(2616005)(4744005)(2906002)(86362001)(8936002)(38100700002)(66476007)(53546011)(66556008)(83380400001)(8676002)(5660300002)(26005)(6666004)(16576012)(52116002)(478600001)(36756003)(31696002)(186003)(16526019)(38350700002)(66946007)(31686004)(316002)(78286007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?U0JubzJxOElXVGE0VW5YRTFkVTZranBva3pMK1U3MUE1V2MzZ2FEV01PSEtm?= =?utf-8?B?WExhcWYzWlBHT0M1eHhUMU1wQjN6MUxFdEVYQ1E4bU5qU3k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ZZzBuZkhGaGhPWUpZ?= =?utf-8?B?Q3VGbm1qdDF5VVhCclBQUkt6Tlo1eENMTGNHQjJJNHExNk1MaXZsdm9XVVpC?= =?utf-8?B?R3RTeDJMeXF2TDEyQ3pLa0lwV2xaUkxUVndUaGdBR2wxbVBXOHVwOTYySDkw?= =?utf-8?B?SEJNU3FoNEN2b0VGdVJ1UFh2Ly9qL3Vjb1JzVWVudEpNV3RoeG5zYmtEVXJW?= =?utf-8?B?L3ZvSmVkMzQ4cFV0WFA3SHoxSVNmV0dqbExvck85TFFtRW1GNXFIVlgrQjhU?= =?utf-8?B?NFY5NWJMeCttUE1mVk8zdy8rendYVkhzc1ZmNmNFdHEvVlFPWnZUSjVYN0tq?= =?utf-8?B?QWhZUmwxM3M3Z1pEKzBnUlNvV2h0c1JCOXNwS0VnNHFzNlZyRURYT0xVOEc2?= =?utf-8?B?cHhXODFtWWVOQU5OdmJUWmUyTzBnb1NUSEtSNXdkcmlwOTd4dlZoUGNsNlBv?= =?utf-8?B?QzQ1S3lnM1NPOEZ0dWZLK2NsTlVHVXdGVjhIcUNxbExzeVQ4TlhMdEhuTjZB?= =?utf-8?B?SGRuM3creDVKendEWE8xTEtTNmxNTEp1bUQwYitsQnZwcEl6TS9ROG9MOUMr?= =?utf-8?B?ZitGcExVQ2FHQ2wvTjFiYXVHNE1xd1FNSkcwVHRDeHZVajNrTmJybnBvQ25s?= =?utf-8?B?VlpCWUJyR1hCM2tOZmRFK0NnUnUxMDdNbC9Gb1RNdUpsRWpkcDE1NHRCcC9l?= =?utf-8?B?bUxENlZFa1BLR1BkYVZrR2RVSk1WQTFSY0RNZ1RINk56bXZEOFc5amE1MTEw?= =?utf-8?Q?S2Iut9p7jPiytZ3151DQSGKc8F/sqABX1rktDVm?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: a25f235e-d911-46d1-cb5e-08d93baeb04d X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4252.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2021 10:06:11.9141 (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: rTRUyIGyd16ACtBgYFDqb0qYPW8r1f5yulpwxWBRYQSCkifgkyEJjoHp6d1PZ5InyHvEiDRmuByecQQNi8F+Rw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4185 X-Proofpoint-GUID: kE3vM2VIoo1iwVxPTrNu1UDO7nMpz6mr X-Proofpoint-ORIG-GUID: kE3vM2VIoo1iwVxPTrNu1UDO7nMpz6mr X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-30_02:2021-06-29,2021-06-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106300065 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/30/21 2:20 PM, Xu, Yanfei wrote: >> Oh, you are right. The current code doesn't actually prevent lock >> stealer from actually stealing the lock in the special case that the >> lock is in the unlock state when the HANDOFF bit is set. In this case, > > How about setting the HANDOFF bit before the top-waiter first give up > cpu and fall asleep. Then It must can get the lock after being woken up, > and there is no chance happen stealing lock.  And I sent a v2 with this. Please ignore this, It is incorrect. Lock stealing is a performance optimization. Yanfei > >> it is free for all and whoever gets the lock will also clear the the >> HANDOFF bit. The comment in __mutex_trylock_or_owner() about "We set the >> HANDOFF bit" isn't quite right.