Skip to content

Commit cfce216

Browse files
committed
Merge tag 'hyperv-next-signed-20240320' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull hyperv updates from Wei Liu: - Use Hyper-V entropy to seed guest random number generator (Michael Kelley) - Convert to platform remove callback returning void for vmbus (Uwe Kleine-König) - Introduce hv_get_hypervisor_version function (Nuno Das Neves) - Rename some HV_REGISTER_* defines for consistency (Nuno Das Neves) - Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_* (Nuno Das Neves) - Cosmetic changes for hv_spinlock.c (Purna Pavan Chandra Aekkaladevi) - Use per cpu initial stack for vtl context (Saurabh Sengar) * tag 'hyperv-next-signed-20240320' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: x86/hyperv: Use Hyper-V entropy to seed guest random number generator x86/hyperv: Cosmetic changes for hv_spinlock.c hyperv-tlfs: Rename some HV_REGISTER_* defines for consistency hv: vmbus: Convert to platform remove callback returning void mshyperv: Introduce hv_get_hypervisor_version function x86/hyperv: Use per cpu initial stack for vtl context hyperv-tlfs: Change prefix of generic HV_REGISTER_* MSRs to HV_MSR_*
2 parents 7b65c81 + f2580a9 commit cfce216

17 files changed

Lines changed: 375 additions & 236 deletions

File tree

arch/arm64/hyperv/hv_core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,22 @@ void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)
160160
return;
161161
panic_reported = true;
162162

163-
guest_id = hv_get_vpreg(HV_REGISTER_GUEST_OSID);
163+
guest_id = hv_get_vpreg(HV_REGISTER_GUEST_OS_ID);
164164

165165
/*
166166
* Hyper-V provides the ability to store only 5 values.
167167
* Pick the passed in error value, the guest_id, the PC,
168168
* and the SP.
169169
*/
170-
hv_set_vpreg(HV_REGISTER_CRASH_P0, err);
171-
hv_set_vpreg(HV_REGISTER_CRASH_P1, guest_id);
172-
hv_set_vpreg(HV_REGISTER_CRASH_P2, regs->pc);
173-
hv_set_vpreg(HV_REGISTER_CRASH_P3, regs->sp);
174-
hv_set_vpreg(HV_REGISTER_CRASH_P4, 0);
170+
hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P0, err);
171+
hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P1, guest_id);
172+
hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P2, regs->pc);
173+
hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P3, regs->sp);
174+
hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P4, 0);
175175

176176
/*
177177
* Let Hyper-V know there is crash data available
178178
*/
179-
hv_set_vpreg(HV_REGISTER_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
179+
hv_set_vpreg(HV_REGISTER_GUEST_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
180180
}
181181
EXPORT_SYMBOL_GPL(hyperv_report_panic);

arch/arm64/hyperv/mshyperv.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919

2020
static bool hyperv_initialized;
2121

22+
int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
23+
{
24+
hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION,
25+
(struct hv_get_vp_registers_output *)info);
26+
27+
return 0;
28+
}
29+
2230
static int __init hyperv_init(void)
2331
{
2432
struct hv_get_vp_registers_output result;
25-
u32 a, b, c, d;
2633
u64 guest_id;
2734
int ret;
2835

@@ -39,7 +46,7 @@ static int __init hyperv_init(void)
3946

4047
/* Setup the guest ID */
4148
guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
42-
hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id);
49+
hv_set_vpreg(HV_REGISTER_GUEST_OS_ID, guest_id);
4350

4451
/* Get the features and hints from Hyper-V */
4552
hv_get_vpreg_128(HV_REGISTER_FEATURES, &result);
@@ -54,15 +61,6 @@ static int __init hyperv_init(void)
5461
ms_hyperv.features, ms_hyperv.priv_high, ms_hyperv.hints,
5562
ms_hyperv.misc_features);
5663

57-
/* Get information about the Hyper-V host version */
58-
hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION, &result);
59-
a = result.as32.a;
60-
b = result.as32.b;
61-
c = result.as32.c;
62-
d = result.as32.d;
63-
pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n",
64-
b >> 16, b & 0xFFFF, a, d & 0xFFFFFF, c, d >> 24);
65-
6664
ret = hv_common_init();
6765
if (ret)
6866
return ret;
@@ -74,6 +72,8 @@ static int __init hyperv_init(void)
7472
return ret;
7573
}
7674

