Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hyperv: Move hv_current_partition_id to arch-generic code

Move hv_current_partition_id and hv_get_partition_id() to hv_common.c,
and call hv_get_partition_id() on arm64 in hyperv_init(). These aren't
specific to x86_64 and will be needed by common code.

Set hv_current_partition_id to HV_PARTITION_ID_SELF by default.

Rename struct hv_get_partition_id to hv_output_get_partition_id, to
make it distinct from the function hv_get_partition_id(), and match
the original Hyper-V struct name.

Remove the BUG()s. Failing to get the id need not crash the machine.

Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1738955002-20821-2-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1738955002-20821-2-git-send-email-nunodasneves@linux.microsoft.com>

authored by

Nuno Das Neves and committed by
Wei Liu
e96204e5 a64dcfb4

+29 -27
+3
arch/arm64/hyperv/mshyperv.c
··· 72 72 return ret; 73 73 } 74 74 75 + if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID) 76 + hv_get_partition_id(); 77 + 75 78 ms_hyperv_late_init(); 76 79 77 80 hyperv_initialized = true;
+1 -24
arch/x86/hyperv/hv_init.c
··· 34 34 #include <clocksource/hyperv_timer.h> 35 35 #include <linux/highmem.h> 36 36 37 - u64 hv_current_partition_id = ~0ull; 38 - EXPORT_SYMBOL_GPL(hv_current_partition_id); 39 - 40 37 void *hv_hypercall_pg; 41 38 EXPORT_SYMBOL_GPL(hv_hypercall_pg); 42 39 ··· 390 393 old_setup_percpu_clockev(); 391 394 } 392 395 393 - static void __init hv_get_partition_id(void) 394 - { 395 - struct hv_get_partition_id *output_page; 396 - u64 status; 397 - unsigned long flags; 398 - 399 - local_irq_save(flags); 400 - output_page = *this_cpu_ptr(hyperv_pcpu_output_arg); 401 - status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page); 402 - if (!hv_result_success(status)) { 403 - /* No point in proceeding if this failed */ 404 - pr_err("Failed to get partition ID: %lld\n", status); 405 - BUG(); 406 - } 407 - hv_current_partition_id = output_page->partition_id; 408 - local_irq_restore(flags); 409 - } 410 - 411 396 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) 412 397 static u8 __init get_vtl(void) 413 398 { ··· 584 605 585 606 register_syscore_ops(&hv_syscore_ops); 586 607 587 - if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID) 608 + if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID) 588 609 hv_get_partition_id(); 589 - 590 - BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull); 591 610 592 611 #ifdef CONFIG_PCI_MSI 593 612 /*
-2
arch/x86/include/asm/mshyperv.h
··· 43 43 44 44 extern void *hv_hypercall_pg; 45 45 46 - extern u64 hv_current_partition_id; 47 - 48 46 extern union hv_ghcb * __percpu *hv_ghcb_pg; 49 47 50 48 bool hv_isolation_type_snp(void);
+22
drivers/hv/hv_common.c
··· 31 31 #include <hyperv/hvhdk.h> 32 32 #include <asm/mshyperv.h> 33 33 34 + u64 hv_current_partition_id = HV_PARTITION_ID_SELF; 35 + EXPORT_SYMBOL_GPL(hv_current_partition_id); 36 + 34 37 /* 35 38 * hv_root_partition, ms_hyperv and hv_nested are defined here with other 36 39 * Hyper-V specific globals so they are shared across all architectures and are ··· 284 281 static inline bool hv_output_page_exists(void) 285 282 { 286 283 return hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE); 284 + } 285 + 286 + void __init hv_get_partition_id(void) 287 + { 288 + struct hv_output_get_partition_id *output; 289 + unsigned long flags; 290 + u64 status, pt_id; 291 + 292 + local_irq_save(flags); 293 + output = *this_cpu_ptr(hyperv_pcpu_input_arg); 294 + status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, &output); 295 + pt_id = output->partition_id; 296 + local_irq_restore(flags); 297 + 298 + if (hv_result_success(status)) 299 + hv_current_partition_id = pt_id; 300 + else 301 + pr_err("Hyper-V: failed to get partition ID: %#x\n", 302 + hv_result(status)); 287 303 } 288 304 289 305 int __init hv_common_init(void)
+2
include/asm-generic/mshyperv.h
··· 58 58 }; 59 59 extern struct ms_hyperv_info ms_hyperv; 60 60 extern bool hv_nested; 61 + extern u64 hv_current_partition_id; 61 62 62 63 extern void * __percpu *hyperv_pcpu_input_arg; 63 64 extern void * __percpu *hyperv_pcpu_output_arg; ··· 208 207 #define VP_INVAL U32_MAX 209 208 210 209 int __init hv_common_init(void); 210 + void __init hv_get_partition_id(void); 211 211 void __init hv_common_free(void); 212 212 void __init ms_hyperv_late_init(void); 213 213 int hv_common_cpu_init(unsigned int cpu);
+1 -1
include/hyperv/hvgdk_mini.h
··· 182 182 183 183 #endif /* CONFIG_X86 */ 184 184 185 - struct hv_get_partition_id { /* HV_OUTPUT_GET_PARTITION_ID */ 185 + struct hv_output_get_partition_id { 186 186 u64 partition_id; 187 187 } __packed; 188 188