From patchwork Tue Jun 30 19:40:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 11634643 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 8172F6C1 for ; Tue, 30 Jun 2020 19:42:09 +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 5AC9E206B6 for ; Tue, 30 Jun 2020 19:42:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="y1eWJ9Hy"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KeVg2mho" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5AC9E206B6 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=Fh5rJIS/oKepNVxVmUNDQf3dzPIUywE7WGX8T2y0Row=; b=y1eWJ9Hy5EdnejTn5W/l3XmggE yzVS+gEjjvl/bh/ZfLWLYhmv1XtcxcZUNEPXdyzyfoNrS72h4l4RZ0UqkPPuG2ktmG3zuAnLdtLDC Q1O8PAu49VmOthoB2tSWV5tKtNIOYv5GhD1tOZ9Bk5aI+UKltUtYAfgkvSDzsofLXqzQVV3LT/iHS Lwa44uGqd6Pc0/Bh5Pbj7IeRko+6e6W4/bGxoyR+CgG3+AL90yke493OWMIwJ5avc6KCAdtiwrZYC R5cCORQS7ib4uN2gLjl7f9bEeANHlF7ZXCe/KoaLk5sN9m1qHmB4iBzoHmfuBawNPR9qQpFstgYCT 5QJmLM7Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqM7T-0001Z1-WA; Tue, 30 Jun 2020 19:40:40 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqM7R-0001YP-7d for linux-arm-kernel@lists.infradead.org; Tue, 30 Jun 2020 19:40:38 +0000 Received: by mail-wr1-x442.google.com with SMTP id f7so18294856wrw.1 for ; Tue, 30 Jun 2020 12:40:35 -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=rRLSrnrN+c8nqpBT9J7tXNJi8icRO8kKzJ/Ly4iCS+k=; b=KeVg2mhofRz2J1pndZl5dK/uignk2uMwR6DEQkPdCf13vFYQJvRVs8fbFaVmP9BEjO 2jbScvFCAFrDeqyn8Xj5w2Cc9hnojmVZxYMIJFXmIPitlsQ1CHIg7Z1/UcdxQcFhSOC+ e5lMNtZpluJZ3KBMGW69jwtjcF0lManEY7jTc7hPt6Y7hbwpfdeIKMzLVwIx0Carxo5m oXFMw6imUU1doFkpqC6uOuxxrXStuTJizSuDLsZs5O6SCn0KZhwZ8rcOrmz7VKAAQA90 h+SE8mFuqf5mXwL+SEpEcUp+/YZODkoXV4VQU7voPpqNecSNxzCW41Q+GAwXe9MZxdoy JUZw== 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=rRLSrnrN+c8nqpBT9J7tXNJi8icRO8kKzJ/Ly4iCS+k=; b=dNO9FHrKRI3nOTONZu2pmakoq7EBHKttMTii82Qm9wPTaFWUaSD58+ofV5OcDDz3zn /kIJocxKWRESAPXFQm5UvS8XG4wMkFcekS4RLeX9I9bOo8H5EU0zbzGV19HkbB4TaT3e YyZaVbcXQrQmM2yk28w6e0bQYiQqFbNGIulX51JfyQ2RmLc7hVGXVC+G3IxiJd5VSkgN jLjskzBpmrEA/aqUibcAotcdrrR51pKA4Bhb0vjF5420OBlpxbNllkbrQjUBzSGwUoNN NfXqBZLGa/3n5BBhfNyYGATcTLmPjZOEMd0rBV/pf2KyOL61fxjyv51+Xk313NUvTO1p +PCQ== X-Gm-Message-State: AOAM532lgrVGzP2hoba+bGU5DxO54swbWx+G0Fwh2Xx63sZcQ5AK/Nfa Zgtn5vpH0dI7C8Q5zVnEKHlxgUc8UUPRgA== X-Google-Smtp-Source: ABdhPJyUl9fMb43XdQ1BH6q+3iCOq/cfzEWHCUy5/xnAvQy83f27H4HNI9aKkorBe0KwaZGusgHUbw== X-Received: by 2002:a5d:4bd2:: with SMTP id l18mr22523342wrt.119.1593546034155; Tue, 30 Jun 2020 12:40:34 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6801:1801:648c:b15a:1e33:d6cb]) by smtp.gmail.com with ESMTPSA id p29sm4585544wmi.43.2020.06.30.12.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:40:33 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, mathieu.poirier@linaro.org Subject: [PATCH v2] coresight: etmv4: Fix CPU power management setup in probe() function. Date: Tue, 30 Jun 2020 20:40:31 +0100 Message-Id: <20200630194031.24625-1-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200630_154037_611521_94B60A97 X-CRM114-Status: GOOD ( 20.15 ) 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:442 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 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_cpuslocked() 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 | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 82fc2fab072a..2d732af8b3e7 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -1398,18 +1398,57 @@ 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)) - cpu_pm_unregister_notifier(&etm4_cpu_pm_nb); + if (--etm4_count != 0) + return; + + 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) @@ -1466,24 +1505,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_cpuslocked() does its own cleanup - exit on error */ + if (ret) { + etmdrvdata[drvdata->cpu] = NULL; + return ret; } - cpus_read_unlock(); - if (etm4_arch_supported(drvdata->arch) == false) { ret = -EINVAL; goto err_arch_supported; @@ -1530,13 +1560,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; }