Skip to content

Commit ee1703c

Browse files
committed
Merge tag 'hyperv-fixes-signed-20211117' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull hyperv fixes from Wei Liu: - Fix ring size calculation for balloon driver (Boqun Feng) - Fix issues in Hyper-V setup code (Sean Christopherson) * tag 'hyperv-fixes-signed-20211117' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: x86/hyperv: Move required MSRs check to initial platform probing x86/hyperv: Fix NULL deref in set_hv_tscchange_cb() if Hyper-V setup fails Drivers: hv: balloon: Use VMBUS_RING_SIZE() wrapper for dm_ring_size
2 parents ef1d8dd + f3e613e commit ee1703c

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ void set_hv_tscchange_cb(void (*cb)(void))
177177
return;
178178
}
179179

180+
if (!hv_vp_index)
181+
return;
182+
180183
hv_reenlightenment_cb = cb;
181184

182185
/* Make sure callback is registered before we write to MSRs */
@@ -383,20 +386,13 @@ static void __init hv_get_partition_id(void)
383386
*/
384387
void __init hyperv_init(void)
385388
{
386-
u64 guest_id, required_msrs;
389+
u64 guest_id;
387390
union hv_x64_msr_hypercall_contents hypercall_msr;
388391
int cpuhp;
389392

390393
if (x86_hyper_type != X86_HYPER_MS_HYPERV)
391394
return;
392395

393-
/* Absolutely required MSRs */
394-
required_msrs = HV_MSR_HYPERCALL_AVAILABLE |
395-
HV_MSR_VP_INDEX_AVAILABLE;
396-
397-
if ((ms_hyperv.features & required_msrs) != required_msrs)
398-
return;
399-
400396
if (hv_common_init())
401397
return;
402398

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,22 @@ static uint32_t __init ms_hyperv_platform(void)
163163
cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS,
164164
&eax, &hyp_signature[0], &hyp_signature[1], &hyp_signature[2]);
165165

166-
if (eax >= HYPERV_CPUID_MIN &&
167-
eax <= HYPERV_CPUID_MAX &&
168-
!memcmp("Microsoft Hv", hyp_signature, 12))
169-
return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
166+
if (eax < HYPERV_CPUID_MIN || eax > HYPERV_CPUID_MAX ||
167+
memcmp("Microsoft Hv", hyp_signature, 12))
168+
return 0;
170169

171-
return 0;
170+
/* HYPERCALL and VP_INDEX MSRs are mandatory for all features. */
171+
eax = cpuid_eax(HYPERV_CPUID_FEATURES);
172+
if (!(eax & HV_MSR_HYPERCALL_AVAILABLE)) {
173+
pr_warn("x86/hyperv: HYPERCALL MSR not available.\n");
174+
return 0;
175+
}
176+
if (!(eax & HV_MSR_VP_INDEX_AVAILABLE)) {
177+
pr_warn("x86/hyperv: VP_INDEX MSR not available.\n");
178+
return 0;
179+
}
180+
181+
return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
172182
}
173183

174184
static unsigned char hv_get_nmi_reason(void)

drivers/hv/hv_balloon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
480480
MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
481481
static atomic_t trans_id = ATOMIC_INIT(0);
482482

483-
static int dm_ring_size = 20 * 1024;
483+
static int dm_ring_size = VMBUS_RING_SIZE(16 * 1024);
484484

485485
/*
486486
* Driver specific state.

0 commit comments

Comments
 (0)