Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp753464ybz; Wed, 15 Apr 2020 18:12:46 -0700 (PDT) X-Google-Smtp-Source: APiQypL1NW+F7IXkaPXOGuBewqMUabArHhn3gnomyrkZSex339zZKPAPEEA9psd56zCkv58+ovnz X-Received: by 2002:a17:906:1a06:: with SMTP id i6mr7425585ejf.90.1586999566490; Wed, 15 Apr 2020 18:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586999566; cv=none; d=google.com; s=arc-20160816; b=ZRNP5njCxFYRushOSrCe68Z1WAs17jiAtTN+6V/X8otvqGYydIXKKAAjTiJM3aV07S iaGas6eJt23DwmQAjP3UJmmo2qfA0NwcpxM5PuHfmGEGsSJ/yTUeumREXDgB2phtt3Us Cb9HiSO4GnKeUw42l5QYxrYZd96u5LCSh4mjTxgB7bD0kwDTC4zvWCpj2qyBp7ktjuDh JjkTGnOYy6Gp+q0UiQC7Ao7wi2RHHahwBYSNSQFLCaoYVIS4oLgxMt/XhFGCsDos/mxt AeRp8ZzVvUAaeDCKr/n4edNagDL9up22M5hJ3FOw5kiiNuFkcYcYYxv2yhyFu402vQ8U m8SA== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=k88r+X75flmgfiffmuE0qlVrsCbiHcgj7P+pMNCOJUU=; b=XBk3eIyynfXV+PZL8ZLk9aSozkiuRCbt/rzBu8r7MIsnvkiXF3vXwyrp79g6nKQmEA HFNIrEiTkNjzToPZP8Yqsu81z5klpJDXWB5W4Qn6RgapZfMsz1FSyKr1o+ps3HIL/IJ5 08AfIihwNeopDLJxPo2/bi7mrj7pi7ad0qZY5iw+O6Qqit33bmZEH4m83n69LX3DmzfT cAzSJM9XyVHDL2p0RLkCNg00+5xCtcBYo9bsn5Jtd/bTwwMbYVH1Sz+mER54TbFFVsf9 YrMqxL9eRGmiE0AiRjfvzjcnjPecqF/k6Tl0VIciO7jWNIa35iJYDLHF2PiYxJdofdZ/ M5Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TyTN6XRS; 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 b3si12325395edq.453.2020.04.15.18.12.23; Wed, 15 Apr 2020 18:12:46 -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=default header.b=TyTN6XRS; 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 S1727919AbgDOWFD (ORCPT + 99 others); Wed, 15 Apr 2020 18:05:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:45674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727839AbgDOWFA (ORCPT ); Wed, 15 Apr 2020 18:05:00 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (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 E234C2076D; Wed, 15 Apr 2020 22:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586988299; bh=LcmVk+AMRQ3I615QuE9bZzomRfxqsLPUOgb5U3DaVgs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=TyTN6XRS19bqHCa2oJwjj/9dUpcAIHXqxkUXY/MydHuKsrpWcd1URLwQ+9Rb6Du1x bv7FKcYyXo8ni7d66CDtmw009qFCygHv+gXEDGdpsLbqGRMnjOyXwL2o1F4WfDvXRU +D+jhl2fzbppuITiTnMA9gcco1sulGduam7so11M= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id AE8F53522AD1; Wed, 15 Apr 2020 15:04:59 -0700 (PDT) Date: Wed, 15 Apr 2020 15:04:59 -0700 From: "Paul E. McKenney" To: Steven Rostedt 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: <20200415220459.GE17661@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200415085348.5511a5fe@gandalf.local.home> <20200415161424.584d07d3@gandalf.local.home> <20200415164116.40564f2c@gandalf.local.home> <20200415174918.154a86d0@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200415174918.154a86d0@gandalf.local.home> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanx, Paul