Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1140169ybe; Wed, 11 Sep 2019 10:00:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhnA2+QsF6ju30jpHVONXI3ilWk5Uu98B8P+90tyG4jT9nh0U0PYFzhtguistFswHXGVhU X-Received: by 2002:a50:8d5e:: with SMTP id t30mr37772201edt.112.1568221202609; Wed, 11 Sep 2019 10:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568221202; cv=none; d=google.com; s=arc-20160816; b=ACb7xqXulRg5v/hddvhOgfNKCkaZOTjwvKj/6sDeY2BDUi8ZJjoYJthhxPYn6yoWBa pndOCYrcKc3HnytbJBxPLdoq4In0x70vJN0Zd9HEE/zLbbqNwEpMyGUtrx579aB0/4DM QUXoxeYo/LS4ahobNh3lOqnezSUu6QAIY2o9MvZrERgWVCXZZpSD53TRttjTWV/TqlPC /GOmbCX0VXPOcyaS1h/Ito74gNnERsv5frCQMuePxBCFgaHALfLIxkSEkgFUXPWhXMDl KZ1sc3YGE/wTNVvSbsR6d/E+QTToOTmZSPxBdv5cCCexQT06+SS6MXcF09RapdSGhkTx +4cQ== 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; bh=ERgjDWG8iP8DGkIqIfA4y5xhFD8QUkvC4KOVIJlbYpE=; b=YGIldpbZqkff9xMw78qm3KwwrfiFm0dwQYY7znonWAvEjVYiaVC9EyR8v13KU1KYpK UMDeQ3QyY/Kwks/GkmFBRsq99Cz2bORlw2VyXTSr+DZOL/rpPhPCUdC12j3al3RJCHxR BVsGJzWtvIZD1DKS6YFnuGrdUqHby7AmjnjiIevqzPXKz8YOH5G+DmriwAHdRHYQge6b VTygPbDB8x++2mbj9rp2zVzPTVpxK1AyRrYFq8zNqt3DHundjK6eQ8ldZc3glr4wn3MO Y2IFazl6Es2nM9OxGkXkss2lQpMfAhXLlJRv28jE3dCkNVf3e1QjQNRmNuYLTILUfMSU 2HkQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si11762423ejv.318.2019.09.11.09.59.38; Wed, 11 Sep 2019 10:00:02 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729534AbfIKQ5l (ORCPT + 99 others); Wed, 11 Sep 2019 12:57:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40390 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729028AbfIKQ5l (ORCPT ); Wed, 11 Sep 2019 12:57:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9701D30833BE; Wed, 11 Sep 2019 16:57:40 +0000 (UTC) Received: from t460p.redhat.com (ovpn-117-113.phx2.redhat.com [10.3.117.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74C7960BEC; Wed, 11 Sep 2019 16:57:36 +0000 (UTC) From: Scott Wood To: Sebastian Andrzej Siewior Cc: linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org, "Paul E . McKenney" , Joel Fernandes , Thomas Gleixner , Steven Rostedt , Peter Zijlstra , Juri Lelli , Clark Williams , Scott Wood Subject: [PATCH RT v3 1/5] rcu: Acquire RCU lock when disabling BHs Date: Wed, 11 Sep 2019 17:57:25 +0100 Message-Id: <20190911165729.11178-2-swood@redhat.com> In-Reply-To: <20190911165729.11178-1-swood@redhat.com> References: <20190911165729.11178-1-swood@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 11 Sep 2019 16:57:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A plain local_bh_disable() is documented as creating an RCU critical section, and (at least) rcutorture expects this to be the case. However, in_softirq() doesn't block a grace period on PREEMPT_RT, since RCU checks preempt_count() directly. Even if RCU were changed to check in_softirq(), that wouldn't allow blocked BH disablers to be boosted. Fix this by calling rcu_read_lock() from local_bh_disable(), and update rcu_read_lock_bh_held() accordingly. Signed-off-by: Scott Wood --- v3: Remove change to rcu_read_lock_bh_held(), and move debug portions of rcu_read_[un]lock_bh() to separate functions --- include/linux/rcupdate.h | 40 ++++++++++++++++++++++++++++++++-------- kernel/softirq.c | 12 +++++++++--- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 388ace315f32..9ce7c5006a5e 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -600,6 +600,36 @@ static inline void rcu_read_unlock(void) rcu_lock_release(&rcu_lock_map); /* Keep acq info for rls diags. */ } +#ifdef CONFIG_PREEMPT_RT_FULL +/* + * On RT, local_bh_disable() calls rcu_read_lock() -- no need to + * track it twice. + */ +static inline void rcu_bh_lock_acquire(void) +{ +} + +static inline void rcu_bh_lock_release(void) +{ +} +#else +static inline void rcu_bh_lock_acquire(void) +{ + __acquire(RCU_BH); + rcu_lock_acquire(&rcu_bh_lock_map); + RCU_LOCKDEP_WARN(!rcu_is_watching(), + "rcu_read_lock_bh() used illegally while idle"); +} + +static inline void rcu_bh_lock_release(void) +{ + RCU_LOCKDEP_WARN(!rcu_is_watching(), + "rcu_read_unlock_bh() used illegally while idle"); + rcu_lock_release(&rcu_bh_lock_map); + __release(RCU_BH); +} +#endif + /** * rcu_read_lock_bh() - mark the beginning of an RCU-bh critical section * @@ -615,10 +645,7 @@ static inline void rcu_read_unlock(void) static inline void rcu_read_lock_bh(void) { local_bh_disable(); - __acquire(RCU_BH); - rcu_lock_acquire(&rcu_bh_lock_map); - RCU_LOCKDEP_WARN(!rcu_is_watching(), - "rcu_read_lock_bh() used illegally while idle"); + rcu_bh_lock_acquire(); } /* @@ -628,10 +655,7 @@ static inline void rcu_read_lock_bh(void) */ static inline void rcu_read_unlock_bh(void) { - RCU_LOCKDEP_WARN(!rcu_is_watching(), - "rcu_read_unlock_bh() used illegally while idle"); - rcu_lock_release(&rcu_bh_lock_map); - __release(RCU_BH); + rcu_bh_lock_release(); local_bh_enable(); } diff --git a/kernel/softirq.c b/kernel/softirq.c index d16d080a74f7..6080c9328df1 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -115,8 +115,10 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int cnt) long soft_cnt; WARN_ON_ONCE(in_irq()); - if (!in_atomic()) + if (!in_atomic()) { local_lock(bh_lock); + rcu_read_lock(); + } soft_cnt = this_cpu_inc_return(softirq_counter); WARN_ON_ONCE(soft_cnt == 0); current->softirq_count += SOFTIRQ_DISABLE_OFFSET; @@ -151,8 +153,10 @@ void _local_bh_enable(void) #endif current->softirq_count -= SOFTIRQ_DISABLE_OFFSET; - if (!in_atomic()) + if (!in_atomic()) { + rcu_read_unlock(); local_unlock(bh_lock); + } } void _local_bh_enable_rt(void) @@ -185,8 +189,10 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt) WARN_ON_ONCE(count < 0); local_irq_enable(); - if (!in_atomic()) + if (!in_atomic()) { + rcu_read_unlock(); local_unlock(bh_lock); + } current->softirq_count -= SOFTIRQ_DISABLE_OFFSET; preempt_check_resched(); -- 1.8.3.1