Skip to content

Commit 75f3cf0

Browse files
NTManglemco
authored andcommitted
rv: Fix multiple definition of __pcpu_unique_da_mon_this
The refactoring in commit 30984cc ("rv: Refactor da_monitor to minimise macros") replaced per-monitor unique variable names (da_mon_##name) with a fixed name (da_mon_this). While this works for 'static' variables (each translation unit gets its own copy), DEFINE_PER_CPU internally generates a non-static dummy variable __pcpu_unique_<n> for each per-cpu definition. The requirement for this variable to be unique although static exists for modules on specific architectures (alpha) and if the kernel is built with CONFIG_DEBUG_FORCE_WEAK_PER_CPU (e.g. Fedora's debug kernel). When multiple per-cpu monitors (e.g. sco and sts) are built-in simultaneously, they all produce the same __pcpu_unique_da_mon_this symbol, causing a link error: ld: kernel/trace/rv/monitors/sts/sts.o: multiple definition of `__pcpu_unique_da_mon_this'; kernel/trace/rv/monitors/sco/sco.o: first defined here Fix this by introducing a DA_MON_NAME macro that expands to a per-monitor unique name (da_mon_<MONITOR_NAME>) via the existing CONCATENATE helper. This restores the uniqueness that was present before the refactoring. Fixes: 30984cc ("rv: Refactor da_monitor to minimise macros") Reviewed-by: Gabriele Monaco <gmonaco@redhat.com> Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Link: https://lore.kernel.org/r/20260216172707.1441516-1-mikhail.v.gavrilov@gmail.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
1 parent 403faa5 commit 75f3cf0

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

include/rv/da_monitor.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include <linux/bug.h>
2121
#include <linux/sched.h>
2222

23+
/*
24+
* Per-cpu variables require a unique name although static in some
25+
* configurations (e.g. CONFIG_DEBUG_FORCE_WEAK_PER_CPU or alpha modules).
26+
*/
27+
#define DA_MON_NAME CONCATENATE(da_mon_, MONITOR_NAME)
28+
2329
static struct rv_monitor rv_this;
2430

2531
static void react(enum states curr_state, enum events event)
@@ -183,14 +189,14 @@ static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
183189
/*
184190
* global monitor (a single variable)
185191
*/
186-
static struct da_monitor da_mon_this;
192+
static struct da_monitor DA_MON_NAME;
187193

188194
/*
189195
* da_get_monitor - return the global monitor address
190196
*/
191197
static struct da_monitor *da_get_monitor(void)
192198
{
193-
return &da_mon_this;
199+
return &DA_MON_NAME;
194200
}
195201

196202
/*
@@ -223,14 +229,14 @@ static inline void da_monitor_destroy(void) { }
223229
/*
224230
* per-cpu monitor variables
225231
*/
226-
static DEFINE_PER_CPU(struct da_monitor, da_mon_this);
232+
static DEFINE_PER_CPU(struct da_monitor, DA_MON_NAME);
227233

228234
/*
229235
* da_get_monitor - return current CPU monitor address
230236
*/
231237
static struct da_monitor *da_get_monitor(void)
232238
{
233-
return this_cpu_ptr(&da_mon_this);
239+
return this_cpu_ptr(&DA_MON_NAME);
234240
}
235241

236242
/*
@@ -242,7 +248,7 @@ static void da_monitor_reset_all(void)
242248
int cpu;
243249

244250
for_each_cpu(cpu, cpu_online_mask) {
245-
da_mon = per_cpu_ptr(&da_mon_this, cpu);
251+
da_mon = per_cpu_ptr(&DA_MON_NAME, cpu);
246252
da_monitor_reset(da_mon);
247253
}
248254
}

0 commit comments

Comments
 (0)