All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types
@ 2019-06-22 22:08 Andy Lutomirski
  2019-06-23 12:42 ` Thomas Gleixner
  2019-06-23 23:57 ` [tip:timers/vdso] " tip-bot for Andy Lutomirski
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Lutomirski @ 2019-06-22 22:08 UTC (permalink / raw)
  To: x86
  Cc: LKML, Borislav Petkov, Andy Lutomirski, Peter Zijlstra, Linus Torvalds

Clean up the vDSO code a bit by giving pvclock_page and hvclock_page
their actual types instead of u8[PAGE_SIZE].  This shouldn't
materially affect the generated code.

Heavily based on a patch from Linus.

Cc: Borislav Petkov <bp@alien8.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/entry/vdso/vclock_gettime.c | 36 ++++++++++++++++++----------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
index 4aed41f638bb..907efc5015ec 100644
--- a/arch/x86/entry/vdso/vclock_gettime.c
+++ b/arch/x86/entry/vdso/vclock_gettime.c
@@ -28,13 +28,33 @@ extern int __vdso_clock_gettime(clockid_t clock, struct timespec *ts);
 extern int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz);
 extern time_t __vdso_time(time_t *t);
 
+/*
+ * Declare the memory-mapped vclock data pages.  These come from hypervisors.
+ * If we ever reintroduce something like direct access to an MMIO clock like
+ * the HPET again, it will go here as well.
+ *
+ * A load from any of these pages will segfault if the clock in question is
+ * disabled, so appropriate compiler barriers and checks need to be used
+ * to prevent stray loads.
+ *
+ * These declarations MUST NOT be const.  The compiler will assume that
+ * an extern const variable has genuinely constant contents, and the
+ * resulting code won't work, since the whole point is that these pages
+ * change over time, possibly while we're accessing them.
+ */
+
 #ifdef CONFIG_PARAVIRT_CLOCK
-extern u8 pvclock_page[PAGE_SIZE]
+/*
+ * This is the vCPU 0 pvclock page.  We only use pvclock from the vDSO
+ * if the hypervisor tells us that all vCPUs can get valid data from the
+ * vCPU 0 page.
+ */
+extern struct pvclock_vsyscall_time_info pvclock_page
 	__attribute__((visibility("hidden")));
 #endif
 
 #ifdef CONFIG_HYPERV_TSCPAGE
-extern u8 hvclock_page[PAGE_SIZE]
+extern struct ms_hyperv_tsc_page hvclock_page
 	__attribute__((visibility("hidden")));
 #endif
 
@@ -69,14 +89,9 @@ notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
 #endif
 
 #ifdef CONFIG_PARAVIRT_CLOCK
