Re: [PM-WIP_CPUFREQ][PATCH V3 6/8] OMAP2+: cpufreq: fix freq_table leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Menon, Nishanth" <nm@xxxxxx> writes:

> On Wed, May 25, 2011 at 17:16, Kevin Hilman <khilman@xxxxxx> wrote:
>>
>> Nishanth Menon <nm@xxxxxx> writes:
>>
>> > Since we have multiple CPUs, the cpuinit call for CPU1 causes
>> > freq_table of CPU0 to be overwritten. Instead, we maintain
>> > a counter to keep track of cpus who use the cpufreq table
>> > allocate it once(one freq table for all CPUs) and free them
>> > once the last user is done with it. We also need to protect
>> > freq_table and this new counter from updates from multiple
>> > contexts to be on a safe side.
>>
>> Not sure I understand the need for all the locking here. ÂOnce allocated
>> and filled, the freq_table isn't changing. ÂAlso, all the functions are
>> only reading the freq_table, not changing it. Â ÂSo what is it you're
>> trying to protect against?
>
> We just have one freq_table for both cpu0 and cpu1. We have common
> data structure(freq_table and users) which is modifiable in two
> APIs(init/exit) and a set of reads. 

The table is not modifiable in two places.  It's only modified once,
upon creation.  After that the table contents are constant.

What is changable is simply the existence of the table.  This can be
handled by simply checking the pointer (or using your counter.)

> What if there is a read path while free occurs -

Then the CPUfreq driver has a bug.  If you want to be safe, check for a
valid pointer or use your counter.

> I may be mistaken, but my understanding is that the
> datastructure used in my code should be secured in my code and I
> cannot depend on higher layer(cpufreq/governors) to ensure that.

When you're talking about potentially concurrent modification of data,
that make sense.  Here you're implementing a plugin for an existing
framework, and you can (and have to) make assumptions about when the
callbacks are used.

Kevin

>>
>> > Signed-off-by: Nishanth Menon <nm@xxxxxx>
>> > ---
>> > Âarch/arm/mach-omap2/omap2plus-cpufreq.c | Â 62 +++++++++++++++++++++++++++----
>> > Â1 files changed, 54 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/arch/arm/mach-omap2/omap2plus-cpufreq.c b/arch/arm/mach-omap2/omap2plus-cpufreq.c
>> > index 3ff3302..f026ac4 100644
>> > --- a/arch/arm/mach-omap2/omap2plus-cpufreq.c
>> > +++ b/arch/arm/mach-omap2/omap2plus-cpufreq.c
>
> [..]
>> > @@ -156,22 +173,48 @@ skip_lpj:
>> >
>> > Âstatic int freq_table_alloc(void)
>> > Â{
>> > - Â Â if (use_opp)
>> > - Â Â Â Â Â Â return opp_init_cpufreq_table(mpu_dev, &freq_table);
>> > + Â Â int ret = 0;
>> >
>> > - Â Â clk_init_cpufreq_table(&freq_table);
>> > - Â Â if (!freq_table)
>> > - Â Â Â Â Â Â return -ENOMEM;
>> > + Â Â mutex_lock(&freq_table_lock);
>> >
>> > - Â Â return 0;
>> > + Â Â freq_table_users++;
>> > + Â Â /* Did we allocate previously? */
>> > + Â Â if (freq_table_users - 1)
>> > + Â Â Â Â Â Â goto out;
>>
>> Rather than the ' - 1', this can just be
>>
>> Â Â if (freq_table_users++)
>> Â Â Â Â Â Â Â Âgoto out;
> ok
>
>>
>> or better, you probably don't need this check protected by the mutex,
>> so this could just return directly, and then take the mutex_lock() after
>> this point.
> The mutex lock was to protect both the freq_table and the count as
> they protect the same resource - freq_table
>
>>
>> However, if you get rid of the mutex (and I think you should), you could
>> use an atomic variable here
> yes, we can use just atomic to protect alloc Vs free - but we cannot
> protect read Vs free
>
>
> Regards,
> Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Arm (vger)]     [ARM Kernel]     [ARM MSM]     [Linux Tegra]     [Linux WPAN Networking]     [Linux Wireless Networking]     [Maemo Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux