Skip to content

Commit 8aab751

Browse files
kelleymhtyhicks
authored andcommitted
Drivers: hv: Redo Hyper-V synthetic MSR get/set functions
Current code defines a separate get and set macro for each Hyper-V synthetic MSR used by the VMbus driver. Furthermore, the get macro can't be converted to a standard function because the second argument is modified in place, which is somewhat bad form. Redo this by providing a single get and a single set function that take a parameter specifying the MSR to be operated on. Fixup usage of the get function. Calling locations are no more complex than before, but the code under arch/x86 and the upcoming code under arch/arm64 is significantly simplified. Also standardize the names of Hyper-V synthetic MSRs that are architecture neutral. But keep the old x86-specific names as aliases that can be removed later when all references (particularly in KVM code) have been cleaned up in a separate patch series. No functional change. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/1614721102-2241-4-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org> (cherry picked from commit f3c5e63) Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 1a6ed31 commit 8aab751

7 files changed

Lines changed: 110 additions & 100 deletions

File tree

arch/x86/hyperv/hv_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int hv_cpu_init(unsigned int cpu)
6161
return -ENOMEM;
6262
*input_arg = page_address(pg);
6363

64-
hv_get_vp_index(msr_vp_index);
64+
msr_vp_index = hv_get_register(HV_REGISTER_VP_INDEX);
6565

6666
hv_vp_index[smp_processor_id()] = msr_vp_index;
6767

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

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
#define HV_X64_MSR_HYPERCALL 0x40000001
125125

126126
/* MSR used to provide vcpu index */
127-
#define HV_X64_MSR_VP_INDEX 0x40000002
127+
#define HV_REGISTER_VP_INDEX 0x40000002
128128

129129
/* MSR used to reset the guest OS. */
130130
#define HV_X64_MSR_RESET 0x40000003
@@ -133,10 +133,10 @@
133133
#define HV_X64_MSR_VP_RUNTIME 0x40000010
134134

135135
/* MSR used to read the per-partition time reference counter */
136-
#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
136+
#define HV_REGISTER_TIME_REF_COUNT 0x40000020
137137

138138
/* A partition's reference time stamp counter (TSC) page */
139-
#define HV_X64_MSR_REFERENCE_TSC 0x40000021
139+
#define HV_REGISTER_REFERENCE_TSC 0x40000021
140140

141141
/* MSR used to retrieve the TSC frequency */
142142
#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
@@ -151,50 +151,50 @@
151151
#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073
152152

153153
/* Define synthetic interrupt controller model specific registers. */
154-
#define HV_X64_MSR_SCONTROL 0x40000080
155-
#define HV_X64_MSR_SVERSION 0x40000081
156-
#define HV_X64_MSR_SIEFP 0x40000082
157-
#define HV_X64_MSR_SIMP 0x40000083
158-
#define HV_X64_MSR_EOM 0x40000084
159-
#define HV_X64_MSR_SINT0 0x40000090
160-
#define HV_X64_MSR_SINT1 0x40000091
161-
#define HV_X64_MSR_SINT2 0x40000092
162-
#define HV_X64_MSR_SINT3 0x40000093
163-
#define HV_X64_MSR_SINT4 0x40000094
164-
#define HV_X64_MSR_SINT5 0x40000095
165-
#define HV_X64_MSR_SINT6 0x40000096
166-
#define HV_X64_MSR_SINT7 0x40000097
167-
#define HV_X64_MSR_SINT8 0x40000098
168-
#define HV_X64_MSR_SINT9 0x40000099
169-
#define HV_X64_MSR_SINT10 0x4000009A
170-
#define HV_X64_MSR_SINT11 0x4000009B
171-
#define HV_X64_MSR_SINT12 0x4000009C
172-
#define HV_X64_MSR_SINT13 0x4000009D
173-
#define HV_X64_MSR_SINT14 0x4000009E
174-
#define HV_X64_MSR_SINT15 0x4000009F
154+
#define HV_REGISTER_SCONTROL 0x40000080
155+
#define HV_REGISTER_SVERSION 0x40000081
156+
#define HV_REGISTER_SIEFP 0x40000082
157+
#define HV_REGISTER_SIMP 0x40000083
158+
#define HV_REGISTER_EOM 0x40000084
159+
#define HV_REGISTER_SINT0 0x40000090
160+
#define HV_REGISTER_SINT1 0x40000091
161+
#define HV_REGISTER_SINT2 0x40000092
162+
#define HV_REGISTER_SINT3 0x40000093
163+
#define HV_REGISTER_SINT4 0x40000094
164+
#define HV_REGISTER_SINT5 0x40000095
165+
#define HV_REGISTER_SINT6 0x40000096
166+
#define HV_REGISTER_SINT7 0x40000097
167+
#define HV_REGISTER_SINT8 0x40000098
168+
#define HV_REGISTER_SINT9 0x40000099
169+
#define HV_REGISTER_SINT10 0x4000009A
170+
#define HV_REGISTER_SINT11 0x4000009B
171+
#define HV_REGISTER_SINT12 0x4000009C
172+
#define HV_REGISTER_SINT13 0x4000009D
173+
#define HV_REGISTER_SINT14 0x4000009E
174+
#define HV_REGISTER_SINT15 0x4000009F
175175

