Skip to content

Commit e591315

Browse files
Shawnshhlijinxia
authored andcommitted
HV:treewide:C99-friendly per_cpu implementation change the per_cpu method
The current implementation of per_cpu relies on several non-c99 features, and in additional involves arbitrary pointer arithmetic which is not MIS- RA C friendly. This patch introduces struct per_cpu_region which holds all the per_cpu variables. Allocation of per_cpu data regions and access to per_cpu vari- ables are greatly simplified, at the cost of making all per_cpu varaibl- es accessible in files. Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
1 parent cbb692d commit e591315

File tree

20 files changed

+95
-130
lines changed

20 files changed

+95
-130
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@ spinlock_t up_count_spinlock = {
1818
.tail = 0
1919
};
2020

21-
void *per_cpu_data_base_ptr;
21+
struct per_cpu_region *per_cpu_data_base_ptr;
2222
int phy_cpu_num = 0;
2323
unsigned long pcpu_sync = 0;
2424
uint32_t up_count = 0;
2525

2626
/* physical cpu active bitmap, support up to 64 cpus */
2727
uint64_t pcpu_active_bitmap = 0;
2828

29-
DEFINE_CPU_DATA(uint8_t[STACK_SIZE], stack) __aligned(16);
30-
DEFINE_CPU_DATA(uint8_t, lapic_id);
31-
DEFINE_CPU_DATA(void *, vcpu);
32-
DEFINE_CPU_DATA(int, state);
33-
3429
/* TODO: add more capability per requirement */
3530
/*APICv features*/
3631
#define VAPIC_FEATURE_VIRT_ACCESS (1 << 0)
@@ -228,7 +223,7 @@ static void alloc_phy_cpu_data(int pcpu_num)
228223
{
229224
phy_cpu_num = pcpu_num;
230225

231-
per_cpu_data_base_ptr = calloc(1, PER_CPU_DATA_SIZE * pcpu_num);
226+
per_cpu_data_base_ptr = calloc(pcpu_num, sizeof(struct per_cpu_region));
232227
ASSERT(per_cpu_data_base_ptr != NULL, "");
233228
}
234229

@@ -294,14 +289,6 @@ static void cpu_set_current_state(uint32_t logical_id, int state)
294289
}
295290

296291
#ifdef STACK_PROTECTOR
297-
struct stack_canary {
298-
/* Gcc generates extra code, using [fs:40] to access canary */
299-
uint8_t reserved[40];
300-
uint64_t canary;
301-
};
302-
303-
static DEFINE_CPU_DATA(struct stack_canary, stack_canary);
304-
305292
static uint64_t get_random_value(void)
306293
{
307294
uint64_t random = 0;

hypervisor/arch/x86/gdt.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
#include <hypervisor.h>
88

9-
DEFINE_CPU_DATA(struct tss_64, tss);
10-
DEFINE_CPU_DATA(struct host_gdt, gdt);
11-
DEFINE_CPU_DATA(uint8_t[STACK_SIZE], mc_stack) __aligned(16);
12-
DEFINE_CPU_DATA(uint8_t[STACK_SIZE], df_stack) __aligned(16);
13-
DEFINE_CPU_DATA(uint8_t[STACK_SIZE], sf_stack) __aligned(16);
14-
159
static void set_tss_desc(union tss_64_descriptor *desc,
1610
void *tss, int tss_limit, int type)
1711
{

hypervisor/arch/x86/guest/instr_emul_wrapper.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@
99
#include "instr_emul_wrapper.h"
1010
#include "instr_emul.h"
1111

12-
struct emul_cnx {
13-
struct vie vie;
14-
struct vm_guest_paging paging;
15-
struct vcpu *vcpu;
16-
};
17-
18-
static DEFINE_CPU_DATA(struct emul_cnx, g_inst_ctxt);
19-
2012
static int
2113
encode_vmcs_seg_desc(int seg, uint32_t *base, uint32_t *lim, uint32_t *acc);
2214

hypervisor/arch/x86/guest/instr_emul_wrapper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ struct vm_guest_paging {
133133
enum vm_paging_mode paging_mode;
134134
};
135135

136+
struct emul_cnx {
137+
struct vie vie;
138+
struct vm_guest_paging paging;
139+
struct vcpu *vcpu;
140+
};
141+
136142
/*
137143
* Identifiers for architecturally defined registers.
138144
*/

hypervisor/arch/x86/irq.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ struct irq_desc {
3737
static struct irq_desc *irq_desc_base;
3838
static int vector_to_irq[NR_MAX_VECTOR + 1];
3939

40-
static DEFINE_CPU_DATA(uint64_t[NR_MAX_IRQS], irq_count);
41-
static DEFINE_CPU_DATA(uint64_t, spurious);
42-
4340
spurious_handler_t spurious_handler;
4441

4542
static void init_irq_desc(void)

hypervisor/arch/x86/softirq.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include <hypervisor.h>
88

9-
static DEFINE_CPU_DATA(uint64_t, softirq_pending);
10-
119
void disable_softirq(int cpu_id)
1210
{
1311
bitmap_clear(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, cpu_id));

hypervisor/arch/x86/timer.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313

1414
uint64_t tsc_hz = 1000000000;
1515

16-
struct per_cpu_timers {
17-
struct list_head timer_list; /* it's for runtime active timer list */
18-
};
19-
20-
static DEFINE_CPU_DATA(struct per_cpu_timers, cpu_timers);
21-
static DEFINE_CPU_DATA(struct dev_handler_node *, timer_node);
22-
23-
2416
static void run_timer(struct timer *timer)
2517
{
2618
/* deadline = 0 means stop timer, we should skip */

hypervisor/bsp/ld/link_ram.ld.in

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ SECTIONS
8080
_ld_bss_end = . ;
8181
} > ram
8282

83-
.discard (NOLOAD):
84-
{
85-
. = ALIGN(4096) ;
86-
_ld_cpu_data_start = .;
87-
*(.cpu_data) ;
88-
. = ALIGN(4096) ;
89-
_ld_cpu_data_end = .;
90-
} > ram
91-
9283
_ld_ram_size = LENGTH(ram) ;
9384
_ld_ram_end = _ld_ram_size + _ld_ram_start ;
9485
}

hypervisor/common/hv_main.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
bool x2apic_enabled;
1111

12-
static DEFINE_CPU_DATA(uint64_t[64], vmexit_cnt);
13-
static DEFINE_CPU_DATA(uint64_t[64], vmexit_time);
14-
1512
static void run_vcpu_pre_work(struct vcpu *vcpu)
1613
{
1714
unsigned long *pending_pre_work = &vcpu->pending_pre_work;

hypervisor/common/schedule.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
#include <hypervisor.h>
88
#include <schedule.h>
99

10-
struct sched_context {
11-
spinlock_t runqueue_lock;
12-
struct list_head runqueue;
13-
unsigned long need_scheduled;
14-
struct vcpu *curr_vcpu;
15-
spinlock_t scheduler_lock;
16-
};
17-
18-
static DEFINE_CPU_DATA(struct sched_context, sched_ctx);
1910
static unsigned long pcpu_used_bitmap;
2011

2112
void init_scheduler(void)

0 commit comments

Comments
 (0)