arch/x86/xen/multicalls.c

Source file repositories/reference/linux-study-clean/arch/x86/xen/multicalls.c

File Facts

System
Linux kernel
Corpus path
arch/x86/xen/multicalls.c
Extension
.c
Size
7369 bytes
Lines
300
Domain
Architecture Layer
Bucket
arch/x86
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mc_buffer {
	unsigned mcidx, argidx, cbidx;
	struct multicall_entry entries[MC_BATCH];
	unsigned char args[MC_ARGS];
	struct callback {
		void (*fn)(void *);
		void *data;
	} callbacks[MC_BATCH];
};

struct mc_debug_data {
	struct multicall_entry entries[MC_BATCH];
	void *caller[MC_BATCH];
	size_t argsz[MC_BATCH];
	unsigned long *args[MC_BATCH];
};

static DEFINE_PER_CPU(struct mc_buffer, mc_buffer);
static struct mc_debug_data mc_debug_data_early __initdata;
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;
	static_key_slow_inc(&mc_debug);

	return 0;
}
early_param("xen_mc_debug", xen_parse_mc_debug);

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

	if (!mc_debug_enabled)
		return 0;

	mcdb = alloc_percpu(struct mc_debug_data);
	if (!mcdb) {
		pr_err("xen_mc_debug inactive\n");
		static_key_slow_dec(&mc_debug);
		return -ENOMEM;
	}

	/* Be careful when switching to percpu debug data. */
	local_irq_save(flags);
	xen_mc_flush();
	mc_debug_data_ptr = mcdb;
	local_irq_restore(flags);

	pr_info("xen_mc_debug active\n");

	return 0;
}
early_initcall(mc_debug_enable);

/* Number of parameters of hypercalls used via multicalls. */
static const uint8_t hpcpars[] = {
	[__HYPERVISOR_mmu_update] = 4,
	[__HYPERVISOR_stack_switch] = 2,
	[__HYPERVISOR_fpu_taskswitch] = 1,
	[__HYPERVISOR_update_descriptor] = 2,
	[__HYPERVISOR_update_va_mapping] = 3,
	[__HYPERVISOR_mmuext_op] = 4,
};

static void print_debug_data(struct mc_buffer *b, struct mc_debug_data *mcdb,
			     int idx)
{
	unsigned int arg;
	unsigned int opidx = mcdb->entries[idx].op & 0xff;
	unsigned int pars = 0;

	pr_err("  call %2d: op=%lu result=%ld caller=%pS ", idx + 1,
	       mcdb->entries[idx].op, b->entries[idx].result,
	       mcdb->caller[idx]);
	if (opidx < ARRAY_SIZE(hpcpars))

Annotation

Implementation Notes