Commit 0fe1e009 authored by Tejun Heo's avatar Tejun Heo

percpu: make percpu symbols in x86 unique

This patch updates percpu related symbols in x86 such that percpu
symbols are unique and don't clash with local symbols.  This serves
two purposes of decreasing the possibility of global percpu symbol
collision and allowing dropping per_cpu__ prefix from percpu symbols.

* arch/x86/kernel/cpu/common.c: rename local variable to avoid collision

* arch/x86/kvm/svm.c: s/svm_data/sd/ for local variables to avoid collision

* arch/x86/kernel/cpu/cpu_debug.c: s/cpu_arr/cpud_arr/
  				   s/priv_arr/cpud_priv_arr/
				   s/cpu_priv_count/cpud_priv_count/

* arch/x86/kernel/cpu/intel_cacheinfo.c: s/cpuid4_info/ici_cpuid4_info/
  					 s/cache_kobject/ici_cache_kobject/
					 s/index_kobject/ici_index_kobject/

* arch/x86/kernel/ds.c: s/cpu_context/cpu_ds_context/

Partly based on Rusty Russell's "alloc_percpu: rename percpu vars
which cause name clashes" patch.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatar(kvm) Avi Kivity <avi@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: x86@kernel.org
parent c6e22f9e
...@@ -1093,7 +1093,7 @@ static void clear_all_debug_regs(void) ...@@ -1093,7 +1093,7 @@ static void clear_all_debug_regs(void)
void __cpuinit cpu_init(void) void __cpuinit cpu_init(void)
{ {
struct orig_ist *orig_ist; struct orig_ist *oist;
struct task_struct *me; struct task_struct *me;
struct tss_struct *t; struct tss_struct *t;
unsigned long v; unsigned long v;
...@@ -1102,7 +1102,7 @@ void __cpuinit cpu_init(void) ...@@ -1102,7 +1102,7 @@ void __cpuinit cpu_init(void)
cpu = stack_smp_processor_id(); cpu = stack_smp_processor_id();
t = &per_cpu(init_tss, cpu); t = &per_cpu(init_tss, cpu);
orig_ist = &per_cpu(orig_ist, cpu); oist = &per_cpu(orig_ist, cpu);
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
if (cpu != 0 && percpu_read(node_number) == 0 && if (cpu != 0 && percpu_read(node_number) == 0 &&
...@@ -1143,12 +1143,12 @@ void __cpuinit cpu_init(void) ...@@ -1143,12 +1143,12 @@ void __cpuinit cpu_init(void)
/* /*
* set up and load the per-CPU TSS * set up and load the per-CPU TSS
*/ */
if (!orig_ist->ist[0]) { if (!oist->ist[0]) {
char *estacks = per_cpu(exception_stacks, cpu); char *estacks = per_cpu(exception_stacks, cpu);
for (v = 0; v < N_EXCEPTION_STACKS; v++) { for (v = 0; v < N_EXCEPTION_STACKS; v++) {
estacks += exception_stack_sizes[v]; estacks += exception_stack_sizes[v];
orig_ist->ist[v] = t->x86_tss.ist[v] = oist->ist[v] = t->x86_tss.ist[v] =
(unsigned long)estacks; (unsigned long)estacks;
} }
} }
......
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#include <asm/apic.h> #include <asm/apic.h>
#include <asm/desc.h> #include <asm/desc.h>
static DEFINE_PER_CPU(struct cpu_cpuX_base [CPU_REG_ALL_BIT], cpu_arr); static DEFINE_PER_CPU(struct cpu_cpuX_base [CPU_REG_ALL_BIT], cpud_arr);
static DEFINE_PER_CPU(struct cpu_private * [MAX_CPU_FILES], priv_arr); static DEFINE_PER_CPU(struct cpu_private * [MAX_CPU_FILES], cpud_priv_arr);
static DEFINE_PER_CPU(int, cpu_priv_count); static DEFINE_PER_CPU(int, cpud_priv_count);
static DEFINE_MUTEX(cpu_debug_lock); static DEFINE_MUTEX(cpu_debug_lock);
...@@ -531,7 +531,7 @@ static int cpu_create_file(unsigned cpu, unsigned type, unsigned reg, ...@@ -531,7 +531,7 @@ static int cpu_create_file(unsigned cpu, unsigned type, unsigned reg,
/* Already intialized */ /* Already intialized */
if (file == CPU_INDEX_BIT) if (file == CPU_INDEX_BIT)
if (per_cpu(cpu_arr[type].init, cpu)) if (per_cpu(cpud_arr[type].init, cpu))
return 0; return 0;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
...@@ -543,8 +543,8 @@ static int cpu_create_file(unsigned cpu, unsigned type, unsigned reg, ...@@ -543,8 +543,8 @@ static int cpu_create_file(unsigned cpu, unsigned type, unsigned reg,
priv->reg = reg; priv->reg = reg;
priv->file = file; priv->file = file;
mutex_lock(&cpu_debug_lock); mutex_lock(&cpu_debug_lock);
per_cpu(priv_arr[type], cpu) = priv; per_cpu(cpud_priv_arr[type], cpu) = priv;
per_cpu(cpu_priv_count, cpu)++; per_cpu(cpud_priv_count, cpu)++;
mutex_unlock(&cpu_debug_lock); mutex_unlock(&cpu_debug_lock);
if (file) if (file)
...@@ -552,10 +552,10 @@ static int cpu_create_file(unsigned cpu, unsigned type, unsigned reg, ...@@ -552,10 +552,10 @@ static int cpu_create_file(unsigned cpu, unsigned type, unsigned reg,
dentry, (void *)priv, &cpu_fops); dentry, (void *)priv, &cpu_fops);
else { else {
debugfs_create_file(cpu_base[type].name, S_IRUGO, debugfs_create_file(cpu_base[type].name, S_IRUGO,
per_cpu(cpu_arr[type].dentry, cpu), per_cpu(cpud_arr[type].dentry, cpu),
(void *)priv, &cpu_fops); (void *)priv, &cpu_fops);
mutex_lock(&cpu_debug_lock); mutex_lock(&cpu_debug_lock);
per_cpu(cpu_arr[type].init, cpu) = 1; per_cpu(cpud_arr[type].init, cpu) = 1;
mutex_unlock(&cpu_debug_lock); mutex_unlock(&cpu_debug_lock);
} }
...@@ -615,7 +615,7 @@ static int cpu_init_allreg(unsigned cpu, struct dentry *dentry) ...@@ -615,7 +615,7 @@ static int cpu_init_allreg(unsigned cpu, struct dentry *dentry)
if (!is_typeflag_valid(cpu, cpu_base[type].flag)) if (!is_typeflag_valid(cpu, cpu_base[type].flag))
continue; continue;
cpu_dentry = debugfs_create_dir(cpu_base[type].name, dentry); cpu_dentry = debugfs_create_dir(cpu_base[type].name, dentry);
per_cpu(cpu_arr[type].dentry, cpu) = cpu_dentry; per_cpu(cpud_arr[type].dentry, cpu) = cpu_dentry;
if (type < CPU_TSS_BIT) if (type < CPU_TSS_BIT)
err = cpu_init_msr(cpu, type, cpu_dentry); err = cpu_init_msr(cpu, type, cpu_dentry);
...@@ -647,11 +647,11 @@ static int cpu_init_cpu(void) ...@@ -647,11 +647,11 @@ static int cpu_init_cpu(void)
err = cpu_init_allreg(cpu, cpu_dentry); err = cpu_init_allreg(cpu, cpu_dentry);
pr_info("cpu%d(%d) debug files %d\n", pr_info("cpu%d(%d) debug files %d\n",
cpu, nr_cpu_ids, per_cpu(cpu_priv_count, cpu)); cpu, nr_cpu_ids, per_cpu(cpud_priv_count, cpu));
if (per_cpu(cpu_priv_count, cpu) > MAX_CPU_FILES) { if (per_cpu(cpud_priv_count, cpu) > MAX_CPU_FILES) {
pr_err("Register files count %d exceeds limit %d\n", pr_err("Register files count %d exceeds limit %d\n",
per_cpu(cpu_priv_count, cpu), MAX_CPU_FILES); per_cpu(cpud_priv_count, cpu), MAX_CPU_FILES);
per_cpu(cpu_priv_count, cpu) = MAX_CPU_FILES; per_cpu(cpud_priv_count, cpu) = MAX_CPU_FILES;
err = -ENFILE; err = -ENFILE;
} }
if (err) if (err)
...@@ -676,8 +676,8 @@ static void __exit cpu_debug_exit(void) ...@@ -676,8 +676,8 @@ static void __exit cpu_debug_exit(void)
debugfs_remove_recursive(cpu_debugfs_dir); debugfs_remove_recursive(cpu_debugfs_dir);
for (cpu = 0; cpu < nr_cpu_ids; cpu++) for (cpu = 0; cpu < nr_cpu_ids; cpu++)
for (i = 0; i < per_cpu(cpu_priv_count, cpu); i++) for (i = 0; i < per_cpu(cpud_priv_count, cpu); i++)
kfree(per_cpu(priv_arr[i], cpu)); kfree(per_cpu(cpud_priv_arr[i], cpu));
} }
module_init(cpu_debug_init); module_init(cpu_debug_init);
......
...@@ -512,8 +512,8 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c) ...@@ -512,8 +512,8 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
/* pointer to _cpuid4_info array (for each cache leaf) */ /* pointer to _cpuid4_info array (for each cache leaf) */
static DEFINE_PER_CPU(struct _cpuid4_info *, cpuid4_info); static DEFINE_PER_CPU(struct _cpuid4_info *, ici_cpuid4_info);
#define CPUID4_INFO_IDX(x, y) (&((per_cpu(cpuid4_info, x))[y])) #define CPUID4_INFO_IDX(x, y) (&((per_cpu(ici_cpuid4_info, x))[y]))
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index) static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
...@@ -526,7 +526,7 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index) ...@@ -526,7 +526,7 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) { if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) {
struct cpuinfo_x86 *d; struct cpuinfo_x86 *d;
for_each_online_cpu(i) { for_each_online_cpu(i) {
if (!per_cpu(cpuid4_info, i)) if (!per_cpu(ici_cpuid4_info, i))
continue; continue;
d = &cpu_data(i); d = &cpu_data(i);
this_leaf = CPUID4_INFO_IDX(i, index); this_leaf = CPUID4_INFO_IDX(i, index);
...@@ -548,7 +548,7 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index) ...@@ -548,7 +548,7 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
c->apicid >> index_msb) { c->apicid >> index_msb) {
cpumask_set_cpu(i, cpumask_set_cpu(i,
to_cpumask(this_leaf->shared_cpu_map)); to_cpumask(this_leaf->shared_cpu_map));
if (i != cpu && per_cpu(cpuid4_info, i)) { if (i != cpu && per_cpu(ici_cpuid4_info, i)) {
sibling_leaf = sibling_leaf =
CPUID4_INFO_IDX(i, index); CPUID4_INFO_IDX(i, index);
cpumask_set_cpu(cpu, to_cpumask( cpumask_set_cpu(cpu, to_cpumask(
...@@ -587,8 +587,8 @@ static void __cpuinit free_cache_attributes(unsigned int cpu) ...@@ -587,8 +587,8 @@ static void __cpuinit free_cache_attributes(unsigned int cpu)
for (i = 0; i < num_cache_leaves; i++) for (i = 0; i < num_cache_leaves; i++)
cache_remove_shared_cpu_map(cpu, i); cache_remove_shared_cpu_map(cpu, i);
kfree(per_cpu(cpuid4_info, cpu)); kfree(per_cpu(ici_cpuid4_info, cpu));
per_cpu(cpuid4_info, cpu) = NULL; per_cpu(ici_cpuid4_info, cpu) = NULL;
} }
static int static int
...@@ -627,15 +627,15 @@ static int __cpuinit detect_cache_attributes(unsigned int cpu) ...@@ -627,15 +627,15 @@ static int __cpuinit detect_cache_attributes(unsigned int cpu)
if (num_cache_leaves == 0) if (num_cache_leaves == 0)
return -ENOENT; return -ENOENT;
per_cpu(cpuid4_info, cpu) = kzalloc( per_cpu(ici_cpuid4_info, cpu) = kzalloc(
sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL); sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL);
if (per_cpu(cpuid4_info, cpu) == NULL) if (per_cpu(ici_cpuid4_info, cpu) == NULL)
return -ENOMEM; return -ENOMEM;
smp_call_function_single(cpu, get_cpu_leaves, &retval, true); smp_call_function_single(cpu, get_cpu_leaves, &retval, true);
if (retval) { if (retval) {
kfree(per_cpu(cpuid4_info, cpu)); kfree(per_cpu(ici_cpuid4_info, cpu));
per_cpu(cpuid4_info, cpu) = NULL; per_cpu(ici_cpuid4_info, cpu) = NULL;
} }
return retval; return retval;
...@@ -647,7 +647,7 @@ static int __cpuinit detect_cache_attributes(unsigned int cpu) ...@@ -647,7 +647,7 @@ static int __cpuinit detect_cache_attributes(unsigned int cpu)
extern struct sysdev_class cpu_sysdev_class; /* from drivers/base/cpu.c */ extern struct sysdev_class cpu_sysdev_class; /* from drivers/base/cpu.c */
/* pointer to kobject for cpuX/cache */ /* pointer to kobject for cpuX/cache */
static DEFINE_PER_CPU(struct kobject *, cache_kobject); static DEFINE_PER_CPU(struct kobject *, ici_cache_kobject);
struct _index_kobject { struct _index_kobject {
struct kobject kobj; struct kobject kobj;
...@@ -656,8 +656,8 @@ struct _index_kobject { ...@@ -656,8 +656,8 @@ struct _index_kobject {
}; };
/* pointer to array of kobjects for cpuX/cache/indexY */ /* pointer to array of kobjects for cpuX/cache/indexY */
static DEFINE_PER_CPU(struct _index_kobject *, index_kobject); static DEFINE_PER_CPU(struct _index_kobject *, ici_index_kobject);
#define INDEX_KOBJECT_PTR(x, y) (&((per_cpu(index_kobject, x))[y])) #define INDEX_KOBJECT_PTR(x, y) (&((per_cpu(ici_index_kobject, x))[y]))
#define show_one_plus(file_name, object, val) \ #define show_one_plus(file_name, object, val) \
static ssize_t show_##file_name \ static ssize_t show_##file_name \
...@@ -876,10 +876,10 @@ static struct kobj_type ktype_percpu_entry = { ...@@ -876,10 +876,10 @@ static struct kobj_type ktype_percpu_entry = {
static void __cpuinit cpuid4_cache_sysfs_exit(unsigned int cpu) static void __cpuinit cpuid4_cache_sysfs_exit(unsigned int cpu)
{ {
kfree(per_cpu(cache_kobject, cpu)); kfree(per_cpu(ici_cache_kobject, cpu));
kfree(per_cpu(index_kobject, cpu)); kfree(per_cpu(ici_index_kobject, cpu));
per_cpu(cache_kobject, cpu) = NULL; per_cpu(ici_cache_kobject, cpu) = NULL;
per_cpu(index_kobject, cpu) = NULL; per_cpu(ici_index_kobject, cpu) = NULL;
free_cache_attributes(cpu); free_cache_attributes(cpu);
} }
...@@ -895,14 +895,14 @@ static int __cpuinit cpuid4_cache_sysfs_init(unsigned int cpu) ...@@ -895,14 +895,14 @@ static int __cpuinit cpuid4_cache_sysfs_init(unsigned int cpu)
return err; return err;
/* Allocate all required memory */ /* Allocate all required memory */
per_cpu(cache_kobject, cpu) = per_cpu(ici_cache_kobject, cpu) =
kzalloc(sizeof(struct kobject), GFP_KERNEL); kzalloc(sizeof(struct kobject), GFP_KERNEL);
if (unlikely(per_cpu(cache_kobject, cpu) == NULL)) if (unlikely(per_cpu(ici_cache_kobject, cpu) == NULL))
goto err_out; goto err_out;
per_cpu(index_kobject, cpu) = kzalloc( per_cpu(ici_index_kobject, cpu) = kzalloc(
sizeof(struct _index_kobject) * num_cache_leaves, GFP_KERNEL); sizeof(struct _index_kobject) * num_cache_leaves, GFP_KERNEL);
if (unlikely(per_cpu(index_kobject, cpu) == NULL)) if (unlikely(per_cpu(ici_index_kobject, cpu) == NULL))
goto err_out; goto err_out;
return 0; return 0;
...@@ -926,7 +926,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) ...@@ -926,7 +926,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
if (unlikely(retval < 0)) if (unlikely(retval < 0))
return retval; return retval;
retval = kobject_init_and_add(per_cpu(cache_kobject, cpu), retval = kobject_init_and_add(per_cpu(ici_cache_kobject, cpu),
&ktype_percpu_entry, &ktype_percpu_entry,
&sys_dev->kobj, "%s", "cache"); &sys_dev->kobj, "%s", "cache");
if (retval < 0) { if (retval < 0) {
...@@ -940,12 +940,12 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) ...@@ -940,12 +940,12 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
this_object->index = i; this_object->index = i;
retval = kobject_init_and_add(&(this_object->kobj), retval = kobject_init_and_add(&(this_object->kobj),
&ktype_cache, &ktype_cache,
per_cpu(cache_kobject, cpu), per_cpu(ici_cache_kobject, cpu),
"index%1lu", i); "index%1lu", i);
if (unlikely(retval)) { if (unlikely(retval)) {
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
kobject_put(&(INDEX_KOBJECT_PTR(cpu, j)->kobj)); kobject_put(&(INDEX_KOBJECT_PTR(cpu, j)->kobj));
kobject_put(per_cpu(cache_kobject, cpu)); kobject_put(per_cpu(ici_cache_kobject, cpu));
cpuid4_cache_sysfs_exit(cpu); cpuid4_cache_sysfs_exit(cpu);
return retval; return retval;
} }
...@@ -953,7 +953,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) ...@@ -953,7 +953,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
} }
cpumask_set_cpu(cpu, to_cpumask(cache_dev_map)); cpumask_set_cpu(cpu, to_cpumask(cache_dev_map));
kobject_uevent(per_cpu(cache_kobject, cpu), KOBJ_ADD); kobject_uevent(per_cpu(ici_cache_kobject, cpu), KOBJ_ADD);
return 0; return 0;
} }
...@@ -962,7 +962,7 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev) ...@@ -962,7 +962,7 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)
unsigned int cpu = sys_dev->id; unsigned int cpu = sys_dev->id;
unsigned long i; unsigned long i;
if (per_cpu(cpuid4_info, cpu) == NULL) if (per_cpu(ici_cpuid4_info, cpu) == NULL)
return; return;
if (!cpumask_test_cpu(cpu, to_cpumask(cache_dev_map))) if (!cpumask_test_cpu(cpu, to_cpumask(cache_dev_map)))
return; return;
...@@ -970,7 +970,7 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev) ...@@ -970,7 +970,7 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)
for (i = 0; i < num_cache_leaves; i++) for (i = 0; i < num_cache_leaves; i++)
kobject_put(&(INDEX_KOBJECT_PTR(cpu, i)->kobj)); kobject_put(&(INDEX_KOBJECT_PTR(cpu, i)->kobj));
kobject_put(per_cpu(cache_kobject, cpu)); kobject_put(per_cpu(ici_cache_kobject, cpu));
cpuid4_cache_sysfs_exit(cpu); cpuid4_cache_sysfs_exit(cpu);
} }
......
...@@ -265,13 +265,13 @@ struct ds_context { ...@@ -265,13 +265,13 @@ struct ds_context {
int cpu; int cpu;
}; };
static DEFINE_PER_CPU(struct ds_context *, cpu_context); static DEFINE_PER_CPU(struct ds_context *, cpu_ds_context);
static struct ds_context *ds_get_context(struct task_struct *task, int cpu) static struct ds_context *ds_get_context(struct task_struct *task, int cpu)
{ {
struct ds_context **p_context = struct ds_context **p_context =
(task ? &task->thread.ds_ctx : &per_cpu(cpu_context, cpu)); (task ? &task->thread.ds_ctx : &per_cpu(cpu_ds_context, cpu));
struct ds_context *context = NULL; struct ds_context *context = NULL;
struct ds_context *new_context = NULL; struct ds_context *new_context = NULL;
......
...@@ -319,7 +319,7 @@ static void svm_hardware_disable(void *garbage) ...@@ -319,7 +319,7 @@ static void svm_hardware_disable(void *garbage)
static void svm_hardware_enable(void *garbage) static void svm_hardware_enable(void *garbage)
{ {
struct svm_cpu_data *svm_data; struct svm_cpu_data *sd;
uint64_t efer; uint64_t efer;
struct descriptor_table gdt_descr; struct descriptor_table gdt_descr;
struct desc_struct *gdt; struct desc_struct *gdt;
...@@ -329,62 +329,61 @@ static void svm_hardware_enable(void *garbage) ...@@ -329,62 +329,61 @@ static void svm_hardware_enable(void *garbage)
printk(KERN_ERR "svm_cpu_init: err EOPNOTSUPP on %d\n", me); printk(KERN_ERR "svm_cpu_init: err EOPNOTSUPP on %d\n", me);
return; return;
} }
svm_data = per_cpu(svm_data, me); sd = per_cpu(svm_data, me);
if (!svm_data) { if (!sd) {
printk(KERN_ERR "svm_cpu_init: svm_data is NULL on %d\n", printk(KERN_ERR "svm_cpu_init: svm_data is NULL on %d\n",
me); me);
return; return;
} }
svm_data->asid_generation = 1; sd->asid_generation = 1;
svm_data->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1; sd->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1;
svm_data->next_asid = svm_data->max_asid + 1; sd->next_asid = sd->max_asid + 1;
kvm_get_gdt(&gdt_descr); kvm_get_gdt(&gdt_descr);
gdt = (struct desc_struct *)gdt_descr.base; gdt = (struct desc_struct *)gdt_descr.base;
svm_data->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS); sd->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS);
rdmsrl(MSR_EFER, efer); rdmsrl(MSR_EFER, efer);
wrmsrl(MSR_EFER, efer | EFER_SVME); wrmsrl(MSR_EFER, efer | EFER_SVME);
wrmsrl(MSR_VM_HSAVE_PA, wrmsrl(MSR_VM_HSAVE_PA,
page_to_pfn(svm_data->save_area) << PAGE_SHIFT); page_to_pfn(sd->save_area) << PAGE_SHIFT);
} }
static void svm_cpu_uninit(int cpu) static void svm_cpu_uninit(int cpu)
{ {
struct svm_cpu_data *svm_data struct svm_cpu_data *sd = per_cpu(svm_data, raw_smp_processor_id());
= per_cpu(svm_data, raw_smp_processor_id());
if (!svm_data) if (!sd)
return; return;
per_cpu(svm_data, raw_smp_processor_id()) = NULL; per_cpu(svm_data, raw_smp_processor_id()) = NULL;
__free_page(svm_data->save_area); __free_page(sd->save_area);
kfree(svm_data); kfree(sd);
} }
static int svm_cpu_init(int cpu) static int svm_cpu_init(int cpu)
{ {
struct svm_cpu_data *svm_data; struct svm_cpu_data *sd;
int r; int r;
svm_data = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL); sd = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL);
if (!svm_data) if (!sd)
return -ENOMEM; return -ENOMEM;
svm_data->cpu = cpu; sd->cpu = cpu;
svm_data->save_area = alloc_page(GFP_KERNEL); sd->save_area = alloc_page(GFP_KERNEL);
r = -ENOMEM; r = -ENOMEM;
if (!svm_data->save_area) if (!sd->save_area)
goto err_1; goto err_1;
per_cpu(svm_data, cpu) = svm_data; per_cpu(svm_data, cpu) = sd;
return 0; return 0;
err_1: err_1:
kfree(svm_data); kfree(sd);
return r; return r;
} }
...@@ -1094,16 +1093,16 @@ static void save_host_msrs(struct kvm_vcpu *vcpu) ...@@ -1094,16 +1093,16 @@ static void save_host_msrs(struct kvm_vcpu *vcpu)
#endif #endif
} }
static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *svm_data) static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)
{ {
if (svm_data->next_asid > svm_data->max_asid) { if (sd->next_asid > sd->max_asid) {
++svm_data->asid_generation; ++sd->asid_generation;
svm_data->next_asid = 1; sd->next_asid = 1;
svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID; svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
} }
svm->asid_generation = svm_data->asid_generation; svm->asid_generation = sd->asid_generation;
svm->vmcb->control.asid = svm_data->next_asid++; svm->vmcb->control.asid = sd->next_asid++;
} }
static unsigned long svm_get_dr(struct kvm_vcpu *vcpu, int dr) static unsigned long svm_get_dr(struct kvm_vcpu *vcpu, int dr)
...@@ -2377,8 +2376,8 @@ static void reload_tss(struct kvm_vcpu *vcpu) ...@@ -2377,8 +2376,8 @@ static void reload_tss(struct kvm_vcpu *vcpu)
{ {
int cpu = raw_smp_processor_id(); int cpu = raw_smp_processor_id();
struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu); struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */ sd->tss_desc->type = 9; /* available 32/64-bit TSS */
load_TR_desc(); load_TR_desc();
} }
...@@ -2386,12 +2385,12 @@ static void pre_svm_run(struct vcpu_svm *svm) ...@@ -2386,12 +2385,12 @@ static void pre_svm_run(struct vcpu_svm *svm)
{ {
int cpu = raw_smp_processor_id(); int cpu = raw_smp_processor_id();
struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu); struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING; svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
/* FIXME: handle wraparound of asid_generation */ /* FIXME: handle wraparound of asid_generation */
if (svm->asid_generation != svm_data->asid_generation) if (svm->asid_generation != sd->asid_generation)
new_asid(svm, svm_data); new_asid(svm, sd);
} }
static void svm_inject_nmi(struct kvm_vcpu *vcpu) static void svm_inject_nmi(struct kvm_vcpu *vcpu)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment