Skip to content

Commit 024ff30

Browse files
committed
Merge tag 'hyperv-fixes-signed-20230804' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull hyperv fixes from Wei Liu: - Fix a bug in a python script for Hyper-V (Ani Sinha) - Workaround a bug in Hyper-V when IBT is enabled (Michael Kelley) - Fix an issue parsing MP table when Linux runs in VTL2 (Saurabh Sengar) - Several cleanup patches (Nischala Yelchuri, Kameron Carr, YueHaibing, ZhiHu) * tag 'hyperv-fixes-signed-20230804' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: Drivers: hv: vmbus: Remove unused extern declaration vmbus_ontimer() x86/hyperv: add noop functions to x86_init mpparse functions vmbus_testing: fix wrong python syntax for integer value comparison x86/hyperv: fix a warning in mshyperv.h x86/hyperv: Disable IBT when hypercall page lacks ENDBR instruction x86/hyperv: Improve code for referencing hyperv_pcpu_input_arg Drivers: hv: Change hv_free_hyperv_page() to take void * argument
2 parents e661f98 + 6ad0f2f commit 024ff30

File tree

13 files changed

+49
-46
lines changed

13 files changed

+49
-46
lines changed

arch/x86/hyperv/hv_apic.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static bool cpu_is_self(int cpu)
107107
static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector,
108108
bool exclude_self)
109109
{
110-
struct hv_send_ipi_ex **arg;
111110
struct hv_send_ipi_ex *ipi_arg;
112111
unsigned long flags;
113112
int nr_bank = 0;
@@ -117,9 +116,8 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector,
117116
return false;
118117

119118
local_irq_save(flags);
120-
arg = (struct hv_send_ipi_ex **)this_cpu_ptr(hyperv_pcpu_input_arg);
119+
ipi_arg = *this_cpu_ptr(hyperv_pcpu_input_arg);
121120

122-
ipi_arg = *arg;
123121
if (unlikely(!ipi_arg))
124122
goto ipi_mask_ex_done;
125123

arch/x86/hyperv/hv_init.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/apic.h>
1515
#include <asm/desc.h>
1616
#include <asm/sev.h>
17+
#include <asm/ibt.h>
1718
#include <asm/hypervisor.h>
1819
#include <asm/hyperv-tlfs.h>
1920
#include <asm/mshyperv.h>
@@ -471,6 +472,26 @@ void __init hyperv_init(void)
471472
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
472473
}
473474

475+
/*
476+
* Some versions of Hyper-V that provide IBT in guest VMs have a bug
477+
* in that there's no ENDBR64 instruction at the entry to the
478+
* hypercall page. Because hypercalls are invoked via an indirect call
479+
* to the hypercall page, all hypercall attempts fail when IBT is
480+
* enabled, and Linux panics. For such buggy versions, disable IBT.
481+
*
482+
* Fixed versions of Hyper-V always provide ENDBR64 on the hypercall
483+
* page, so if future Linux kernel versions enable IBT for 32-bit
484+
* builds, additional hypercall page hackery will be required here
485+
* to provide an ENDBR32.
486+
*/
487+
#ifdef CONFIG_X86_KERNEL_IBT
488+
if (cpu_feature_enabled(X86_FEATURE_IBT) &&
489+
*(u32 *)hv_hypercall_pg != gen_endbr()) {
490+
setup_clear_cpu_cap(X86_FEATURE_IBT);
491+
pr_warn("Hyper-V: Disabling IBT because of Hyper-V bug\n");
492+
}
493+
#endif
494+
474495
/*
475496
* hyperv_init() is called before LAPIC is initialized: see
476497
* apic_intr_mode_init() -> x86_platform.apic_post_init() and

arch/x86/hyperv/hv_vtl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ void __init hv_vtl_init_platform(void)
2525
x86_init.irqs.pre_vector_init = x86_init_noop;
2626
x86_init.timers.timer_init = x86_init_noop;
2727

28+
/* Avoid searching for BIOS MP tables */
29+
x86_init.mpparse.find_smp_config = x86_init_noop;
30+
x86_init.mpparse.get_smp_config = x86_init_uint_noop;
31+
2832
x86_platform.get_wallclock = get_rtc_noop;
2933
x86_platform.set_wallclock = set_rtc_noop;
3034
x86_platform.get_nmi_reason = hv_get_nmi_reason;

