Skip to contentSkip to conversation

x86/boot/compressed/64: fix warning for 32-bit trampoline copy

PATCH Superseded Arnd Bergmann 2 participants 3 messages Feb 22, 2018 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot/compressed/64: fix warning for 32-bit trampoline copy

gcc-8 warns that we copy TRAMPOLINE_32BIT_CODE_SIZE bytes from the pointer to the function into actual trampoline, when that pointer is only 8 bytes:

In file included from arch/x86/boot/compressed/pgtable_64.c:3:
arch/x86/boot/compressed/pgtable_64.c: In function 'paging_prepare':
arch/x86/boot/compressed/../string.h:18:23: error: '__builtin_memcpy' reading 96 bytes from a region of size 8 [-Werror=stringop-overflow=]

 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
                       ^~~~~~~~~~~~~~~~~~~~~~~

arch/x86/boot/compressed/pgtable_64.c:62:2: note: in expansion of macro 'memcpy'
memcpy(trampoline + TRAMPOLINE_32BIT_CODE_OFFSET / sizeof(unsigned long), ^~~~~~

I assume what was intended here is to copy the trampoline itself rather than the pointer to the trampoline.

Cc Martin Sebor <[email protected]>
Fixes b91993a87aff ("x86/boot/compressed/64: Prepare trampoline memory")

---
This is a fairly new warning in gcc, it's possible that the code is correct and the warning message got it wrong, please double-check this.

Was the 32-bit trampoline code in the 64-bit decompressor tested successfully?

---
 arch/x86/boot/compressed/pgtable_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/pgtable_64.c +1 -1
index dad5da7b4c1a..35a0542fe397 100644
@@ -60,7 +60,7 @@ struct paging_config paging_prepare(void)
 
 	/* Copy trampoline code in place */
 	memcpy(trampoline + TRAMPOLINE_32BIT_CODE_OFFSET / sizeof(unsigned long),
-			&trampoline_32bit_src, TRAMPOLINE_32BIT_CODE_SIZE);
+			trampoline_32bit_src, TRAMPOLINE_32BIT_CODE_SIZE);
 
 	/*
 	 * Set up a new page table that will be used for switching from 4-
Signature · 1 line
2.9.0
#1 lore raw
Quoted 15 lines · Arnd Bergmann

gcc-8 warns that we copy TRAMPOLINE_32BIT_CODE_SIZE bytes from the pointer to the function into actual trampoline, when that pointer is only 8 bytes:

In file included from arch/x86/boot/compressed/pgtable_64.c:3:
arch/x86/boot/compressed/pgtable_64.c: In function 'paging_prepare':
arch/x86/boot/compressed/../string.h:18:23: error: '__builtin_memcpy' reading 96 bytes from a region of size 8 [-Werror=stringop-overflow=]

 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
                       ^~~~~~~~~~~~~~~~~~~~~~~

arch/x86/boot/compressed/pgtable_64.c:62:2: note: in expansion of macro 'memcpy'
memcpy(trampoline + TRAMPOLINE_32BIT_CODE_OFFSET / sizeof(unsigned long), ^~~~~~

I assume what was intended here is to copy the trampoline itself rather than the pointer to the trampoline.

Quoted 8 lines
Cc Martin Sebor <[email protected]>
Fixes b91993a87aff ("x86/boot/compressed/64: Prepare trampoline memory")

---
This is a fairly new warning in gcc, it's possible that the code is correct and the warning message got it wrong, please double-check this.

Was the 32-bit trampoline code in the 64-bit decompressor tested successfully?

Yes, it was. Actually it tested on every boot of any 64-bit machine.

The fix is wrong and it breaks boot. The bug is in trampoline_32bit_src declaration. Could you check if this helps with the warning:

arch/x86/boot/compressed/pgtable.h +1 -1
index 6e0db2260147..5e0b1c4abef4 100644
@@ -12,7 +12,7 @@
 
 #ifndef __ASSEMBLER__
 
-extern void (*trampoline_32bit_src)(void *return_ptr);
+extern void trampoline_32bit_src(void *return_ptr);
 
 #endif /* __ASSEMBLER__ */
 #endif /* BOOT_COMPRESSED_PAGETABLE_H */
Signature · 1 line
 Kirill A. Shutemov
#2 lore raw
Quoted 23 lines · Kirill A. Shutemov
Quoted 22 lines · Arnd Bergmann

gcc-8 warns that we copy TRAMPOLINE_32BIT_CODE_SIZE bytes from the pointer to the function into actual trampoline, when that pointer is only 8 bytes:

In file included from arch/x86/boot/compressed/pgtable_64.c:3:
arch/x86/boot/compressed/pgtable_64.c: In function 'paging_prepare':
arch/x86/boot/compressed/../string.h:18:23: error: '__builtin_memcpy' reading 96 bytes from a region of size 8 [-Werror=stringop-overflow=]

 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
                       ^~~~~~~~~~~~~~~~~~~~~~~

arch/x86/boot/compressed/pgtable_64.c:62:2: note: in expansion of macro 'memcpy'
memcpy(trampoline + TRAMPOLINE_32BIT_CODE_OFFSET / sizeof(unsigned long), ^~~~~~

I assume what was intended here is to copy the trampoline itself rather than the pointer to the trampoline.

Cc Martin Sebor <[email protected]>
Fixes b91993a87aff ("x86/boot/compressed/64: Prepare trampoline memory")

---
This is a fairly new warning in gcc, it's possible that the code is correct and the warning message got it wrong, please double-check this.

Quoted 6 lines
Quoted 1 line

Was the 32-bit trampoline code in the 64-bit decompressor tested successfully?

Yes, it was. Actually it tested on every boot of any 64-bit machine.

The fix is wrong and it breaks boot. The bug is in trampoline_32bit_src declaration. Could you check if this helps with the warning:

Got it, yes that definitely explains the problem. Your patch fixes it and I'll follow up with a new submission using this change, unless you want to send it as a patch yourself.

Arnd

Quoted 15 lines
arch/x86/boot/compressed/pgtable.h +1 -2
index 6e0db2260147..5e0b1c4abef4 100644
@@ -12,7 +12,7 @@
 
 #ifndef __ASSEMBLER__
 
-extern void (*trampoline_32bit_src)(void *return_ptr);
+extern void trampoline_32bit_src(void *return_ptr);
 
 #endif /* __ASSEMBLER__ */
 #endif /* BOOT_COMPRESSED_PAGETABLE_H */
--
 Kirill A. Shutemov