Skip to contentSkip to conversation

xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y

PATCH In review Julien Grall 3 participants 6 messages Jan 30, 2021 – Feb 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y

From: Julien Grall <[email protected]>

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 version (such as 9.4 provided by Debian sid), the compiler will DCE stage will not managed 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, moving the permission check from do_memory_op() to xenmem_add_to_physmap_batch() does the trick.

Note that this required to move the implementation of xapt_permision_check() earlier on so it can be called in xemem_add_to_physmap_batch().

No functional change intended.

Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")

---

This also resolves a randconfig issue on the gitlab CI.

The gitlab CI is used to provide basic testing on a per-series basis. So I would like to request this patch to be merged in Xen 4.15 in order to reduce the number of failure not related to the series tested.

Note that there are a few more randconfig issues that needs to be addressed.

---
 xen/common/memory.c | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)
xen/common/memory.c +21 -23
index 01cab7e4930e..b047a93a703a 100644
@@ -898,11 +898,32 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
     return rc;
 }
 
+static long xatp_permission_check(struct domain *d, unsigned int space)
+{
+    if ( !paging_mode_translate(d) )
+        return -EACCES;
+
+    /*
+     * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain
+     * to map this kind of space to itself.
+     */
+    if ( (space == XENMAPSPACE_dev_mmio) &&
+         (!is_hardware_domain(d) || (d != current->domain)) )
+        return -EACCES;
+
+    return xsm_add_to_physmap(XSM_TARGET, current->domain, d);
+}
+
 static int xenmem_add_to_physmap_batch(struct domain *d,
                                        struct xen_add_to_physmap_batch *xatpb,
                                        unsigned int extent)
 {
     union add_to_physmap_extra extra = {};
+    int rc;
+
+    rc = xatp_permission_check(d, xatpb->space);
+    if ( rc )
+        return rc;
 
     if ( unlikely(xatpb->size < extent) )
         return -EILSEQ;
@@ -1038,22 +1059,6 @@ static int get_reserved_device_memory(xen_pfn_t start, xen_ulong_t nr,
 }
 #endif
 
-static long xatp_permission_check(struct domain *d, unsigned int space)
-{
-    if ( !paging_mode_translate(d) )
-        return -EACCES;
-
-    /*
-     * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain
-     * to map this kind of space to itself.
-     */
-    if ( (space == XENMAPSPACE_dev_mmio) &&
-         (!is_hardware_domain(d) || (d != current->domain)) )
-        return -EACCES;
-
-    return xsm_add_to_physmap(XSM_TARGET, current->domain, d);
-}
-
 unsigned int ioreq_server_max_frames(const struct domain *d)
 {
     unsigned int nr = 0;
@@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 
-        rc = xatp_permission_check(d, xatpb.space);
-        if ( rc )
-        {
-            rcu_unlock_domain(d);
-            return rc;
-        }
-
         rc = xenmem_add_to_physmap_batch(d, &xatpb, start_extent);
 
         rcu_unlock_domain(d);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Julien Grall
xen/common/memory.c +0 -0
@@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1452

Quoted 10 lines
xen/common/memory.c +0 -7
-        rc = xatp_permission_check(d, xatpb.space);
-        if ( rc )
-        {
-            rcu_unlock_domain(d);
-            return rc;
-        }
-
         rc = xenmem_add_to_physmap_batch(d, &xatpb, start_extent);
 
         rcu_unlock_domain(d);

I'd be okay with the code movement if you did so consistently, i.e. also for the other invocation. I realize this would have an effect on the dm-op call of the function, but I wonder whether this wouldn't even be a good thing. If not, I think duplicating xenmem_add_to_physmap()'s early ASSERT() into xenmem_add_to_physmap_batch() would be the better course of action.

Jan

#2 lore raw

Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y [and 1 more messages]

In reply to Julien Grall

Julien Grall writes ("[PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

Quoted 3 lines

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.

Thanks for the clear explanation.

Quoted 3 lines

It is not entirely clear why the compiler DCE is not detecting the unused code. However, moving the permission check from do_memory_op() to xenmem_add_to_physmap_batch() does the trick.

How unfortunate.

Quoted 3 lines
Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")

I have reviewed the diff, but not the code in context.

Quoted 3 lines

The gitlab CI is used to provide basic testing on a per-series basis. So I would like to request this patch to be merged in Xen 4.15 in order to reduce the number of failure not related to the series tested.

Quite so.

Jan Beulich writes ("Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

Quoted 14 lines · Julien Grall
Quoted 13 lines
xen/common/memory.c +0 -7
@@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 
-        rc = xatp_permission_check(d, xatpb.space);
-        if ( rc )
-        {
-            rcu_unlock_domain(d);
-            return rc;
-        }
-
         rc = xenmem_add_to_physmap_batch(d, &xatpb, start_extent);
 
Quoted 9 lines

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1452

Quoted 1 line
xen/common/memory.c +0 -0
         rcu_unlock_domain(d);

I'd be okay with the code movement if you did so consistently, i.e. also for the other invocation. I realize this would have an effect on the dm-op call of the function, but I wonder whether this wouldn't even be a good thing. If not, I think duplicating xenmem_add_to_physmap()'s early ASSERT() into xenmem_add_to_physmap_batch() would be the better course of action.

Jan, can you confirm whether in your opinion this patch as originally posted by Julien is *correct* as is ? In particular, Julien did not intend a functional change. Have you satisfied yourself that there is no functional change here ?

I understand your objectiion above to relate to style or neatness, rather than function. Is that correct ? And that your proposed additional change would have some impact whilch would have to be assessed.

In which case I think it would be better to defer the style improvement until after the release.

IOW, the original patch

assuming a favourable functional code review from a relevant maintainer.

Thanks,
Ian.

#3 lore raw

Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y [and 1 more messages]

Quoted 50 lines · Ian Jackson

Julien Grall writes ("[PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

Quoted 3 lines

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.

Thanks for the clear explanation.

Quoted 3 lines

It is not entirely clear why the compiler DCE is not detecting the unused code. However, moving the permission check from do_memory_op() to xenmem_add_to_physmap_batch() does the trick.

How unfortunate.

Quoted 3 lines
Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")

I have reviewed the diff, but not the code in context.

Quoted 3 lines

The gitlab CI is used to provide basic testing on a per-series basis. So I would like to request this patch to be merged in Xen 4.15 in order to reduce the number of failure not related to the series tested.

Quite so.

Jan Beulich writes ("Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

Quoted 14 lines · Julien Grall
Quoted 13 lines
xen/common/memory.c +0 -7
@@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 
-        rc = xatp_permission_check(d, xatpb.space);
-        if ( rc )
-        {
-            rcu_unlock_domain(d);
-            return rc;
-        }
-
         rc = xenmem_add_to_physmap_batch(d, &xatpb, start_extent);
 
Quoted 9 lines

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1452

Quoted 1 line
xen/common/memory.c +0 -0
         rcu_unlock_domain(d);

I'd be okay with the code movement if you did so consistently, i.e. also for the other invocation. I realize this would have an effect on the dm-op call of the function, but I wonder whether this wouldn't even be a good thing. If not, I think duplicating xenmem_add_to_physmap()'s early ASSERT() into xenmem_add_to_physmap_batch() would be the better course of action.

Quoted 4 lines

Jan, can you confirm whether in your opinion this patch as originally posted by Julien is *correct* as is ? In particular, Julien did not intend a functional change. Have you satisfied yourself that there is no functional change here ?

Yes and yes.

Quoted 2 lines

I understand your objectiion above to relate to style or neatness, rather than function. Is that correct ?

Yes.

Quoted 3 lines

And that your proposed
additional change would have some impact whilch would have to be assessed.

The first of the proposed alternatives may need further investigation, yes. The second of the alternatives would shrink this patch to a 2-line one, i.e. far less code churn, and is not in need of any assessment afaia. In fact I believe this latter alternative was discussed as the approach to take here, before the patch was submitted.

Jan

Quoted 13 lines

In which case I think it would be better to defer the style improvement until after the release.

IOW, the original patch

assuming a favourable functional code review from a relevant maintainer.

Thanks,
Ian.

#4 lore raw

Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y [and 1 more messages]

Jan Beulich writes ("Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y [and 1 more messages]"):

Quoted 2 lines · Ian Jackson
Quoted 1 line

Julien Grall writes ("[PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

...

Quoted 11 lines
Quoted 4 lines

Jan, can you confirm whether in your opinion this patch as originally posted by Julien is *correct* as is ? In particular, Julien did not intend a functional change. Have you satisfied yourself that there is no functional change here ?

Yes and yes.

Quoted 2 lines

I understand your objectiion above to relate to style or neatness, rather than function. Is that correct ?

Yes.

Right, thanks.

Quoted 10 lines
Quoted 3 lines

And that your proposed
additional change would have some impact whilch would have to be assessed.

The first of the proposed alternatives may need further investigation, yes. The second of the alternatives would shrink this patch to a 2-line one, i.e. far less code churn, and is not in need of any assessment afaia. In fact I believe this latter alternative was discussed as the approach to take here, before the patch was submitted.

Sorry I missed that part. I would be happy with that other approach too, so for that approach (adding a duplicated ASSERT) is also

I'm not a huge fan of code duplication, in general. I suggest that if the ASSERT is duplicated it might be worth leaving comment(s) by each one pointing to the other.

Ian.

#5 lore raw

Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y [and 1 more messages]

In reply to Jan Beulich
Quoted 67 lines · Jan Beulich
Quoted 50 lines · Ian Jackson

Julien Grall writes ("[PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

Quoted 3 lines

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.

Thanks for the clear explanation.

Quoted 3 lines

It is not entirely clear why the compiler DCE is not detecting the unused code. However, moving the permission check from do_memory_op() to xenmem_add_to_physmap_batch() does the trick.

How unfortunate.

Quoted 3 lines
Fixes d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only")

I have reviewed the diff, but not the code in context.

Quoted 3 lines

The gitlab CI is used to provide basic testing on a per-series basis. So I would like to request this patch to be merged in Xen 4.15 in order to reduce the number of failure not related to the series tested.

Quite so.

Jan Beulich writes ("Re: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y"):

Quoted 14 lines · Julien Grall
Quoted 13 lines
xen/common/memory.c +0 -7
@@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
          if ( d == NULL )
              return -ESRCH;
 
-        rc = xatp_permission_check(d, xatpb.space);
-        if ( rc )
-        {
-            rcu_unlock_domain(d);
-            return rc;
-        }
-
          rc = xenmem_add_to_physmap_batch(d, &xatpb, start_extent);
 
Quoted 9 lines

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1452

Quoted 1 line
xen/common/memory.c +0 -0
          rcu_unlock_domain(d);

I'd be okay with the code movement if you did so consistently, i.e. also for the other invocation. I realize this would have an effect on the dm-op call of the function, but I wonder whether this wouldn't even be a good thing. If not, I think duplicating xenmem_add_to_physmap()'s early ASSERT() into xenmem_add_to_physmap_batch() would be the better course of action.

Quoted 4 lines

Jan, can you confirm whether in your opinion this patch as originally posted by Julien is *correct* as is ? In particular, Julien did not intend a functional change. Have you satisfied yourself that there is no functional change here ?

Yes and yes.

Quoted 2 lines

I understand your objectiion above to relate to style or neatness, rather than function. Is that correct ?

Yes.

Quoted 3 lines

And that your proposed
additional change would have some impact whilch would have to be assessed.

Quoted 6 lines

The first of the proposed alternatives may need further investigation, yes. The second of the alternatives would shrink this patch to a 2-line one, i.e. far less code churn, and is not in need of any assessment afaia. In fact I believe this latter alternative was discussed as the approach to take here, before the patch was submitted.

Right, I chose this approach over the one discussed previously because it doesn't duplicate the check for auto-translated domain and I couldn't really find a good way to justify it in the code (you requested one).

Regarding calling the xatp_permission_check() from xenmem_add_to_physmap(). It would means that the DM code will have two XSM check (one XSM_DM_PRIV, one XSM_TARGET). It is not clear to me whether this is going to be introducing more headache for the XSM folks.

Therefore, for Xen 4.15, I would prefer to stick with my patch.

Cheers,

Signature · 1 line
Julien Grall