Module Name: src
Committed By: nonaka
Date: Sat Dec 7 11:45:45 UTC 2019
Modified Files:
src/sys/arch/x86/x86: cpu.c hyperv.c hypervvar.h
src/sys/dev/hyperv: hyperv_common.c hypervvar.h vmbus.c vmbusvar.h
Log Message:
Get a Hyper-V virtual processor id in cpu_hatch().
Currently, it is got in config_interrupts context.
However, since it is required when attaching a device,
it is got earlier than now.
To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/hyperv.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/x86/hypervvar.h
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/hyperv/hyperv_common.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/hyperv/hypervvar.h \
src/sys/dev/hyperv/vmbusvar.h
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/hyperv/vmbus.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.177 src/sys/arch/x86/x86/cpu.c:1.178
--- src/sys/arch/x86/x86/cpu.c:1.177 Wed Nov 27 06:24:33 2019
+++ src/sys/arch/x86/x86/cpu.c Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.177 2019/11/27 06:24:33 maxv Exp $ */
+/* $NetBSD: cpu.c,v 1.178 2019/12/07 11:45:45 nonaka Exp $ */
/*
* Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.177 2019/11/27 06:24:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.178 2019/12/07 11:45:45 nonaka Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -118,6 +118,13 @@ __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.17
#include "tsc.h"
+#ifndef XEN
+#include "hyperv.h"
+#if NHYPERV > 0
+#include <x86/x86/hypervvar.h>
+#endif
+#endif
+
static int cpu_match(device_t, cfdata_t, void *);
static void cpu_attach(device_t, device_t, void *);
static void cpu_defer(device_t);
@@ -863,6 +870,9 @@ cpu_hatch(void *v)
cpu_init_msrs(ci, true);
cpu_probe(ci);
cpu_speculation_init(ci);
+#if NHYPERV > 0
+ hyperv_init_cpu(ci);
+#endif
ci->ci_data.cpu_cc_freq = cpu_info_primary.ci_data.cpu_cc_freq;
/* cpu_get_tsc_freq(ci); */
Index: src/sys/arch/x86/x86/hyperv.c
diff -u src/sys/arch/x86/x86/hyperv.c:1.5 src/sys/arch/x86/x86/hyperv.c:1.6
--- src/sys/arch/x86/x86/hyperv.c:1.5 Sat Nov 30 05:28:28 2019
+++ src/sys/arch/x86/x86/hyperv.c Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hyperv.c,v 1.5 2019/11/30 05:28:28 nonaka Exp $ */
+/* $NetBSD: hyperv.c,v 1.6 2019/12/07 11:45:45 nonaka Exp $ */
/*-
* Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
#ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.5 2019/11/30 05:28:28 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.6 2019/12/07 11:45:45 nonaka Exp $");
#endif
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -113,6 +113,8 @@ static char hyperv_features3_str[256];
static int hyperv_idtvec;
+uint32_t hyperv_vcpuid[MAXCPUS];
+
static struct timecounter hyperv_timecounter = {
.tc_get_timecount = hyperv_get_timecount,
.tc_counter_mask = 0xffffffff,
@@ -495,12 +497,45 @@ hyperv_early_init(void)
{
u_int features, pm_features, features3;
u_int maxleaf;
+ int i;
if (!hyperv_probe(&maxleaf, &features, &pm_features, &features3))
return;
if (features & CPUID_HV_MSR_TIME_REFCNT)
x86_delay = delay_func = delay_msr;
+
+ if (features & CPUID_HV_MSR_VP_INDEX) {
+ /* Save virtual processor id. */
+ hyperv_vcpuid[0] = rdmsr(MSR_HV_VP_INDEX);
+ } else {
+ /* Set virtual processor id to 0 for compatibility. */
+ hyperv_vcpuid[0] = 0;
+ }
+ for (i = 1; i < MAXCPUS; i++)
+ hyperv_vcpuid[i] = hyperv_vcpuid[0];
+}
+
+void
+hyperv_init_cpu(struct cpu_info *ci)
+{
+ u_int features, pm_features, features3;
+ u_int maxleaf;
+
+ if (!hyperv_probe(&maxleaf, &features, &pm_features, &features3))
+ return;
+
+ if (features & CPUID_HV_MSR_VP_INDEX)
+ hyperv_vcpuid[ci->ci_index] = rdmsr(MSR_HV_VP_INDEX);
+}
+
+uint32_t
+hyperv_get_vcpuid(cpuid_t cpu)
+{
+
+ if (cpu < MAXCPUS)
+ return hyperv_vcpuid[cpu];
+ return 0;
}
static bool
@@ -798,14 +833,6 @@ vmbus_init_synic_md(struct vmbus_softc *
pd = &sc->sc_percpu[cpu];
- if (hyperv_features & CPUID_HV_MSR_VP_INDEX) {
- /* Save virtual processor id. */
- pd->vcpuid = rdmsr(MSR_HV_VP_INDEX);
- } else {
- /* Set virtual processor id to 0 for compatibility. */
- pd->vcpuid = 0;
- }
-
/*
* Setup the SynIC message.
*/
Index: src/sys/arch/x86/x86/hypervvar.h
diff -u src/sys/arch/x86/x86/hypervvar.h:1.1 src/sys/arch/x86/x86/hypervvar.h:1.2
--- src/sys/arch/x86/x86/hypervvar.h:1.1 Fri May 24 14:28:48 2019
+++ src/sys/arch/x86/x86/hypervvar.h Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervvar.h,v 1.1 2019/05/24 14:28:48 nonaka Exp $ */
+/* $NetBSD: hypervvar.h,v 1.2 2019/12/07 11:45:45 nonaka Exp $ */
/*-
* Copyright (c) 2009-2012,2016 Microsoft Corp.
@@ -32,6 +32,7 @@
#define _X86_HYPERVVAR_H_
void hyperv_early_init(void);
+void hyperv_init_cpu(struct cpu_info *);
device_t device_hyperv_register(device_t, void *);
#endif /* _X86_HYPERVVAR_H_ */
Index: src/sys/dev/hyperv/hyperv_common.c
diff -u src/sys/dev/hyperv/hyperv_common.c:1.3 src/sys/dev/hyperv/hyperv_common.c:1.4
--- src/sys/dev/hyperv/hyperv_common.c:1.3 Fri Dec 6 12:46:06 2019
+++ src/sys/dev/hyperv/hyperv_common.c Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hyperv_common.c,v 1.3 2019/12/06 12:46:06 nonaka Exp $ */
+/* $NetBSD: hyperv_common.c,v 1.4 2019/12/07 11:45:45 nonaka Exp $ */
/*-
* Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.3 2019/12/06 12:46:06 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.4 2019/12/07 11:45:45 nonaka Exp $");
#include "hyperv.h"
@@ -56,6 +56,7 @@ __weak_alias(hyperv_set_event_proc, hype
__weak_alias(hyperv_set_message_proc, hyperv_voidop);
__weak_alias(hyperv_send_eom, hyperv_voidop);
__weak_alias(hyperv_intr, hyperv_voidop);
+__weak_alias(hyperv_get_vcpuid, hyperv_nullop);
__weak_alias(vmbus_init_interrupts_md, hyperv_voidop);
__weak_alias(vmbus_deinit_interrupts_md, hyperv_voidop);
__weak_alias(vmbus_init_synic_md, hyperv_voidop);
Index: src/sys/dev/hyperv/hypervvar.h
diff -u src/sys/dev/hyperv/hypervvar.h:1.2 src/sys/dev/hyperv/hypervvar.h:1.3
--- src/sys/dev/hyperv/hypervvar.h:1.2 Fri May 24 14:28:48 2019
+++ src/sys/dev/hyperv/hypervvar.h Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervvar.h,v 1.2 2019/05/24 14:28:48 nonaka Exp $ */
+/* $NetBSD: hypervvar.h,v 1.3 2019/12/07 11:45:45 nonaka Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -65,6 +65,7 @@ int hyperv_synic_supported(void);
int hyperv_is_gen1(void);
void hyperv_send_eom(void);
void hyperv_intr(void);
+uint32_t hyperv_get_vcpuid(cpuid_t);
struct vmbus_softc;
void vmbus_init_interrupts_md(struct vmbus_softc *);
Index: src/sys/dev/hyperv/vmbusvar.h
diff -u src/sys/dev/hyperv/vmbusvar.h:1.2 src/sys/dev/hyperv/vmbusvar.h:1.3
--- src/sys/dev/hyperv/vmbusvar.h:1.2 Fri May 24 14:28:48 2019
+++ src/sys/dev/hyperv/vmbusvar.h Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: vmbusvar.h,v 1.2 2019/05/24 14:28:48 nonaka Exp $ */
+/* $NetBSD: vmbusvar.h,v 1.3 2019/12/07 11:45:45 nonaka Exp $ */
/* $OpenBSD: hypervvar.h,v 1.13 2017/06/23 19:05:42 mikeb Exp $ */
/*
@@ -146,7 +146,6 @@ SLIST_HEAD(vmbus_devices, vmbus_dev);
struct vmbus_percpu_data {
void *simp; /* Synthetic Interrupt Message Page */
void *siep; /* Synthetic Interrupt Event Flags Page */
- uint32_t vcpuid; /* Virtual cpuid */
/* Rarely used fields */
struct hyperv_dma simp_dma;
Index: src/sys/dev/hyperv/vmbus.c
diff -u src/sys/dev/hyperv/vmbus.c:1.6 src/sys/dev/hyperv/vmbus.c:1.7
--- src/sys/dev/hyperv/vmbus.c:1.6 Fri Dec 6 12:46:06 2019
+++ src/sys/dev/hyperv/vmbus.c Sat Dec 7 11:45:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $ */
+/* $NetBSD: vmbus.c,v 1.7 2019/12/07 11:45:45 nonaka Exp $ */
/* $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $ */
/*-
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.7 2019/12/07 11:45:45 nonaka Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1093,7 +1093,7 @@ vmbus_channel_cpu_set(struct vmbus_chann
}
ch->ch_cpuid = cpu;
- ch->ch_vcpu = sc->sc_percpu[cpu].vcpuid;
+ ch->ch_vcpu = hyperv_get_vcpuid(cpu);
}
void