Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3353443pxf; Mon, 5 Apr 2021 09:48:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb49f+bdqQD8bJvRjjN3y0Z8LMCnNDrlrJ5SmnSrT93lPRaDDMv50lWAQa8wGUcZ9BpMfI X-Received: by 2002:a17:907:788e:: with SMTP id ku14mr30202353ejc.17.1617641292568; Mon, 05 Apr 2021 09:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617641292; cv=none; d=google.com; s=arc-20160816; b=k20TqbW8wf+HyUoF/AT3hznp7/i6nyJqQqV77va2fY7cEHlNtI0yhPvPdBtoJAfSd1 JCPe6Kw6rjXdzf6244VzBnKKvPwutl0RbmLP9AEnsVXwYEbkaRzJPamGDJu2cU3Z0RJy WJ/zzpkX2WfqscN21UY/MEMRL3fziOe2QSTKPyyCd2y+6LwL7+fldoz13d/4HwzaZWEh e1JRr/n7wPuPCo7I1bHf24LSXxzsd5J0u5FEfztPQB9wHOcAlTb4tdxN++pbcs/qwxfY 6YAh3TxB7xJhf22186pJ+N9RRV55ctnfHyL6FKircr3FHW53bb1UVVDOxr48QL/BFMDp 1qqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UtTDC0XwVL+naaynNizNMcG/OiryWERRRDXQJ/+JrxY=; b=blzw+ltXx3JWfSJ5ACH519Zu1UNwLTdHiwq2CppH6UYJ57DF2A2AzbYyiMkrd35ADX AFSPw2qwZT5FGKGi3RaRMVqveKO2uL/MRfx5V3s2h6kZgQnHvNL0dp9l1YemSijIoXVF 17AYJdsrZvOyP6eErht+Jh3P4k6DBdoXlA8fsT9NXIxKm6NIeKlLnIclML8/urqap5vl zvrLYTlhNDozFUQWG6CppxEyOxylervAjq3XnprSXeJtckxP5Z0RWC38GgyerRzBLCYt IAGEC/1ZeDsU1WBCKMcATw5u2jX9X+hLDXc4ekRb29PhdoBOiA3KgeZQ6QwzGJtTG681 BvoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Erhxp3XX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i19si8424525edc.451.2021.04.05.09.47.49; Mon, 05 Apr 2021 09:48:12 -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=@linuxfoundation.org header.s=korg header.b=Erhxp3XX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239889AbhDEJSG (ORCPT + 99 others); Mon, 5 Apr 2021 05:18:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:34014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239791AbhDEJOT (ORCPT ); Mon, 5 Apr 2021 05:14:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E81B861394; Mon, 5 Apr 2021 09:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617614053; bh=xCGmuBCetSBOXtZaRSCKhhI8Vsve5Ejh8kNFeNeeWUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Erhxp3XXj5nqyThqp2IS/TtWweNrhsTzKqg77PgIqMns2c6+chpiOyyQqxEkc/0kv x+6i18Z6bgyQ5xTfS1K/JK0myw8dqFhnOwp1nPHDRqfPUEGfrAU98CN/K1la/o/Y57 Ph7gY6CMng78+ECSgPgIh+mS5mCR2KAEkMSRoPXE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Ingo Molnar , Davidlohr Bueso , Sasha Levin Subject: [PATCH 5.11 031/152] locking/ww_mutex: Simplify use_ww_ctx & ww_ctx handling Date: Mon, 5 Apr 2021 10:53:00 +0200 Message-Id: <20210405085035.261136288@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210405085034.233917714@linuxfoundation.org> References: <20210405085034.233917714@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long [ Upstream commit 5de2055d31ea88fd9ae9709ac95c372a505a60fa ] The use_ww_ctx flag is passed to mutex_optimistic_spin(), but the function doesn't use it. The frequent use of the (use_ww_ctx && ww_ctx) combination is repetitive. In fact, ww_ctx should not be used at all if !use_ww_ctx. Simplify ww_mutex code by dropping use_ww_ctx from mutex_optimistic_spin() an clear ww_ctx if !use_ww_ctx. In this way, we can replace (use_ww_ctx && ww_ctx) by just (ww_ctx). Signed-off-by: Waiman Long Signed-off-by: Ingo Molnar Acked-by: Davidlohr Bueso Link: https://lore.kernel.org/r/20210316153119.13802-2-longman@redhat.com Signed-off-by: Sasha Levin --- kernel/locking/mutex.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 5352ce50a97e..2c25b830203c 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -636,7 +636,7 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock) */ static __always_inline bool mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, - const bool use_ww_ctx, struct mutex_waiter *waiter) + struct mutex_waiter *waiter) { if (!waiter) { /* @@ -712,7 +712,7 @@ fail: #else static __always_inline bool mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, - const bool use_ww_ctx, struct mutex_waiter *waiter) + struct mutex_waiter *waiter) { return false; } @@ -932,6 +932,9 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, struct ww_mutex *ww; int ret; + if (!use_ww_ctx) + ww_ctx = NULL; + might_sleep(); #ifdef CONFIG_DEBUG_MUTEXES @@ -939,7 +942,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, #endif ww = container_of(lock, struct ww_mutex, base); - if (use_ww_ctx && ww_ctx) { + if (ww_ctx) { if (unlikely(ww_ctx == READ_ONCE(ww->ctx))) return -EALREADY; @@ -956,10 +959,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip); if (__mutex_trylock(lock) || - mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, NULL)) { + mutex_optimistic_spin(lock, ww_ctx, NULL)) { /* got the lock, yay! */ lock_acquired(&lock->dep_map, ip); - if (use_ww_ctx && ww_ctx) + if (ww_ctx) ww_mutex_set_context_fastpath(ww, ww_ctx); preempt_enable(); return 0; @@ -970,7 +973,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, * After waiting to acquire the wait_lock, try again. */ if (__mutex_trylock(lock)) { - if (use_ww_ctx && ww_ctx) + if (ww_ctx) __ww_mutex_check_waiters(lock, ww_ctx); goto skip_wait; @@ -1023,7 +1026,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, goto err; } - if (use_ww_ctx && ww_ctx) { + if (ww_ctx) { ret = __ww_mutex_check_kill(lock, &waiter, ww_ctx); if (ret) goto err; @@ -1036,7 +1039,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, * ww_mutex needs to always recheck its position since its waiter * list is not FIFO ordered. */ - if ((use_ww_ctx && ww_ctx) || !first) { + if (ww_ctx || !first) { first = __mutex_waiter_is_first(lock, &waiter); if (first) __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); @@ -1049,7 +1052,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, * or we must see its unlock and acquire. */ if (__mutex_trylock(lock) || - (first && mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, &waiter))) + (first && mutex_optimistic_spin(lock, ww_ctx, &waiter))) break; spin_lock(&lock->wait_lock); @@ -1058,7 +1061,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, acquired: __set_current_state(TASK_RUNNING); - if (use_ww_ctx && ww_ctx) { + if (ww_ctx) { /* * Wound-Wait; we stole the lock (!first_waiter), check the * waiters as anyone might want to wound us. @@ -1078,7 +1081,7 @@ skip_wait: /* got the lock - cleanup and rejoice! */ lock_acquired(&lock->dep_map, ip); - if (use_ww_ctx && ww_ctx) + if (ww_ctx) ww_mutex_lock_acquired(ww, ww_ctx); spin_unlock(&lock->wait_lock); -- 2.30.1