Skip to contentSkip to conversation

drivers/hv: correct tsc page sequence invalid value

PATCH In review Denis V. Lunev 2 participants 5 messages Nov 2, 2015 – Nov 12, 2015 Hyper-V/Azure core and drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/hv: correct tsc page sequence invalid value

From: Andrey Smetanin <[email protected]>

Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly:

HvlGetReferenceTime proc near
xchg ax, ax
loc_1401C3132:

                 mov     rax, cs:HvlpReferenceTscPage
                 mov     r9d, [rax]
                 test    r9d, r9d
                 jz      short loc_1401C3176

rdtsc
mov rcx, cs:HvlpReferenceTscPage
shl rdx, 20h
or rdx, rax
mov rax, [rcx+8]
mov rcx, cs:HvlpReferenceTscPage
mov r8, [rcx+10h]
mul rdx
mov rax, cs:HvlpReferenceTscPage
add rdx, r8
mov ecx, [rax]
cmp ecx, r9d
jnz short loc_1401C3132
jmp short loc_1401C3184
loc_1401C3176:
mov ecx, 40000020h
rdmsr
shl rdx, 20h
or rdx, rax
loc_1401C3184:
mov rax, rdx
retn
HvlGetReferenceTime endp

This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor.

CC "K. Y. Srinivasan" <[email protected]>
CC Haiyang Zhang <[email protected]>
CC Vitaly Kuznetsov <[email protected]>

TARGET: Microsoft Hyper-V Linux guest drivers

---
 drivers/hv/hv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv.c +2 -2
index 6341be8..68d0701 100644
@@ -139,7 +139,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource *arg)
 	cycle_t current_tick;
 	struct ms_hyperv_tsc_page *tsc_pg = hv_context.tsc_page;
 
-	if (tsc_pg->tsc_sequence != -1) {
+	if (tsc_pg->tsc_sequence != 0) {
 		/*
 		 * Use the tsc page to compute the value.
 		 */
@@ -161,7 +161,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource *arg)
 			if (tsc_pg->tsc_sequence == sequence)
 				return current_tick;
 
-			if (tsc_pg->tsc_sequence != -1)
+			if (tsc_pg->tsc_sequence != 0)
 				continue;
 			/*
 			 * Fallback using MSR method.
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 54 lines

-----Original Message-----
From: Denis V. Lunev [mailto:[email protected]]
Sent: Monday, November 2, 2015 3:34 AM
Cc: [email protected]; [email protected]; linux- [email protected]; Andrey Smetanin <[email protected]>; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Vitaly Kuznetsov <[email protected]>; Denis V. Lunev <[email protected]>
Subject: [PATCH 1/1] drivers/hv: correct tsc page sequence invalid value

From: Andrey Smetanin <[email protected]>

Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly:

HvlGetReferenceTime proc near
xchg ax, ax
loc_1401C3132:

                 mov     rax, cs:HvlpReferenceTscPage
                 mov     r9d, [rax]
                 test    r9d, r9d
                 jz      short loc_1401C3176

rdtsc
mov rcx, cs:HvlpReferenceTscPage
shl rdx, 20h
or rdx, rax
mov rax, [rcx+8]
mov rcx, cs:HvlpReferenceTscPage
mov r8, [rcx+10h]
mul rdx
mov rax, cs:HvlpReferenceTscPage
add rdx, r8
mov ecx, [rax]
cmp ecx, r9d
jnz short loc_1401C3132
jmp short loc_1401C3184
loc_1401C3176:
mov ecx, 40000020h
rdmsr
shl rdx, 20h
or rdx, rax
loc_1401C3184:
mov rax, rdx
retn
HvlGetReferenceTime endp

Quoted 6 lines

This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor.

CC "K. Y. Srinivasan" <[email protected]>

Thanks Andrey; the Hyper-V team will be updating the Hyper-V documentation.

Regards,

K. Y

Quoted 35 lines
CC Haiyang Zhang <[email protected]>
CC Vitaly Kuznetsov <[email protected]>

TARGET: Microsoft Hyper-V Linux guest drivers

---
 drivers/hv/hv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv.c +1 -1
index 6341be8..68d0701 100644
@@ -139,7 +139,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource
 *arg)
 	cycle_t current_tick;
 	struct ms_hyperv_tsc_page *tsc_pg = hv_context.tsc_page;
 
-	if (tsc_pg->tsc_sequence != -1) {
+	if (tsc_pg->tsc_sequence != 0) {
 		/*
 		 * Use the tsc page to compute the value.
drivers/hv/hv.c +1 -1
 		 */
@@ -161,7 +161,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource
 *arg)
 			if (tsc_pg->tsc_sequence == sequence)
 				return current_tick;
 
