From patchwork Wed May 9 19:36:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10390673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63B1460236 for ; Wed, 9 May 2018 19:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52FCC28469 for ; Wed, 9 May 2018 19:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4757D284D4; Wed, 9 May 2018 19:38:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1A9E28469 for ; Wed, 9 May 2018 19:38:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 863986B0572; Wed, 9 May 2018 15:38:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 79A346B0575; Wed, 9 May 2018 15:38:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CF806B0574; Wed, 9 May 2018 15:38:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by kanga.kvack.org (Postfix) with ESMTP id E39716B056F for ; Wed, 9 May 2018 15:38:46 -0400 (EDT) Received: by mail-wr0-f198.google.com with SMTP id q67-v6so11661217wrb.12 for ; Wed, 09 May 2018 12:38:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qmZ7BYWlAtA8OPKncRUCWF8rG+mJeQNOCX9xu3f6f7U=; b=HIwsebpJn2OZBmosW+yEI2FdVZnvaposd5sw6FZt/7wp5UbmOzoq7lflKt8v71kB7s bYUqDuluut5X/kY4PNSp7seB6W+zAGgIbyNumKUa3/MHWFSLhmZvauaRlv+8Ioa6xHDl 6pk9NDjLkC3fNwRl+UZXo14puXDZA5smC2gFLQJ9EqJ49WtjXmhCWms6VHa3W2R0guc4 gNxdg0hUuYl6JZHFtdqr+GSY1RntSqkdU296p70kJuClm90T3YVUWb/vVoyaMhD17jJv ofA5r/VK5xurSuimvDfsb47xLEtun5J7yUp18fuQSDPGi30na4hHpRgHAi7tTgNfedg1 cvkw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de X-Gm-Message-State: ALKqPwd+3fMlNlFQYtHMmFKHL41KfKkLuia3icAGKzpfL0oMLodcd9Xk 1q9UNx1gR5ESt5BJ44xTR/qgavaX9jGy0Xa0GJsn4eZZEUxGEJWx8UU7+lWBtJQXi3BNKhA8KnA cWPQ8GBs9E3IwfzLRlqCs5O0aUq5rGDd5QC6WJhfhVntPZmOVPaPzPacrrsatKJqs5w== X-Received: by 2002:a1c:e046:: with SMTP id x67-v6mr6225029wmg.154.1525894726478; Wed, 09 May 2018 12:38:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoF9S0VVwoTflEAgFuq+hTh8pD4K/9K2mO/j285FpKqswXCGvm7myTFgOVJWAbORBcMNViu X-Received: by 2002:a1c:e046:: with SMTP id x67-v6mr6225015wmg.154.1525894725582; Wed, 09 May 2018 12:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525894725; cv=none; d=google.com; s=arc-20160816; b=o0SBX9v811+KADlOJggmmW6vLEMWtd9+Cxy/YKfTCaycsGCWRRf4mgAFexrAg5bMeO uY4PHhkY7Spu7Rbg/7WPXomU31QtGTm/weFavjImtK6AFHGlD56Pt7CIsu2qcX7KS22F LyEavwuHjh7iL/o8tdew4BTBC7cClOnPActYk1UfMfjDTMvssU++pnT5CD2cIKm1ZKgC Ub0lTZArVD9tcwuM0VTnDrOc/4HH3VIb6n2t//2/qCijnTYAxFZh9p1tadmaZ2CXXBiv J6lHqta6RSBrdD6rlamFqx536VVBoYGmLuc6iQkE5MQvngxFAFVb52+t5xH8O6zkwiXg sdwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=qmZ7BYWlAtA8OPKncRUCWF8rG+mJeQNOCX9xu3f6f7U=; b=h3YFnPw0uLVoRMti2U/cmrmq75XP37aUpeZIL9kD0RpEo1rfOwpmZ+Z7SeYGLkmPMl j8lYhjcG9KY/fqUgeJPT6ysT3rNtOMFTSJFvw8A4clHrHNjvDgOumZMckt73QTEdsJF8 OaCDdYXrR/G/RHUVis3VqQb62eIopAL7LHf81FGT5irKTMtx7PfX5ZbHv1Bw+nxwnEMt FuNyC6nRK/XeCRwWwoQltwJ6XDcP3ESTmS+MmHvdEboYhe+5aoErorsgoB102zqMl5Og 7Wa3UojB7aVcWWjuA0LroDYyz4UcZ6Xh92U9vZbIocj7snxvVvXiu6Xnt+59OssHEPhi o9JA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from Galois.linutronix.de (Galois.linutronix.de. [2a01:7a0:2:106d:700::1]) by mx.google.com with ESMTPS id k4si8401814wmb.24.2018.05.09.12.38.45 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 09 May 2018 12:38:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) client-ip=2a01:7a0:2:106d:700::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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); +/** + * refcount_dec_and_lock_irqsave - return holding spinlock with disabled + * interrupts if able to decrement refcount 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 acquired + * 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);