Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5033120imw; Tue, 19 Jul 2022 19:19:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1snrwGkNUKNMWRzYR1staEAEurazvdPev1GsJN0eCj7ApjQc2xPDIK32HQP7qKfE26DUGrs X-Received: by 2002:a17:902:cec5:b0:16c:4108:d292 with SMTP id d5-20020a170902cec500b0016c4108d292mr36099337plg.137.1658283577082; Tue, 19 Jul 2022 19:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658283577; cv=none; d=google.com; s=arc-20160816; b=oiSRyBXhscEDXoZK3MkfEokvlsvrJsQzC3G01nhgt55JdWXA94zaxJFFmmYH4TYWJ3 JdAAJUeuA89vwMpF5BHFXwzGBBi1Ib86bQTI4ch2F0bM+5zuITiMt4imiRxZooOLNLNE M3SXPTq7E7OwEnbqfOpgGrUw8idEzin2PuPWDD4d+5PF36t9BoZ0MaKkrUzz0ZYHRTUt k6THS9/iY0O3QgDRiXJAWrNgKwlsaqxflfesK1Rc5Sdj+cf9ptenlxVntSqNtDR9nz/q xpFG/W8TTLGkgiLfgMK2sBQgQ76HW7GpacEgUW/QupwYjJYUdZFp4fXYrg8kwcreMMDG AigQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=rJFJglb4/UlXPUAHi1JzAHBD/M9s09bPsFmPwi9LOVE=; b=ZSmK63wvkONqWmug2tN0g+x3TOawh0zmzAvUWHpnj5KB91AAmtT6aeQPwMU1k99oII /2g39CehQIqafQgVyyx47WcoSqrnhCV/cunnU5vL2kjl1CwyOSrKv918J+EKZAIx9QJ4 EXsIbcl3fafv9pSbgLeSU3l/9FXAetTlFg7nuULspQnFt/aj+fR/YiXMgqAU6m/1CDay enr5+vL1x1Vq8LVB7dLgzYxAROL8zhE69oghuXcY+bkV9kGm9DX7VHYDCzvSx1KHWAtH Iy6hyqd+4EQVBqYANsjoAdLE+Sh+Z7ZYZsvju9OjYvim3K7VOTsL7Q1kPrLihIwi/1ga HKgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xs4all.nl header.s=xs4all01 header.b=K+cK7q+3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a170902a41400b0016a7b95cf3esi17451592plq.210.2022.07.19.19.19.22; Tue, 19 Jul 2022 19:19:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xs4all.nl header.s=xs4all01 header.b=K+cK7q+3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240076AbiGTBoN (ORCPT + 99 others); Tue, 19 Jul 2022 21:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240053AbiGTBoM (ORCPT ); Tue, 19 Jul 2022 21:44:12 -0400 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 19 Jul 2022 18:44:09 PDT Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.167]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 270F6F45 for ; Tue, 19 Jul 2022 18:44:08 -0700 (PDT) X-KPN-MessageId: 48b152f4-07cd-11ed-92d5-005056abbe64 Received: from smtp.kpnmail.nl (unknown [10.31.155.39]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 48b152f4-07cd-11ed-92d5-005056abbe64; Wed, 20 Jul 2022 03:42:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=xs4all01; h=content-type:mime-version:message-id:subject:to:from:date; bh=rJFJglb4/UlXPUAHi1JzAHBD/M9s09bPsFmPwi9LOVE=; b=K+cK7q+3qNmRzBhVqnrb6dcvzHwTNPb0eIHNfYy+/w9+5NhJGbV4DGkcBa1KUI0oE0OnCKtb5VKsW LBKidygns/An+tmmTcJlAhuoay2aJjeeiCNVbTnTJzIAWDDdO8D1ZIK0F2S6YnaJRALGwkDW5hyNiw FVnqretpsqOtryhtSVt95SRQwlK+f4XfUyyZwt9HFoV8bZ0RziblHCGN29eCMfURmr8ud2muyNUPpY zzTh3AZb/rYAvinh6li1lZLbR/g/ewjqq/uMdSHwFDqXM4EHdlWg1OqUy84NWH+GUIfHEXnjlsdDM6 3lIuKGlcofXTuBTPowWEM6pmbH5ny1w== X-KPN-MID: 33|X/FwXldpKQeT69J14RQrO3wWCDlNHTXiDFH+z4/5b410baHBlVm0Lo5m+k0owV3 TzWwt78voBp9KvHnL1iswi5re4OiCxH/fUHIxGdjKB4U= X-KPN-VerifiedSender: Yes X-CMASSUN: 33|kw9TlpbAUpy2EFas4/riRupArFIg6BG1fOWsU6N4exHkaFUlNJ5+lQgOtSkXTgm dJHzaYn3cIm9roNAMOgcphw== X-Originating-IP: 86.86.234.244 Received: from wim.jer (86-86-234-244.fixed.kpn.net [86.86.234.244]) by smtp.xs4all.nl (Halon) with ESMTPSA id 4a3e2c51-07cd-11ed-b8b0-005056ab7447; Wed, 20 Jul 2022 03:43:02 +0200 (CEST) Date: Wed, 20 Jul 2022 03:43:00 +0200 From: Jeroen Roovers To: "Guilherme G. Piccoli" Cc: akpm@linux-foundation.org, bhe@redhat.com, pmladek@suse.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, x86@kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, halves@canonical.com, fabiomirmar@gmail.com, alejandro.j.jimenez@oracle.com, andriy.shevchenko@linux.intel.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, d.hatayama@jp.fujitsu.com, dave.hansen@linux.intel.com, dyoung@redhat.com, feng.tang@intel.com, gregkh@linuxfoundation.org, mikelley@microsoft.com, hidehiro.kawai.ez@hitachi.com, jgross@suse.com, john.ogness@linutronix.de, keescook@chromium.org, luto@kernel.org, mhiramat@kernel.org, mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, stern@rowland.harvard.edu, tglx@linutronix.de, vgoyal@redhat.com, vkuznets@redhat.com, will@kernel.org, linux-parisc@vger.kernel.org, "James E.J. Bottomley" , Helge Deller Subject: Re: [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path Message-ID: <20220720034300.6d2905b8@wim.jer> In-Reply-To: <20220719195325.402745-8-gpiccoli@igalia.com> References: <20220719195325.402745-1-gpiccoli@igalia.com> <20220719195325.402745-8-gpiccoli@igalia.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Guilherme, On Tue, 19 Jul 2022 16:53:20 -0300 "Guilherme G. Piccoli" wrote: > The panic notifiers' callbacks execute in an atomic context, with > interrupts/preemption disabled, and all CPUs not running the panic > function are off, so it's very dangerous to wait on a regular > spinlock, there's a risk of deadlock. > > Refactor the panic notifier of parisc/power driver to make use > of spin_trylock - for that, we've added a second version of the > soft-power function. Also, some comments were reorganized and > trailing white spaces, useless header inclusion and blank lines > were removed. > > Cc: "James E.J. Bottomley" > Acked-by: Helge Deller # parisc > Signed-off-by: Guilherme G. Piccoli > > --- > > V2: > - Added Helge's ACK - thanks! > > arch/parisc/include/asm/pdc.h | 1 + > arch/parisc/kernel/firmware.c | 27 +++++++++++++++++++++++---- > drivers/parisc/power.c | 17 ++++++++++------- > 3 files changed, 34 insertions(+), 11 deletions(-) > > diff --git a/arch/parisc/include/asm/pdc.h > b/arch/parisc/include/asm/pdc.h index b643092d4b98..7a106008e258 > 100644 --- a/arch/parisc/include/asm/pdc.h > +++ b/arch/parisc/include/asm/pdc.h > @@ -83,6 +83,7 @@ int pdc_do_firm_test_reset(unsigned long > ftc_bitmap); int pdc_do_reset(void); > int pdc_soft_power_info(unsigned long *power_reg); > int pdc_soft_power_button(int sw_control); > +int pdc_soft_power_button_panic(int sw_control); > void pdc_io_reset(void); > void pdc_io_reset_devices(void); > int pdc_iodc_getc(void); > diff --git a/arch/parisc/kernel/firmware.c > b/arch/parisc/kernel/firmware.c index 6a7e315bcc2e..0e2f70b592f4 > 100644 --- a/arch/parisc/kernel/firmware.c > +++ b/arch/parisc/kernel/firmware.c > @@ -1232,15 +1232,18 @@ int __init pdc_soft_power_info(unsigned long > *power_reg) } > > /* > - * pdc_soft_power_button - Control the soft power button behaviour > - * @sw_control: 0 for hardware control, 1 for software control > + * pdc_soft_power_button{_panic} - Control the soft power button > behaviour > + * @sw_control: 0 for hardware control, 1 for software control > * > * > * This PDC function places the soft power button under software or > * hardware control. > - * Under software control the OS may control to when to allow to > shut > - * down the system. Under hardware control pressing the power button > + * Under software control the OS may control to when to allow to shut > + * down the system. Under hardware control pressing the power button > * powers off the system immediately. > + * > + * The _panic version relies in spin_trylock to prevent deadlock > + * on panic path. in => on > */ > int pdc_soft_power_button(int sw_control) > { > @@ -1254,6 +1257,22 @@ int pdc_soft_power_button(int sw_control) > return retval; > } > > +int pdc_soft_power_button_panic(int sw_control) > +{ > + int retval; > + unsigned long flags; > + > + if (!spin_trylock_irqsave(&pdc_lock, flags)) { > + pr_emerg("Couldn't enable soft power button\n"); > + return -EBUSY; /* ignored by the panic notifier */ > + } > + > + retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, > __pa(pdc_result), sw_control); > + spin_unlock_irqrestore(&pdc_lock, flags); > + > + return retval; > +} > + > /* > * pdc_io_reset - Hack to avoid overlapping range registers of > Bridges devices. > * Primarily a problem on T600 (which parisc-linux doesn't support) > but diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c > index 456776bd8ee6..8512884de2cf 100644 > --- a/drivers/parisc/power.c > +++ b/drivers/parisc/power.c > @@ -37,7 +37,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -175,16 +174,21 @@ static void powerfail_interrupt(int code, void > *x) > > > -/* parisc_panic_event() is called by the panic handler. > - * As soon as a panic occurs, our tasklets above will not be > - * executed any longer. This function then re-enables the > - * soft-power switch and allows the user to switch off the system > +/* > + * parisc_panic_event() is called by the panic handler. > + * > + * As soon as a panic occurs, our tasklets above will not > + * be executed any longer. This function then re-enables > + * the soft-power switch and allows the user to switch off > + * the system. We rely in pdc_soft_power_button_panic() > + * since this version spin_trylocks (instead of regular > + * spinlock), preventing deadlocks on panic path. > */ > static int parisc_panic_event(struct notifier_block *this, > unsigned long event, void *ptr) > { > /* re-enable the soft-power switch */ > - pdc_soft_power_button(0); > + pdc_soft_power_button_panic(0); > return NOTIFY_DONE; > } > > @@ -193,7 +197,6 @@ static struct notifier_block parisc_panic_block = > { .priority = INT_MAX, > }; > > - > static int __init power_init(void) > { > unsigned long ret; Kind regards, jer