From patchwork Fri Dec 20 15:56:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 22680 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5F04C23FC0 for ; Fri, 20 Dec 2013 15:56:12 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id h16sf11123834oag.8 for ; Fri, 20 Dec 2013 07:56:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type:content-transfer-encoding; bh=wkRP7MuIO1yV6N/jMi452hnpGyQAUuLsHzDjRthvTBQ=; b=ClKw+Dvr5CbPu1tJiyVy+i9lBcwCaGulBTQypV70q5MBZphCIz/hvsby9piEVwiLYb s3fPQAIoYga2HxoC8osfcIJjPbbkjdCevvgrBXUbzVPxZowThi6u0LMmvVOVu5ta+/J2 ptCLD/1svY8m5Vo2z+jW18a3RIByBHJLiO7HtMwEGA/zPCVxNGq1s0KIx0cll2l/qP1+ ZGKV2Q0mU5Gwp4kSSZ4U4KO26+xjDV8V04totHF1TUODnsSfKhLT3RTD4JI4Gf0hJ9OF 6dLoiplxCtxprvgdjpSCbu8HLRoyk5QPLzZkEWh2tZ4dapU0ig93Qdv0MG0UThHt6YnT /OZA== X-Gm-Message-State: ALoCoQnAi7Ia7teBnI/qFH0iz9f4kaJzbQ2tSFUFH4v/mpE0M+fv/TBVtQAvDjNhAfJImgVIffMN X-Received: by 10.182.66.193 with SMTP id h1mr3608809obt.47.1387554971981; Fri, 20 Dec 2013 07:56:11 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.76.72 with SMTP id i8ls763871qew.59.gmail; Fri, 20 Dec 2013 07:56:11 -0800 (PST) X-Received: by 10.58.187.81 with SMTP id fq17mr5606014vec.14.1387554971840; Fri, 20 Dec 2013 07:56:11 -0800 (PST) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id tw10si1593614vec.82.2013.12.20.07.56.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Dec 2013 07:56:11 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id lc6so1561709vcb.27 for ; Fri, 20 Dec 2013 07:56:11 -0800 (PST) X-Received: by 10.58.235.129 with SMTP id um1mr5513123vec.17.1387554971738; Fri, 20 Dec 2013 07:56:11 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp71456ved; Fri, 20 Dec 2013 07:56:11 -0800 (PST) X-Received: by 10.68.219.167 with SMTP id pp7mr9348277pbc.125.1387554970384; Fri, 20 Dec 2013 07:56:10 -0800 (PST) Received: from mail-pb0-f43.google.com (mail-pb0-f43.google.com [209.85.160.43]) by mx.google.com with ESMTPS id ty3si5584100pbc.47.2013.12.20.07.56.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Dec 2013 07:56:10 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.43 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.43; Received: by mail-pb0-f43.google.com with SMTP id rq2so2762201pbb.30 for ; Fri, 20 Dec 2013 07:56:09 -0800 (PST) X-Received: by 10.68.190.169 with SMTP id gr9mr9499120pbc.30.1387554969660; Fri, 20 Dec 2013 07:56:09 -0800 (PST) Received: from localhost ([122.167.204.159]) by mx.google.com with ESMTPSA id qf7sm19790926pac.14.2013.12.20.07.56.05 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 20 Dec 2013 07:56:08 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH Resend] cpufreq: remove sysfs files for CPU which failed to come back after resume Date: Fri, 20 Dec 2013 21:26:02 +0530 Message-Id: <610b63b7594e5cd364c498f60e69b9e174db9257.1387554926.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e MIME-Version: 1.0 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , There are cases where cpufreq_add_dev() may fail for some CPUs during resume. With the current code we will still have sysfs cpufreq files for such CPUs, and struct cpufreq_policy would be already freed for them. Hence any operation on those sysfs files would result in kernel warnings. To fix this, lets remove those sysfs files or put the associated kobject in case of such errors. Also, to make it simple lets remove the sysfs links from all the CPUs (except policy->cpu) during suspend as that operation wouldn't result with a loss of sysfs file permissions. And so we will create those links during resume as well. Reported-and-tested-by: Bjørn Mork Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 63 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 02d534d..fab042e 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -845,8 +845,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy) #ifdef CONFIG_HOTPLUG_CPU static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, - unsigned int cpu, struct device *dev, - bool frozen) + unsigned int cpu, struct device *dev) { int ret = 0; unsigned long flags; @@ -877,11 +876,7 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, } } - /* Don't touch sysfs links during light-weight init */ - if (!frozen) - ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); - - return ret; + return sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); } #endif @@ -926,6 +921,27 @@ err_free_policy: return NULL; } +static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) +{ + struct kobject *kobj; + struct completion *cmp; + + down_read(&policy->rwsem); + kobj = &policy->kobj; + cmp = &policy->kobj_unregister; + up_read(&policy->rwsem); + kobject_put(kobj); + + /* + * We need to make sure that the underlying kobj is + * actually not referenced anymore by anybody before we + * proceed with unloading. + */ + pr_debug("waiting for dropping of refcount\n"); + wait_for_completion(cmp); + pr_debug("wait complete\n"); +} + static void cpufreq_policy_free(struct cpufreq_policy *policy) { free_cpumask_var(policy->related_cpus); @@ -986,7 +1002,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, list_for_each_entry(tpolicy, &cpufreq_policy_list, policy_list) { if (cpumask_test_cpu(cpu, tpolicy->related_cpus)) { read_unlock_irqrestore(&cpufreq_driver_lock, flags); - ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev, frozen); + ret = cpufreq_add_policy_cpu(tpolicy, cpu, dev); up_read(&cpufreq_rwsem); return ret; } @@ -1096,7 +1112,10 @@ err_get_freq: if (cpufreq_driver->exit) cpufreq_driver->exit(policy); err_set_policy_cpu: + if (frozen) + cpufreq_policy_put_kobj(policy); cpufreq_policy_free(policy); + nomem_out: up_read(&cpufreq_rwsem); @@ -1118,7 +1137,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) } static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, - unsigned int old_cpu, bool frozen) + unsigned int old_cpu) { struct device *cpu_dev; int ret; @@ -1126,10 +1145,6 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, /* first sibling now owns the new sysfs dir */ cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu)); - /* Don't touch sysfs files during light-weight tear-down */ - if (frozen) - return cpu_dev->id; - sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); ret = kobject_move(&policy->kobj, &cpu_dev->kobj); if (ret) { @@ -1196,7 +1211,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, if (!frozen) sysfs_remove_link(&dev->kobj, "cpufreq"); } else if (cpus > 1) { - new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen); + new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu); if (new_cpu >= 0) { update_policy_cpu(policy, new_cpu); @@ -1218,8 +1233,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev, int ret; unsigned long flags; struct cpufreq_policy *policy; - struct kobject *kobj; - struct completion *cmp; read_lock_irqsave(&cpufreq_driver_lock, flags); policy = per_cpu(cpufreq_cpu_data, cpu); @@ -1249,22 +1262,8 @@ static int __cpufreq_remove_dev_finish(struct device *dev, } } - if (!frozen) { - down_read(&policy->rwsem); - kobj = &policy->kobj; - cmp = &policy->kobj_unregister; - up_read(&policy->rwsem); - kobject_put(kobj); - - /* - * We need to make sure that the underlying kobj is - * actually not referenced anymore by anybody before we - * proceed with unloading. - */ - pr_debug("waiting for dropping of refcount\n"); - wait_for_completion(cmp); - pr_debug("wait complete\n"); - } + if (!frozen) + cpufreq_policy_put_kobj(policy); /* * Perform the ->exit() even during light-weight tear-down,