Skip to content

Commit 715ad3e

Browse files
committed
xen: fix multicall debug feature
Initializing a percpu variable with the address of a struct tagged as .initdata is breaking the build with CONFIG_SECTION_MISMATCH_WARN_ONLY not set to "y". Fix that by using an access function instead returning the .initdata struct address if the percpu space of the struct hasn't been allocated yet. Fixes: 368990a ("xen: fix multicall debug data referencing") Reported-by: Borislav Petkov <bp@alien8.de> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Acked-by: "Borislav Petkov (AMD)" <bp@alien8.de> Tested-by: "Borislav Petkov (AMD)" <bp@alien8.de> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20250327190602.26015-1-jgross@suse.com>
1 parent 64a66e2 commit 715ad3e

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

arch/x86/xen/multicalls.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,20 @@ struct mc_debug_data {
5454

5555
static DEFINE_PER_CPU(struct mc_buffer, mc_buffer);
5656
static struct mc_debug_data mc_debug_data_early __initdata;
57-
static DEFINE_PER_CPU(struct mc_debug_data *, mc_debug_data) =
58-
&mc_debug_data_early;
5957
static struct mc_debug_data __percpu *mc_debug_data_ptr;
6058
DEFINE_PER_CPU(unsigned long, xen_mc_irq_flags);
6159

6260
static struct static_key mc_debug __ro_after_init;
6361
static bool mc_debug_enabled __initdata;
6462

63+
static struct mc_debug_data * __ref get_mc_debug(void)
64+
{
65+
if (!mc_debug_data_ptr)
66+
return &mc_debug_data_early;
67+
68+
return this_cpu_ptr(mc_debug_data_ptr);
69+
}
70+
6571
static int __init xen_parse_mc_debug(char *arg)
6672
{
6773
mc_debug_enabled = true;
@@ -71,20 +77,16 @@ static int __init xen_parse_mc_debug(char *arg)
7177
}
7278
early_param("xen_mc_debug", xen_parse_mc_debug);
7379

74-
void mc_percpu_init(unsigned int cpu)
75-
{
76-
per_cpu(mc_debug_data, cpu) = per_cpu_ptr(mc_debug_data_ptr, cpu);
77-
}
78-
7980
static int __init mc_debug_enable(void)
8081
{
8182
unsigned long flags;
83+
struct mc_debug_data __percpu *mcdb;
8284

8385
if (!mc_debug_enabled)
8486
return 0;
8587

86-
mc_debug_data_ptr = alloc_percpu(struct mc_debug_data);
87-
if (!mc_debug_data_ptr) {
88+
mcdb = alloc_percpu(struct mc_debug_data);
89+
if (!mcdb) {
8890
pr_err("xen_mc_debug inactive\n");
8991
static_key_slow_dec(&mc_debug);
9092
return -ENOMEM;
@@ -93,7 +95,7 @@ static int __init mc_debug_enable(void)
9395
/* Be careful when switching to percpu debug data. */
9496
local_irq_save(flags);
9597
xen_mc_flush();
96-
mc_percpu_init(0);
98+
mc_debug_data_ptr = mcdb;
9799
local_irq_restore(flags);
98100

99101
pr_info("xen_mc_debug active\n");
@@ -155,7 +157,7 @@ void xen_mc_flush(void)
155157
trace_xen_mc_flush(b->mcidx, b->argidx, b->cbidx);
156158

157159
if (static_key_false(&mc_debug)) {
158-
mcdb = __this_cpu_read(mc_debug_data);
160+
mcdb = get_mc_debug();
159161
memcpy(mcdb->entries, b->entries,
160162
b->mcidx * sizeof(struct multicall_entry));
161163
}
@@ -235,7 +237,7 @@ struct multicall_space __xen_mc_entry(size_t args)
235237

236238
ret.mc = &b->entries[b->mcidx];
237239
if (static_key_false(&mc_debug)) {
238-
struct mc_debug_data *mcdb = __this_cpu_read(mc_debug_data);
240+
struct mc_debug_data *mcdb = get_mc_debug();
239241

240242
mcdb->caller[b->mcidx] = __builtin_return_address(0);
241243
mcdb->argsz[b->mcidx] = args;

arch/x86/xen/smp_pv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ static int xen_pv_kick_ap(unsigned int cpu, struct task_struct *idle)
305305
return rc;
306306

307307
xen_pmu_init(cpu);
308-
mc_percpu_init(cpu);
309308

310309
/*
311310
* Why is this a BUG? If the hypercall fails then everything can be

arch/x86/xen/xen-ops.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ void xen_mc_callback(void (*fn)(void *), void *data);
261261
*/
262262
struct multicall_space xen_mc_extend_args(unsigned long op, size_t arg_size);
263263

264-
/* Do percpu data initialization for multicalls. */
265-
void mc_percpu_init(unsigned int cpu);
266-
267264
extern bool is_xen_pmu;
268265

269266
irqreturn_t xen_pmu_irq_handler(int irq, void *dev_id);

0 commit comments

Comments
 (0)