Skip to content

Commit

Permalink
xen: fix multicall debug feature
Browse files Browse the repository at this point in the history
[ Upstream commit 715ad3e ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Juergen Gross authored and Greg Kroah-Hartman committed Apr 25, 2025
1 parent b02c2ac commit fa0d996
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
26 changes: 14 additions & 12 deletions arch/x86/xen/multicalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ struct mc_debug_data {

static DEFINE_PER_CPU(struct mc_buffer, mc_buffer);
static struct mc_debug_data mc_debug_data_early __initdata;
static DEFINE_PER_CPU(struct mc_debug_data *, mc_debug_data) =
&mc_debug_data_early;
static struct mc_debug_data __percpu *mc_debug_data_ptr;
DEFINE_PER_CPU(unsigned long, xen_mc_irq_flags);

static struct static_key mc_debug __ro_after_init;
static bool mc_debug_enabled __initdata;

static struct mc_debug_data * __ref get_mc_debug(void)
{
if (!mc_debug_data_ptr)
return &mc_debug_data_early;

return this_cpu_ptr(mc_debug_data_ptr);
}

static int __init xen_parse_mc_debug(char *arg)
{
mc_debug_enabled = true;
Expand All @@ -71,20 +77,16 @@ static int __init xen_parse_mc_debug(char *arg)
}
early_param("xen_mc_debug", xen_parse_mc_debug);

void mc_percpu_init(unsigned int cpu)
{
per_cpu(mc_debug_data, cpu) = per_cpu_ptr(mc_debug_data_ptr, cpu);
}

static int __init mc_debug_enable(void)
{
unsigned long flags;
struct mc_debug_data __percpu *mcdb;

if (!mc_debug_enabled)
return 0;

mc_debug_data_ptr = alloc_percpu(struct mc_debug_data);
if (!mc_debug_data_ptr) {
mcdb = alloc_percpu(struct mc_debug_data);
if (!mcdb) {
pr_err("xen_mc_debug inactive\n");
static_key_slow_dec(&mc_debug);
return -ENOMEM;
Expand All @@ -93,7 +95,7 @@ static int __init mc_debug_enable(void)
/* Be careful when switching to percpu debug data. */
local_irq_save(flags);
xen_mc_flush();
mc_percpu_init(0);
mc_debug_data_ptr = mcdb;
local_irq_restore(flags);

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

if (static_key_false(&mc_debug)) {
mcdb = __this_cpu_read(mc_debug_data);
mcdb = get_mc_debug();
memcpy(mcdb->entries, b->entries,
b->mcidx * sizeof(struct multicall_entry));
}
Expand Down Expand Up @@ -235,7 +237,7 @@ struct multicall_space __xen_mc_entry(size_t args)

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

mcdb->caller[b->mcidx] = __builtin_return_address(0);
mcdb->argsz[b->mcidx] = args;
Expand Down
1 change: 0 additions & 1 deletion arch/x86/xen/smp_pv.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ static int xen_pv_kick_ap(unsigned int cpu, struct task_struct *idle)
return rc;

xen_pmu_init(cpu);
mc_percpu_init(cpu);

/*
* Why is this a BUG? If the hypercall fails then everything can be
Expand Down
3 changes: 0 additions & 3 deletions arch/x86/xen/xen-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ void xen_mc_callback(void (*fn)(void *), void *data);
*/
struct multicall_space xen_mc_extend_args(unsigned long op, size_t arg_size);

/* Do percpu data initialization for multicalls. */
void mc_percpu_init(unsigned int cpu);

extern bool is_xen_pmu;

irqreturn_t xen_pmu_irq_handler(int irq, void *dev_id);
Expand Down

0 comments on commit fa0d996

Please sign in to comment.