Re: [tip:perf/urgent] perf/x86: Set pmu->module in Intel PMU modules
From: Linus Torvalds
Date: Thu Jan 05 2017 - 13:47:52 EST
On Thu, Jan 5, 2017 at 7:52 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> The first time I saw this I thought about doing something like the
> below, but never got around to testing if that works and subsequently
> forgot about things again.
>
> Does this make sense and or work?
I'd argue against it.
It will "work", but it's fragile. In particular, if something ever
ends up using perf_pmu_register() through some indirect helper
function, it will do the wrong thing, because
> +#define perf_pmu_register(_pmu, _name, _type) \
> +({ \
> + (_pmu)->module = THIS_MODULE; \
> + __perf_pmu_register((_pmu), (_name), (_type)); \
> +})
.. at that point "THIS_MODULE" could be the module that contains the
helper function that may not actually be the actual end-point module.
Looking at the situation right now, that never happens and all the
users seem to be "leaf" modules. But it would worry me a bit.
Linus