Skip to content

Commit 9c5b80b

Browse files
committed
Merge tag 'hyperv-next-signed-20210216' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull Hyper-V updates from Wei Liu: - VMBus hardening patches from Andrea Parri and Andres Beltran. - Patches to make Linux boot as the root partition on Microsoft Hypervisor from Wei Liu. - One patch to add a new sysfs interface to support hibernation on Hyper-V from Dexuan Cui. - Two miscellaneous clean-up patches from Colin and Gustavo. * tag 'hyperv-next-signed-20210216' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: (31 commits) Revert "Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer" iommu/hyperv: setup an IO-APIC IRQ remapping domain for root partition x86/hyperv: implement an MSI domain for root partition asm-generic/hyperv: import data structures for mapping device interrupts asm-generic/hyperv: introduce hv_device_id and auxiliary structures asm-generic/hyperv: update hv_interrupt_entry asm-generic/hyperv: update hv_msi_entry x86/hyperv: implement and use hv_smp_prepare_cpus x86/hyperv: provide a bunch of helper functions ACPI / NUMA: add a stub function for node_to_pxm() x86/hyperv: handling hypercall page setup for root x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary x86/hyperv: allocate output arg pages if required clocksource/hyperv: use MSR-based access if running as root Drivers: hv: vmbus: skip VMBus initialization if Linux is root x86/hyperv: detect if Linux is the root partition asm-generic/hyperv: change HV_CPU_POWER_MANAGEMENT to HV_CPU_MANAGEMENT hv: hyperv.h: Replace one-element array with flexible-array in struct icmsg_negotiate hv_netvsc: Restrict configurations on isolated guests Drivers: hv: vmbus: Enforce 'VMBus version >= 5.2' on isolated guests ...
2 parents 08179b4 + 3019270 commit 9c5b80b

24 files changed

Lines changed: 1717 additions & 233 deletions

File tree

‎Documentation/ABI/stable/sysfs-bus-vmbus‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
What: /sys/bus/vmbus/hibernation
2+
Date: Jan 2021
3+
KernelVersion: 5.12
4+
Contact: Dexuan Cui <decui@microsoft.com>
5+
Description: Whether the host supports hibernation for the VM.
6+
Users: Daemon that sets up swap partition/file for hibernation.
7+
18
What: /sys/bus/vmbus/devices/<UUID>/id
29
Date: Jul 2009
310
KernelVersion: 2.6.31

‎arch/x86/hyperv/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
obj-y := hv_init.o mmu.o nested.o
3-
obj-$(CONFIG_X86_64) += hv_apic.o
2+
obj-y := hv_init.o mmu.o nested.o irqdomain.o
3+
obj-$(CONFIG_X86_64) += hv_apic.o hv_proc.o
44

55
ifdef CONFIG_X86_64
66
obj-$(CONFIG_PARAVIRT_SPINLOCKS) += hv_spinlock.o

‎arch/x86/hyperv/hv_init.c‎

Lines changed: 114 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/acpi.h>
1111
#include <linux/efi.h>
1212
#include <linux/types.h>
13+
#include <linux/bitfield.h>
1314
#include <asm/apic.h>
1415
#include <asm/desc.h>
1516
#include <asm/hypervisor.h>
@@ -26,8 +27,11 @@
2627
#include <linux/cpuhotplug.h>
2728
#include <linux/syscore_ops.h>
2829
#include <clocksource/hyperv_timer.h>
30+
#include <linux/highmem.h>
2931

3032
int hyperv_init_cpuhp;
33+
u64 hv_current_partition_id = ~0ull;
34+
EXPORT_SYMBOL_GPL(hv_current_partition_id);
3135

3236
void *hv_hypercall_pg;
3337
EXPORT_SYMBOL_GPL(hv_hypercall_pg);
@@ -44,6 +48,9 @@ EXPORT_SYMBOL_GPL(hv_vp_assist_page);
4448
void __percpu **hyperv_pcpu_input_arg;
4549
EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
4650

51+
void __percpu **hyperv_pcpu_output_arg;
52+
EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
53+
4754
u32 hv_max_vp_index;
4855
EXPORT_SYMBOL_GPL(hv_max_vp_index);
4956

@@ -76,12 +83,19 @@ static int hv_cpu_init(unsigned int cpu)
7683
void **input_arg;
7784
struct page *pg;
7885

