Skip to contentSkip to conversation

clocksource/drivers/hyperv: use Hyper-V's page size to calculate PFN

PATCH In review Anirudh Rayabharam 4 participants 6 messages Nov 3, 2022 – Dec 2, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource/drivers/hyperv: use Hyper-V's page size to calculate PFN

__phys_to_pfn() will return a PFN based on the guest page size, which might be different from Hyper-V's page size that is always 4K. The PFN for the TSC page always needs to be a Hyper-V PFN.

Use HVPFN_DOWN() to calculate the PFN of the TSC page from the physical address.

---
 drivers/clocksource/hyperv_timer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clocksource/hyperv_timer.c +3 -2
index 11332c82d1af..18de1f439ffd 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/acpi.h>
+#include <linux/hyperv.h>
 #include <clocksource/hyperv_timer.h>
 #include <asm/hyperv-tlfs.h>
 #include <asm/mshyperv.h>
@@ -412,7 +413,7 @@ static void resume_hv_clock_tsc(struct clocksource *arg)
 	/* Re-enable the TSC page */
 	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
 	tsc_msr.enable = 1;
-	tsc_msr.pfn = __phys_to_pfn(phys_addr);
+	tsc_msr.pfn = HVPFN_DOWN(phys_addr);
 	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
 }
 
@@ -532,7 +533,7 @@ static bool __init hv_init_tsc_clocksource(void)
 	 */
 	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
 	tsc_msr.enable = 1;
-	tsc_msr.pfn = __phys_to_pfn(phys_addr);
+	tsc_msr.pfn = HVPFN_DOWN(phys_addr);
 	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
 
 	clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

From: Anirudh Rayabharam <[email protected]> Sent: Thursday, November 3, 2022 8:24 AM

Quoted 45 lines

__phys_to_pfn() will return a PFN based on the guest page size, which might be different from Hyper-V's page size that is always 4K. The PFN for the TSC page always needs to be a Hyper-V PFN.

Use HVPFN_DOWN() to calculate the PFN of the TSC page from the physical address.

---
 drivers/clocksource/hyperv_timer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clocksource/hyperv_timer.c +3 -3
index 11332c82d1af..18de1f439ffd 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/acpi.h>
+#include <linux/hyperv.h>
 #include <clocksource/hyperv_timer.h>
 #include <asm/hyperv-tlfs.h>
 #include <asm/mshyperv.h>
@@ -412,7 +413,7 @@ static void resume_hv_clock_tsc(struct clocksource *arg)
 	/* Re-enable the TSC page */
 	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
 	tsc_msr.enable = 1;
-	tsc_msr.pfn = __phys_to_pfn(phys_addr);
+	tsc_msr.pfn = HVPFN_DOWN(phys_addr);
 	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
 }
 
@@ -532,7 +533,7 @@ static bool __init hv_init_tsc_clocksource(void)
 	 */
 	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
 	tsc_msr.enable = 1;
-	tsc_msr.pfn = __phys_to_pfn(phys_addr);
+	tsc_msr.pfn = HVPFN_DOWN(phys_addr);
 	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
 
 	clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
--
Quoted 1 line

2.34.1

maintainer
#2 lore raw
Quoted 44 lines · Michael Kelley (LINUX)

From: Anirudh Rayabharam <[email protected]> Sent: Thursday, November 3, 2022 8:24 AM

Quoted 43 lines

__phys_to_pfn() will return a PFN based on the guest page size, which might be different from Hyper-V's page size that is always 4K. The PFN for the TSC page always needs to be a Hyper-V PFN.

Use HVPFN_DOWN() to calculate the PFN of the TSC page from the physical address.

---
 drivers/clocksource/hyperv_timer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clocksource/hyperv_timer.c +3 -2
index 11332c82d1af..18de1f439ffd 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/acpi.h>
+#include <linux/hyperv.h>
 #include <clocksource/hyperv_timer.h>
 #include <asm/hyperv-tlfs.h>
 #include <asm/mshyperv.h>
@@ -412,7 +413,7 @@ static void resume_hv_clock_tsc(struct clocksource *arg)
 	/* Re-enable the TSC page */
 	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
 	tsc_msr.enable = 1;
-	tsc_msr.pfn = __phys_to_pfn(phys_addr);
+	tsc_msr.pfn = HVPFN_DOWN(phys_addr);
 	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
 }
 
@@ -532,7 +533,7 @@ static bool __init hv_init_tsc_clocksource(void)
 	 */
 	tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC);
 	tsc_msr.enable = 1;
-	tsc_msr.pfn = __phys_to_pfn(phys_addr);
+	tsc_msr.pfn = HVPFN_DOWN(phys_addr);
 	hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64);
 
Quoted 5 lines
Quoted 3 lines
drivers/clocksource/hyperv_timer.c +0 -1
 	clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
--

2.34.1

Thank you both for the quick turnaround. I will just squash this patch into the previous one.

#3 lore raw

Hi,

On 03/11/2022 16:48, Wei Liu wrote:

[ ... ]

Quoted 4 lines
Quoted 1 line

Thank you both for the quick turnaround. I will just squash this patch into the previous one.

Can you point to the mailing list the squashed version ?

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
maintainer
#4 lore raw
Quoted 5 lines · Daniel Lezcano

Hi,

On 03/11/2022 16:48, Wei Liu wrote:

Quoted 8 lines

[ ... ]

Quoted 4 lines
Quoted 1 line

Thank you both for the quick turnaround. I will just squash this patch into the previous one.

Can you point to the mailing list the squashed version ?

The squashed patch is this one:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4ad1aa571214e8d6468a1806794d987b374b5a08

Thanks,
Wei.

#5 lore raw
Quoted 10 lines · Wei Liu
Quoted 9 lines · Daniel Lezcano

Hi,

On 03/11/2022 16:48, Wei Liu wrote:

[ ... ]

Quoted 2 lines
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Thank you both for the quick turnaround. I will just squash this patch into the previous one.

Can you point to the mailing list the squashed version ?

The squashed patch is this one:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4ad1aa571214e8d6468a1806794d987b374b5a08

Thanks!

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog