Skip to content

Commit e96204e

Browse files
NunoDasNevesliuw
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/1738955002-20821-2-git-send-email-nunodasneves@linux.microsoft.com Signed-off-by: Wei Liu <[email protected]> Message-ID: <1738955002-20821-2-git-send-email-nunodasneves@linux.microsoft.com>
1 parent a64dcfb commit e96204e

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

arch/arm64/hyperv/mshyperv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ static int __init hyperv_init(void)
7272
return ret;
7373
}
7474

75+
if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
76+
hv_get_partition_id();
77+
7578
ms_hyperv_late_init();
7679

7780
hyperv_initialized = true;

arch/x86/hyperv/hv_init.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#include <clocksource/hyperv_timer.h>
3535
#include <linux/highmem.h>
3636

37-
u64 hv_current_partition_id = ~0ull;
38-
EXPORT_SYMBOL_GPL(hv_current_partition_id);
39-
4037
void *hv_hypercall_pg;
4138
EXPORT_SYMBOL_GPL(hv_hypercall_pg);
4239

@@ -393,24 +390,6 @@ static void __init hv_stimer_setup_percpu_clockev(void)
393390
old_setup_percpu_clockev();
394391
}
395392

396-
static void __init hv_get_partition_id(void)
397-
{
398-
struct hv_get_partition_id *output_page;
399-
u64 status;
400-
unsigned long flags;
401-
402-
local_irq_save(flags);
403-
output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
404-
status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
405-
if (!hv_result_success(status)) {
406-
/* No point in proceeding if this failed */
407-
pr_err("Failed to get partition ID: %lld\n", status);
408-
BUG();
409-
}
410-
hv_current_partition_id = output_page->partition_id;
411-
local_irq_restore(flags);
412-
}
413-
414393
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
415394
static u8 __init get_vtl(void)
416395
{
@@ -605,11 +584,9 @@ void __init hyperv_init(void)
605584

606585
register_syscore_ops(&hv_syscore_ops);
607586

608-
if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
587+
if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
609588
hv_get_partition_id();
610589

611-
BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull);
612-
613590
#ifdef CONFIG_PCI_MSI
614591
/*
615592
* If we're running as root, we want to create our own PCI MSI domain.

arch/x86/include/asm/mshyperv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ extern bool hyperv_paravisor_present;
4343

4444
extern void *hv_hypercall_pg;
4545

46-
extern u64 hv_current_partition_id;
47-
4846
extern union hv_ghcb * __percpu *hv_ghcb_pg;
4947

5048
bool hv_isolation_type_snp(void);

drivers/hv/hv_common.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include <hyperv/hvhdk.h>
3232
#include <asm/mshyperv.h>
3333

34+
u64 hv_current_partition_id = HV_PARTITION_ID_SELF;
35+
EXPORT_SYMBOL_GPL(hv_current_partition_id);
36+
3437
/*
3538
* hv_root_partition, ms_hyperv and hv_nested are defined here with other
3639
* Hyper-V specific globals so they are shared across all architectures and are
@@ -283,6 +286,25 @@ static inline bool hv_output_page_exists(void)
283286
return hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE);
284287
}
285288

289+
void __init hv_get_partition_id(void)
290+
{
291+
struct hv_output_get_partition_id *output;
292+
unsigned long flags;
293+
u64 status, pt_id;
294+
295+
local_irq_save(flags);
296+
output = *this_cpu_ptr(hyperv_pcpu_input_arg);
297+
status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, &output);
298+
pt_id = output->partition_id;
299+
local_irq_restore(flags);
300+
301+
if (hv_result_success(status))
302+
hv_current_partition_id = pt_id;
303+
else
304+
pr_err("Hyper-V: failed to get partition ID: %#x\n",
305+
hv_result(status));
306+
}
307+
286308
int __init hv_common_init(void)
287309
{
288310
int i;

include/asm-generic/mshyperv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct ms_hyperv_info {
5858
};
5959
extern struct ms_hyperv_info ms_hyperv;
6060
extern bool hv_nested;
61+
extern u64 hv_current_partition_id;
6162

6263
extern void * __percpu *hyperv_pcpu_input_arg;
6364
extern void * __percpu *hyperv_pcpu_output_arg;
@@ -207,6 +208,7 @@ extern u64 (*hv_read_reference_counter)(void);
207208
#define VP_INVAL U32_MAX
208209

209210
int __init hv_common_init(void);
211+
void __init hv_get_partition_id(void);
210212
void __init hv_common_free(void);
211213
void __init ms_hyperv_late_init(void);
212214
int hv_common_cpu_init(unsigned int cpu);

include/hyperv/hvgdk_mini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct hv_tsc_emulation_control { /* HV_TSC_INVARIANT_CONTROL */
182182

183183
#endif /* CONFIG_X86 */
184184

185-
struct hv_get_partition_id { /* HV_OUTPUT_GET_PARTITION_ID */
185+
struct hv_output_get_partition_id {
186186
u64 partition_id;
187187
} __packed;
188188

0 commit comments

Comments
 (0)