aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorK. Y. Srinivasan <kys@microsoft.com>2018-05-16 17:53:31 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-05-19 07:23:17 -0400
commit68bb7bfb7985df2bd15c2dc975cb68b7a901488a (patch)
tree78d6850907788482f4d746843142933ff54d0c4a
parent6b48cb5f8347bc0153ff1d7b075db92e6723ffdb (diff)
X86/Hyper-V: Enable IPI enlightenments
Hyper-V supports hypercalls to implement IPI; use them. Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Cc: olaf@aepfle.de Cc: sthemmin@microsoft.com Cc: gregkh@linuxfoundation.org Cc: jasowang@redhat.com Cc: Michael.H.Kelley@microsoft.com Cc: hpa@zytor.com Cc: apw@canonical.com Cc: devel@linuxdriverproject.org Cc: vkuznets@redhat.com Link: https://lkml.kernel.org/r/20180516215334.6547-2-kys@linuxonhyperv.com
-rw-r--r--arch/x86/hyperv/hv_apic.c117
-rw-r--r--arch/x86/hyperv/hv_init.c27
-rw-r--r--arch/x86/include/asm/hyperv-tlfs.h15
-rw-r--r--arch/x86/include/asm/mshyperv.h1
4 files changed, 160 insertions, 0 deletions
diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index ca20e31d311c..3e0de61f1a7c 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -33,6 +33,8 @@
33#ifdef CONFIG_X86_64 33#ifdef CONFIG_X86_64
34#if IS_ENABLED(CONFIG_HYPERV) 34#if IS_ENABLED(CONFIG_HYPERV)
35 35
36static struct apic orig_apic;
37
36static u64 hv_apic_icr_read(void) 38static u64 hv_apic_icr_read(void)
37{ 39{
38 u64 reg_val; 40 u64 reg_val;
@@ -88,8 +90,123 @@ static void hv_apic_eoi_write(u32 reg, u32 val)
88 wrmsr(HV_X64_MSR_EOI, val, 0); 90 wrmsr(HV_X64_MSR_EOI, val, 0);
89} 91}
90 92
93/*
94 * IPI implementation on Hyper-V.
95 */
96static bool __send_ipi_mask(const struct cpumask *mask, int vector)
97{
98 int cur_cpu, vcpu;
99 struct ipi_arg_non_ex **arg;
100 struct ipi_arg_non_ex *ipi_arg;
101 int ret = 1;
102 unsigned long flags;
103
104 if (cpumask_empty(mask))
105 return true;
106
107 if (!hv_hypercall_pg)
108 return false;
109
110 if ((vector < HV_IPI_LOW_VECTOR) || (vector > HV_IPI_HIGH_VECTOR))
111 return false;
112
113 local_irq_save(flags);
114 arg = (struct ipi_arg_non_ex **)this_cpu_ptr(hyperv_pcpu_input_arg);
115
116 ipi_arg = *arg;
117 if (unlikely(!ipi_arg))
118 goto ipi_mask_done;
119
120 ipi_arg->vector = vector;
121 ipi_arg->reserved = 0;
122 ipi_arg->cpu_mask = 0;
123
124 for_each_cpu(cur_cpu, mask) {
125 vcpu = hv_cpu_number_to_vp_number(cur_cpu);
126 /*
127 * This particular version of the IPI hypercall can
128 * only target upto 64 CPUs.
129 */
130 if (vcpu >= 64)
131 goto ipi_mask_done;
132
133 __set_bit(vcpu, (unsigned long *)&ipi_arg->cpu_mask);
134 }
135
136 ret = hv_do_hypercall(HVCALL_SEND_IPI, ipi_arg, NULL);
137
138ipi_mask_done:
139 local_irq_restore(flags);
140 return ((ret == 0) ? true : false);
141}
142
143static bool __send_ipi_one(int cpu, int vector)
144{
145 struct cpumask mask = CPU_MASK_NONE;
146
147 cpumask_set_cpu(cpu, &mask);
148 return __send_ipi_mask(&mask, vector);
149}
150
151static void hv_send_ipi(int cpu, int vector)
152{
153 if (!__send_ipi_one(cpu, vector))
154 orig_apic.send_IPI(cpu, vector);
155}
156
157static void hv_send_ipi_mask(const struct cpumask *mask, int vector)
158{
159 if (!__send_ipi_mask(mask, vector))
160 orig_apic.send_IPI_mask(mask, vector);
161}
162
163static void hv_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)
164{
165 unsigned int this_cpu = smp_processor_id();
166 struct cpumask new_mask;
167 const struct cpumask *local_mask;
168
169 cpumask_copy(&new_mask, mask);
170 cpumask_clear_cpu(this_cpu, &new_mask);
171 local_mask = &new_mask;
172 if (!__send_ipi_mask(local_mask, vector))
173 orig_apic.send_IPI_mask_allbutself(mask, vector);
174}
175
176static void hv_send_ipi_allbutself(int vector)
177{
178 hv_send_ipi_mask_allbutself(cpu_online_mask, vector);
179}
180
181static void hv_send_ipi_all(int vector)
182{
183 if (!__send_ipi_mask(cpu_online_mask, vector))
184 orig_apic.send_IPI_all(vector);
185}
186
187static void hv_send_ipi_self(int vector)
188{
189 if (!__send_ipi_one(smp_processor_id(), vector))
190 orig_apic.send_IPI_self(vector);
191}
192
91void __init hv_apic_init(void) 193void __init hv_apic_init(void)
92{ 194{
195 if (ms_hyperv.hints & HV_X64_CLUSTER_IPI_RECOMMENDED) {
196 pr_info("Hyper-V: Using IPI hypercalls\n");
197 /*
198 * Set the IPI entry points.
199 */
200 orig_apic = *apic;
201
202 apic->send_IPI = hv_send_ipi;
203 apic->send_IPI_mask = hv_send_ipi_mask;
204 apic->send_IPI_mask_allbutself = hv_send_ipi_mask_allbutself;
205 apic->send_IPI_allbutself = hv_send_ipi_allbutself;
206 apic->send_IPI_all = hv_send_ipi_all;
207 apic->send_IPI_self = hv_send_ipi_self;
208 }
209
93 if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) { 210 if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) {
94 pr_info("Hyper-V: Using MSR based APIC access\n"); 211 pr_info("Hyper-V: Using MSR based APIC access\n");
95 apic_set_eoi_write(hv_apic_eoi_write); 212 apic_set_eoi_write(hv_apic_eoi_write);
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 71e50fc2b7ef..6bc90d68ac8b 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -91,12 +91,19 @@ EXPORT_SYMBOL_GPL(hv_vp_index);
91struct hv_vp_assist_page **hv_vp_assist_page; 91struct hv_vp_assist_page **hv_vp_assist_page;
92EXPORT_SYMBOL_GPL(hv_vp_assist_page); 92EXPORT_SYMBOL_GPL(hv_vp_assist_page);
93 93
94void __percpu **hyperv_pcpu_input_arg;
95EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
96
94u32 hv_max_vp_index; 97u32 hv_max_vp_index;
95 98
96static int hv_cpu_init(unsigned int cpu) 99static int hv_cpu_init(unsigned int cpu)
97{ 100{
98 u64 msr_vp_index; 101 u64 msr_vp_index;
99 struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()]; 102 struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()];
103 void **input_arg;
104
105 input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
106 *input_arg = page_address(alloc_page(GFP_KERNEL));
100 107
101 hv_get_vp_index(msr_vp_index); 108 hv_get_vp_index(msr_vp_index);
102 109
@@ -217,6 +224,16 @@ static int hv_cpu_die(unsigned int cpu)
217{ 224{
218 struct hv_reenlightenment_control re_ctrl; 225 struct hv_reenlightenment_control re_ctrl;
219 unsigned int new_cpu; 226 unsigned int new_cpu;
227 unsigned long flags;
228 void **input_arg;
229 void *input_pg = NULL;
230
231 local_irq_save(flags);
232 input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
233 input_pg = *input_arg;
234 *input_arg = NULL;
235 local_irq_restore(flags);
236 free_page((unsigned long)input_pg);
220 237
221 if (hv_vp_assist_page && hv_vp_assist_page[cpu]) 238 if (hv_vp_assist_page && hv_vp_assist_page[cpu])
222 wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); 239 wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0);
@@ -260,6 +277,16 @@ void __init hyperv_init(void)
260 if ((ms_hyperv.features & required_msrs) != required_msrs) 277 if ((ms_hyperv.features & required_msrs) != required_msrs)
261 return; 278 return;
262 279
280 /*
281 * Allocate the per-CPU state for the hypercall input arg.
282 * If this allocation fails, we will not be able to setup
283 * (per-CPU) hypercall input page and thus this failure is
284 * fatal on Hyper-V.
285 */
286 hyperv_pcpu_input_arg = alloc_percpu(void *);
287
288 BUG_ON(hyperv_pcpu_input_arg == NULL);
289
263 /* Allocate percpu VP index */ 290 /* Allocate percpu VP index */
264 hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), 291 hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
265 GFP_KERNEL); 292 GFP_KERNEL);
diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e0c496..332e786d4deb 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -164,6 +164,11 @@
164 */ 164 */
165#define HV_X64_DEPRECATING_AEOI_RECOMMENDED (1 << 9) 165#define HV_X64_DEPRECATING_AEOI_RECOMMENDED (1 << 9)
166 166
167/*
168 * Recommend using cluster IPI hypercalls.
169 */
170#define HV_X64_CLUSTER_IPI_RECOMMENDED (1 << 10)
171
167/* Recommend using the newer ExProcessorMasks interface */ 172/* Recommend using the newer ExProcessorMasks interface */
168#define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED (1 << 11) 173#define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED (1 << 11)
169 174
@@ -329,10 +334,14 @@ struct hv_tsc_emulation_status {
329#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \ 334#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
330 (~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1)) 335 (~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1))
331 336
337#define HV_IPI_LOW_VECTOR 0x10
338#define HV_IPI_HIGH_VECTOR 0xff
339
332/* Declare the various hypercall operations. */ 340/* Declare the various hypercall operations. */
333#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002 341#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
334#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003 342#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
335#define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008 343#define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
344#define HVCALL_SEND_IPI 0x000b
336#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 345#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
337#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014 346#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
338#define HVCALL_POST_MESSAGE 0x005c 347#define HVCALL_POST_MESSAGE 0x005c
@@ -706,4 +715,10 @@ struct hv_enlightened_vmcs {
706#define HV_STIMER_AUTOENABLE (1ULL << 3) 715#define HV_STIMER_AUTOENABLE (1ULL << 3)
707#define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F) 716#define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F)
708 717
718struct ipi_arg_non_ex {
719 u32 vector;
720 u32 reserved;
721 u64 cpu_mask;
722};
723
709#endif 724#endif
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 162977b82e2e..1eff91599c2b 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -122,6 +122,7 @@ static inline void hv_disable_stimer0_percpu_irq(int irq) {}
122#if IS_ENABLED(CONFIG_HYPERV) 122#if IS_ENABLED(CONFIG_HYPERV)
123extern struct clocksource *hyperv_cs; 123extern struct clocksource *hyperv_cs;
124extern void *hv_hypercall_pg; 124extern void *hv_hypercall_pg;
125extern void __percpu **hyperv_pcpu_input_arg;
125 126
126static inline u64 hv_do_hypercall(u64 control, void *input, void *output) 127static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
127{ 128{