gcc-9: properly declare the {pv,hv}clock_page storage [Linux 4.14.137]

This Linux kernel change "gcc-9: properly declare the {pv,hv}clock_page storage" is included in the Linux 4.14.137 release. This change is authored by Linus Torvalds <torvalds [at] linux-foundation.org> on Wed May 1 11:20:53 2019 -0700. The commit for this change in Linux stable tree is f73e824 (patch) which is from upstream commit 459e3a2. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 459e3a2.

gcc-9: properly declare the {pv,hv}clock_page storage

commit 459e3a21535ae3c7a9a123650e54f5c882b8fcbf upstream.

The pvlock_page and hvclock_page variables are (as the name implies)
addresses to pages, created by the linker script.

But we declared them as just "extern u8" variables, which _works_, but
now that gcc does some more bounds checking, it causes warnings like

    warning: array subscript 1 is outside array bounds of ā€˜u8[1]ā€™

when we then access more than one byte from those variables.

Fix this by simply making the declaration of the variables match
reality, which makes the compiler happy too.

Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 arch/x86/entry/vdso/vclock_gettime.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
index 9c35dc0..4925593 100644
--- a/arch/x86/entry/vdso/vclock_gettime.c
+++ b/arch/x86/entry/vdso/vclock_gettime.c
@@ -29,12 +29,12 @@
 extern time_t __vdso_time(time_t *t);

 #ifdef CONFIG_PARAVIRT_CLOCK
-extern u8 pvclock_page
+extern u8 pvclock_page[PAGE_SIZE]
    __attribute__((visibility("hidden")));
 #endif

 #ifdef CONFIG_HYPERV_TSCPAGE
-extern u8 hvclock_page
+extern u8 hvclock_page[PAGE_SIZE]
    __attribute__((visibility("hidden")));
 #endif

Leave a Reply

Your email address will not be published. Required fields are marked *