From patchwork Mon Nov 19 18:55:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10689323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A03F713AD for ; Mon, 19 Nov 2018 18:57:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F9E82A46A for ; Mon, 19 Nov 2018 18:57:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83BF02A470; Mon, 19 Nov 2018 18:57:45 +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 1D40F2A46A for ; Mon, 19 Nov 2018 18:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06EFE6B1BF1; Mon, 19 Nov 2018 13:57:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 01FB66B1BF2; Mon, 19 Nov 2018 13:57:40 -0500 (EST) 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 E7E5A6B1BF3; Mon, 19 Nov 2018 13:57:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id B502B6B1BF1 for ; Mon, 19 Nov 2018 13:57:40 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id v64so10151021qka.5 for ; Mon, 19 Nov 2018 10:57:40 -0800 (PST) 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; bh=uY5ycgX/HkngIbFCmCg84ZdpAOa7T8I2cZvXNdRsYzg=; b=gZUMCShAEcBWrpCuULCv5NuDhDP1DXajymzA+REMMVtK0I5GPG0Qa7OAGm09cXtWt7 ocFrb0pWz0ztF6oiYp9Pp64VKZJ5tNDJgViZn/rJ2HK7rX6SQubSv+lmv+ik8Z5Fy6UU gvGwZOjk0hSleRe5OHL+BU7uqVAG/7cfUoo/MSrneSVKQKAfbLWcywXm+tyQnG3MjsWr +fk2MMranDGY6uBBwdDSiKkInikZ7PZfBzcVLIxMMUUxGbR7sn9C9gdYNIx3JsmZztxr 351C+ANvexyOo2xIGMZH3yrmZyApqvhdkThkxglV0XznMOiV7po4y4FOMsL0gYpcFt0j DWGA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gII12v98PZn+mjF+5JdGgboOH1ERX8FWbjRg3M9fl3ihe4ovL10 1COH4y528SE2dCs3/YTe7fvD2cVa+fW3dnyVw3yg2TDDwpmKGZcz9lCqtZCvdd/ay6W7wgQoa2A ej48vzUWbaDz9iKjE9anWsLovCRfPTrN2M6YbvwkxjFoQkJPeP792yAft54u8UntzGQ== X-Received: by 2002:a0c:8a54:: with SMTP id 20mr22476810qvu.94.1542653860498; Mon, 19 Nov 2018 10:57:40 -0800 (PST) X-Google-Smtp-Source: AJdET5cGK+6emzn5Bxb9BfKLp6hogssdy+InuGgvfo2wPG0QssYjL3sLCm1yQoUK6Bll58vltGpW X-Received: by 2002:a0c:8a54:: with SMTP id 20mr22476776qvu.94.1542653859690; Mon, 19 Nov 2018 10:57:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542653859; cv=none; d=google.com; s=arc-20160816; b=OjvwnhEK+BVn5eNRE352PwmI9Yqzo0YBQfnlhFz1WLT5ZwZRgcXGEnuK3uthasLCkR YWujviz6S5vv7soRviqH5qgydyLNBLHxcR2jvKDueVFRUXCD/NsjyORIPf19CgjGbI30 ydoOrWU5U7waYlKphIHGgleLo//3GvTIvKAaCxEeLJUpCdv2TT8mwRITmfcyb/nibzlb 8BVU7pqllFTZmTJx8lQUp2SR+vD2uPaEvzzrKaCCxngmZr43Mq3aXC+jjcMGWMuAbcG/ 7O7rbz8nqoRFZBROunXmxt+RrRNWz5mgl63h547dqoDmeDYnz0fJ4DMiIwX8JffTO6Mm J6JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=uY5ycgX/HkngIbFCmCg84ZdpAOa7T8I2cZvXNdRsYzg=; b=O9H4mh7tfg08uIaRizC/ywKewRrzy24J/V2Zor2TnQvPP/V6XuYV52nNSgIFbZHgz4 um8DevCo1IT9ePg0HoNTEYiNFn8oFtSD+9rEhCz0DrkuK7NkZiJWwpxcRQPqXfgpJgZr CFpGB7xSXHRKYPRW6w+qB/OvmMSgeH4qufpCaoRzFLIpJBvyP/Pu7M+uj07cbTAFiprH UUyDNPYplCYKGFZ+XFlrYAHdt/GEBLtyJJrKUtawFlp3JiZf9otJZqwks4VltG0G23Om 73wcz0HD+g9alIUSywTTd+AlPDUANFAWRARckZQ4tUj0cJHcqLoD3JMG3EJmZCTIVoly 0ybA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id d4si1166412qkf.87.2018.11.19.10.57.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 10:57:39 -0800 (PST) Received-SPF: pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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) 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 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;