Re: [raw v1 2/4] [NET] Use raw_cpu ops for SNMP stats

From: Ingo Molnar
Date: Tue Oct 08 2013 - 03:21:23 EST



* Christoph Lameter <cl@xxxxxxxxx> wrote:

> SNMP stats are not protected by preemption but by bh handling.

Most forms of bh exclusion work via the preemption count though, and
softirq contexts themselves are generally not preemptible [to other CPUs]
either.

So the warnings should, in most cases, not trigger.

> Since protection is provided outside of preemption raw_cpu_ops
> need to be used to avoid false positives.

Could you quote the warning that pops up? It might be better to annotate
the specific safe usages than to potentially hide bugs:

> --- linux.orig/include/net/snmp.h 2013-10-07 09:16:07.595206864 -0500
> +++ linux/include/net/snmp.h 2013-10-07 09:16:07.591206909 -0500
> @@ -126,7 +126,7 @@ struct linux_xfrm_mib {
> extern __typeof__(type) __percpu *name[SNMP_ARRAY_SZ]
>
> #define SNMP_INC_STATS_BH(mib, field) \
> - __this_cpu_inc(mib[0]->mibs[field])
> + raw_cpu_inc(mib[0]->mibs[field])
>
> #define SNMP_INC_STATS_USER(mib, field) \
> this_cpu_inc(mib[0]->mibs[field])
> @@ -141,7 +141,7 @@ struct linux_xfrm_mib {
> this_cpu_dec(mib[0]->mibs[field])
>
> #define SNMP_ADD_STATS_BH(mib, field, addend) \
> - __this_cpu_add(mib[0]->mibs[field], addend)
> + raw_cpu_add(mib[0]->mibs[field], addend)
>
> #define SNMP_ADD_STATS_USER(mib, field, addend) \
> this_cpu_add(mib[0]->mibs[field], addend)

Doing this will hide any true bugs if any of these primitives is used in
an unsafe context.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/