176176
/*
177177
* Synthetic Timer MSRs. Four timers per vcpu.
178178
*/
179-
#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
180-
#define HV_X64_MSR_STIMER0_COUNT 0x400000B1
181-
#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
182-
#define HV_X64_MSR_STIMER1_COUNT 0x400000B3
183-
#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
184-
#define HV_X64_MSR_STIMER2_COUNT 0x400000B5
185-
#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
186-
#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
179+
#define HV_REGISTER_STIMER0_CONFIG 0x400000B0
180+
#define HV_REGISTER_STIMER0_COUNT 0x400000B1
181+
#define HV_REGISTER_STIMER1_CONFIG 0x400000B2
182+
#define HV_REGISTER_STIMER1_COUNT 0x400000B3
183+
#define HV_REGISTER_STIMER2_CONFIG 0x400000B4
184+
#define HV_REGISTER_STIMER2_COUNT 0x400000B5
185+
#define HV_REGISTER_STIMER3_CONFIG 0x400000B6
186+
#define HV_REGISTER_STIMER3_COUNT 0x400000B7
187187

188188
/* Hyper-V guest idle MSR */
189189
#define HV_X64_MSR_GUEST_IDLE 0x400000F0
190190

191191
/* Hyper-V guest crash notification MSR's */
192-
#define HV_X64_MSR_CRASH_P0 0x40000100
193-
#define HV_X64_MSR_CRASH_P1 0x40000101
194-
#define HV_X64_MSR_CRASH_P2 0x40000102
195-
#define HV_X64_MSR_CRASH_P3 0x40000103
196-
#define HV_X64_MSR_CRASH_P4 0x40000104
197-
#define HV_X64_MSR_CRASH_CTL 0x40000105
192+
#define HV_REGISTER_CRASH_P0 0x40000100
193+
#define HV_REGISTER_CRASH_P1 0x40000101
194+
#define HV_REGISTER_CRASH_P2 0x40000102
195+
#define HV_REGISTER_CRASH_P3 0x40000103
196+
#define HV_REGISTER_CRASH_P4 0x40000104
197+
#define HV_REGISTER_CRASH_CTL 0x40000105
198198

199199
/* TSC emulation after migration */
200200
#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
@@ -204,6 +204,32 @@
204204
/* TSC invariant control */
205205
#define HV_X64_MSR_TSC_INVARIANT_CONTROL 0x40000118
206206

207+
/* Register name aliases for temporary compatibility */
208+
#define HV_X64_MSR_STIMER0_COUNT HV_REGISTER_STIMER0_COUNT
209+
#define HV_X64_MSR_STIMER0_CONFIG HV_REGISTER_STIMER0_CONFIG
210+
#define HV_X64_MSR_STIMER1_COUNT HV_REGISTER_STIMER1_COUNT
211+
#define HV_X64_MSR_STIMER1_CONFIG HV_REGISTER_STIMER1_CONFIG
212+
#define HV_X64_MSR_STIMER2_COUNT HV_REGISTER_STIMER2_COUNT
213+
#define HV_X64_MSR_STIMER2_CONFIG HV_REGISTER_STIMER2_CONFIG
214+
#define HV_X64_MSR_STIMER3_COUNT HV_REGISTER_STIMER3_COUNT
215+
#define HV_X64_MSR_STIMER3_CONFIG HV_REGISTER_STIMER3_CONFIG
216+
#define HV_X64_MSR_SCONTROL HV_REGISTER_SCONTROL
217+
#define HV_X64_MSR_SVERSION HV_REGISTER_SVERSION
218+
#define HV_X64_MSR_SIMP HV_REGISTER_SIMP
219+
#define HV_X64_MSR_SIEFP HV_REGISTER_SIEFP
220+
#define HV_X64_MSR_VP_INDEX HV_REGISTER_VP_INDEX
221+
#define HV_X64_MSR_EOM HV_REGISTER_EOM
222+
#define HV_X64_MSR_SINT0 HV_REGISTER_SINT0
223+
#define HV_X64_MSR_SINT15 HV_REGISTER_SINT15
224+
#define HV_X64_MSR_CRASH_P0 HV_REGISTER_CRASH_P0
225+
#define HV_X64_MSR_CRASH_P1 HV_REGISTER_CRASH_P1
226+
#define HV_X64_MSR_CRASH_P2 HV_REGISTER_CRASH_P2
227+
#define HV_X64_MSR_CRASH_P3 HV_REGISTER_CRASH_P3
228+
#define HV_X64_MSR_CRASH_P4 HV_REGISTER_CRASH_P4
229+
#define HV_X64_MSR_CRASH_CTL HV_REGISTER_CRASH_CTL
230+
#define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT
231+
#define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC
232+
207233
/*
208234
* Declare the MSR used to setup pages used to communicate with the hypervisor.
209235
*/

