Commit 003659f
perf/core: Fix perf_pmu_register() vs. perf_init_event()
There is a fairly obvious race between perf_init_event() doing
idr_find() and perf_pmu_register() doing idr_alloc() with an
incompletely initialized PMU pointer.
Avoid by doing idr_alloc() on a NULL pointer to register the id, and
swizzling the real struct pmu pointer at the end using idr_replace().
Also making sure to not set struct pmu members after publishing
the struct pmu, duh.
[ introduce idr_cmpxchg() in order to better handle the idr_replace()
error case -- if it were to return an unexpected pointer, it will
already have replaced the value and there is no going back. ]
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20241104135517.858805880@infradead.org1 parent 2565e42 commit 003659f
1 file changed
+26
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11830 | 11830 | | |
11831 | 11831 | | |
11832 | 11832 | | |
| 11833 | + | |
| 11834 | + | |
| 11835 | + | |
| 11836 | + | |
| 11837 | + | |
| 11838 | + | |
| 11839 | + | |
| 11840 | + | |
| 11841 | + | |
| 11842 | + | |
| 11843 | + | |
| 11844 | + | |
| 11845 | + | |
| 11846 | + | |
| 11847 | + | |
11833 | 11848 | | |
11834 | 11849 | | |
11835 | 11850 | | |
| |||
11856 | 11871 | | |
11857 | 11872 | | |
11858 | 11873 | | |
11859 | | - | |
| 11874 | + | |
11860 | 11875 | | |
11861 | 11876 | | |
11862 | 11877 | | |
11863 | 11878 | | |
11864 | 11879 | | |
11865 | 11880 | | |
11866 | 11881 | | |
| 11882 | + | |
11867 | 11883 | | |
11868 | 11884 | | |
11869 | 11885 | | |
| |||
11912 | 11928 | | |
11913 | 11929 | | |
11914 | 11930 | | |
| 11931 | + | |
| 11932 | + | |
| 11933 | + | |
| 11934 | + | |
| 11935 | + | |
11915 | 11936 | | |
11916 | | - | |
| 11937 | + | |
11917 | 11938 | | |
11918 | 11939 | | |
11919 | 11940 | | |
11920 | 11941 | | |
11921 | 11942 | | |
11922 | 11943 | | |
| 11944 | + | |
| 11945 | + | |
| 11946 | + | |
11923 | 11947 | | |
11924 | 11948 | | |
11925 | 11949 | | |
| |||
0 commit comments