Received: by 10.192.165.148 with SMTP id m20csp284483imm; Wed, 9 May 2018 12:39:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqjWFjDlsDwS06NvGvdzg2Bj9NLia2EU3aoSudiA293lpQmpUr0Pfam7PSrE/ezrTG05PaT X-Received: by 2002:a65:508d:: with SMTP id r13-v6mr30908897pgp.134.1525894765398; Wed, 09 May 2018 12:39:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525894765; cv=none; d=google.com; s=arc-20160816; b=NY1L3kteLVKY/EXtl2LsakkqyBHFg7zNmPu78xTqZWzTiSoNK2CMMGkoYhgonNZdQX nxSoWpGvBkn2A3vQdDfNZeqZBu9sUFBHzEgkKgFXehSVrfeeXpVUy8pqiNn0Xil7x4NG tYj1CxsxGnuvyG9AazsqLZgjb/GJhkVlSrCSuI7mOinKJNEiGHHcS7/XIYAl0XcyOrtc C9QXvBkxFBYx7xITzxXiA25x1cup6pu/5Hg6IwOdmposzQ7WVgwDRCkfB5Mlku0jHIwU l/GvBurbq8HugflbEtvKqREROp9R5o5/cGUFCaktk72n2I0jkTxecQQYfFkXRxT2qeIn ufnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qmZ7BYWlAtA8OPKncRUCWF8rG+mJeQNOCX9xu3f6f7U=; b=q1bwGgkw1J9a7V1+A3JLVu9cXi0AcKQrhBV4sY03cqT9qNMOVLD/DbXtUBqYYAsyxT MDyF8ZPvSAXzRs1Lpo8H7ENZOo/fWOJYy+oRHIsxK80VAAkPEewFkA3fiAdkv+XtXcCt IW/buP/TMr+iYtrtCh9+a8bu1MxUkWTPHuf3KsyIyVW0f1bXL8tstZ5nmG/o+Jrw2vRt P/16ONRigJU80xV6S4AVF2Roiy9w1xLd6fzUuw/kQFdeDjQfPm7ldVwlIiPpp/fMCYOe iusjcczi2F8wJ2U+Q5vZpWkJsJesNDjhRyVzN/wfPN6YBKu4wv1s8Qvclslv8DNPhy8O BB5Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5-v6si22311838pgu.551.2018.05.09.12.39.10; Wed, 09 May 2018 12:39:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965654AbeEITiv (ORCPT + 99 others); Wed, 9 May 2018 15:38:51 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:34571 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965398AbeEITis (ORCPT ); Wed, 9 May 2018 15:38:48 -0400 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fGUvB-0005v9-0G; Wed, 09 May 2018 21:38:41 +0200 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, Peter Zijlstra , Ingo Molnar , linux-mm@kvack.org, Shaohua Li , linux-raid@vger.kernel.org, Anna-Maria Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 4/8] locking/refcount: implement refcount_dec_and_lock_irqsave() Date: Wed, 9 May 2018 21:36:41 +0200 Message-Id: <20180509193645.830-5-bigeasy@linutronix.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509193645.830-1-bigeasy@linutronix.de> References: <20180509193645.830-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anna-Maria Gleixner There are in-tree users of refcount_dec_and_lock() which must acquire the spin lock with interrupts disabled. To workaround the lack of an irqsave variant of refcount_dec_and_lock() they use local_irq_save() at the call site. This causes extra code and creates in some places unneeded long interrupt disabled times. These places need also extra treatment for PREEMPT_RT due to the disconnect of the irq disabling and the lock function. Implement the missing irqsave variant of the function. Signed-off-by: Anna-Maria Gleixner [bigeasy: s@atomic_dec_and_lock@refcount_dec_and_lock@g] Signed-off-by: Sebastian Andrzej Siewior --- include/linux/refcount.h | 4 +++- lib/refcount.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/linux/refcount.h b/include/linux/refcount.h index 4193c41e383a..a685da2c4522 100644 --- a/include/linux/refcount.h +++ b/include/linux/refcount.h @@ -98,5 +98,7 @@ extern __must_check bool refcount_dec_if_one(refcount_t *= r); extern __must_check bool refcount_dec_not_one(refcount_t *r); extern __must_check bool refcount_dec_and_mutex_lock(refcount_t *r, struct= mutex *lock); extern __must_check bool refcount_dec_and_lock(refcount_t *r, spinlock_t *= lock); - +extern __must_check bool refcount_dec_and_lock_irqsave(refcount_t *r, + spinlock_t *lock, + unsigned long *flags); #endif /* _LINUX_REFCOUNT_H */ diff --git a/lib/refcount.c b/lib/refcount.c index 0eb48353abe3..d3b81cefce91 100644 --- a/lib/refcount.c +++ b/lib/refcount.c @@ -350,3 +350,31 @@ bool refcount_dec_and_lock(refcount_t *r, spinlock_t *= lock) } EXPORT_SYMBOL(refcount_dec_and_lock); =20 +/** + * refcount_dec_and_lock_irqsave - return holding spinlock with disabled + * interrupts if able to decrement refcoun= t to 0 + * @r: the refcount + * @lock: the spinlock to be locked + * @flags: saved IRQ-flags if the is acquired + * + * Same as refcount_dec_and_lock() above except that the spinlock is acqui= red + * with disabled interupts. + * + * Return: true and hold spinlock if able to decrement refcount to 0, false + * otherwise + */ +bool refcount_dec_and_lock_irqsave(refcount_t *r, spinlock_t *lock, + unsigned long *flags) +{ + if (refcount_dec_not_one(r)) + return false; + + spin_lock_irqsave(lock, *flags); + if (!refcount_dec_and_test(r)) { + spin_unlock_irqrestore(lock, *flags); + return false; + } + + return true; +} +EXPORT_SYMBOL(refcount_dec_and_lock_irqsave); --=20 2.17.0