-			if (tsc_pg->tsc_sequence != -1)
+			if (tsc_pg->tsc_sequence != 0)
 				continue;
 			/*

* Fallback using MSR method.
--
2.1.4

#2 lore raw
Quoted 59 lines · KY Srinivasan
Quoted 53 lines

-----Original Message-----
From: Denis V. Lunev [mailto:[email protected]]
Sent: Monday, November 2, 2015 3:34 AM
Cc: [email protected]; [email protected]; linux- [email protected]; Andrey Smetanin <[email protected]>; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Vitaly Kuznetsov <[email protected]>; Denis V. Lunev <[email protected]>
Subject: [PATCH 1/1] drivers/hv: correct tsc page sequence invalid value

From: Andrey Smetanin <[email protected]>

Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly:

HvlGetReferenceTime proc near
xchg ax, ax
loc_1401C3132:

                  mov     rax, cs:HvlpReferenceTscPage
                  mov     r9d, [rax]
                  test    r9d, r9d
                  jz      short loc_1401C3176

rdtsc
mov rcx, cs:HvlpReferenceTscPage
shl rdx, 20h
or rdx, rax
mov rax, [rcx+8]
mov rcx, cs:HvlpReferenceTscPage
mov r8, [rcx+10h]
mul rdx
mov rax, cs:HvlpReferenceTscPage
add rdx, r8
mov ecx, [rax]
cmp ecx, r9d
jnz short loc_1401C3132
jmp short loc_1401C3184
loc_1401C3176:
mov ecx, 40000020h
rdmsr
shl rdx, 20h
or rdx, rax
loc_1401C3184:
mov rax, rdx
retn
HvlGetReferenceTime endp

Quoted 6 lines

This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor.

CC "K. Y. Srinivasan" <[email protected]>
Quoted 7 lines

Thanks Andrey; the Hyper-V team will be updating the Hyper-V documentation.

Regards,

K. Y

K.Y.,

can you pls clarify the state of this patch? It is a bit unclear to me whether it is applied or not.

By the way, I also do not see the following patch "drivers/hv: cleanup synic msrs if vmbus connect failed" as applied in the Linux-next. You have promised to resend it will correct author.

Thank you in advance,
Den

#3 lore raw
Quoted 78 lines

-----Original Message-----
From: Denis V. Lunev [mailto:[email protected]]
Sent: Wednesday, November 11, 2015 11:16 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; Andrey Smetanin <[email protected]>; Haiyang Zhang <[email protected]>; Vitaly Kuznetsov <[email protected]>
Subject: Re: [PATCH 1/1] drivers/hv: correct tsc page sequence invalid value

Quoted 6 lines · KY Srinivasan
Quoted 6 lines

-----Original Message-----
From: Denis V. Lunev [mailto:[email protected]]
Sent: Monday, November 2, 2015 3:34 AM
Cc: [email protected]; [email protected]; linux- [email protected]; Andrey Smetanin <[email protected]>;

KY

Quoted 47 lines
Quoted 47 lines

Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Vitaly Kuznetsov <[email protected]>; Denis V. Lunev <[email protected]>
Subject: [PATCH 1/1] drivers/hv: correct tsc page sequence invalid value

From: Andrey Smetanin <[email protected]>

Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly:

HvlGetReferenceTime proc near
xchg ax, ax
loc_1401C3132:

                  mov     rax, cs:HvlpReferenceTscPage
                  mov     r9d, [rax]
                  test    r9d, r9d
                  jz      short loc_1401C3176

rdtsc
mov rcx, cs:HvlpReferenceTscPage
shl rdx, 20h
or rdx, rax
mov rax, [rcx+8]
mov rcx, cs:HvlpReferenceTscPage
mov r8, [rcx+10h]
mul rdx
mov rax, cs:HvlpReferenceTscPage
add rdx, r8
mov ecx, [rax]
cmp ecx, r9d
jnz short loc_1401C3132
jmp short loc_1401C3184
loc_1401C3176:
mov ecx, 40000020h
rdmsr
shl rdx, 20h
or rdx, rax
loc_1401C3184:
mov rax, rdx
retn
HvlGetReferenceTime endp

Quoted 7 lines
Quoted 6 lines

This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor.

CC "K. Y. Srinivasan" <[email protected]>

Thanks Andrey; the Hyper-V team will be updating the Hyper-V

documentation.

Quoted 3 lines
Quoted 7 lines
Quoted 3 lines

Regards,

K. Y

K.Y.,

can you pls clarify the state of this patch? It is a bit unclear to me whether it is applied or not.

I will be submitting this shortly.

Quoted 5 lines

By the way, I also do not see the following patch "drivers/hv: cleanup synic msrs if vmbus connect failed" as applied in the Linux-next. You have promised to resend it will correct author.

It was resent on October 29. It is in Greg's queue.

Regards,

K. Y

Quoted 3 lines

Thank you in advance,
Den

#4 lore raw
Quoted 88 lines · KY Srinivasan
Quoted 75 lines

-----Original Message-----
From: Denis V. Lunev [mailto:[email protected]]
Sent: Wednesday, November 11, 2015 11:16 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; Andrey Smetanin <[email protected]>; Haiyang Zhang <[email protected]>; Vitaly Kuznetsov <[email protected]>
Subject: Re: [PATCH 1/1] drivers/hv: correct tsc page sequence invalid value

Quoted 5 lines · KY Srinivasan
Quoted 5 lines

-----Original Message-----
From: Denis V. Lunev [mailto:[email protected]]
Sent: Monday, November 2, 2015 3:34 AM
Cc: [email protected]; [email protected]; linux- [email protected]; Andrey Smetanin <[email protected]>;

KY

Quoted 47 lines
Quoted 47 lines

Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Vitaly Kuznetsov <[email protected]>; Denis V. Lunev <[email protected]>
Subject: [PATCH 1/1] drivers/hv: correct tsc page sequence invalid value

From: Andrey Smetanin <[email protected]>

Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly:

HvlGetReferenceTime proc near
xchg ax, ax
loc_1401C3132:

                   mov     rax, cs:HvlpReferenceTscPage
                   mov     r9d, [rax]
                   test    r9d, r9d
                   jz      short loc_1401C3176

rdtsc
mov rcx, cs:HvlpReferenceTscPage
shl rdx, 20h
or rdx, rax
mov rax, [rcx+8]
mov rcx, cs:HvlpReferenceTscPage
mov r8, [rcx+10h]
mul rdx
mov rax, cs:HvlpReferenceTscPage
add rdx, r8
mov ecx, [rax]
cmp ecx, r9d
jnz short loc_1401C3132
jmp short loc_1401C3184
loc_1401C3176:
mov ecx, 40000020h
rdmsr
shl rdx, 20h
or rdx, rax
loc_1401C3184:
mov rax, rdx
retn
HvlGetReferenceTime endp

Quoted 7 lines
Quoted 6 lines

This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor.

CC "K. Y. Srinivasan" <[email protected]>

Thanks Andrey; the Hyper-V team will be updating the Hyper-V

documentation.

Quoted 2 lines
Quoted 7 lines
Quoted 3 lines

Regards,

K. Y

K.Y.,

can you pls clarify the state of this patch? It is a bit unclear to me whether it is applied or not.

I will be submitting this shortly.

Quoted 4 lines

By the way, I also do not see the following patch "drivers/hv: cleanup synic msrs if vmbus connect failed" as applied in the Linux-next. You have promised to resend it will correct author.

Quoted 7 lines

It was resent on October 29. It is in Greg's queue.

Regards,

K. Y

Quoted 2 lines

Thank you in advance,
Den

thank you very much for this update :)

Den