75+
ms_hyperv_late_init();
76+
7777
hyperv_initialized = true;
7878
return 0;
7979
}

arch/arm64/include/asm/hyperv-tlfs.h

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
* byte ordering of Linux running on ARM64, so no special handling is required.
2222
*/
2323

24-
/*
25-
* These Hyper-V registers provide information equivalent to the CPUID
26-
* instruction on x86/x64.
27-
*/
28-
#define HV_REGISTER_HYPERVISOR_VERSION 0x00000100 /*CPUID 0x40000002 */
29-
#define HV_REGISTER_FEATURES 0x00000200 /*CPUID 0x40000003 */
30-
#define HV_REGISTER_ENLIGHTENMENTS 0x00000201 /*CPUID 0x40000004 */
31-
3224
/*
3325
* Group C Features. See the asm-generic version of hyperv-tlfs.h
3426
* for a description of Feature Groups.
@@ -41,28 +33,29 @@
4133
#define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(13)
4234

4335
/*
44-
* Synthetic register definitions equivalent to MSRs on x86/x64
36+
* To support arch-generic code calling hv_set/get_register:
37+
* - On x86, HV_MSR_ indicates an MSR accessed via rdmsrl/wrmsrl
38+
* - On ARM, HV_MSR_ indicates a VP register accessed via hypercall
4539
*/
46-
#define HV_REGISTER_CRASH_P0 0x00000210
47-
#define HV_REGISTER_CRASH_P1 0x00000211
48-
#define HV_REGISTER_CRASH_P2 0x00000212
49-
#define HV_REGISTER_CRASH_P3 0x00000213
50-
#define HV_REGISTER_CRASH_P4 0x00000214
51-
#define HV_REGISTER_CRASH_CTL 0x00000215
40+
#define HV_MSR_CRASH_P0 (HV_REGISTER_GUEST_CRASH_P0)
41+
#define HV_MSR_CRASH_P1 (HV_REGISTER_GUEST_CRASH_P1)
42+
#define HV_MSR_CRASH_P2 (HV_REGISTER_GUEST_CRASH_P2)
43+
#define HV_MSR_CRASH_P3 (HV_REGISTER_GUEST_CRASH_P3)
44+
#define HV_MSR_CRASH_P4 (HV_REGISTER_GUEST_CRASH_P4)
45+
#define HV_MSR_CRASH_CTL (HV_REGISTER_GUEST_CRASH_CTL)
5246

53-
#define HV_REGISTER_GUEST_OSID 0x00090002
54-
#define HV_REGISTER_VP_INDEX 0x00090003
55-
#define HV_REGISTER_TIME_REF_COUNT 0x00090004
56-
#define HV_REGISTER_REFERENCE_TSC 0x00090017
47+
#define HV_MSR_VP_INDEX (HV_REGISTER_VP_INDEX)
48+
#define HV_MSR_TIME_REF_COUNT (HV_REGISTER_TIME_REF_COUNT)
49+
#define HV_MSR_REFERENCE_TSC (HV_REGISTER_REFERENCE_TSC)
5750

58-
#define HV_REGISTER_SINT0 0x000A0000
59-
#define HV_REGISTER_SCONTROL 0x000A0010
60-
#define HV_REGISTER_SIEFP 0x000A0012
61-
#define HV_REGISTER_SIMP 0x000A0013
62-
#define HV_REGISTER_EOM 0x000A0014
51+
#define HV_MSR_SINT0 (HV_REGISTER_SINT0)
52+
#define HV_MSR_SCONTROL (HV_REGISTER_SCONTROL)
53+
#define HV_MSR_SIEFP (HV_REGISTER_SIEFP)
54+
#define HV_MSR_SIMP (HV_REGISTER_SIMP)
55+
#define HV_MSR_EOM (HV_REGISTER_EOM)
6356

64-
#define HV_REGISTER_STIMER0_CONFIG 0x000B0000
65-
#define HV_REGISTER_STIMER0_COUNT 0x000B0001
57+
#define HV_MSR_STIMER0_CONFIG (HV_REGISTER_STIMER0_CONFIG)
58+
#define HV_MSR_STIMER0_COUNT (HV_REGISTER_STIMER0_COUNT)
6659

