From patchwork Tue Jun 23 20:46:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 11621759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 380D8138C for ; Tue, 23 Jun 2020 20:48:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1171720781 for ; Tue, 23 Jun 2020 20:48:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="D33BlUbf"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zOyLjz4T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1171720781 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=L0ky/RIQOitfSh8X9nNY0b+hDozpSUlvilZateqgXTc=; b=D33BlUbfYWIryK4BWczcUSHnL7 mvJeJX8LPn9T7tWu7MLkiiR8LWqKTaIpOIMyW6fjfM9O8aDsPq2qFHfiFJTZNFNOLbjL6mxxwHRDG 64R1hlRaGQYIau8xLZEgbZicLwZG7Eo9rScSOwj2ZY9H2HErrw19KhX4zQxRan+TUcIIAjDrWq4ru 08+fqz+8IV6SUkaf3jEaxum3MwhNZJj6oxLfU8oCFf04LiI+8cMMU+rdvxR9gbaT7j/k1r7Nao6nH 2DfJggwy2gstEcfxYwEXBCn/eGu7yOd1NXgaydjxBjTGeRJtxl3XQHjAEVZaEIUnRwNysvZKGpiJ+ TZ69SvUA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnpoA-0004mL-IS; Tue, 23 Jun 2020 20:46:18 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnpo7-0004l9-3a for linux-arm-kernel@lists.infradead.org; Tue, 23 Jun 2020 20:46:16 +0000 Received: by mail-wm1-x341.google.com with SMTP id o8so115751wmh.4 for ; Tue, 23 Jun 2020 13:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=rIBrHEmoEoq5dD4sbN+dCN0rNAZPrX3ei51u3pHhUGw=; b=zOyLjz4TW5IPUWZiOK8lyQPabj47TqYZtWErzVEyhm3zvznYeYCtst/O43qpDVIg0l eRtk7efuHapZfP+gr1DjyoFb8Sw/XdRBbpROFhbHQvHS5lSNhAxC1PAacD2hdylEQKTk /3fUac+hWj/xSDFy5hFJieSpZJJlHW8rgwVPLA/UxqUnVtW7cGRbyNX7SACsoNmou+51 F/D6ZBc+ofDtZYV/bH6t3Y4O2odUrqeXSPumz4qfLsGOTRZkmXwRtiVNkHLAPLhJ7dux daPmgIy4OD5FOIb0nIuPYAOrQS7uargsXpjJwXnmL88mJHpdbSd9Pxf5CMbaOXqlvcd7 pWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rIBrHEmoEoq5dD4sbN+dCN0rNAZPrX3ei51u3pHhUGw=; b=ngJeug/dNbUa0qGlloeZCjyqWOZomvQ33CgOkEMakbzrPHazVPgU8IiXcc84QJr5Cl 4dSG2aDaAs5m3CzeTF5IS4CoXPHG9Z8eZLP2qtrNkU8vpk2YsjZjnrMziMQgmeyDAj4T 9tvwhkexYMIzuSHbxMBxqtIqhLzlqg9IXvzAVHOpb7FRwyu2z1Wl/ZT7rItdDd9kSmXz DdVrX5YNBRbWJ1DwtsbDp9cDKbovRnBO05EmWLyORWGhHbJU8B4E4T8HTI1p8Bj5YKXH HclwNsCVMLDfptcC6fJdlu4sKwQHXdxFHb223225tI9sH1zA6r0n11tAQ5c8FO8K/wm5 A1ug== X-Gm-Message-State: AOAM531CPxRf1XbDz/EjVqV/OZoxUfM17LKCNQEZYwIziaexRujgrMDk 5H32LilbAwMAsFDvqGE97spVacujgTSX3Q== X-Google-Smtp-Source: ABdhPJyoxcDFp+/bMEqCMTy1pwxsH+3x59M4y1cJQrPwq6wUkUYg8JatDT3Pzwrf3c4ZrpgtXEdgVQ== X-Received: by 2002:a7b:c7c2:: with SMTP id z2mr25527630wmk.39.1592945172213; Tue, 23 Jun 2020 13:46:12 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6801:1801:f1c4:7c99:41fa:9084]) by smtp.gmail.com with ESMTPSA id o15sm24190210wrv.48.2020.06.23.13.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 13:46:11 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, mathieu.poirier@linaro.org Subject: [PATCH] coresight: etmv4: Fix CPU power management setup in probe() function. Date: Tue, 23 Jun 2020 21:46:06 +0100 Message-Id: <20200623204606.13045-1-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:341 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mike Leach , suzuki.poulose@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The current probe() function calls a pair of cpuhp_xxx API functions to setup CPU hotplug handling. The hotplug lock is held for the duration of the two calls and other CPU related code using cpus_read_lock() / cpus_read_unlock() calls. The problem is that on error states, goto: statements bypass the cpus_read_unlock() call. This code has increased in complexity as the driver has developed. This patch introduces a pair of helper functions etm4_pm_setup() and etm4_pm_clear() which correct the issues above and group the PM code a little better. The two functions etm4_cpu_pm_register() and etm4_cpu_pm_unregister() are dropped as these call cpu_pm_register_notifier() / ..unregister_notifier() dependent on CONFIG_CPU_PM - but this define is used to nop these functions out in the pm headers - so the wrapper functions are superfluous. Fixes: f188b5e76aae ("coresight: etm4x: Save/restore state across CPU low power states") Fixes: e9f5d63f84fe ("hwtracing/coresight-etm4x: Use cpuhp_setup_state_nocalls_cpuslocked()") Fixes: 58eb457be028 ("etm4x: Convert to hotplug state machine") Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/coresight-etm4x.c | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 919b76fa49c4..4dd59de440de 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -1407,18 +1407,56 @@ static struct notifier_block etm4_cpu_pm_nb = { .notifier_call = etm4_cpu_pm_notify, }; -static int etm4_cpu_pm_register(void) +/* Setup PM. Called with cpus locked. Deals with error conditions and counts */ +static int etm4_pm_setup_cpuslocked(void) { - if (IS_ENABLED(CONFIG_CPU_PM)) - return cpu_pm_register_notifier(&etm4_cpu_pm_nb); + int ret; - return 0; + if (etm4_count++) + return 0; + + ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb); + if (ret) + goto reduce_count; + + ret = cpuhp_setup_state_nocalls_cpuslocked( + CPUHP_AP_ARM_CORESIGHT_STARTING, "arm/coresight4:starting", + etm4_starting_cpu, etm4_dying_cpu); + + if (ret) + goto unregister_notifier; + + ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN, + "arm/coresight4:online", + etm4_online_cpu, NULL); + + /* HP dyn state ID returned in ret on success */ + if (ret > 0) { + hp_online = ret; + return 0; + } + + /* failed dyn state - remove others */ + cpuhp_remove_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING); + +unregister_notifier: + cpu_pm_unregister_notifier(&etm4_cpu_pm_nb); + +reduce_count: + --etm4_count; + return ret; } -static void etm4_cpu_pm_unregister(void) +static void etm4_pm_clear(void) { - if (IS_ENABLED(CONFIG_CPU_PM)) + if (--etm4_count == 0) { cpu_pm_unregister_notifier(&etm4_cpu_pm_nb); + cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING); + if (hp_online) { + cpuhp_remove_state_nocalls(hp_online); + hp_online = 0; + } + } } static int etm4_probe(struct amba_device *adev, const struct amba_id *id) @@ -1475,24 +1513,15 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) etm4_init_arch_data, drvdata, 1)) dev_err(dev, "ETM arch init failed\n"); - if (!etm4_count++) { - cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING, - "arm/coresight4:starting", - etm4_starting_cpu, etm4_dying_cpu); - ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN, - "arm/coresight4:online", - etm4_online_cpu, NULL); - if (ret < 0) - goto err_arch_supported; - hp_online = ret; + ret = etm4_pm_setup_cpuslocked(); + cpus_read_unlock(); - ret = etm4_cpu_pm_register(); - if (ret) - goto err_arch_supported; + /* etm4_pm_setup does its own cleanup - just exit on error here */ + if (ret) { + etmdrvdata[drvdata->cpu] = NULL; + return ret; } - cpus_read_unlock(); - if (etm4_arch_supported(drvdata->arch) == false) { ret = -EINVAL; goto err_arch_supported; @@ -1544,13 +1573,7 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) err_arch_supported: etmdrvdata[drvdata->cpu] = NULL; - if (--etm4_count == 0) { - etm4_cpu_pm_unregister(); - - cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING); - if (hp_online) - cpuhp_remove_state_nocalls(hp_online); - } + etm4_pm_clear(); return ret; }