arch/x86/hyperv/ivm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(hv_ghcb_msr_read);
247247
static int hv_mark_gpa_visibility(u16 count, const u64 pfn[],
248248
enum hv_mem_host_visibility visibility)
249249
{
250-
struct hv_gpa_range_for_visibility **input_pcpu, *input;
250+
struct hv_gpa_range_for_visibility *input;
251251
u16 pages_processed;
252252
u64 hv_status;
253253
unsigned long flags;
@@ -263,9 +263,8 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[],
263263
}
264264

265265
local_irq_save(flags);
266-
input_pcpu = (struct hv_gpa_range_for_visibility **)
267-
this_cpu_ptr(hyperv_pcpu_input_arg);
268-
input = *input_pcpu;
266+
input = *this_cpu_ptr(hyperv_pcpu_input_arg);
267+
269268
if (unlikely(!input)) {
270269
local_irq_restore(flags);
271270
return -EINVAL;

arch/x86/hyperv/mmu.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
6161
const struct flush_tlb_info *info)
6262
{
6363
int cpu, vcpu, gva_n, max_gvas;
64-
struct hv_tlb_flush **flush_pcpu;
6564
struct hv_tlb_flush *flush;
6665
u64 status;
6766
unsigned long flags;
@@ -74,10 +73,7 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
7473

7574
local_irq_save(flags);
7675

77-
flush_pcpu = (struct hv_tlb_flush **)
78-
this_cpu_ptr(hyperv_pcpu_input_arg);
79-
80-
flush = *flush_pcpu;
76+
flush = *this_cpu_ptr(hyperv_pcpu_input_arg);
8177

8278
if (unlikely(!flush)) {
8379
local_irq_restore(flags);
@@ -178,17 +174,13 @@ static u64 hyperv_flush_tlb_others_ex(const struct cpumask *cpus,
178174
const struct flush_tlb_info *info)
179175
{
180176
int nr_bank = 0, max_gvas, gva_n;
181-
struct hv_tlb_flush_ex **flush_pcpu;
182177
struct hv_tlb_flush_ex *flush;
183178
u64 status;
184179

185180
if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED))
186181
return HV_STATUS_INVALID_PARAMETER;
187182

188-
flush_pcpu = (struct hv_tlb_flush_ex **)
189-
this_cpu_ptr(hyperv_pcpu_input_arg);
190-
191-
flush = *flush_pcpu;
183+
flush = *this_cpu_ptr(hyperv_pcpu_input_arg);
192184

193185
if (info->mm) {
194186
/*

arch/x86/hyperv/nested.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
int hyperv_flush_guest_mapping(u64 as)
2121
{
22-
struct hv_guest_mapping_flush **flush_pcpu;
2322
struct hv_guest_mapping_flush *flush;
2423
u64 status;
2524
unsigned long flags;
@@ -30,10 +29,7 @@ int hyperv_flush_guest_mapping(u64 as)
3029

3130
local_irq_save(flags);
3231

33-
flush_pcpu = (struct hv_guest_mapping_flush **)
34-
this_cpu_ptr(hyperv_pcpu_input_arg);
35-
36-
flush = *flush_pcpu;
32+
flush = *this_cpu_ptr(hyperv_pcpu_input_arg);
3733

3834
if (unlikely(!flush)) {
3935
local_irq_restore(flags);
@@ -90,7 +86,6 @@ EXPORT_SYMBOL_GPL(hyperv_fill_flush_guest_mapping_list);
9086
int hyperv_flush_guest_mapping_range(u64 as,
9187
hyperv_fill_flush_list_func fill_flush_list_func, void *data)
9288
{
93-
struct hv_guest_mapping_flush_list **flush_pcpu;
9489
struct hv_guest_mapping_flush_list *flush;
9590
u64 status;
9691
unsigned long flags;
@@ -102,10 +97,8 @@ int hyperv_flush_guest_mapping_range(u64 as,
10297

10398
local_irq_save(flags);
10499

105-
flush_pcpu = (struct hv_guest_mapping_flush_list **)
106-
this_cpu_ptr(hyperv_pcpu_input_arg);
100+
flush = *this_cpu_ptr(hyperv_pcpu_input_arg);
107101

108-
flush = *flush_pcpu;
109102
if (unlikely(!flush)) {
110103
local_irq_restore(flags);
111104
goto fault;

arch/x86/include/asm/mshyperv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <linux/types.h>
66
#include <linux/nmi.h>
77
#include <linux/msi.h>
8-
#include <asm/io.h>
8+
#include <linux/io.h>
99
#include <asm/hyperv-tlfs.h>
1010
#include <asm/nospec-branch.h>
1111
#include <asm/paravirt.h>

drivers/hv/connection.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ int vmbus_connect(void)
209209
* Setup the vmbus event connection for channel interrupt
210210
* abstraction stuff
211211
*/
212-
vmbus_connection.int_page =
213-
(void *)hv_alloc_hyperv_zeroed_page();
212+
vmbus_connection.int_page = hv_alloc_hyperv_zeroed_page();
214213
if (vmbus_connection.int_page == NULL) {
215214
ret = -ENOMEM;
216215
goto cleanup;
@@ -225,8 +224,8 @@ int vmbus_connect(void)
225224
* Setup the monitor notification facility. The 1st page for
226225
* parent->child and the 2nd page for child->parent
227226
*/
228-
vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_page();
229-
vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_page();
227+
vmbus_connection.monitor_pages[0] = hv_alloc_hyperv_page();
228+
vmbus_connection.monitor_pages[1] = hv_alloc_hyperv_page();
230229
if ((vmbus_connection.monitor_pages[0] == NULL) ||
231230
(vmbus_connection.monitor_pages[1] == NULL)) {
232231
ret = -ENOMEM;
@@ -333,15 +332,15 @@ void vmbus_disconnect(void)
333332
destroy_workqueue(vmbus_connection.work_queue);
334333

335334
if (vmbus_connection.int_page) {
336-
hv_free_hyperv_page((unsigned long)vmbus_connection.int_page);
335+
hv_free_hyperv_page(vmbus_connection.int_page);
337336
vmbus_connection.int_page = NULL;
338337
}
339338

340339
set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[0], 1);
341340
set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[1], 1);
342341

343-
hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[0]);
344-
hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[1]);
342+
hv_free_hyperv_page(vmbus_connection.monitor_pages[0]);
343+
hv_free_hyperv_page(vmbus_connection.monitor_pages[1]);
345344
vmbus_connection.monitor_pages[0] = NULL;
346345
vmbus_connection.monitor_pages[1] = NULL;
347346
}

