Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1061711pxk; Fri, 18 Sep 2020 02:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw70EZ7JNwPgcnCaSsOLhOfYArixPHNK2QoW9/WpLHg4nKI9qGJzXvCU0trsPGXhEubHMZI X-Received: by 2002:a17:906:7f06:: with SMTP id d6mr34385637ejr.553.1600422853429; Fri, 18 Sep 2020 02:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600422853; cv=none; d=google.com; s=arc-20160816; b=KdJ8PxIxrn71tL0JvvvXV5wWgGCD+l3fP9dt8Mr4+wgREl5afQecb7YK09opW5K9q7 z64GH3DssaEbojofe878/0fjOOTGWT/+K7AzZSDC6u/p9KNcHEmR7h0HpSsZHJz9kwUb hUZio+dPDPc7htgU/jFaEY4tbWSbEqHN1+wTTUVxQet+s3XPjFQmWLpLV8xKgmZSWslb 3F90uvZ0i/dIOdgUhuAAJnn+bX/Yi+cIHO9/zhueOftNoiV/m6qOJNWymqQg/14y3YE3 fHpISRYM+7EJVL8X9b536ehMOvjTJgoXa4HKLona8pRJpKaT2IzPyQX+IMw/ZFN+SPNE QXNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:from:dkim-signature:dkim-signature:date; bh=+Qm1htnKsvz8zTpt2XsYk232RHrbCVjmVseH61BDccI=; b=Rt42JTUvW9zN+RWJQ9BAARrdn9pELL8X0M4nAGi4KhWxzbjMAqk5+Zq+N32UPWao9n JAX59wU3Iv4W8VRPiLsEtmslbAkQ/NFepdEH/SQ8pPb7+7IJ2uwAE0MzdsA86KnIZcC/ 56HBjfyk4tGyLEAnf7Vp0l2hE6nhdQkfqqOVPIeexSRv+EJOwpUt5zpM1Xq1jkQp9tWa oPgyDWBt9r/BtYpNpOJj9UjLFtTPhPkdT9iYLYW929FNLpzlbsdxsN0kEvKAUiWxntoK TtEOK0pmibxgn7h8E1qdFq4r6gKQlRy8jfnDim3Y/ZkOlRxCUk6FrPyyBySL37rzp9ux dmrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=rMXsujxL; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt6si1797618ejb.290.2020.09.18.02.53.50; Fri, 18 Sep 2020 02:54:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=rMXsujxL; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726405AbgIRIgh (ORCPT + 99 others); Fri, 18 Sep 2020 04:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbgIRIgh (ORCPT ); Fri, 18 Sep 2020 04:36:37 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0013AC06174A; Fri, 18 Sep 2020 01:36:36 -0700 (PDT) Date: Fri, 18 Sep 2020 08:36:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600418195; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Qm1htnKsvz8zTpt2XsYk232RHrbCVjmVseH61BDccI=; b=rMXsujxLx3RLAGL0BdsECac4MW9toHVn7W1mBPiwB+JEmW3kYLb/SNdTJ/XbZLJNFWTBjV HNZdJubRQGHUIzibl152yd+KeKLu4NyNWA6/ctThByyPLAo5MahnNpVLuWC8A/JyGtQDQc xmg6c5e/bfhLdm0dpbE44+6u9B9ovn+1xQRkiZB7BWBOxerO4r3P4ojMAovESf/1L8Qs97 qHZ+5VC0KQDVMPEWhMIF8IxWF7HrVb8wU5tKJdmez9EUKDR33Aia0TnpY+Ccqcm9imPkK8 tPnBD98KZetPx8R0K8pGV5aXU8Kekgr+wXay34uWUvRmG9eo5MPfzT8MEbRqyw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600418195; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Qm1htnKsvz8zTpt2XsYk232RHrbCVjmVseH61BDccI=; b=WrYdHJuOBEvm+u1qw6GgTo033lwVjfjl9txOY6ssZcLlnG/Gkh5wwG4nQU2cAeEXw52h/z nt3F0o1uq1bJyDBA== From: "tip-bot2 for Hou Tao" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] locking/percpu-rwsem: Use this_cpu_{inc,dec}() for read_count Cc: Hou Tao , "Peter Zijlstra (Intel)" , Will Deacon , Oleg Nesterov , x86 , LKML In-Reply-To: <20200915140750.137881-1-houtao1@huawei.com> References: <20200915140750.137881-1-houtao1@huawei.com> MIME-Version: 1.0 Message-ID: <160041819402.15536.17324618125529434873.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/urgent branch of tip: Commit-ID: e6b1a44eccfcab5e5e280be376f65478c3b2c7a2 Gitweb: https://git.kernel.org/tip/e6b1a44eccfcab5e5e280be376f65478c3b2c7a2 Author: Hou Tao AuthorDate: Tue, 15 Sep 2020 22:07:50 +08:00 Committer: Peter Zijlstra CommitterDate: Wed, 16 Sep 2020 16:26:56 +02:00 locking/percpu-rwsem: Use this_cpu_{inc,dec}() for read_count The __this_cpu*() accessors are (in general) IRQ-unsafe which, given that percpu-rwsem is a blocking primitive, should be just fine. However, file_end_write() is used from IRQ context and will cause load-store issues on architectures where the per-cpu accessors are not natively irq-safe. Fix it by using the IRQ-safe this_cpu_*() for operations on read_count. This will generate more expensive code on a number of platforms, which might cause a performance regression for some of the other percpu-rwsem users. If any such is reported, we can consider alternative solutions. Fixes: 70fe2f48152e ("aio: fix freeze protection of aio writes") Signed-off-by: Hou Tao Signed-off-by: Peter Zijlstra (Intel) Acked-by: Will Deacon Acked-by: Oleg Nesterov Link: https://lkml.kernel.org/r/20200915140750.137881-1-houtao1@huawei.com --- include/linux/percpu-rwsem.h | 8 ++++---- kernel/locking/percpu-rwsem.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h index 5e033fe..5fda40f 100644 --- a/include/linux/percpu-rwsem.h +++ b/include/linux/percpu-rwsem.h @@ -60,7 +60,7 @@ static inline void percpu_down_read(struct percpu_rw_semaphore *sem) * anything we did within this RCU-sched read-size critical section. */ if (likely(rcu_sync_is_idle(&sem->rss))) - __this_cpu_inc(*sem->read_count); + this_cpu_inc(*sem->read_count); else __percpu_down_read(sem, false); /* Unconditional memory barrier */ /* @@ -79,7 +79,7 @@ static inline bool percpu_down_read_trylock(struct percpu_rw_semaphore *sem) * Same as in percpu_down_read(). */ if (likely(rcu_sync_is_idle(&sem->rss))) - __this_cpu_inc(*sem->read_count); + this_cpu_inc(*sem->read_count); else ret = __percpu_down_read(sem, true); /* Unconditional memory barrier */ preempt_enable(); @@ -103,7 +103,7 @@ static inline void percpu_up_read(struct percpu_rw_semaphore *sem) * Same as in percpu_down_read(). */ if (likely(rcu_sync_is_idle(&sem->rss))) { - __this_cpu_dec(*sem->read_count); + this_cpu_dec(*sem->read_count); } else { /* * slowpath; reader will only ever wake a single blocked @@ -115,7 +115,7 @@ static inline void percpu_up_read(struct percpu_rw_semaphore *sem) * aggregate zero, as that is the only time it matters) they * will also see our critical section. */ - __this_cpu_dec(*sem->read_count); + this_cpu_dec(*sem->read_count); rcuwait_wake_up(&sem->writer); } preempt_enable(); diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c index 8bbafe3..70a32a5 100644 --- a/kernel/locking/percpu-rwsem.c +++ b/kernel/locking/percpu-rwsem.c @@ -45,7 +45,7 @@ EXPORT_SYMBOL_GPL(percpu_free_rwsem); static bool __percpu_down_read_trylock(struct percpu_rw_semaphore *sem) { - __this_cpu_inc(*sem->read_count); + this_cpu_inc(*sem->read_count); /* * Due to having preemption disabled the decrement happens on @@ -71,7 +71,7 @@ static bool __percpu_down_read_trylock(struct percpu_rw_semaphore *sem) if (likely(!atomic_read_acquire(&sem->block))) return true; - __this_cpu_dec(*sem->read_count); + this_cpu_dec(*sem->read_count); /* Prod writer to re-evaluate readers_active_check() */ rcuwait_wake_up(&sem->writer);