arch/x86/include/asm/mshyperv.h

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,22 @@ typedef int (*hyperv_fill_flush_list_func)(
1414
struct hv_guest_mapping_flush_list *flush,
1515
void *data);
1616

17-
#define hv_init_timer(timer, tick) \
18-
wrmsrl(HV_X64_MSR_STIMER0_COUNT + (2*timer), tick)
19-
#define hv_init_timer_config(timer, val) \
20-
wrmsrl(HV_X64_MSR_STIMER0_CONFIG + (2*timer), val)
21-
22-
#define hv_get_simp(val) rdmsrl(HV_X64_MSR_SIMP, val)
23-
#define hv_set_simp(val) wrmsrl(HV_X64_MSR_SIMP, val)
24-
25-
#define hv_get_siefp(val) rdmsrl(HV_X64_MSR_SIEFP, val)
26-
#define hv_set_siefp(val) wrmsrl(HV_X64_MSR_SIEFP, val)
27-
28-
#define hv_get_synic_state(val) rdmsrl(HV_X64_MSR_SCONTROL, val)
29-
#define hv_set_synic_state(val) wrmsrl(HV_X64_MSR_SCONTROL, val)
17+
static inline void hv_set_register(unsigned int reg, u64 value)
18+
{
19+
wrmsrl(reg, value);
20+
}
3021

31-
#define hv_get_vp_index(index) rdmsrl(HV_X64_MSR_VP_INDEX, index)
22+
static inline u64 hv_get_register(unsigned int reg)
23+
{
24+
u64 value;
3225

33-
#define hv_signal_eom() wrmsrl(HV_X64_MSR_EOM, 0)
26+
rdmsrl(reg, value);
27+
return value;
28+
}
3429

35-
#define hv_get_synint_state(int_num, val) \
36-
rdmsrl(HV_X64_MSR_SINT0 + int_num, val)
37-
#define hv_set_synint_state(int_num, val) \
38-
wrmsrl(HV_X64_MSR_SINT0 + int_num, val)
3930
#define hv_recommend_using_aeoi() \
4031
(!(ms_hyperv.hints & HV_DEPRECATING_AEOI_RECOMMENDED))
4132

42-
#define hv_get_crash_ctl(val) \
43-
rdmsrl(HV_X64_MSR_CRASH_CTL, val)
44-
45-
#define hv_get_time_ref_count(val) \
46-
rdmsrl(HV_X64_MSR_TIME_REF_COUNT, val)
47-
48-
#define hv_get_reference_tsc(val) \
49-
rdmsrl(HV_X64_MSR_REFERENCE_TSC, val)
50-
#define hv_set_reference_tsc(val) \
51-
wrmsrl(HV_X64_MSR_REFERENCE_TSC, val)
5233
#define hv_set_clocksource_vdso(val) \
5334
((val).vdso_clock_mode = VDSO_CLOCKMODE_HVCLOCK)
5435
#define hv_enable_vdso_clocksource() \

drivers/clocksource/hyperv_timer.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ static int hv_ce_set_next_event(unsigned long delta,
6868

6969
current_tick = hv_read_reference_counter();
7070
current_tick += delta;
71-
hv_init_timer(0, current_tick);
71+
hv_set_register(HV_REGISTER_STIMER0_COUNT, current_tick);
7272
return 0;
7373
}
7474