drivers/hv/hv_balloon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ static int hv_free_page_report(struct page_reporting_dev_info *pr_dev_info,
16281628
WARN_ON_ONCE(nents > HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES);
16291629
WARN_ON_ONCE(sgl->length < (HV_HYP_PAGE_SIZE << page_reporting_order));
16301630
local_irq_save(flags);
1631-
hint = *(struct hv_memory_hint **)this_cpu_ptr(hyperv_pcpu_input_arg);
1631+
hint = *this_cpu_ptr(hyperv_pcpu_input_arg);
16321632
if (!hint) {
16331633
local_irq_restore(flags);
16341634
return -ENOSPC;

drivers/hv/hv_common.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ void *hv_alloc_hyperv_zeroed_page(void)
115115
}
116116
EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
117117

118-
void hv_free_hyperv_page(unsigned long addr)
118+
void hv_free_hyperv_page(void *addr)
119119
{
120120
if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
121-
free_page(addr);
121+
free_page((unsigned long)addr);
122122
else
123-
kfree((void *)addr);
123+
kfree(addr);
124124
}
125125
EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
126126

@@ -253,7 +253,7 @@ static void hv_kmsg_dump_unregister(void)
253253
atomic_notifier_chain_unregister(&panic_notifier_list,
254254
&hyperv_panic_report_block);
255255

256-
hv_free_hyperv_page((unsigned long)hv_panic_page);
256+
hv_free_hyperv_page(hv_panic_page);
257257
hv_panic_page = NULL;
258258
}
259259

@@ -270,7 +270,7 @@ static void hv_kmsg_dump_register(void)
270270
ret = kmsg_dump_register(&hv_kmsg_dumper);
271271
if (ret) {
272272
pr_err("Hyper-V: kmsg dump register error 0x%x\n", ret);
273-
hv_free_hyperv_page((unsigned long)hv_panic_page);
273+
hv_free_hyperv_page(hv_panic_page);
274274
hv_panic_page = NULL;
275275
}
276276
}

0 commit comments

Comments
 (0)