From: Jon Hunter Subject: Re: [PATCH v1 1/2] soc/tegra: pmc: Turn powergates_lock into spinlock Date: Mon, 15 Oct 2018 13:52:26 +0100 Message-ID: <7369869e-e58f-3760-d428-b00fb9cd28d9@nvidia.com> References: <20180830183635.4474-1-digetx@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20180830183635.4474-1-digetx@gmail.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Dmitry Osipenko , Thierry Reding Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org List-Id: linux-tegra@vger.kernel.org On 30/08/18 19:36, Dmitry Osipenko wrote: > This fixes splats like the one below if CONFIG_DEBUG_ATOMIC_SLEEP=y > and machine (Tegra30) booted with SMP=n or all secondary CPU's are put > offline. > > BUG: sleeping function called from invalid context at kernel/locking/mutex.c:254 > in_atomic(): 1, irqs_disabled(): 128, pid: 0, name: swapper/0 > CPU: 0 PID: 0 Comm: swapper/0 Tainted: G C 4.18.0-next-20180821-00180-gc3ebb6544e44-dirty #823 > Hardware name: NVIDIA Tegra SoC (Flattened Device Tree) > [] (unwind_backtrace) from [] (show_stack+0x20/0x24) > [] (show_stack) from [] (dump_stack+0x94/0xa8) > [] (dump_stack) from [] (___might_sleep+0x13c/0x174) > [] (___might_sleep) from [] (__might_sleep+0x70/0xa8) > [] (__might_sleep) from [] (mutex_lock+0x2c/0x70) > [] (mutex_lock) from [] (tegra_powergate_is_powered+0x44/0xa8) > [] (tegra_powergate_is_powered) from [] (tegra30_cpu_rail_off_ready+0x30/0x74) > [] (tegra30_cpu_rail_off_ready) from [] (tegra30_idle_lp2+0xa0/0x108) > [] (tegra30_idle_lp2) from [] (cpuidle_enter_state+0x140/0x540) > [] (cpuidle_enter_state) from [] (cpuidle_enter+0x40/0x4c) > [] (cpuidle_enter) from [] (call_cpuidle+0x30/0x48) > [] (call_cpuidle) from [] (do_idle+0x238/0x28c) > [] (do_idle) from [] (cpu_startup_entry+0x28/0x2c) > [] (cpu_startup_entry) from [] (rest_init+0xd8/0xdc) > [] (rest_init) from [] (start_kernel+0x41c/0x430) Given the above, rather than converting to a spinlock I wonder if we are just better off dropping the mutex completely from tegra_powergate_is_powered()? Otherwise ... > Signed-off-by: Dmitry Osipenko > --- > drivers/soc/tegra/pmc.c | 36 ++++++++++++++++++------------------ > 1 file changed, 18 insertions(+), 18 deletions(-) > > diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c > index 2d6f3fcf3211..d6bc9f66f1cd 100644 > --- a/drivers/soc/tegra/pmc.c > +++ b/drivers/soc/tegra/pmc.c > @@ -186,7 +186,7 @@ struct tegra_pmc_soc { > * @lp0_vec_phys: physical base address of the LP0 warm boot code > * @lp0_vec_size: size of the LP0 warm boot code > * @powergates_available: Bitmap of available power gates > - * @powergates_lock: mutex for power gate register access > + * @powergates_lock: lock for power gate register access > */ > struct tegra_pmc { > struct device *dev; > @@ -215,7 +215,7 @@ struct tegra_pmc { > u32 lp0_vec_size; > DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX); > > - struct mutex powergates_lock; > + spinlock_t powergates_lock; > }; > > static struct tegra_pmc *pmc = &(struct tegra_pmc) { > @@ -288,10 +288,10 @@ static int tegra_powergate_set(unsigned int id, bool new_state) > if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) > return -EINVAL; > > - mutex_lock(&pmc->powergates_lock); > + spin_lock(&pmc->powergates_lock); > > if (tegra_powergate_state(id) == new_state) { > - mutex_unlock(&pmc->powergates_lock); > + spin_unlock(&pmc->powergates_lock); > return 0; > } > > @@ -300,7 +300,7 @@ static int tegra_powergate_set(unsigned int id, bool new_state) > err = readx_poll_timeout(tegra_powergate_state, id, status, > status == new_state, 10, 100000); > > - mutex_unlock(&pmc->powergates_lock); > + spin_unlock(&pmc->powergates_lock); ... the above readx_poll_timeout needs to be converted to the atomic version. Furthermore, the above 100ms timeout is probably not suited to spinlock. Cheers Jon -- nvpublic