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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham 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 3A931C43441 for ; Mon, 19 Nov 2018 18:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BDF820851 for ; Mon, 19 Nov 2018 18:57:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0BDF820851 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730584AbeKTFWc (ORCPT ); Tue, 20 Nov 2018 00:22:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32894 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730364AbeKTFWc (ORCPT ); Tue, 20 Nov 2018 00:22:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E56CCD25F; Mon, 19 Nov 2018 18:57:38 +0000 (UTC) Received: from llong.com (dhcp-17-55.bos.redhat.com [10.18.17.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42C51608E7; Mon, 19 Nov 2018 18:57:37 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Petr Mladek , Sergey Senozhatsky , Andrey Ryabinin , Tejun Heo , Andrew Morton , Waiman Long Subject: [PATCH v2 11/17] locking/rwsem: Mark rwsem.wait_lock as a terminal lock Date: Mon, 19 Nov 2018 13:55:20 -0500 Message-Id: <1542653726-5655-12-git-send-email-longman@redhat.com> In-Reply-To: <1542653726-5655-1-git-send-email-longman@redhat.com> References: <1542653726-5655-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 19 Nov 2018 18:57:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The wait_lock in a rwsem is always acquired with IRQ disabled. For the rwsem-xadd.c implementation, no other lock will be called while holding the wait_lock. So it satisfies the condition of being a terminal lock. By marking it as terminal, the lockdep overhead will be reduced. Signed-off-by: Waiman Long --- include/linux/rwsem.h | 11 ++++++++++- kernel/locking/rwsem-xadd.c | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 67dbb57..a2a2385 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -77,16 +77,25 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem) # define __RWSEM_DEP_MAP_INIT(lockname) #endif +/* + * The wait_lock is marked as a terminal lock to reduce lockdep overhead + * when the rwsem-xadd.c is used. This is implied when + * CONFIG_RWSEM_SPIN_ON_OWNER is true. The rwsem-spinlock.c implementation + * allows calling wake_up_process() while holding the wait_lock. So it + * can't be marked as terminal in this case. + */ #ifdef CONFIG_RWSEM_SPIN_ON_OWNER #define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED, .owner = NULL +#define __RWSEM_WAIT_LOCK_INIT(x) __RAW_TERMINAL_SPIN_LOCK_UNLOCKED(x) #else #define __RWSEM_OPT_INIT(lockname) +#define __RWSEM_WAIT_LOCK_INIT(x) __RAW_SPIN_LOCK_UNLOCKED(x) #endif #define __RWSEM_INITIALIZER(name) \ { __RWSEM_INIT_COUNT(name), \ .wait_list = LIST_HEAD_INIT((name).wait_list), \ - .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock) \ + .wait_lock = __RWSEM_WAIT_LOCK_INIT(name.wait_lock) \ __RWSEM_OPT_INIT(name) \ __RWSEM_DEP_MAP_INIT(name) } diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index 09b1800..3dbe593 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -85,6 +85,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, #endif atomic_long_set(&sem->count, RWSEM_UNLOCKED_VALUE); raw_spin_lock_init(&sem->wait_lock); + lockdep_set_terminal_class(&sem->wait_lock); INIT_LIST_HEAD(&sem->wait_list); #ifdef CONFIG_RWSEM_SPIN_ON_OWNER sem->owner = NULL; -- 1.8.3.1