Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1178755 > unrolled thread
| Started by | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| First post | 2015-07-07 19:20 +0200 |
| Last post | 2015-07-08 14:40 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH V2] acpi-cpufreq: replace per_cpu with driver_data of policy Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2015-07-07 19:20 +0200
Re: [PATCH V2] acpi-cpufreq: replace per_cpu with driver_data of policy Pan Xinhui <xinhuix.pan@intel.com> - 2015-07-08 14:40 +0200
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2015-07-07 19:20 +0200 |
| Subject | Re: [PATCH V2] acpi-cpufreq: replace per_cpu with driver_data of policy |
| Message-ID | <pJEHg-8rS-1@gated-at.bofh.it> |
Hi Pan,
On Tue, Jul 07, 2015 at 08:43:26PM +0800, Pan Xinhui wrote:
> @@ -364,19 +363,24 @@ static u32 get_cur_val(const struct cpumask *mask)
>
> static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
> {
> - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu);
> + struct acpi_cpufreq_data *data;
> + struct cpufreq_policy *policy;
> unsigned int freq;
> unsigned int cached_freq;
>
> pr_debug("get_cur_freq_on_cpu (%d)\n", cpu);
>
> - if (unlikely(data == NULL ||
> - data->acpi_data == NULL || data->freq_table == NULL)) {
> + policy = cpufreq_cpu_get(cpu);
> + if (unlikely(!policy))
> + return 0;
> +
> + data = policy->driver_data;
> + cpufreq_cpu_put(policy);
If we put policy here can we guarantee that memory pointed to by data
stays valid? Shoudln't we issue cpufreq_cpu_put(policy) after we done
assessing the pointer?
> + if (unlikely(!data || !data->acpi_data || !data->freq_table))
> return 0;
> - }
>
> cached_freq = data->freq_table[data->acpi_data->state].frequency;
> - freq = extract_freq(get_cur_val(cpumask_of(cpu)), data);
> + freq = extract_freq(get_cur_val(cpumask_of(cpu), data), data);
> if (freq != cached_freq) {
> /*
> * The dreaded BIOS frequency change behind our back.
Thanks.
--
Dmitry
--
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/
[toc] | [next] | [standalone]
| From | Pan Xinhui <xinhuix.pan@intel.com> |
|---|---|
| Date | 2015-07-08 14:40 +0200 |
| Message-ID | <pJWNR-2GX-13@gated-at.bofh.it> |
| In reply to | #1178755 |
hi, Dmitry
thanks for your reply
On 2015年07月08日 01:11, Dmitry Torokhov wrote:
> Hi Pan,
>
> On Tue, Jul 07, 2015 at 08:43:26PM +0800, Pan Xinhui wrote:
>> @@ -364,19 +363,24 @@ static u32 get_cur_val(const struct cpumask *mask)
>>
>> static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
>> {
>> - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu);
>> + struct acpi_cpufreq_data *data;
>> + struct cpufreq_policy *policy;
>> unsigned int freq;
>> unsigned int cached_freq;
>>
>> pr_debug("get_cur_freq_on_cpu (%d)\n", cpu);
>>
>> - if (unlikely(data == NULL ||
>> - data->acpi_data == NULL || data->freq_table == NULL)) {
>> + policy = cpufreq_cpu_get(cpu);
>> + if (unlikely(!policy))
>> + return 0;
>> +
>> + data = policy->driver_data;
>> + cpufreq_cpu_put(policy);
>
> If we put policy here can we guarantee that memory pointed to by data
> stays valid? Shoudln't we issue cpufreq_cpu_put(policy) after we done
> assessing the pointer?
>
*driver_data* is used internal by acpi-cpufreq driver. So probably issuing
cpufreq_cpu_put(policy) after we get *driver_data* is OKay.
The worry you have is about the race. we set *driver_data* to NULL then
free it in ->exit callback while ->get callback is using it.
CPU A CPU B
->get ->exit
data = policy->driver_data;
if (!data ....)
policy->driver_data = NULL;
kfree(data);
access data ....
yes, it might happen in real world. As Viresh says, it is more like to be a core level work.
But this race exists in current codes, too. Maybe down_write policy->rwsem can avoid this race(need double check).
thanks for pointing out it. :)
thanks
xinhui
>> + if (unlikely(!data || !data->acpi_data || !data->freq_table))
>> return 0;
>> - }
>>
>> cached_freq = data->freq_table[data->acpi_data->state].frequency;
>> - freq = extract_freq(get_cur_val(cpumask_of(cpu)), data);
>> + freq = extract_freq(get_cur_val(cpumask_of(cpu), data), data);
>> if (freq != cached_freq) {
>> /*
>> * The dreaded BIOS frequency change behind our back.
>
> Thanks.
>
--
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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web