79-
input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
8086
/* hv_cpu_init() can be called with IRQs disabled from hv_resume() */
81-
pg = alloc_page(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
87+
pg = alloc_pages(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL, hv_root_partition ? 1 : 0);
8288
if (unlikely(!pg))
8389
return -ENOMEM;
90+
91+
input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
8492
*input_arg = page_address(pg);
93+
if (hv_root_partition) {
94+
void **output_arg;
95+
96+
output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
97+
*output_arg = page_address(pg + 1);
98+
}
8599

86100
hv_get_vp_index(msr_vp_index);
87101

@@ -208,14 +222,23 @@ static int hv_cpu_die(unsigned int cpu)
208222
unsigned int new_cpu;
209223
unsigned long flags;
210224
void **input_arg;
211-
void *input_pg = NULL;
225+
void *pg;
212226

213227
local_irq_save(flags);
214228
input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
215-
input_pg = *input_arg;
229+
pg = *input_arg;
216230
*input_arg = NULL;
231+
232+
if (hv_root_partition) {
233+
void **output_arg;
234+
235+
output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
236+
*output_arg = NULL;
237+
}
238+
217239
local_irq_restore(flags);
218-
free_page((unsigned long)input_pg);
240+
241+
free_pages((unsigned long)pg, hv_root_partition ? 1 : 0);
219242

220243
if (hv_vp_assist_page && hv_vp_assist_page[cpu])
221244
wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0);
@@ -264,6 +287,9 @@ static int hv_suspend(void)
264287
union hv_x64_msr_hypercall_contents hypercall_msr;
265288
int ret;
266289

290+
if (hv_root_partition)
291+
return -EPERM;
292+
267293
/*
268294
* Reset the hypercall page as it is going to be invalidated
269295
* accross hibernation. Setting hv_hypercall_pg to NULL ensures
@@ -334,6 +360,24 @@ static void __init hv_stimer_setup_percpu_clockev(void)
334360
old_setup_percpu_clockev();
335361
}
336362

363+
static void __init hv_get_partition_id(void)
364+
{
365+
struct hv_get_partition_id *output_page;
366+
u64 status;
367+
unsigned long flags;
368+
369+
local_irq_save(flags);
370+
output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
371+
status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
372+
if ((status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS) {
373+
/* No point in proceeding if this failed */
374+
pr_err("Failed to get partition ID: %lld\n", status);
375+
BUG();
376+
}
377+
hv_current_partition_id = output_page->partition_id;
378+
local_irq_restore(flags);
379+
}
380+
337381
/*
338382
* This function is to be invoked early in the boot sequence after the
339383
* hypervisor has been detected.
@@ -368,6 +412,12 @@ void __init hyperv_init(void)
368412

369413
BUG_ON(hyperv_pcpu_input_arg == NULL);
370414

415+
/* Allocate the per-CPU state for output arg for root */
416+
if (hv_root_partition) {
417+
hyperv_pcpu_output_arg = alloc_percpu(void *);
418+
BUG_ON(hyperv_pcpu_output_arg == NULL);
419+
}
420+
371421
/* Allocate percpu VP index */
372422
hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
373423
GFP_KERNEL);
@@ -408,8 +458,35 @@ void __init hyperv_init(void)
408458

409459
rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
410460
hypercall_msr.enable = 1;
411-
hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
412-
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
461+
462+
if (hv_root_partition) {
463+
struct page *pg;
464+
void *src, *dst;
465+
466+
/*
467+
* For the root partition, the hypervisor will set up its
468+
* hypercall page. The hypervisor guarantees it will not show
469+
* up in the root's address space. The root can't change the
470+
* location of the hypercall page.
471+
*
472+
* Order is important here. We must enable the hypercall page
473+
* so it is populated with code, then copy the code to an
474+
* executable page.
475+
*/
476+
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
477+
478+
pg = vmalloc_to_page(hv_hypercall_pg);
479+
dst = kmap(pg);
480+
src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE,
481+
MEMREMAP_WB);
482+
BUG_ON(!(src && dst));
483+
memcpy(dst, src, HV_HYP_PAGE_SIZE);
484+
memunmap(src);
485+
kunmap(pg);
486+
} else {
487+
hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
488+
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
489+
}
413490

414491
/*
415492
* hyperv_init() is called before LAPIC is initialized: see
@@ -428,6 +505,21 @@ void __init hyperv_init(void)
428505
register_syscore_ops(&hv_syscore_ops);
429506

430507
hyperv_init_cpuhp = cpuhp;
508+
509+
if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
510+
hv_get_partition_id();
511+
512+
BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull);
513+
514+
#ifdef CONFIG_PCI_MSI
515+
/*
516+
* If we're running as root, we want to create our own PCI MSI domain.
517+
* We can't set this in hv_pci_init because that would be too late.
518+
*/
519+
if (hv_root_partition)
520+
x86_init.irqs.create_pci_msi_domain = hv_create_pci_msi_domain;
521+
#endif
522+
431523
return;
432524

433525
remove_cpuhp_state:
@@ -552,6 +644,20 @@ EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);
552644

553645
bool hv_is_hibernation_supported(void)
554646
{
555-
return acpi_sleep_state_supported(ACPI_STATE_S4);
647+
return !hv_root_partition && acpi_sleep_state_supported(ACPI_STATE_S4);
556648
}
557649
EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
650+
651+
enum hv_isolation_type hv_get_isolation_type(void)
652+
{
653+
if (!(ms_hyperv.features_b & HV_ISOLATION))
654+
return HV_ISOLATION_TYPE_NONE;
655+
return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b);
656+
}
657+
EXPORT_SYMBOL_GPL(hv_get_isolation_type);
658+
659+
bool hv_is_isolation_supported(void)
660+
{
661+
return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE;
662+
}
663+
EXPORT_SYMBOL_GPL(hv_is_isolation_supported);

0 commit comments

Comments
 (0)