From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2F8DC11F65 for ; Wed, 30 Jun 2021 14:51:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4422613EB for ; Wed, 30 Jun 2021 14:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235766AbhF3OyM (ORCPT ); Wed, 30 Jun 2021 10:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235849AbhF3OyH (ORCPT ); Wed, 30 Jun 2021 10:54:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B427C061756 for ; Wed, 30 Jun 2021 07:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=JgdlP3cFU+vqIL3Uh6fKL6vJvakGNcLFSQqStMEuC/4=; b=qqmHBWd7keTTspxBpDdFabaB7i kSnOxGTQp1v2ABJPDbQOjNcBMe74rTXoiAGRgSo4k3Iv9BeoEQCarBLfdKx2ko185yPiZInTOZkRH P1tkEoqg59o+YI3ZowyE8jUufVHk3Ps8jkLyQlydW/7HXtXFQuKiagVugpsbIcHA8iiohnxHcasNA fpXSfp9+/myT8a3T2qQbhjBjDB1fBEzt87Bzof+8cmO/ldvdlw8AN0WQnq0KCWaUqBITuw75lhkrm efuPQD0HDMONPj6nwuGorDPhRoJb8QFoU/QSQ1CErHlZoM90fxghGng0tLvsqsWbvg9LUrlD/Hr4Q FfsUEfGg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1lybXc-005SgJ-MW; Wed, 30 Jun 2021 14:50:31 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 47E353002D3; Wed, 30 Jun 2021 16:50:15 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2AF242C635D2C; Wed, 30 Jun 2021 16:50:15 +0200 (CEST) Date: Wed, 30 Jun 2021 16:50:15 +0200 From: Peter Zijlstra To: "Xu, Yanfei" Cc: Waiman Long , Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org Subject: Re: [PATCH] locking/mutex: Reduce chance of setting HANDOFF bit on unlocked mutex Message-ID: References: <20210629201138.31507-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 30, 2021 at 10:43:37PM +0800, Xu, Yanfei wrote: > > +static inline struct task_struct *__mutex_trylock_or_owner(struct mutex *lock, bool handoff) > > { > > unsigned long owner, curr = (unsigned long)current; > > > > owner = atomic_long_read(&lock->owner); > > for (;;) { /* must loop, can race against a flag */ > > + unsigned long flags = __owner_flags(owner); > > unsigned long task = owner & ~MUTEX_FLAGS; > > > > if (task) { > > + if (flags & MUTEX_FLAG_PICKUP) { > > > > + if (task != curr) > > + break; > > + > > + flags &= ~MUTEX_FLAG_PICKUP; > > + > > Hmm.. Should we also clear HANDOFF bit here? I don't find where it is > cleared. Should already be gone; see __mutex_handoff().