Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp755472ybz; Wed, 15 Apr 2020 18:15:15 -0700 (PDT) X-Google-Smtp-Source: APiQypJdGAj+vz7xGMEhVRcEKl4QI4J+C54+0IPxzEdhJrdr4aVRjSrqftv0kbq1jTJhiQWFgysc X-Received: by 2002:a17:906:1c8a:: with SMTP id g10mr7899974ejh.342.1586999715662; Wed, 15 Apr 2020 18:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586999715; cv=none; d=google.com; s=arc-20160816; b=dG/Tsl1KiWZhAhnBUn5Y0NJ4BhU+ajcrSb3CR4VlIkLg0bDYgeoA7qv+BRgI82Tf9m YVKHfmajXN3bGyBnC55nJ8N64TFL5hGZmSPwd48/fjIQU3db1iidanjqkMpb5g0sDw9t HRthuzjdFcDGivfsj+vl293YPkmJjW7/vJTxHsvoirR5R/8Li+KHvdJVOa0vzeMqQp97 /U7QVOfTrYkRXgiAa46cbFovonQNvRJNeEnMItarP7FSqwtSt0ewGO168eCRjUy5JJQw kVDsWNsUWnoScCBPSFDDqdCjQyUGXAP7fgqgrDIoih6uObroMZVyGRO2BEEF3ExzAMIT gYfA== 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:subject:cc:to:from:date; bh=jrD36ykA7JYd9XpGODkvD0tgVXFdrQKi/XYqxviOqRY=; b=AiOOsXrEC/XgfM0O0UjwzY0ODqLVS2P4LNJFQ4MKgSoEQ1W/AHfOdeIokDwW0hi6Gs anKetnhO9FCaKPNwHAlVhD21GkFVMRktjyzP2zFIp6WJm/YFoOIJY293rsLq0L0JSxYX hRm3m1az7Q6P5fiasllypNcy6Ko5zVt5jCMDm32GXFXKOaDl09qt2vt1Y2R6UUO1n7M2 9bDg2s7CIGM88QA/DdremY8FR89pAXYcOccL+ius5j/A959ujoGVvwbBjzwP1ZNj1b9I PEtZmZh9DaGgj4/g0+zOV0AQPSvfpLpYSUH+E/H9o52P0INix3CcohWAJxDz1Naz2m9I Slhg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w18si4996759edv.491.2020.04.15.18.14.53; Wed, 15 Apr 2020 18:15:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732749AbgDOWvc (ORCPT + 99 others); Wed, 15 Apr 2020 18:51:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:34244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbgDOWvY (ORCPT ); Wed, 15 Apr 2020 18:51:24 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B2642076D; Wed, 15 Apr 2020 22:51:23 +0000 (UTC) Date: Wed, 15 Apr 2020 18:51:21 -0400 From: Steven Rostedt To: "Paul E. McKenney" Cc: John Stultz , Josh Triplett , lkml , Bjorn Andersson , Saravana Kannan , Todd Kjos , Stephen Boyd , Peter Zijlstra , Thomas Gleixner Subject: Re: On trace_*_rcuidle functions in modules Message-ID: <20200415185121.381a4bc3@gandalf.local.home> In-Reply-To: <20200415220459.GE17661@paulmck-ThinkPad-P72> References: <20200415085348.5511a5fe@gandalf.local.home> <20200415161424.584d07d3@gandalf.local.home> <20200415164116.40564f2c@gandalf.local.home> <20200415174918.154a86d0@gandalf.local.home> <20200415220459.GE17661@paulmck-ThinkPad-P72> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Apr 2020 15:04:59 -0700 "Paul E. McKenney" wrote: > On Wed, Apr 15, 2020 at 05:49:18PM -0400, Steven Rostedt wrote: > > On Wed, 15 Apr 2020 14:02:04 -0700 > > John Stultz wrote: > > > > > > > > So in my case your concerns may not be a problem, but I guess > > > generally it might. Though I'd hope the callback would be unregistered > > > (and whatever waiting for the grace period to complete be done) before > > > the module removal is complete. But maybe I'm still missing your > > > point? > > > > Hmm, you may have just brought up a problem here... > > > > You're saying that cpu_pm_register_notifier() callers are called from non > > RCU watching context? If that's the case, we have this: > > > > int cpu_pm_unregister_notifier(struct notifier_block *nb) > > { > > return atomic_notifier_chain_unregister(&cpu_pm_notifier_chain, nb); > > } > > > > And this: > > > > int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, > > struct notifier_block *n) > > { > > unsigned long flags; > > int ret; > > > > spin_lock_irqsave(&nh->lock, flags); > > ret = notifier_chain_unregister(&nh->head, n); > > spin_unlock_irqrestore(&nh->lock, flags); > > synchronize_rcu(); > > return ret; > > } > > > > Which means that if something registered a cpu_pm notifier, then > > unregistered it, and freed whatever the notifier accesses, then there's a > > chance that the synchronize_rcu() can return before the called notifier > > finishes, and anything that notifier accesses could have been freed. > > > > I believe that module code should not be able to be run in RCU non watching > > context, and neither should notifiers. I think we just stumbled on a bug. > > > > Paul? > > Or we say that such modules cannot be unloaded. Or that such modules' > exit handlers, after disentangling themselves from the idle loop, must > invoke synchronize_rcu_rude() or similar, just as modules that use > call_rcu() are currently required to invoke rcu_barrier(). > > Or is it possible to upgrade the protection that modules use? > > My guess is that invoking rcu_irq_enter() and rcu_irq_exit() around every > potential call into module code out of the PM code is a non-starter, > but I cannot prove that either way. > No this has nothing to do with modules. This is a bug right now with the cpu_pm notifier (after looking at the code, it's not a bug right now, see below). Say you have something that allocates some data and registers a callback to the cpu_pm notifier that access that data. Then for some reason, you want to remove that notifier and free the data. Usually you would do: cpu_pm_unregister_notifier(my_notifier); kfree(my_data); But the problem is that the callback of that my_notifier could be executing in a RCU non-watching space, and the cpu_pm_unregister_notifier() can return before the my_notifier is done, and the my_data is freed. Then the callback for the my_notifier could still be accessing the my_data. /me goes and reads the code and sees this is not an issue, and you can ignore the above concern. I was about to suggest a patch, but that has already been written... 313c8c16ee62b ("PM / CPU: replace raw_notifier with atomic_notifier") Which surrounds the notifier callbacks with rcu_irq_enter_irqson() Which means that if John moves the code to use the notifier, then he could also remove the _rcuidle(), because RCU will be watching. -- Steve