6760
union hv_msi_entry {
6861
u64 as_uint64[2];

arch/arm64/include/asm/mshyperv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ void hv_set_vpreg(u32 reg, u64 value);
3131
u64 hv_get_vpreg(u32 reg);
3232
void hv_get_vpreg_128(u32 reg, struct hv_get_vp_registers_output *result);
3333

34-
static inline void hv_set_register(unsigned int reg, u64 value)
34+
static inline void hv_set_msr(unsigned int reg, u64 value)
3535
{
3636
hv_set_vpreg(reg, value);
3737
}
3838

39-
static inline u64 hv_get_register(unsigned int reg)
39+
static inline u64 hv_get_msr(unsigned int reg)
4040
{
4141
return hv_get_vpreg(reg);
4242
}

arch/x86/hyperv/hv_init.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,14 @@ void hyperv_cleanup(void)
667667
hv_hypercall_pg = NULL;
668668

669669
/* Reset the hypercall page */
670-
hypercall_msr.as_uint64 = hv_get_register(HV_X64_MSR_HYPERCALL);
670+
hypercall_msr.as_uint64 = hv_get_msr(HV_X64_MSR_HYPERCALL);
671671
hypercall_msr.enable = 0;
672-
hv_set_register(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
672+
hv_set_msr(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
673673

674674
/* Reset the TSC page */
675-
tsc_msr.as_uint64 = hv_get_register(HV_X64_MSR_REFERENCE_TSC);
675+
tsc_msr.as_uint64 = hv_get_msr(HV_X64_MSR_REFERENCE_TSC);
676676
tsc_msr.enable = 0;
677-
hv_set_register(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
677+
hv_set_msr(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
678678
}
679679

680680
void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)

arch/x86/hyperv/hv_spinlock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <asm/paravirt.h>
1717
#include <asm/apic.h>
1818

19-
static bool __initdata hv_pvspin = true;
19+
static bool hv_pvspin __initdata = true;
2020

2121
static void hv_qlock_kick(int cpu)
2222
{
@@ -64,6 +64,7 @@ __visible bool hv_vcpu_is_preempted(int vcpu)
6464
{
6565
return false;
6666
}
67+
6768
PV_CALLEE_SAVE_REGS_THUNK(hv_vcpu_is_preempted);
6869

6970
void __init hv_init_spinlocks(void)

arch/x86/hyperv/hv_vtl.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <asm/i8259.h>
1313
#include <asm/mshyperv.h>
1414
#include <asm/realmode.h>
15+
#include <../kernel/smpboot.h>
1516

1617
extern struct boot_params boot_params;
1718
static struct real_mode_header hv_vtl_real_mode_header;
@@ -65,7 +66,7 @@ static void hv_vtl_ap_entry(void)
6566
((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params);
6667
}
6768

68-
static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored)
69+
static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored)
6970
{
7071
u64 status;
7172
int ret = 0;
@@ -79,7 +80,9 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored)
7980
struct ldttss_desc *ldt;
8081
struct desc_struct *gdt;
8182

82-
u64 rsp = current->thread.sp;
83+
struct task_struct *idle = idle_thread_get(cpu);
84+
u64 rsp = (unsigned long)idle->thread.sp;
85+
8386
u64 rip = (u64)&hv_vtl_ap_entry;
8487

8588
native_store_gdt(&gdt_ptr);
@@ -206,7 +209,15 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)
206209

207210
static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip)
208211
{
209-
int vp_id;
212+
int vp_id, cpu;
213+
214+
/* Find the logical CPU for the APIC ID */
215+
for_each_present_cpu(cpu) {
216+
if (arch_match_cpu_phys_id(cpu, apicid))
217+
break;
218+
}
219+
if (cpu >= nr_cpu_ids)
220+
return -EINVAL;
210221

211222
pr_debug("Bringing up CPU with APIC ID %d in VTL2...\n", apicid);
212223
vp_id = hv_vtl_apicid_to_vp_id(apicid);
@@ -220,7 +231,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip)
220231
return -EINVAL;
221232
}
222233

223-
return hv_vtl_bringup_vcpu(vp_id, start_eip);
234+
return hv_vtl_bringup_vcpu(vp_id, cpu, start_eip);
224235
}
225236

226237
int __init hv_vtl_early_init(void)

0 commit comments

Comments
 (0)