7575
static int hv_ce_shutdown(struct clock_event_device *evt)
7676
{
77-
hv_init_timer(0, 0);
78-
hv_init_timer_config(0, 0);
77+
hv_set_register(HV_REGISTER_STIMER0_COUNT, 0);
78+
hv_set_register(HV_REGISTER_STIMER0_CONFIG, 0);
7979
if (direct_mode_enabled)
8080
hv_disable_stimer0_percpu_irq(stimer0_irq);
8181

@@ -105,7 +105,7 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt)
105105
timer_cfg.direct_mode = 0;
106106
timer_cfg.sintx = stimer0_message_sint;
107107
}
108-
hv_init_timer_config(0, timer_cfg.as_uint64);
108+
hv_set_register(HV_REGISTER_STIMER0_CONFIG, timer_cfg.as_uint64);
109109
return 0;
110110
}
111111

@@ -331,7 +331,7 @@ static u64 notrace read_hv_clock_tsc(void)
331331
u64 current_tick = hv_read_tsc_page(hv_get_tsc_page());
332332

333333
if (current_tick == U64_MAX)
334-
hv_get_time_ref_count(current_tick);
334+
current_tick = hv_get_register(HV_REGISTER_TIME_REF_COUNT);
335335

336336
return current_tick;
337337
}
@@ -352,9 +352,9 @@ static void suspend_hv_clock_tsc(struct clocksource *arg)
352352
u64 tsc_msr;
353353

354354
/* Disable the TSC page */
355-
hv_get_reference_tsc(tsc_msr);
355+
tsc_msr = hv_get_register(HV_REGISTER_REFERENCE_TSC);
356356
tsc_msr &= ~BIT_ULL(0);
357-
hv_set_reference_tsc(tsc_msr);
357+
hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr);
358358
}
359359

360360

@@ -364,10 +364,10 @@ static void resume_hv_clock_tsc(struct clocksource *arg)
364364
u64 tsc_msr;
365365

366366
/* Re-enable the TSC page */
367-
hv_get_reference_tsc(tsc_msr);
367+
tsc_msr = hv_get_register(HV_REGISTER_REFERENCE_TSC);
368368
tsc_msr &= GENMASK_ULL(11, 0);
369369
tsc_msr |= BIT_ULL(0) | (u64)phys_addr;
370-
hv_set_reference_tsc(tsc_msr);
370+
hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr);
371371
}
372372

373373
static int hv_cs_enable(struct clocksource *cs)
@@ -389,14 +389,12 @@ static struct clocksource hyperv_cs_tsc = {
389389

390390
static u64 notrace read_hv_clock_msr(void)
391391
{
392-
u64 current_tick;
393392
/*
394393
* Read the partition counter to get the current tick count. This count
395394
* is set to 0 when the partition is created and is incremented in
396395
* 100 nanosecond units.
397396
*/
398-
hv_get_time_ref_count(current_tick);
399-
return current_tick;
397+
return hv_get_register(HV_REGISTER_TIME_REF_COUNT);
400398
}
401399

402400
static u64 notrace read_hv_clock_msr_cs(struct clocksource *arg)
@@ -436,10 +434,10 @@ static bool __init hv_init_tsc_clocksource(void)
436434
* (which already has at least the low 12 bits set to zero since
437435
* it is page aligned). Also set the "enable" bit, which is bit 0.
438436
*/
439-
hv_get_reference_tsc(tsc_msr);
437+
tsc_msr = hv_get_register(HV_REGISTER_REFERENCE_TSC);
440438
tsc_msr &= GENMASK_ULL(11, 0);
441439
tsc_msr = tsc_msr | 0x1 | (u64)phys_addr;
442-
hv_set_reference_tsc(tsc_msr);
440+
hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr);
443441

444442
hv_set_clocksource_vdso(hyperv_cs_tsc);
445443
clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);

drivers/hv/hv.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,34 +198,36 @@ void hv_synic_enable_regs(unsigned int cpu)
198198
union hv_synic_scontrol sctrl;
199199

200200
/* Setup the Synic's message page */
201-
hv_get_simp(simp.as_uint64);
201+
simp.as_uint64 = hv_get_register(HV_REGISTER_SIMP);
202202
simp.simp_enabled = 1;
203203
simp.base_simp_gpa = virt_to_phys(hv_cpu->synic_message_page)
204204
>> HV_HYP_PAGE_SHIFT;
205205

206-
hv_set_simp(simp.as_uint64);
206+
hv_set_register(HV_REGISTER_SIMP, simp.as_uint64);
207207

