From patchwork Mon Jan 18 13:06:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 365532 Delivered-To: patch@linaro.org Received: by 2002:a17:906:fb05:0:0:0:0 with SMTP id lz5csp2731500ejb; Mon, 18 Jan 2021 05:07:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuPxguOZdDC4oeoNvw41T+fn49mKbkjk20L1626NRck/AmDBCShlHEf0Yy+EGckUJngwhm X-Received: by 2002:a17:906:350b:: with SMTP id r11mr17980344eja.143.1610975232225; Mon, 18 Jan 2021 05:07:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610975232; cv=none; d=google.com; s=arc-20160816; b=SvK+6XsHLraPdlmqMqwEx2Xs6XS+SI/kDrrLfoQhOcYA1JM1hN1ZH3fVt5XDgpKd37 FUWQpUGwPj8aD9d+M6ClRiW/N5Q21h08Y79nOSx5UoGQGm0lu0QwD6Rab+3GayznMH8t RJBJsj9n8DH+JgUIlNoHVw//0niNUXUJRBVSCggKYPk9rDJbCfPcJUK/0IHKh4m0yUAy yCc+WuzJ9+pGBNGUfUa3rkoh+I8Y9cSkHRIjznATRHZMbBXk6fauoyJOu+Bk4d560rQq HRkICrzGUF3jk66J2Bp/el/HBPJHFgH2y8kKdJvDTs8PHPn0BRGTyozfTcwqUnQZYZQ4 OKoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=BoSBnxjMyyHzFvdw+IKIalzlP1OM8AZYV3P2GXb8a60=; b=whuTNY1L5+YTTBIPZ2alYszwjVC+n2D6SrnnRjjtQNCL/IYAUXarRCsf1WCWBTH6QR Ze75rNk98Q8kSxzqLq/RTsLrRFxSI0A+apKAIWl1ONR97Ppsf0FlZ2nYOVE3r1BKujVn u9DMoBbrbItdb5szB150pPN+U10oGI350bDQioLsIzGu45EKc+VKjFvlQwPVQwDE8/VQ 8E7EQHEtWfs0JM+gNXVrMl88lDnqf8cEprxoNGyyBzAd4afCVkbgOxp9qS0aSRqWIaE9 SsgY2bwbL8jg7Jr1+RWx+YD0eXhbKT47BmeSEP3MgFG5qywTR4rF40x+3wHRH2GnmkzM IQPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ihX8NYmA; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si112881edx.575.2021.01.18.05.07.11; Mon, 18 Jan 2021 05:07:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-msm-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=@linaro.org header.s=google header.b=ihX8NYmA; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392050AbhARNHI (ORCPT + 15 others); Mon, 18 Jan 2021 08:07:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392047AbhARNG7 (ORCPT ); Mon, 18 Jan 2021 08:06:59 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF073C061575 for ; Mon, 18 Jan 2021 05:06:18 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id kx7so230151pjb.2 for ; Mon, 18 Jan 2021 05:06:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BoSBnxjMyyHzFvdw+IKIalzlP1OM8AZYV3P2GXb8a60=; b=ihX8NYmAyFhi6oGl9XblUkolWfCbb3eic+NOtQufiy9AA6uFY2djru0n4AZ7JURqh/ CG9FehGi/L8uDZ5hheYLMvxrefZIOaLK0Cn+CWGNDlpgV4WmR+wr7KRpUWLkjvdNySgL rf/ejttbzq+kOrmuXUNkWlBS5faW6ospjL0rRilBstXVXBwftKwsv/bAXHgtJ3oOcbOa DHIxvv6JnnF9jJwQeQ2VSwBBQwXN+fTcGtAJQcidiAmUyJQhB08fkeV7zpkKgqvmnOi5 CW4DhwsD1sPbo0B1wOkAxTPq3NS31Chvw2HN9LDvlBYkolCrwxD2PnOP6JmIclYJgh5H 1WQQ== 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=BoSBnxjMyyHzFvdw+IKIalzlP1OM8AZYV3P2GXb8a60=; b=rv94RMX7qpmtrPwBvwuZp6UG/+B1ZpzxlwFmRuy39p/vXyMwga+W+J+tSNYANDF8Sy 8xp8Axb3W5w+rUiJsd8zWIqwj0vV8en5CMgx+bo3dLea5/AkNm50xYq7l6Mi2u64+SOQ D9Wxkm4JVzVAHlBqiJaO6btyvIygP1GHNnr9CeJogGWEf7h+S14ARhMtYteXKFdI+KpI H7akjO4qjsADewLNBi3xlk7aZIhPJi1Ew/KWDEYxpL/lM+OetgkX5+KDvwUzUbb4ZYGp izhd2Oy3YTUppx4/jyPoHNxpsst63tu4j5uAmKmv6Xuu7J7T3CU4M3X6YM8D8Gjs+jcx NlAA== X-Gm-Message-State: AOAM53267CfN3ZYTPIgzt2umLdkgQ33tQVK7eQYn2zAap2Qo37A5jqrm wjFzSNuMKLqoPQ3ekc/I105aQJMQuoHnOw== X-Received: by 2002:a17:902:7086:b029:dc:8d:feab with SMTP id z6-20020a1709027086b02900dc008dfeabmr26580034plk.22.1610975178380; Mon, 18 Jan 2021 05:06:18 -0800 (PST) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id 21sm15938147pfx.84.2021.01.18.05.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 05:06:17 -0800 (PST) From: Shawn Guo To: "Rafael J . Wysocki" , Viresh Kumar Cc: Ionela Voinescu , Bjorn Andersson , Andy Gross , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, Shawn Guo Subject: [PATCH] cpufreq: qcom-hw: drop devm_xxx() calls from init/exit hooks Date: Mon, 18 Jan 2021 21:06:03 +0800 Message-Id: <20210118130603.16176-1-shawn.guo@linaro.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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. Fixes: f17b3e44320b ("cpufreq: qcom-hw: Use devm_platform_ioremap_resource() to simplify code") Suggested-by: Bjorn Andersson Signed-off-by: Shawn Guo --- I took some of the commit log from Ionela. drivers/cpufreq/qcom-cpufreq-hw.c | 43 ++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c index 9ed5341dc515..b529b49649e0 100644 --- 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(struct cpufreq_policy *policy) 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(struct cpufreq_policy *policy) index = args.args[0]; - base = devm_platform_ioremap_resource(pdev, index); - if (IS_ERR(base)) - return PTR_ERR(base); + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); - if (!data) { - ret = -ENOMEM; - goto error; + res = platform_get_resource(pdev, IORESOURCE_MEM, index); + if (!res) { + dev_err(dev, "failed to get mem resource %d\n", index); + ret = -ENODEV; + goto free_data; + } + + if (!request_mem_region(res->start, resource_size(res), res->name)) { + dev_err(dev, "failed to request resource %pR\n", res); + ret = -EBUSY; + goto free_data; + } + + 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->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(struct cpufreq_policy *policy) return 0; error: - devm_iounmap(dev, base); + iounmap(data->base); +release_region: + release_mem_region(res->start, resource_size(res)); +free_data: + kfree(data); return ret; } @@ -357,12 +378,14 @@ static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) { 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; 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); + iounmap(data->base); + release_mem_region(res->start, resource_size(res)); + kfree(data); return 0; }