From patchwork Tue Sep 24 15:49:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 2934291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E058F9F289 for ; Tue, 24 Sep 2013 15:50:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E94D2037A for ; Tue, 24 Sep 2013 15:50:26 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84A03202F9 for ; Tue, 24 Sep 2013 15:50:21 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOUsC-0002Pf-AD; Tue, 24 Sep 2013 15:50:00 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOUs4-0003WZ-Ff; Tue, 24 Sep 2013 15:49:52 +0000 Received: from mail-qc0-f171.google.com ([209.85.216.171]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOUrr-0003Tu-Vh for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2013 15:49:42 +0000 Received: by mail-qc0-f171.google.com with SMTP id x19so3165745qcw.2 for ; Tue, 24 Sep 2013 08:49:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=UVK6Xg1qd4TTFYLCh/kd+gjmlEJC1dCJohIvwSwuXfM=; b=SaZyjIHuuIn2rHuUWtc0bmH/4W0T1folQWFpxtWOiUKJxxBLtb0zUL9EK1P8HKMsE+ h9iw5edPBYGzpmQWUdP8n0XRtDIpaVytO7RegNnr+6hCg6sLDgm+kMQkF81OSmesF/Cp X9V3g91ZaJVoSeSg1bCzDyUT+N5pDVc1qMqrF6x/nfycHy1luK1v4qfmtcbjb+K813XK dF+6SakEcwxiKCrsiZ/clvDgQSzp+Yj6qCAa+7LncF0ncSaKgTEkkiS+9L7ngykMdE/G sbzqIGS5xDkde9/QWHhkTxiDSx4Kb1bYiy5S8JpOCdPgTPahM2g22wh1alINTyilGo7J Zfng== X-Gm-Message-State: ALoCoQkg6kV8Mo5gN56wciZ2Kx0Z4ZEMytRJJ0PtHk8HpfRgrrLfcuKSswmXdEbIjHaVtMkCbUJ+ X-Received: by 10.224.22.75 with SMTP id m11mr30204937qab.27.1380037758414; Tue, 24 Sep 2013 08:49:18 -0700 (PDT) Received: from xanadu.home (modemcable044.209-83-70.mc.videotron.ca. [70.83.209.44]) by mx.google.com with ESMTPSA id 5sm55446240qao.3.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Sep 2013 08:49:18 -0700 (PDT) Date: Tue, 24 Sep 2013 11:49:17 -0400 (EDT) From: Nicolas Pitre To: Lorenzo Pieralisi Subject: Re: [PATCH] ARM: MCPM: don't explode if invoked without being initialized first In-Reply-To: <20130924085101.GA25927@e102568-lin.cambridge.arm.com> Message-ID: References: <20130924085101.GA25927@e102568-lin.cambridge.arm.com> User-Agent: Alpine 2.03 (LFD 1266 2009-07-14) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130924_114940_132419_9F908B88 X-CRM114-Status: GOOD ( 28.82 ) X-Spam-Score: -2.6 (--) Cc: "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 24 Sep 2013, Lorenzo Pieralisi wrote: > On Mon, Sep 23, 2013 at 08:24:34PM +0100, Nicolas Pitre wrote: > > > > Currently mcpm_cpu_power_down() and mcpm_cpu_suspend() trigger BUG() > > if mcpm_platform_register() is not called beforehand. This may occur > > for many reasons such as some incomplete device tree passed to the kernel > > or the like. > > > > Let's be nicer to users and avoid killing the kernel if that happens by > > logging a warning and returning to the caller. The mcpm_cpu_suspend() > > user is already set to deal with this situation, and so is cpu_die() > > invoking mcpm_cpu_die(). > > > > The problematic case would have been the B.L switcher's usage of > > mcpm_cpu_power_down(), however it has to call mcpm_cpu_power_up() first > > which is already set to catch an error resulting from a missing > > mcpm_platform_register() call. > > > > Signed-off-by: Nicolas Pitre > > > > diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c > > index 370236dd1a..3fd43f1fd2 100644 > > --- a/arch/arm/common/mcpm_entry.c > > +++ b/arch/arm/common/mcpm_entry.c > > @@ -51,7 +51,8 @@ void mcpm_cpu_power_down(void) > > { > > phys_reset_t phys_reset; > > > > - BUG_ON(!platform_ops); > > + if (WARN_ON_ONCE(!platform_ops)) > > + return; > > BUG_ON(!irqs_disabled()); > > I think it should be: > > if (WARN_ON_ONCE(!platform_ops || !platform_ops->power_down)) > return; > > since even if platform_ops has been initialized we might still be end > up with a NULL function pointer. Good point. > Probably the test for the function pointer belongs in: > > mcpm_platform_register() Well, some methods may be optional. For example there is no suspend support possible with the DCSCB backend. And you can't do much in mcpm_platform_register() other than refuse the whole registration even though some methods are still usable. Amended patch below. From: Nicolas Pitre Date: Mon, 23 Sep 2013 14:08:05 -0400 Subject: [PATCH] ARM: MCPM: don't explode if invoked without being initialized first Currently mcpm_cpu_power_down() and mcpm_cpu_suspend() trigger BUG() if mcpm_platform_register() is not called beforehand. This may occur for many reasons such as some incomplete device tree passed to the kernel or the like. Let's be nicer to users and avoid killing the kernel if that happens by logging a warning and returning to the caller. The mcpm_cpu_suspend() user is already set to deal with this situation, and so is cpu_die() invoking mcpm_cpu_die(). The problematic case would have been the B.L switcher's usage of mcpm_cpu_power_down(), however it has to call mcpm_cpu_power_up() first which is already set to catch an error resulting from a missing mcpm_platform_register() call. Signed-off-by: Nicolas Pitre diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c index 370236dd1a..990250965f 100644 --- a/arch/arm/common/mcpm_entry.c +++ b/arch/arm/common/mcpm_entry.c @@ -51,7 +51,8 @@ void mcpm_cpu_power_down(void) { phys_reset_t phys_reset; - BUG_ON(!platform_ops); + if (WARN_ON_ONCE(!platform_ops || !platform_ops->power_down)) + return; BUG_ON(!irqs_disabled()); /* @@ -93,7 +94,8 @@ void mcpm_cpu_suspend(u64 expected_residency) { phys_reset_t phys_reset; - BUG_ON(!platform_ops); + if (WARN_ON_ONCE(!platform_ops || !platform_ops->suspend)) + return; BUG_ON(!irqs_disabled()); /* Very similar to mcpm_cpu_power_down() */ diff --git a/arch/arm/include/asm/mcpm.h b/arch/arm/include/asm/mcpm.h index 0f7b7620e9..fc82a88f5b 100644 --- a/arch/arm/include/asm/mcpm.h +++ b/arch/arm/include/asm/mcpm.h @@ -76,8 +76,11 @@ int mcpm_cpu_power_up(unsigned int cpu, unsigned int cluster); * * This must be called with interrupts disabled. * - * This does not return. Re-entry in the kernel is expected via - * mcpm_entry_point. + * On success this does not return. Re-entry in the kernel is expected + * via mcpm_entry_point. + * + * This will return if mcpm_platform_register() has not been called + * previously in which case the caller should take appropriate action. */ void mcpm_cpu_power_down(void); @@ -98,8 +101,11 @@ void mcpm_cpu_power_down(void); * * This must be called with interrupts disabled. * - * This does not return. Re-entry in the kernel is expected via - * mcpm_entry_point. + * On success this does not return. Re-entry in the kernel is expected + * via mcpm_entry_point. + * + * This will return if mcpm_platform_register() has not been called + * previously in which case the caller should take appropriate action. */ void mcpm_cpu_suspend(u64 expected_residency);