Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp706135imp; Thu, 21 Feb 2019 09:30:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IZGsWiU48SBopGEySupK6K1W+H3P4f1LQeHO2Gle+bm9nu8AEEG3zbnIU0e89aUJlKNZvCf X-Received: by 2002:a63:a5b:: with SMTP id z27mr34846334pgk.78.1550770239335; Thu, 21 Feb 2019 09:30:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550770239; cv=none; d=google.com; s=arc-20160816; b=nSncP11PGaLJv0digP8jT1D4AsS+6UkLXVaA0yBD6vXEA36+u2Kq6tBkm8bJ5mmlln i5ZDNa9vFY68kV/ru8HYOkEO6k/mdWZ910oCLRrThHNSeU5OKXmaXNgkc2EvRHHMmZta vX+tuFQ4aO37z9y2IX9qnelT+a/fF/em0NdBYrw9C+ZqZqLJaB2YWC+yMqGGIkBeHJvX INJvIZ45w+T0fCfitYqg0U9cUr1Pr7ZdspzmeugTeH+CPEdWdYp1BDZaLxgbodPICJsq 8fNNpxByXeFuAOVi5dteB7931jyPt0pvqLLIU9ZEHohWy/3tud0jlVq3hpgEeJtbAImY x3LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=y3AP1IEJYgEAl+Z8eisfhD39mykYCmVcCZPAi6U+YDk=; b=K2xPbJKKD2Zw/zm3iA+UoDsDocHsXI75CnX/hbFmXvg8YbJbZd40F6/WNOZq2D8SVa YcIlp6g8urHn2I6ZBshWjo9wtcv3udNtrhjRxIcD2ohUc8f1SFalV2KRoBmQpa/8v+Y/ 63ZB42tNc0NfXBAhXFKh919nUEyzltmY68ys3yX/vvQuEpSleGlfHWSxYDkyWZPg/MR0 PRzoEJ0UrIbW/XKrPwnF9gV3eMH/KSbjQlI7pVmL+DwRGdhba3o315lNoQVyRa0qqMcC 3kn+X2zL2P2brCJj/VXcTm3aTCQH2VmKMsiJmyibO1XZK8ZtxG8QAusc8sGCyQJ15OfH aozQ== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o8si6690037pgl.23.2019.02.21.09.30.23; Thu, 21 Feb 2019 09:30:39 -0800 (PST) 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728623AbfBUR37 (ORCPT + 99 others); Thu, 21 Feb 2019 12:29:59 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46074 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726311AbfBUR36 (ORCPT ); Thu, 21 Feb 2019 12:29:58 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1LHOgKQ069402 for ; Thu, 21 Feb 2019 12:29:57 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qsxqbdpm2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 21 Feb 2019 12:29:57 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Feb 2019 17:29:56 -0000 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 21 Feb 2019 17:29:49 -0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1LHTmO924641626 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Feb 2019 17:29:48 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6237B205F; Thu, 21 Feb 2019 17:29:48 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 45749B2064; Thu, 21 Feb 2019 17:29:48 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.80.207.192]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 21 Feb 2019 17:29:48 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 56BC416C3B5F; Thu, 21 Feb 2019 09:29:48 -0800 (PST) Date: Thu, 21 Feb 2019 09:29:48 -0800 From: "Paul E. McKenney" To: Joel Fernandes Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Alexei Starovoitov , Christian Brauner , Daniel Borkmann , David Ahern , "David S. Miller" , Ido Schimmel , Ingo Molnar , "moderated list:INTEL ETHERNET DRIVERS" , Jakub Kicinski , Jeff Kirsher , Jesper Dangaard Brouer , John Fastabend , Josh Triplett , keescook@chromium.org, Lai Jiangshan , Martin KaFai Lau , Mathieu Desnoyers , netdev@vger.kernel.org, rcu@vger.kernel.org, Song Liu , Steven Rostedt , xdp-newbies@vger.kernel.org, Yonghong Song Subject: Re: [PATCH RFC 3/5] sched/cpufreq: Fix incorrect RCU API usage Reply-To: paulmck@linux.ibm.com References: <20190221054942.132388-1-joel@joelfernandes.org> <20190221054942.132388-4-joel@joelfernandes.org> <20190221091805.GX32477@hirez.programming.kicks-ass.net> <20190221152139.GB19213@google.com> <20190221153117.GT32494@hirez.programming.kicks-ass.net> <20190221155218.GZ11787@linux.ibm.com> <20190221161144.GU32494@hirez.programming.kicks-ass.net> <20190221171311.GA118415@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190221171311.GA118415@google.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19022117-0064-0000-0000-000003ACB109 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010638; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01164346; UDB=6.00608024; IPR=6.00944932; MB=3.00025682; MTD=3.00000008; XFM=3.00000015; UTC=2019-02-21 17:29:55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19022117-0065-0000-0000-00003C7D45F3 Message-Id: <20190221172948.GA11787@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-21_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=987 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902210125 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 21, 2019 at 12:13:11PM -0500, Joel Fernandes wrote: > On Thu, Feb 21, 2019 at 05:11:44PM +0100, Peter Zijlstra wrote: > > On Thu, Feb 21, 2019 at 07:52:18AM -0800, Paul E. McKenney wrote: > > > On Thu, Feb 21, 2019 at 04:31:17PM +0100, Peter Zijlstra wrote: > > > > On Thu, Feb 21, 2019 at 10:21:39AM -0500, Joel Fernandes wrote: > > > > > On Thu, Feb 21, 2019 at 10:18:05AM +0100, Peter Zijlstra wrote: > > > > > > On Thu, Feb 21, 2019 at 12:49:40AM -0500, Joel Fernandes (Google) wrote: > > > > > > > @@ -34,8 +34,12 @@ void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, > > > > > > > if (WARN_ON(!data || !func)) > > > > > > > return; > > > > > > > > > > > > > > - if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu))) > > > > > > > + rcu_read_lock(); > > > > > > > + if (WARN_ON(rcu_dereference(per_cpu(cpufreq_update_util_data, cpu)))) { > > > > > > > + rcu_read_unlock(); > > > > > > > return; > > > > > > > + } > > > > > > > + rcu_read_unlock(); > > > > > > > > > > > > > > data->func = func; > > > > > > > rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data); > > > > > For whatever it is worth, in that case it could use rcu_access_pointer(). > > > And this primitive does not do the lockdep check for being within an RCU > > > read-side critical section. As Peter says, if there is no dereferencing, > > > there can be no use-after-free bug, so the RCU read-side critical is > > > not needed. > > > > On top of that, I suspect this is under the write-side lock (we're doing > > assignment after all). > > Yes it is under a policy->rwsem, just confirmed that. > > And indeed rcu_read_lock() is not needed here in this patch, thanks for > pointing that out. Sometimes the word "dereference" plays some visual tricks > and in this case tempted me to add an RCU reader section ;-) Assuming you > guys are in agreement with usage of rcu_access_pointer() here to keep sparse > happy, I'll rework the patch accordingly and resubmit with that. Works for me! Thanx, Paul