208208
/* Setup the Synic's event page */
209-
hv_get_siefp(siefp.as_uint64);
209+
siefp.as_uint64 = hv_get_register(HV_REGISTER_SIEFP);
210210
siefp.siefp_enabled = 1;
211211
siefp.base_siefp_gpa = virt_to_phys(hv_cpu->synic_event_page)
212212
>> HV_HYP_PAGE_SHIFT;
213213

214-
hv_set_siefp(siefp.as_uint64);
214+
hv_set_register(HV_REGISTER_SIEFP, siefp.as_uint64);
215215

216216
/* Setup the shared SINT. */
217-
hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
217+
shared_sint.as_uint64 = hv_get_register(HV_REGISTER_SINT0 +
218+
VMBUS_MESSAGE_SINT);
218219

219220
shared_sint.vector = hv_get_vector();
220221
shared_sint.masked = false;
221222
shared_sint.auto_eoi = hv_recommend_using_aeoi();
222-
hv_set_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
223+
hv_set_register(HV_REGISTER_SINT0 + VMBUS_MESSAGE_SINT,
224+
shared_sint.as_uint64);
223225

224226
/* Enable the global synic bit */
225-
hv_get_synic_state(sctrl.as_uint64);
227+
sctrl.as_uint64 = hv_get_register(HV_REGISTER_SCONTROL);
226228
sctrl.enable = 1;
227229

228-
hv_set_synic_state(sctrl.as_uint64);
230+
hv_set_register(HV_REGISTER_SCONTROL, sctrl.as_uint64);
229231
}
230232

231233
int hv_synic_init(unsigned int cpu)
@@ -247,32 +249,35 @@ void hv_synic_disable_regs(unsigned int cpu)
247249
union hv_synic_siefp siefp;
248250
union hv_synic_scontrol sctrl;
249251

250-
hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
252+
shared_sint.as_uint64 = hv_get_register(HV_REGISTER_SINT0 +
253+
VMBUS_MESSAGE_SINT);
251254

252255
shared_sint.masked = 1;
253256

254257
/* Need to correctly cleanup in the case of SMP!!! */
255258
/* Disable the interrupt */
256-
hv_set_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
259+
hv_set_register(HV_REGISTER_SINT0 + VMBUS_MESSAGE_SINT,
260+
shared_sint.as_uint64);
257261

258-
hv_get_simp(simp.as_uint64);
262+
simp.as_uint64 = hv_get_register(HV_REGISTER_SIMP);
259263
simp.simp_enabled = 0;
260264
simp.base_simp_gpa = 0;
261265

262-
hv_set_simp(simp.as_uint64);
266+
hv_set_register(HV_REGISTER_SIMP, simp.as_uint64);
263267

264-
hv_get_siefp(siefp.as_uint64);
268+
siefp.as_uint64 = hv_get_register(HV_REGISTER_SIEFP);
265269
siefp.siefp_enabled = 0;
266270
siefp.base_siefp_gpa = 0;
267271

268-
hv_set_siefp(siefp.as_uint64);
272+
hv_set_register(HV_REGISTER_SIEFP, siefp.as_uint64);
269273

270274
/* Disable the global synic bit */
271-
hv_get_synic_state(sctrl.as_uint64);
275+
sctrl.as_uint64 = hv_get_register(HV_REGISTER_SCONTROL);
272276
sctrl.enable = 0;
273-
hv_set_synic_state(sctrl.as_uint64);
277+
hv_set_register(HV_REGISTER_SCONTROL, sctrl.as_uint64);
274278
}
275279

280+
276281
int hv_synic_cleanup(unsigned int cpu)
277282
{
278283
struct vmbus_channel *channel, *sc;

drivers/hv/vmbus_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ static int vmbus_bus_init(void)
14731473
* Register for panic kmsg callback only if the right
14741474
* capability is supported by the hypervisor.
14751475
*/
1476-
hv_get_crash_ctl(hyperv_crash_ctl);
1476+
hyperv_crash_ctl = hv_get_register(HV_REGISTER_CRASH_CTL);
14771477
if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) {
14781478
hv_panic_page = (void *)hv_alloc_hyperv_zeroed_page();
14791479
if (hv_panic_page) {

include/asm-generic/mshyperv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
8585
* possibly deliver another msg from the
8686
* hypervisor
8787
*/
88-
hv_signal_eom();
88+
hv_set_register(HV_REGISTER_EOM, 0);
8989
}
9090
}
9191

0 commit comments

Comments
 (0)