Skip to content

Commit db28323

Browse files
committed
x86/xen: fix percpu vcpu_info allocation
Today the percpu struct vcpu_info is allocated via DEFINE_PER_CPU(), meaning that it could cross a page boundary. In this case registering it with the hypervisor will fail, resulting in a panic(). This can easily be fixed by using DEFINE_PER_CPU_ALIGNED() instead, as struct vcpu_info is guaranteed to have a size of 64 bytes, matching the cache line size of x86 64-bit processors (Xen doesn't support 32-bit processors). Fixes: 5ead97c ("xen: Core Xen implementation") Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 7bf9a6b commit db28323

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

arch/x86/xen/enlighten.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ EXPORT_SYMBOL_GPL(hypercall_page);
3333
* and xen_vcpu_setup for details. By default it points to share_info->vcpu_info
3434
* but during boot it is switched to point to xen_vcpu_info.
3535
* The pointer is used in xen_evtchn_do_upcall to acknowledge pending events.
36+
* Make sure that xen_vcpu_info doesn't cross a page boundary by making it
37+
* cache-line aligned (the struct is guaranteed to have a size of 64 bytes,
38+
* which matches the cache line size of 64-bit x86 processors).
3639
*/
3740
DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
38-
DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
41+
DEFINE_PER_CPU_ALIGNED(struct vcpu_info, xen_vcpu_info);
3942

4043
/* Linux <-> Xen vCPU id mapping */
4144
DEFINE_PER_CPU(uint32_t, xen_vcpu_id);
@@ -160,6 +163,7 @@ void xen_vcpu_setup(int cpu)
160163
int err;
161164
struct vcpu_info *vcpup;
162165

166+
BUILD_BUG_ON(sizeof(*vcpup) > SMP_CACHE_BYTES);
163167
BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info);
164168

165169
/*

arch/x86/xen/xen-ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern void *xen_initial_gdt;
2121
struct trap_info;
2222
void xen_copy_trap_info(struct trap_info *traps);
2323

24-
DECLARE_PER_CPU(struct vcpu_info, xen_vcpu_info);
24+
DECLARE_PER_CPU_ALIGNED(struct vcpu_info, xen_vcpu_info);
2525
DECLARE_PER_CPU(unsigned long, xen_cr3);
2626
DECLARE_PER_CPU(unsigned long, xen_current_cr3);
2727

0 commit comments

Comments
 (0)