From patchwork Mon Mar 1 16:14:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 388715 Delivered-To: patch@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp3625847jap; Mon, 1 Mar 2021 11:20:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFbR9obi8Qx7+wOvUqPyAylDwyjcwjcp+qvpWVl72Di1dozl6inGjNUlKIF5EyuVTQOWo/ X-Received: by 2002:a17:906:4d18:: with SMTP id r24mr14046701eju.493.1614626452981; Mon, 01 Mar 2021 11:20:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614626452; cv=none; d=google.com; s=arc-20160816; b=SJZFPrmL1Im+pbe6FUTTGRT8icexE2jgO4xixaMGCDqhLLVU9FhbSwPY/aLqCY8qTY YdFc8YXOSd6I5pTfYqS0vRk1dTOg+dkoG8yXybSuQmNjK3o30ZmPbKs0oJDMT6y7++wK UV33rXVDz8SV84cx+pzRcFVvmEBA/eq8bqf1AfaK9K7Hd/eB0NgZq+XDfuinwpz7gwnl mlYwwBgz/DJ5bBcky/Vqeg1tEwLkEQvybH/YChUD/WWNwzZEAcSHFNnJvhRf2Jd894d4 37k70HEg1hrcLAHGCQSnyFkVe2vC/9WoR6Mh9W4RHjKNgweHEhJjYIBizdVXdN6B4CC1 FhJw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Wc8dDvguRWjp8AqWhYJn0ssPwNnJ6c5Ic5J9qcqGpSQ=; b=CsMVcg/2giS3xUKfADWg+4IA/6earwZ2toahPGEX6y7g22vUVzLEVA87sTVFEWW62f st0rWpT3gkDwHgazWKK3T4uHAZQ7Iu6vZhWsjLbS0+glGDD6ZqcMQohU/RKHnK4slvBe OzyePA3gGgGkZY9WMcI4InoGNQya6j2bvXuL6oBtR7hXw8WbM7CIXAiVhm9qQofSACma xFcEoSsT/8rkdhF6yFKgncBdqPHnK59TpinnalWyMsDhmmQIiFpdvrgMDY8e495eYbWo NojOxil+SPGOfwqyYf03KRtMZ2bnZ+SCWZ8bYXC9LTu1fZFllhcRHd0hgPP+iE16dllT uvXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K6pWg96M; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si8513951ejj.20.2021.03.01.11.20.52; Mon, 01 Mar 2021 11:20:52 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K6pWg96M; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240412AbhCATTR (ORCPT + 13 others); Mon, 1 Mar 2021 14:19:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:43896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241251AbhCATPX (ORCPT ); Mon, 1 Mar 2021 14:15:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E6C86529E; Mon, 1 Mar 2021 17:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619977; bh=K0J7as9wFhYoyMSPxRC+Khg1wn1se4ke0OPxdrssz3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K6pWg96MCRtMWJTBwsnfuk2vuIz3CHZbL8sRnwrjZwyulhsbW4TQJetfVKA6v2jPK CaT5XtDMfO2jD6je3zCMB+kuJJkVKu8TdfeyKrM0RHrvNlGMVIGSLoo0pQgGu9Azzn 1duvcc75mP+lVyL5FE/EDrV2OZsTsBJbpzmh64k8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bjorn Andersson , Shawn Guo , Viresh Kumar Subject: [PATCH 5.10 622/663] cpufreq: qcom-hw: drop devm_xxx() calls from init/exit hooks Date: Mon, 1 Mar 2021 17:14:30 +0100 Message-Id: <20210301161212.622073587@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Shawn Guo commit 67fc209b527d023db4d087c68e44e9790aa089ef upstream. Commit f17b3e44320b ("cpufreq: qcom-hw: Use devm_platform_ioremap_resource() to simplify code") introduces a regression on platforms using the driver, by failing to initialise a policy, when one is created post hotplug. When all the CPUs of a policy are hoptplugged out, the call to .exit() and later to devm_iounmap() does not release the memory region that was requested during devm_platform_ioremap_resource(). Therefore, a subsequent call to .init() will result in the following error, which will prevent a new policy to be initialised: [ 3395.915416] CPU4: shutdown [ 3395.938185] psci: CPU4 killed (polled 0 ms) [ 3399.071424] CPU5: shutdown [ 3399.094316] psci: CPU5 killed (polled 0 ms) [ 3402.139358] CPU6: shutdown [ 3402.161705] psci: CPU6 killed (polled 0 ms) [ 3404.742939] CPU7: shutdown [ 3404.765592] psci: CPU7 killed (polled 0 ms) [ 3411.492274] Detected VIPT I-cache on CPU4 [ 3411.492337] GICv3: CPU4: found redistributor 400 region 0:0x0000000017ae0000 [ 3411.492448] CPU4: Booted secondary processor 0x0000000400 [0x516f802d] [ 3411.503654] qcom-cpufreq-hw 17d43000.cpufreq: can't request region for resource [mem 0x17d45800-0x17d46bff] With that being said, the original code was tricky and skipping memory region request intentionally to hide this issue. The true cause is that those devm_xxx() device managed functions shouldn't be used for cpufreq init/exit hooks, because &pdev->dev is alive across the hooks and will not trigger auto resource free-up. Let's drop the use of device managed functions and manually allocate/free resources, so that the issue can be fixed properly. Cc: v5.10+ # v5.10+ Fixes: f17b3e44320b ("cpufreq: qcom-hw: Use devm_platform_ioremap_resource() to simplify code") Suggested-by: Bjorn Andersson Signed-off-by: Shawn Guo Signed-off-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/qcom-cpufreq-hw.c | 40 ++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -32,6 +32,7 @@ struct qcom_cpufreq_soc_data { struct qcom_cpufreq_data { void __iomem *base; + struct resource *res; const struct qcom_cpufreq_soc_data *soc_data; }; @@ -280,6 +281,7 @@ static int qcom_cpufreq_hw_cpu_init(stru struct of_phandle_args args; struct device_node *cpu_np; struct device *cpu_dev; + struct resource *res; void __iomem *base; struct qcom_cpufreq_data *data; int ret, index; @@ -303,18 +305,33 @@ static int qcom_cpufreq_hw_cpu_init(stru index = args.args[0]; - base = devm_platform_ioremap_resource(pdev, index); - if (IS_ERR(base)) - return PTR_ERR(base); + res = platform_get_resource(pdev, IORESOURCE_MEM, index); + if (!res) { + dev_err(dev, "failed to get mem resource %d\n", index); + return -ENODEV; + } + + if (!request_mem_region(res->start, resource_size(res), res->name)) { + dev_err(dev, "failed to request resource %pR\n", res); + return -EBUSY; + } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + base = ioremap(res->start, resource_size(res)); + if (IS_ERR(base)) { + dev_err(dev, "failed to map resource %pR\n", res); + ret = PTR_ERR(base); + goto release_region; + } + + data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) { ret = -ENOMEM; - goto error; + goto unmap_base; } data->soc_data = of_device_get_match_data(&pdev->dev); data->base = base; + data->res = res; /* HW should be in enabled state to proceed */ if (!(readl_relaxed(base + data->soc_data->reg_enable) & 0x1)) { @@ -349,7 +366,11 @@ static int qcom_cpufreq_hw_cpu_init(stru return 0; error: - devm_iounmap(dev, base); + kfree(data); +unmap_base: + iounmap(data->base); +release_region: + release_mem_region(res->start, resource_size(res)); return ret; } @@ -357,12 +378,15 @@ static int qcom_cpufreq_hw_cpu_exit(stru { struct device *cpu_dev = get_cpu_device(policy->cpu); struct qcom_cpufreq_data *data = policy->driver_data; - struct platform_device *pdev = cpufreq_get_driver_data(); + struct resource *res = data->res; + void __iomem *base = data->base; dev_pm_opp_remove_all_dynamic(cpu_dev); dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); kfree(policy->freq_table); - devm_iounmap(&pdev->dev, data->base); + kfree(data); + iounmap(base); + release_mem_region(res->start, resource_size(res)); return 0; }