Skip to content

Commit

Permalink
Merge tag 'for-linus-6.15a-rc3-tag' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/xen/tip

Pull xen fix from Juergen Gross:
 "Just a single fix for the Xen multicall driver avoiding a percpu
  variable referencing initdata by its initializer"

* tag 'for-linus-6.15a-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
  xen: fix multicall debug feature
  • Loading branch information
Linus Torvalds committed Apr 17, 2025
2 parents e2516ab + 715ad3e commit 85a9793
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 85a9793

Please sign in to comment.