-static notrace const struct pvclock_vsyscall_time_info *get_pvti0(void)
-{
-	return (const struct pvclock_vsyscall_time_info *)&pvclock_page;
-}
-
 static notrace u64 vread_pvclock(void)
 {
-	const struct pvclock_vcpu_time_info *pvti = &get_pvti0()->pvti;
+	const struct pvclock_vcpu_time_info *pvti = &pvclock_page.pvti;
 	u32 version;
 	u64 ret;
 
@@ -117,10 +132,7 @@ static notrace u64 vread_pvclock(void)
 #ifdef CONFIG_HYPERV_TSCPAGE
 static notrace u64 vread_hvclock(void)
 {
-	const struct ms_hyperv_tsc_page *tsc_pg =
-		(const struct ms_hyperv_tsc_page *)&hvclock_page;
-
-	return hv_read_tsc_page(tsc_pg);
+	return hv_read_tsc_page(&hvclock_page);
 }
 #endif
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types
  2019-06-22 22:08 [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types Andy Lutomirski
@ 2019-06-23 12:42 ` Thomas Gleixner
       [not found]   ` <CAHk-=whywzng7FLV9X67RPmHNnygK+7VJV+zh4njT6BA+h9tCw@mail.gmail.com>
  2019-06-23 23:57 ` [tip:timers/vdso] " tip-bot for Andy Lutomirski
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2019-06-23 12:42 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: x86, LKML, Borislav Petkov, Peter Zijlstra, Linus Torvalds

On Sat, 22 Jun 2019, Andy Lutomirski wrote:

> Clean up the vDSO code a bit by giving pvclock_page and hvclock_page
> their actual types instead of u8[PAGE_SIZE].  This shouldn't
> materially affect the generated code.
> 
> Heavily based on a patch from Linus.
> 
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

So either this wants a

From: Linus line

or this tag should be:

Originally-by: Linus ...

Hmm?

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types
       [not found]   ` <CAHk-=whywzng7FLV9X67RPmHNnygK+7VJV+zh4njT6BA+h9tCw@mail.gmail.com>
@ 2019-06-23 13:10     ` Thomas Gleixner
  2019-06-23 16:03       ` Andy Lutomirski
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2019-06-23 13:10 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Andrew Lutomirski, the arch/x86 maintainers, LKML,
	Borislav Petkov, Peter Zijlstra

On Sun, 23 Jun 2019, Linus Torvalds wrote:

> Andy added comments and changed the patch in other ways too, so I think
> it's fine to have him as author, and my sign-off is just for the original
> smaller patch.

Well, that will earn me a nastigram from the next checkers as it's not
compliant to our SOB rules ....

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types
  2019-06-23 13:10     ` Thomas Gleixner
@ 2019-06-23 16:03       ` Andy Lutomirski
  2019-06-23 22:19         ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Lutomirski @ 2019-06-23 16:03 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Linus Torvalds, Andrew Lutomirski, the arch/x86 maintainers,
	LKML, Borislav Petkov, Peter Zijlstra


> On Jun 23, 2019, at 6:10 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> 
>> On Sun, 23 Jun 2019, Linus Torvalds wrote:
>> 
>> Andy added comments and changed the patch in other ways too, so I think
>> it's fine to have him as author, and my sign-off is just for the original
>> smaller patch.
> 
> Well, that will earn me a nastigram from the next checkers as it's not
> compliant to our SOB rules ....
> 

Feel free to add:

Originally-by: Linus ...

I had assumed the textual description was enough.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types
  2019-06-23 16:03       ` Andy Lutomirski
@ 2019-06-23 22:19         ` Thomas Gleixner
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Gleixner @ 2019-06-23 22:19 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Linus Torvalds, Andrew Lutomirski, the arch/x86 maintainers,
	LKML, Borislav Petkov, Peter Zijlstra

On Sun, 23 Jun 2019, Andy Lutomirski wrote:

> 
> > On Jun 23, 2019, at 6:10 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> > 
> >> On Sun, 23 Jun 2019, Linus Torvalds wrote:
> >> 
> >> Andy added comments and changed the patch in other ways too, so I think
> >> it's fine to have him as author, and my sign-off is just for the original
> >> smaller patch.
> > 
> > Well, that will earn me a nastigram from the next checkers as it's not
> > compliant to our SOB rules ....
> > 
> 
> Feel free to add:
> 
> Originally-by: Linus ...
> 
> I had assumed the textual description was enough.

Ha, completely forgot about Co-developed-by. That does the trick nicely.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip:timers/vdso] x86/vdso: Give the [ph]vclock_page declarations real types
  2019-06-22 22:08 [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types Andy Lutomirski
  2019-06-23 12:42 ` Thomas Gleixner
@ 2019-06-23 23:57 ` tip-bot for Andy Lutomirski
  1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Andy Lutomirski @ 2019-06-23 23:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: torvalds, luto, linux-kernel, mingo, bp, peterz, hpa, tglx

Commit-ID:  ecf9db3d1f1a8fd2c335148891c3b044e9ce0628
Gitweb:     https://git.kernel.org/tip/ecf9db3d1f1a8fd2c335148891c3b044e9ce0628
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Sat, 22 Jun 2019 15:08:18 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 24 Jun 2019 01:21:31 +0200

x86/vdso: Give the [ph]vclock_page declarations real types

Clean up the vDSO code a bit by giving pvclock_page and hvclock_page
their actual types instead of u8[PAGE_SIZE].  This shouldn't
materially affect the generated code.

Heavily based on a patch from Linus.

[ tglx: Adapted to the unified VDSO code ]

Co-developed-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/6920c5188f8658001af1fc56fd35b815706d300c.1561241273.git.luto@kernel.org
---
 arch/x86/include/asm/vdso/gettimeofday.h | 36 +++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/vdso/gettimeofday.h b/arch/x86/include/asm/vdso/gettimeofday.h
index f92752d6cbcf..5b63f1f78a1f 100644
--- a/arch/x86/include/asm/vdso/gettimeofday.h
+++ b/arch/x86/include/asm/vdso/gettimeofday.h
@@ -26,13 +26,33 @@
 
 #define VDSO_HAS_CLOCK_GETRES 1
 
+/*
+ * Declare the memory-mapped vclock data pages.  These come from hypervisors.
+ * If we ever reintroduce something like direct access to an MMIO clock like
+ * the HPET again, it will go here as well.
+ *
+ * A load from any of these pages will segfault if the clock in question is
+ * disabled, so appropriate compiler barriers and checks need to be used
+ * to prevent stray loads.
+ *
+ * These declarations MUST NOT be const.  The compiler will assume that
+ * an extern const variable has genuinely constant contents, and the
+ * resulting code won't work, since the whole point is that these pages
+ * change over time, possibly while we're accessing them.
+ */
+
 #ifdef CONFIG_PARAVIRT_CLOCK
-extern u8 pvclock_page[PAGE_SIZE]
+/*
+ * This is the vCPU 0 pvclock page.  We only use pvclock from the vDSO
+ * if the hypervisor tells us that all vCPUs can get valid data from the
+ * vCPU 0 page.
+ */
+extern struct pvclock_vsyscall_time_info pvclock_page
 	__attribute__((visibility("hidden")));
 #endif
 
 #ifdef CONFIG_HYPERV_TSCPAGE
-extern u8 hvclock_page[PAGE_SIZE]
+extern struct ms_hyperv_tsc_page hvclock_page
 	__attribute__((visibility("hidden")));
 #endif
 
@@ -131,14 +151,9 @@ clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
 #endif
 
 #ifdef CONFIG_PARAVIRT_CLOCK
-static const struct pvclock_vsyscall_time_info *get_pvti0(void)
-{
-	return (const struct pvclock_vsyscall_time_info *)&pvclock_page;
-}
-
 static u64 vread_pvclock(void)
 {
-	const struct pvclock_vcpu_time_info *pvti = &get_pvti0()->pvti;
+	const struct pvclock_vcpu_time_info *pvti = &pvclock_page.pvti;
 	u32 version;
 	u64 ret;
 
@@ -180,10 +195,7 @@ static u64 vread_pvclock(void)
 #ifdef CONFIG_HYPERV_TSCPAGE
 static u64 vread_hvclock(void)
 {
-	const struct ms_hyperv_tsc_page *tsc_pg =
-		(const struct ms_hyperv_tsc_page *)&hvclock_page;
-
-	return hv_read_tsc_page(tsc_pg);
+	return hv_read_tsc_page(&hvclock_page);
 }
 #endif
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-24  3:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-22 22:08 [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types Andy Lutomirski
2019-06-23 12:42 ` Thomas Gleixner
     [not found]   ` <CAHk-=whywzng7FLV9X67RPmHNnygK+7VJV+zh4njT6BA+h9tCw@mail.gmail.com>
2019-06-23 13:10     ` Thomas Gleixner
2019-06-23 16:03       ` Andy Lutomirski
2019-06-23 22:19         ` Thomas Gleixner
2019-06-23 23:57 ` [tip:timers/vdso] " tip-bot for Andy Lutomirski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.