Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp853955imp; Wed, 20 Feb 2019 10:10:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IaI/WOxCfvDIXgaBoR945+HRRcHOAKHVWmyCYgAzOBCXaT5c4g8gGcWPQoAiE2jAqwMKVl1 X-Received: by 2002:a63:cf4c:: with SMTP id b12mr16046390pgj.316.1550686211031; Wed, 20 Feb 2019 10:10:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550686211; cv=none; d=google.com; s=arc-20160816; b=k9HGrHayDKGMkuK36E6RPL7R6x4eChynaD0qUObXTKPVVybPJ2pLsMGLAZG6FlLTvY g0TLZGGDVVPh00XVC3hJmE8mhKSdQMyODv+9ZLEszb08FOxVlVC81pD14cdl7LrtbWsa mpTx6OCqVHDVRGVrksAB8bthbv0P/kDB7I/4srBsXajv7HEUfMUdUEuPV0ZAPMNmTDJ9 vgp6+9KD6bQz+lTreVZy51118G3sva/fbFMgFHNCe7LQV/UprNM4i8ankJ5dubI3oHPV /oN0ff7TQ/2Xo57Jn7NZErWibcyrzhz2W63G2Ml4RAqkxpU+Lb8Y/jWDFzaE6hcmEyiA Go8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pT2WI0iYdHDoEv6W67natUFu/U0PIMIh3oiHvWB9Li4=; b=vN54rKFJLcpsdnZqDpJTIu8WQy8NT7QnhMkpWCINeeO+NUf09FYClWrdTlgKTyAsnQ rlTDH1s+quhUk3RoNL6lLscL/z/ckxiI3od6AlKwiB+KFAg4sHlN8JhJfoN+npcyo8aC ZKZgQNqK1+/JTSPx2hUhtel1rg4frJiPtb4Pk45axHVFK1lyZAaWUAz651M+4ojxbdiy JAgbDOGuatYZuE8MbEDHm047wQdgcd1rcjghp/2lhhgkPn6Z4jRy7bKdmN7Ms3Hp8yD5 zRp2UZ4OKcCoomh2gZ9qwsH23PuRwomPCwlYPZ09Lj/EtJpMRsbeRCo/T7kaYggzJEKA mSmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=IskHqcEI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11si18731783pgk.344.2019.02.20.10.09.55; Wed, 20 Feb 2019 10:10:11 -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; dkim=pass header.i=@joelfernandes.org header.s=google header.b=IskHqcEI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726601AbfBTSIz (ORCPT + 99 others); Wed, 20 Feb 2019 13:08:55 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40526 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbfBTSIy (ORCPT ); Wed, 20 Feb 2019 13:08:54 -0500 Received: by mail-qt1-f194.google.com with SMTP id j36so28260173qta.7 for ; Wed, 20 Feb 2019 10:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pT2WI0iYdHDoEv6W67natUFu/U0PIMIh3oiHvWB9Li4=; b=IskHqcEIb+j0Hr9YWTsw4EwjQZ1y0epU44bLymSuQLCL8+mdGBhjBsAmMHtH/Q4yGC GeEpCHTWvIlLy6xN+KyKLuQ0xF9stEoModZlE3iJXxeAF1pSr+v3m5mImc/8FP4zX5nq J/6OuXkT+mtllSddOjoithFjgijYe21Obtzh0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pT2WI0iYdHDoEv6W67natUFu/U0PIMIh3oiHvWB9Li4=; b=e/CZccAOhHvc7H+UifB+BAGc7/OqB4EcaqDudPDMvcG8ISuEfU09clJdReZUM+H63S KdLf9bpOFB7rlfiPa7w4F46NwDqPkrcZrktHvjh0qwIFyfhd6dTAz2fA60OgChlWySmw cOlZnfaoQpSkyQtUxGqVnarHYdJtUD4TlIxnS7gnaqdtXzprRQruTJ3vuV9hNp57Hy9x dbFWJwL8EOIdSYO4NXleSUJe23rbKivOzJPrlvP+OQkHUDPes5OyHkWXhf8S7HZXE9tQ o1+Qynteox1cvYX++qS5kV6AcWA5r3qONInBF19YDMUtv+vNGdOlSOBKft1Pd5eHk4fw h4pQ== X-Gm-Message-State: AHQUAubPOEmkCPGi5PcnIz2wHhA6UARooS/J/mCGQXOokwQ9wq/3sjx6 /oGBeZ+PmtlSX3QPP4O2KJFR53tOdTo= X-Received: by 2002:aed:302f:: with SMTP id 44mr11626107qte.178.1550686133160; Wed, 20 Feb 2019 10:08:53 -0800 (PST) Received: from localhost ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id j66sm11831189qkj.27.2019.02.20.10.08.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 10:08:51 -0800 (PST) Date: Wed, 20 Feb 2019 13:08:51 -0500 From: Joel Fernandes To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org Subject: Re: [RFC 1/5] net: rtnetlink: Fix incorrect RCU API usage Message-ID: <20190220180851.GA97771@google.com> References: <20190220040827.136184-1-joel@joelfernandes.org> <20190220040827.136184-2-joel@joelfernandes.org> <20190220164034.GM11787@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190220164034.GM11787@linux.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 20, 2019 at 08:40:34AM -0800, Paul E. McKenney wrote: > On Tue, Feb 19, 2019 at 11:08:23PM -0500, Joel Fernandes (Google) wrote: > > From: Joel Fernandes > > > > rtnl_register_internal() and rtnl_unregister_all tries to directly > > dereference an RCU protected pointed outside RCU read side section. > > While this is Ok to do since a lock is held, let us use the correct > > API to avoid programmer bugs in the future. > > > > This also fixes sparse warnings arising from not using RCU API. > > > > net/core/rtnetlink.c:332:13: warning: incorrect type in assignment > > (different address spaces) net/core/rtnetlink.c:332:13: expected > > struct rtnl_link **tab net/core/rtnetlink.c:332:13: got struct > > rtnl_link *[noderef] * > > > > Signed-off-by: Joel Fernandes > > First, thank you for doing this! No problem, it is my pleasure. It is just good to see these warnings/errors show up (which I didn't anticipate when I first wrote the check) so we can harden the kernel more fwiw. > I was going to complain that these were update-side accesses, but it > looks like rtnl_dereference() already handles both readers and updaters. > > So looks good to me, but the maintainers of course have the final word. Thanks! Also my confidence level is a bit less for patches 4/5 and 5/5, could you share your thoughts on those? The scheduler code seems to use rcu_assign_pointer() in those where it seems a WRITE_ONCE() would just suffice. In fact, in some cases I replaced with smp_store_release() just to be safe. Speaking of which, do you feel those are legit uses of rcu_assign_pointer() or would you expect rcu_assign_pointer() to be used only for RCU protected pointers? I am hoping it is the latter since that is what the sparse check expects (and RCU protected pointer being assigned to). - Joel > > > --- > > net/core/rtnetlink.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c > > index 5ea1bed08ede..98be4b4818a9 100644 > > --- a/net/core/rtnetlink.c > > +++ b/net/core/rtnetlink.c > > @@ -188,7 +188,7 @@ static int rtnl_register_internal(struct module *owner, > > msgindex = rtm_msgindex(msgtype); > > > > rtnl_lock(); > > - tab = rtnl_msg_handlers[protocol]; > > + tab = rtnl_dereference(rtnl_msg_handlers[protocol]); > > if (tab == NULL) { > > tab = kcalloc(RTM_NR_MSGTYPES, sizeof(void *), GFP_KERNEL); > > if (!tab) > > @@ -329,7 +329,7 @@ void rtnl_unregister_all(int protocol) > > BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX); > > > > rtnl_lock(); > > - tab = rtnl_msg_handlers[protocol]; > > + tab = rtnl_dereference(rtnl_msg_handlers[protocol]); > > if (!tab) { > > rtnl_unlock(); > > return; > > -- > > 2.21.0.rc0.258.g878e2cd30e-goog > > >