Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3331389yba; Sun, 28 Apr 2019 23:44:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFgp2JU/mj7JpMQFKx8IZayqTUIcmZu8EGsSn/t5vWqafk9mV/MDVf3vNyG9WO23e50Sd4 X-Received: by 2002:a63:f058:: with SMTP id s24mr3790950pgj.257.1556520285661; Sun, 28 Apr 2019 23:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556520285; cv=none; d=google.com; s=arc-20160816; b=DRwIsag3K0w0Aiqcp1QYon+AZvx0lgP3AjwTXJV16OOXQGgPeghYX+HhB42UL86ehB w8Q/bnJ/SpKLjvu+KrK5QIBG1So22I0HDB5DHT1VRqKs1TB+3Sw5JogxgMsh/Tvmzxnz mKpW5KeF3w9YaTOFZVekKYSvJ214+M1rVMAkoLXFDbkE7aBcrKXshZS7T2/2Vfpqhvfo wHr/VtiWROq31WjB/W4l7rmFKRkIjQSm8PpNHk7RZwfccCRzFMWWeT+zMw8o0a+tr5AE 4e8hMM+ubquIz92LtaxO+vsKREkhMHmN2ITW+TXd+OG/sOmqGzcTaDKhux6Nhda+oRPm gz3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=6gE5WV8wFQPvP6ael5WrD7cgZpoM049F50y0eFUk8zw=; b=NMgm+BDXhM5R0yYgW+H9tp5sKrtBP+q4N0a7ZMcS7lBImxI2yzjZS5IS5LRsUixKk9 xqd469V9AE/V+03YENdrjuuY/FwgXgZN/cBKPyPCFmge5EU2KFpDKUS99EXZ/73/ED2/ s8r1q6b/BgTOYhfL7twXcZp9WEGIT9+wt0ebV6GkpgvDYwPetDYYuz9/x4HWKJ37d3i2 Igb42w+fAHOxL3pkJCXRbeCDa+U9CqCWW+5CWywkJhug126A10dBxw26h5Zxs7UCXiXd qDSLh8attvC4ycYHU9ti2hqgv8KO/D5LmnuEIxkhXKHSXlKI30/PFPFKgT7TMm/aUC/f pviw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=EYrLGhvr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 133si34083879pfu.82.2019.04.28.23.44.30; Sun, 28 Apr 2019 23:44:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=EYrLGhvr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727321AbfD2GmV (ORCPT + 99 others); Mon, 29 Apr 2019 02:42:21 -0400 Received: from terminus.zytor.com ([198.137.202.136]:47435 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbfD2GmU (ORCPT ); Mon, 29 Apr 2019 02:42:20 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3T6fxxT784645 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 28 Apr 2019 23:41:59 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3T6fxxT784645 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1556520120; bh=6gE5WV8wFQPvP6ael5WrD7cgZpoM049F50y0eFUk8zw=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=EYrLGhvrdohOjoxQ3Ng4lBkg7zw6hQ+hWsBStJcv3XV24ilV5j36tekemw2eqmRh5 BXUA5iHFRnSqmIsXoQN2Qx/Yi8WNkfB12F9MFAejN1xaXR+w8PyvJ0txoSuCZg17ah msjxpR3xliitIlV0zu6D6lwnMJ6yFh2K+MtgFdwbdFF8kwK0eD96A+E2x9xKbhr26w 8RlJcaw0jvvFzicgWwqApn3pYI/72pa71Jp57KvhJAOAwB/acep59Ro+EowbzNf0uD f0oVfyoHECws+22Ymc+Wp90F5NRIAfos1pp7kP6wYHK9SEkgMpDY2oXbQMnZcHjbg1 kJxIUg9Liq9/g== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3T6fxXO784642; Sun, 28 Apr 2019 23:41:59 -0700 Date: Sun, 28 Apr 2019 23:41:59 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jakub Kicinski Message-ID: Cc: tglx@linutronix.de, will.deacon@arm.com, akpm@linux-foundation.org, paulmck@linux.vnet.ibm.com, peterz@infradead.org, simon.horman@netronome.com, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, torvalds@linux-foundation.org, jakub.kicinski@netronome.com Reply-To: simon.horman@netronome.com, peterz@infradead.org, jakub.kicinski@netronome.com, hpa@zytor.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, mingo@kernel.org, akpm@linux-foundation.org, will.deacon@arm.com, tglx@linutronix.de, paulmck@linux.vnet.ibm.com In-Reply-To: <20190330000854.30142-4-jakub.kicinski@netronome.com> References: <20190330000854.30142-4-jakub.kicinski@netronome.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/static_key: Don't take sleeping locks in __static_key_slow_dec_deferred() Git-Commit-ID: 94b5f312cfb4a66055d9b688dc9ab6b297eb9dcc X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 94b5f312cfb4a66055d9b688dc9ab6b297eb9dcc Gitweb: https://git.kernel.org/tip/94b5f312cfb4a66055d9b688dc9ab6b297eb9dcc Author: Jakub Kicinski AuthorDate: Fri, 29 Mar 2019 17:08:54 -0700 Committer: Ingo Molnar CommitDate: Mon, 29 Apr 2019 08:29:21 +0200 locking/static_key: Don't take sleeping locks in __static_key_slow_dec_deferred() Changing jump_label state is protected by jump_label_lock(). Rate limited static_key_slow_dec(), however, will never directly call jump_label_update(), it will schedule a delayed work instead. Therefore it's unnecessary to take both the cpus_read_lock() and jump_label_lock(). This allows static_key_slow_dec_deferred() to be called from atomic contexts, like socket destructing in net/tls, without the need for another indirection. Signed-off-by: Jakub Kicinski Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Simon Horman Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: alexei.starovoitov@gmail.com Cc: ard.biesheuvel@linaro.org Cc: oss-drivers@netronome.com Cc: yamada.masahiro@socionext.com Link: https://lkml.kernel.org/r/20190330000854.30142-4-jakub.kicinski@netronome.com Signed-off-by: Ingo Molnar --- kernel/jump_label.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 02c3d11264dd..de6efdecc70d 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -221,9 +221,7 @@ static bool static_key_slow_try_dec(struct static_key *key) return true; } -static void __static_key_slow_dec_cpuslocked(struct static_key *key, - unsigned long rate_limit, - struct delayed_work *work) +static void __static_key_slow_dec_cpuslocked(struct static_key *key) { lockdep_assert_cpus_held(); @@ -231,23 +229,15 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key, return; jump_label_lock(); - if (atomic_dec_and_test(&key->enabled)) { - if (rate_limit) { - atomic_inc(&key->enabled); - schedule_delayed_work(work, rate_limit); - } else { - jump_label_update(key); - } - } + if (atomic_dec_and_test(&key->enabled)) + jump_label_update(key); jump_label_unlock(); } -static void __static_key_slow_dec(struct static_key *key, - unsigned long rate_limit, - struct delayed_work *work) +static void __static_key_slow_dec(struct static_key *key) { cpus_read_lock(); - __static_key_slow_dec_cpuslocked(key, rate_limit, work); + __static_key_slow_dec_cpuslocked(key); cpus_read_unlock(); } @@ -255,21 +245,21 @@ void jump_label_update_timeout(struct work_struct *work) { struct static_key_deferred *key = container_of(work, struct static_key_deferred, work.work); - __static_key_slow_dec(&key->key, 0, NULL); + __static_key_slow_dec(&key->key); } EXPORT_SYMBOL_GPL(jump_label_update_timeout); void static_key_slow_dec(struct static_key *key) { STATIC_KEY_CHECK_USE(key); - __static_key_slow_dec(key, 0, NULL); + __static_key_slow_dec(key); } EXPORT_SYMBOL_GPL(static_key_slow_dec); void static_key_slow_dec_cpuslocked(struct static_key *key) { STATIC_KEY_CHECK_USE(key); - __static_key_slow_dec_cpuslocked(key, 0, NULL); + __static_key_slow_dec_cpuslocked(key); } void __static_key_slow_dec_deferred(struct static_key *key, @@ -277,7 +267,11 @@ void __static_key_slow_dec_deferred(struct static_key *key, unsigned long timeout) { STATIC_KEY_CHECK_USE(key); - __static_key_slow_dec(key, timeout, work); + + if (static_key_slow_try_dec(key)) + return; + + schedule_delayed_work(work, timeout); } EXPORT_SYMBOL_GPL(__static_key_slow_dec_deferred);