memory: fix build with COVERAGE but !HVM
PATCH 1/1 memory: fix build with COVERAGE but !HVM
Xen is heavily relying on the DCE stage to remove unused code so the linker doesn't throw an error because a function is not implemented yet we defined a prototype for it.
On some GCC versions (such as 9.4 provided by Debian sid), the compiler DCE stage will not manage to figure that out for xenmem_add_to_physmap_batch():
ld: ld: prelink.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference to xenmem_add_to_physmap_one' /xen/xen/common/memory.c:942:(.text+0x22145): relocation truncated to fit: R_X86_64_PLT32 against undefined symbol xenmem_add_to_physmap_one' prelink-efi.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference to `xenmem_add_to_physmap_one' make[2]: *** [Makefile:215: /root/xen/xen/xen.efi] Error 1
make[2]: *** Waiting for unfinished jobs....
ld: /xen/xen/.xen-syms.0: hidden symbol `xenmem_add_to_physmap_one' isn't defined
ld: final link failed: bad value
It is not entirely clear why the compiler DCE is not detecting the unused code. However, cloning the check introduced by the commit below into xenmem_add_to_physmap_batch() does the trick.
No functional change intended.
---
Julien, since I reused most of your patch'es description, I've kept your S-o-b. Please let me know if you want me to drop it.
xen/common/memory.c +13 -0
@@ -904,6 +904,19 @@ static int xenmem_add_to_physmap_batch(s {union add_to_physmap_extra extra = {}; +/* +* While, unlike xenmem_add_to_physmap(), this function is static, there +* still have been cases observed where xatp_permission_check(), invoked +* by our caller, doesn't lead to elimination of this entire function when +* the compile time evaluation of paging_mode_translate(d) is false. Guard +* against this be replicating the same check here. +*/ +if ( !paging_mode_translate (d) ) + { +ASSERT_UNREACHABLE (); +return -EACCES ; + } +if (unlikely (xatpb->size < extent) )return -EILSEQ ;
Quoted 23 lines · Jan Beulich
Xen is heavily relying on the DCE stage to remove unused code so the linker doesn't throw an error because a function is not implemented yet we defined a prototype for it.
On some GCC versions (such as 9.4 provided by Debian sid), the compiler DCE stage will not manage to figure that out for
xenmem_add_to_physmap_batch():ld: ld: prelink.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference toxenmem_add_to_physmap_one' /xen/xen/common/memory.c:942:(.text+0x22145): relocation truncated to fit: R_X86_64_PLT32 against undefined symbolxenmem_add_to_physmap_one' prelink-efi.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference to `xenmem_add_to_physmap_one' make[2]: *** [Makefile:215:/root/xen/xen/xen.efi] Error 1
make[2]: *** Waiting for unfinished jobs....
ld: /xen/xen/.xen-syms.0: hidden symbol `xenmem_add_to_physmap_one' isn't defined
ld: final link failed: bad valueIt is not entirely clear why the compiler DCE is not detecting the unused code. However, cloning the check introduced by the commit below into
xenmem_add_to_physmap_batch()does the trick.
Quoted 7 lines
No functional change intended.
Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")Reported-by Oleksandr Tyshchenko <[email protected]>Signed-off-by Julien Grall <[email protected]>Signed-off-by Jan Beulich <[email protected]>Release-Acked-by Ian Jackson <[email protected]>
Quoted 37 lines · Jan Beulich
Xen is heavily relying on the DCE stage to remove unused code so the linker doesn't throw an error because a function is not implemented yet we defined a prototype for it.
On some GCC versions (such as 9.4 provided by Debian sid), the compiler DCE stage will not manage to figure that out for
xenmem_add_to_physmap_batch():ld: ld: prelink.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference toxenmem_add_to_physmap_one' /xen/xen/common/memory.c:942:(.text+0x22145): relocation truncated to fit: R_X86_64_PLT32 against undefined symbolxenmem_add_to_physmap_one' prelink-efi.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference to `xenmem_add_to_physmap_one' make[2]: *** [Makefile:215:/root/xen/xen/xen.efi] Error 1
make[2]: *** Waiting for unfinished jobs....
ld: /xen/xen/.xen-syms.0: hidden symbol `xenmem_add_to_physmap_one' isn't defined
ld: final link failed: bad valueIt is not entirely clear why the compiler DCE is not detecting the unused code. However, cloning the check introduced by the commit below into
xenmem_add_to_physmap_batch()does the trick.No functional change intended.
Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")Reported-by Oleksandr Tyshchenko <[email protected]>Signed-off-by Julien Grall <[email protected]>Signed-off-by Jan Beulich <[email protected]>Release-Acked-by Ian Jackson <[email protected]>---
Julien, since I reused most of your patch'es description, I've kept your S-o-b. Please let me know if you want me to drop it.
xen/common/memory.c static int xenmem_add_to_physmap_batch(s · line 913
Quoted 10 lines
xen/common/memory.c +7
-0@@ -904,6 +904,19 @@ static int xenmem_add_to_physmap_batch(s {union add_to_physmap_extra extra = {}; +/* +* While, unlike xenmem_add_to_physmap(), this function is static, there +* still have been cases observed where xatp_permission_check(), invoked +* by our caller, doesn't lead to elimination of this entire function when +* the compile time evaluation of paging_mode_translate(d) is false. Guard +* against this be replicating the same check here. +*/
comment can be far more precise/concise.
/* In some configurations, (!HVM, COVERAGE), the xenmem_add_to_physmap_one() call doesn't succumb to dead-code-elimination. Duplicate the short-circut from xatp_permission_check() to try and help the compiler out. */
~Andrew
Quoted 41 lines · Andrew Cooper
Quoted 40 lines · Jan Beulich
Xen is heavily relying on the DCE stage to remove unused code so the linker doesn't throw an error because a function is not implemented yet we defined a prototype for it.
On some GCC versions (such as 9.4 provided by Debian sid), the compiler DCE stage will not manage to figure that out for
xenmem_add_to_physmap_batch():ld: ld: prelink.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference toxenmem_add_to_physmap_one' /xen/xen/common/memory.c:942:(.text+0x22145): relocation truncated to fit: R_X86_64_PLT32 against undefined symbolxenmem_add_to_physmap_one' prelink-efi.o: in function `xenmem_add_to_physmap_batch':
/xen/xen/common/memory.c:942: undefined reference to `xenmem_add_to_physmap_one' make[2]: *** [Makefile:215:/root/xen/xen/xen.efi] Error 1
make[2]: *** Waiting for unfinished jobs....
ld: /xen/xen/.xen-syms.0: hidden symbol `xenmem_add_to_physmap_one' isn't defined
ld: final link failed: bad valueIt is not entirely clear why the compiler DCE is not detecting the unused code. However, cloning the check introduced by the commit below into
xenmem_add_to_physmap_batch()does the trick.No functional change intended.
Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")Reported-by Oleksandr Tyshchenko <[email protected]>Signed-off-by Julien Grall <[email protected]>Signed-off-by Jan Beulich <[email protected]>Release-Acked-by Ian Jackson <[email protected]>---
Julien, since I reused most of your patch'es description, I've kept your S-o-b. Please let me know if you want me to drop it.xen/common/memory.c +0
-0@@ -904,6 +904,19 @@ static int xenmem_add_to_physmap_batch(s {union add_to_physmap_extra extra = {};
Quoted 9 lines
xen/common/memory.c static int xenmem_add_to_physmap_batch(s · line 913
Quoted 7 lines
xen/common/memory.c +7
-0+/* +* While, unlike xenmem_add_to_physmap(), this function is static, there +* still have been cases observed where xatp_permission_check(), invoked +* by our caller, doesn't lead to elimination of this entire function when +* the compile time evaluation of paging_mode_translate(d) is false. Guard +* against this be replicating the same check here. +*/ Acked-by Andrew Cooper <[email protected]>,
Thanks.
Quoted 7 lines
but I feel this
comment can be far more precise/concise./* In some configurations, (!HVM, COVERAGE), the
xenmem_add_to_physmap_one()call doesn't succumb to dead-code-elimination. Duplicate the short-circut fromxatp_permission_check()to try and help the compiler out. */
I'm perfectly fine to take this one. I have to admit though that I first needed to look up "succumb" ...
Jan