All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/efi: boot fix duplicated index, offset calculate operation in the copy_mapping loop
@ 2022-04-24 14:44 Paran Lee
  2022-04-25  6:02 ` Jan Beulich
  2022-04-25  6:03 ` Jan Beulich
  0 siblings, 2 replies; 3+ messages in thread
From: Paran Lee @ 2022-04-24 14:44 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Austin Kim, xen-devel

It doesn't seem necessary to do that
duplicated calculation of mfn to addr and l4 table index
in the copy_mapping loop.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
---
 xen/common/efi/boot.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index ac1b235372..7da4269c32 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -1470,7 +1470,9 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,
 
     for ( ; mfn < end; mfn = next )
     {
-        l4_pgentry_t l4e = efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)];
+        unsigned long addr = mfn << PAGE_SHIFT;
+        unsigned long l4_table_idx = l4_table_offset(addr);
+        l4_pgentry_t l4e = efi_l4t[l4_table_idx];
         unsigned long va = (unsigned long)mfn_to_virt(mfn);
 
         if ( !(mfn & ((1UL << (L4_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) )
@@ -1489,7 +1491,7 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,
 
             l3dst = alloc_mapped_pagetable(&l3mfn);
             BUG_ON(!l3dst);
-            efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)] =
+            efi_l4t[l4_table_idx] =
                 l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR);
         }
         else
@@ -1497,7 +1499,7 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,
 
         if ( !l3src )
             l3src = map_l3t_from_l4e(idle_pg_table[l4_table_offset(va)]);
-        l3dst[l3_table_offset(mfn << PAGE_SHIFT)] = l3src[l3_table_offset(va)];
+        l3dst[l3_table_offset(addr)] = l3src[l3_table_offset(va)];
     }
 
     unmap_domain_page(l3src);
-- 
2.25.1



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

* Re: [PATCH] xen/efi: boot fix duplicated index, offset calculate operation in the copy_mapping loop
  2022-04-24 14:44 [PATCH] xen/efi: boot fix duplicated index, offset calculate operation in the copy_mapping loop Paran Lee
@ 2022-04-25  6:02 ` Jan Beulich
  2022-04-25  6:03 ` Jan Beulich
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2022-04-25  6:02 UTC (permalink / raw)
  To: Paran Lee; +Cc: Austin Kim, xen-devel

On 24.04.2022 16:44, Paran Lee wrote:
> It doesn't seem necessary to do that
> duplicated calculation of mfn to addr and l4 table index
> in the copy_mapping loop.

I'm not convinced this is an improvement. If the compiler sees fit, it
can CSE things like this, but it may see reasons not to (register
pressure, for example). Furthermore ...

> --- a/xen/common/efi/boot.c
> +++ b/xen/common/efi/boot.c
> @@ -1470,7 +1470,9 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,
>  
>      for ( ; mfn < end; mfn = next )
>      {
> -        l4_pgentry_t l4e = efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)];
> +        unsigned long addr = mfn << PAGE_SHIFT;

... this isn't 32-bit clean (we build EFI for 64-bit architectures
only right now, but this should not result in there being issues if
anyone wanted to enable the code for 32-bit as well).

> +        unsigned long l4_table_idx = l4_table_offset(addr);

There's no reason I can see for this to be wider than unsigned int.

> +        l4_pgentry_t l4e = efi_l4t[l4_table_idx];
>          unsigned long va = (unsigned long)mfn_to_virt(mfn);
>  
>          if ( !(mfn & ((1UL << (L4_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) )
> @@ -1489,7 +1491,7 @@ static __init void copy_mapping(unsigned long mfn, unsigned long end,
>  
>              l3dst = alloc_mapped_pagetable(&l3mfn);
>              BUG_ON(!l3dst);
> -            efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)] =
> +            efi_l4t[l4_table_idx] =
>                  l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR);

_If_ your change was to be taken, you'd want to unwrap this statement
now that it first on a single line.

Jan



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

* Re: [PATCH] xen/efi: boot fix duplicated index, offset calculate operation in the copy_mapping loop
  2022-04-24 14:44 [PATCH] xen/efi: boot fix duplicated index, offset calculate operation in the copy_mapping loop Paran Lee
  2022-04-25  6:02 ` Jan Beulich
@ 2022-04-25  6:03 ` Jan Beulich
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2022-04-25  6:03 UTC (permalink / raw)
  To: Paran Lee; +Cc: Austin Kim, xen-devel

On 24.04.2022 16:44, Paran Lee wrote:
> It doesn't seem necessary to do that
> duplicated calculation of mfn to addr and l4 table index
> in the copy_mapping loop.
> 
> Signed-off-by: Paran Lee <p4ranlee@gmail.com>

Oh, one more thing: Please submit patches _To_ the list, with maintainers
on _Cc_ (not the other way around).

Jan



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

end of thread, other threads:[~2022-04-25  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 14:44 [PATCH] xen/efi: boot fix duplicated index, offset calculate operation in the copy_mapping loop Paran Lee
2022-04-25  6:02 ` Jan Beulich
2022-04-25  6:03 ` Jan Beulich

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.