Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp884392pxb; Thu, 15 Apr 2021 08:44:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+GglkzjmRxUWyJ4Uf56WP+zDU2qSLdbe8nr0YGuRdPZsxfk0UaZJuqzT3TrtFnk6SPuhn X-Received: by 2002:a63:c847:: with SMTP id l7mr4051086pgi.445.1618501457235; Thu, 15 Apr 2021 08:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618501457; cv=none; d=google.com; s=arc-20160816; b=Xi5QD7UE3WOJ89lhPh10oc4Vzo0JnB4B7x64IF2L/1Ul2Ge+n7aYFySXUK4FPGRLrK KtE5ctJR/dh3kycmxX/xfByxrXkixrio7f1OezG36GCplT2qvQV45us+sSmDA7JbLRVD Xd2WoB53eZ8xISD8RtgUFDFfHehx8QvOh8oVI4JTfgpp/UU7jcgbKkcUDu5JwsFvyRkh zQGYVHGfudKmq77PXyZ5pNyZHX/Zaqsjk+48FfxDp2kGEkTCrIRFMkr8Y5m8iJHIznBw +safGzshvl8GNiQL+VNHWka1vpDqBqZyUa3nllFWCAZ9FXIlH9x2vDZydwhedpQNnpHJ LUyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=SFZ0jdbEI7CvBOZcObgMStJTg2BVUBrm23X039YlSaM=; b=UHdlUv4hOhecOLnvpbCBOEfZXkKaysQ+k36WF3qdmFZwuGoemZhXzMXDhM5z32qs/i u7pUfAAjRZLKEoSW4woyh5uQhVpVJ0w12fTjX5QO19nxz2aLKHKR9lIt40ibgUtsxW0U W+crXg010Mi3naQjrN64mEuF97wQA1OHIPP2zZcGOCGFaBBkWakDiXLvZEO+iN3frdd/ DIzSpn1hLeZlKd5vwKL/KRoRvh+/VyV+RpVuAFRVsltibloqvbB5Wb4TezSX/G3MIyZ9 PJeD6m12moYKVW7p7CP5DyOi7PO9AjyFA6bMb09YToDbY/yNrJsrIxi8oMc7TYRrbQI7 OjYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a0p+pbB8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q24si3698709plr.89.2021.04.15.08.44.04; Thu, 15 Apr 2021 08:44:17 -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=pass header.i=@kernel.org header.s=k20201202 header.b=a0p+pbB8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233520AbhDOPnu (ORCPT + 99 others); Thu, 15 Apr 2021 11:43:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:34892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbhDOPnt (ORCPT ); Thu, 15 Apr 2021 11:43:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 90881610F7; Thu, 15 Apr 2021 15:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618501406; bh=YLMhMQguNSx4cZXG9Ecz53WEtgSkn7njMrvxU0oHs/Q=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=a0p+pbB838oArB86PRe1JQ/6hGuRAKy3yXxMsJWrg5nY9uo537LZTre9p5RYKTClZ tFmjz/Qx5nC1tp2nGFST7PakZyKn6qJ3Ip+HnrvRd8Cdcs6i6SLlBkreZLLBKBGIm1 2vTETyo8zvZBmrdh4kgtWkLAYgJZ2D5FUdA1/m6DSLvADlvJ3doGyd5wL8399Hosua EvrzkaA3Br7FOJ5bHhK7fCpj299HvwhrVMxJddeHe36+kyMl0MiCsAuOrggEcRStGs H4JEhPuT8Rx351DdjP5lxNZExW+ak05dhE48CmIXjTZ8SnC1IbwRIG422G5oahCT/Q 0IuT9BTlatX+w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 30CEB5C011B; Thu, 15 Apr 2021 08:43:26 -0700 (PDT) Date: Thu, 15 Apr 2021 08:43:26 -0700 From: "Paul E. McKenney" To: "Xu, Yanfei" Cc: rcu@vger.kernel.org, LKML Subject: Re: [Qestion] Is preempt_disable/enable needed in non-preemption code path Message-ID: <20210415154326.GF4510@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 11:04:05PM +0800, Xu, Yanfei wrote: > Hi experts, > > I am learning rcu mechanism and its codes. When looking at the > rcu_blocking_is_gp(), I found there is a pair preemption disable/enable > operation in non-preemption code path. And it has been a long time. I can't > understand why we need it? Is there some thing I missed? If not, can we > remove the unnecessary operation like blow? Good point, you are right that preemption is disabled anyway in that block of code. However, preempt_disable() and preempt_enable() also prevent the compiler from moving that READ_ONCE() around. So my question to you is whether it is safe to remove those statements entirely or whether they should instead be replaced by barrier() or similar. Thanx, Paul > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index da6f5213fb74..c6d95a00715e 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -3703,7 +3703,6 @@ static int rcu_blocking_is_gp(void) > if (IS_ENABLED(CONFIG_PREEMPTION)) > return rcu_scheduler_active == RCU_SCHEDULER_INACTIVE; > might_sleep(); /* Check for RCU read-side critical section. */ > - preempt_disable(); > /* > * If the rcu_state.n_online_cpus counter is equal to one, > * there is only one CPU, and that CPU sees all prior accesses > @@ -3718,7 +3717,6 @@ static int rcu_blocking_is_gp(void) > * Those memory barriers are provided by CPU-hotplug code. > */ > ret = READ_ONCE(rcu_state.n_online_cpus) <= 1; > - preempt_enable(); > return ret; > } > > > > Best regards, > Yanfei