All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] memory: fix build with COVERAGE but !HVM
@ 2021-02-01 16:20 Jan Beulich
  2021-02-01 18:26 ` Andrew Cooper
  2021-02-01 18:26 ` Wei Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Beulich @ 2021-02-01 16:20 UTC (permalink / raw)
  To: xen-devel
  Cc: Andrew Cooper, George Dunlap, Ian Jackson, Julien Grall,
	Stefano Stabellini, Wei Liu

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.

Fixes: d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")
Reported-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
---
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.

--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -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;
 


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

* Re: [PATCH] memory: fix build with COVERAGE but !HVM
  2021-02-01 16:20 [PATCH] memory: fix build with COVERAGE but !HVM Jan Beulich
@ 2021-02-01 18:26 ` Andrew Cooper
  2021-02-02  8:28   ` Jan Beulich
  2021-02-01 18:26 ` Wei Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Cooper @ 2021-02-01 18:26 UTC (permalink / raw)
  To: Jan Beulich, xen-devel
  Cc: George Dunlap, Ian Jackson, Julien Grall, Stefano Stabellini, Wei Liu

On 01/02/2021 16:20, Jan Beulich wrote:
> 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.
>
> Fixes: d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")
> Reported-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Release-Acked-by: Ian Jackson <iwj@xenproject.org>
> ---
> 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.
>
> --- a/xen/common/memory.c
> +++ b/xen/common/memory.c
> @@ -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.
> +     */

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>, 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 from
xatp_permission_check() to try and help the compiler out. */

~Andrew


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

* Re: [PATCH] memory: fix build with COVERAGE but !HVM
  2021-02-01 16:20 [PATCH] memory: fix build with COVERAGE but !HVM Jan Beulich
  2021-02-01 18:26 ` Andrew Cooper
@ 2021-02-01 18:26 ` Wei Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2021-02-01 18:26 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel, Andrew Cooper, George Dunlap, Ian Jackson,
	Julien Grall, Stefano Stabellini, Wei Liu

On Mon, Feb 01, 2021 at 05:20:54PM +0100, Jan Beulich wrote:
> 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.
> 
> Fixes: d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")
> Reported-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Release-Acked-by: Ian Jackson <iwj@xenproject.org>

Reviewed-by: Wei Liu <wl@xen.org>


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

* Re: [PATCH] memory: fix build with COVERAGE but !HVM
  2021-02-01 18:26 ` Andrew Cooper
@ 2021-02-02  8:28   ` Jan Beulich
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2021-02-02  8:28 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: George Dunlap, Ian Jackson, Julien Grall, Stefano Stabellini,
	Wei Liu, xen-devel

On 01.02.2021 19:26, Andrew Cooper wrote:
> On 01/02/2021 16:20, Jan Beulich wrote:
>> 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.
>>
>> Fixes: d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")
>> Reported-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>> Signed-off-by: Julien Grall <jgrall@amazon.com>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> Release-Acked-by: Ian Jackson <iwj@xenproject.org>
>> ---
>> 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.
>>
>> --- a/xen/common/memory.c
>> +++ b/xen/common/memory.c
>> @@ -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.
>> +     */
> 
> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>,

Thanks.

> 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 from
> xatp_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


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

end of thread, other threads:[~2021-02-02  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 16:20 [PATCH] memory: fix build with COVERAGE but !HVM Jan Beulich
2021-02-01 18:26 ` Andrew Cooper
2021-02-02  8:28   ` Jan Beulich
2021-02-01 18:26 ` Wei Liu

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.