Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755205AbbBBEyM (ORCPT ); Sun, 1 Feb 2015 23:54:12 -0500 Received: from mail-ob0-f175.google.com ([209.85.214.175]:45496 "EHLO mail-ob0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755057AbbBBEyF (ORCPT ); Sun, 1 Feb 2015 23:54:05 -0500 MIME-Version: 1.0 In-Reply-To: <54CF0106.5050601@oracle.com> References: <54CEECF7.7020504@oracle.com> <54CEF123.5050106@oracle.com> <54CEF574.6040404@oracle.com> <54CEF7AA.80401@oracle.com> <54CEFA23.7040705@oracle.com> <54CF0106.5050601@oracle.com> Date: Mon, 2 Feb 2015 10:24:05 +0530 Message-ID: Subject: Re: [PATCH Resend] cpufreq: Set cpufreq_cpu_data to NULL before putting kobject From: Viresh Kumar To: ethan zhao Cc: Rafael Wysocki , santosh shilimkar , Linaro Kernel Mailman List , "linux-pm@vger.kernel.org" , linux-kernel Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2026 Lines: 49 On 2 February 2015 at 10:15, ethan zhao wrote: > On 2015/2/2 12:26, Viresh Kumar wrote: > But there is no checking against refcount in or before > > cpufreq_policy_free(), that is one issue I mentioned. As I said earlier, the completion will only fire once the refcount is zero. And so there is no need of any check here. >> That routines doesn't have any tricks and simply frees the policy. >> Because, before calling cpufreq_policy_put_kobj(), we have set >> the per-cpu variable to NULL, nobody else will get the policy > > It is possible cpufreq_cpu_get() within the PPC thread was called just > before __cpufreq_remove_dev_finish() is to be called in another thread, > so you set the per_cpu(cpufreq_cpu_data, cpu) to NULL will not prevent > the actions between cpufreq_cpu_get and cpufreq_cpu_put(). > > And then the freeing happens in __cpufreq_remove_dev_finish(). It will.. You aren't looking closely enough. If cpufreq_cpu_get() is called just before remove-dev, then cpufreq_cpu_get() will take: read_lock_irqsave(&cpufreq_driver_lock, flags); And it will do: read_unlock_irqrestore(&cpufreq_driver_lock, flags); only after increasing the refcount with kobject_get(). While on the other side __cpufreq_remove_dev_finish() will do this: write_lock_irqsave(&cpufreq_driver_lock, flags); policy = per_cpu(cpufreq_cpu_data, cpu); per_cpu(cpufreq_cpu_data, cpu) = NULL; write_unlock_irqrestore(&cpufreq_driver_lock, flags); So, it will wait for the read_lock in cpufreq_cpu_get() to finish before setting per-cpu variable to NULL. And so, after kobject_put() in cpufreq_policy_put_kobj(), we will wait for the completion to fire and that will only happen once a corresponding cpufreq_cpu_put() is issued. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/