All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5] x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image
@ 2018-04-18 10:26 Daniel Kiper
  2018-04-18 16:00 ` Jan Beulich
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Kiper @ 2018-04-18 10:26 UTC (permalink / raw)
  To: xen-devel; +Cc: andrew.cooper3, jbeulich

Commit 0d31d16 (x86/setup: do not relocate Xen over current Xen image
placement) disallowed src/dst images overlaps when relocating Xen image.
Though it deliberately allowed destination region between __image_base__
and (__image_base__ + XEN_IMG_OFFSET) overlaps with the end of source
image. And here is the problem. If anything between __page_tables_start
and __page_tables_end in source image lands in the overlap then some or
even all page table entries may not be updated. This usually means boom
in early boot which will be difficult to the investigate. So, I think
that we have three choices to fix the issue:
  - drop XEN_IMG_OFFSET from
    if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )
  - add XEN_IMG_OFFSET to xen_phys_start in PFN_DOWN(xen_phys_start)
    used in loops as one of conditions,
  - change PFN_DOWN(xen_phys_start) to PFN_DOWN(xen_remap_end_pfn)
    proposed in earlier version of this patch.

This patch implements the second option. This way we still allow source
and destination partial overlap as described above but PTEs are properly
updated now.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 xen/arch/x86/setup.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index b2baee3..040fd03 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1012,6 +1012,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             l3_pgentry_t *pl3e;
             l2_pgentry_t *pl2e;
             int i, j, k;
+            unsigned long pte_update_limit;
 
             /* Select relocation address. */
             e = end - reloc_size;
@@ -1019,6 +1020,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             bootsym(trampoline_xen_phys_start) = e;
 
             /*
+             * All PTEs with PFNs above pte_update_limit
+             * were updated earlier. Skip them.
+             */
+            pte_update_limit = PFN_DOWN(e + XEN_IMG_OFFSET);
+
+            /*
              * Perform relocation to new physical address.
              * Before doing so we must sync static/global data with main memory
              * with a barrier(). After this we must *not* modify static/global
@@ -1041,7 +1048,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                     /* Not present, 1GB mapping, or already relocated? */
                     if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
                          (l3e_get_flags(*pl3e) & _PAGE_PSE) ||
-                         (l3e_get_pfn(*pl3e) > PFN_DOWN(xen_phys_start)) )
+                         (l3e_get_pfn(*pl3e) > pte_update_limit) )
                         continue;
                     *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
                                             xen_phys_start);
@@ -1051,7 +1058,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                         /* Not present, PSE, or already relocated? */
                         if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ||
                              (l2e_get_flags(*pl2e) & _PAGE_PSE) ||
-                             (l2e_get_pfn(*pl2e) > PFN_DOWN(xen_phys_start)) )
+                             (l2e_get_pfn(*pl2e) > pte_update_limit) )
                             continue;
                         *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
                                                 xen_phys_start);
@@ -1075,7 +1082,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                 unsigned int flags;
 
                 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ||
-                     (l2e_get_pfn(*pl2e) > PFN_DOWN(xen_phys_start)) )
+                     (l2e_get_pfn(*pl2e) > pte_update_limit) )
                     continue;
 
                 if ( !using_2M_mapping() )
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH v5] x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image
  2018-04-18 10:26 [PATCH v5] x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image Daniel Kiper
@ 2018-04-18 16:00 ` Jan Beulich
  2018-04-19  9:28   ` Daniel Kiper
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2018-04-18 16:00 UTC (permalink / raw)
  To: Daniel Kiper; +Cc: Andrew Cooper, xen-devel

>>> On 18.04.18 at 12:26, <daniel.kiper@oracle.com> wrote:
> @@ -1019,6 +1020,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>              bootsym(trampoline_xen_phys_start) = e;
>  
>              /*
> +             * All PTEs with PFNs above pte_update_limit
> +             * were updated earlier. Skip them.
> +             */
> +            pte_update_limit = PFN_DOWN(e + XEN_IMG_OFFSET);

I don't understand the comment: No PTE updates happen before this point
afaict. It is just that PTEs pointing above that address are not candidates
for relocation. I think the comment should at least mention the overlap
scenario your trying to deal with, with the important point being that there
may actually be PTEs pointing into [e, e + XEN_IMG_OFFSET).

The actual code adjustments look fine to me now, albeit I wonder whether
>= wouldn't be more appropriate to use.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH v5] x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image
  2018-04-18 16:00 ` Jan Beulich
@ 2018-04-19  9:28   ` Daniel Kiper
  2018-04-19 12:05     ` Jan Beulich
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Kiper @ 2018-04-19  9:28 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Andrew Cooper, xen-devel

On Wed, Apr 18, 2018 at 10:00:53AM -0600, Jan Beulich wrote:
> >>> On 18.04.18 at 12:26, <daniel.kiper@oracle.com> wrote:
> > @@ -1019,6 +1020,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
> >              bootsym(trampoline_xen_phys_start) = e;
> >
> >              /*
> > +             * All PTEs with PFNs above pte_update_limit
> > +             * were updated earlier. Skip them.
> > +             */
> > +            pte_update_limit = PFN_DOWN(e + XEN_IMG_OFFSET);
>
> I don't understand the comment: No PTE updates happen before this point
> afaict. It is just that PTEs pointing above that address are not candidates
> for relocation. I think the comment should at least mention the overlap
> scenario your trying to deal with, with the important point being that there
> may actually be PTEs pointing into [e, e + XEN_IMG_OFFSET).

What do you think about that:

  All PTEs pointing above that address are not candidates for relocation.
  Due to possibility of partial overlap of the end of source image and the
  beginning of region for destination image some PTEs may point to
  addresses in range [e, e + XEN_IMG_OFFSET).

> The actual code adjustments look fine to me now, albeit I wonder whether
> >= wouldn't be more appropriate to use.

You are right. Currently first 2 MiB mapping of the image, in the worst case,
can be relocated twice. I will fix this.

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH v5] x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image
  2018-04-19  9:28   ` Daniel Kiper
@ 2018-04-19 12:05     ` Jan Beulich
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2018-04-19 12:05 UTC (permalink / raw)
  To: Daniel Kiper; +Cc: Andrew Cooper, xen-devel

>>> On 19.04.18 at 11:28, <daniel.kiper@oracle.com> wrote:
> On Wed, Apr 18, 2018 at 10:00:53AM -0600, Jan Beulich wrote:
>> >>> On 18.04.18 at 12:26, <daniel.kiper@oracle.com> wrote:
>> > @@ -1019,6 +1020,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>> >              bootsym(trampoline_xen_phys_start) = e;
>> >
>> >              /*
>> > +             * All PTEs with PFNs above pte_update_limit
>> > +             * were updated earlier. Skip them.
>> > +             */
>> > +            pte_update_limit = PFN_DOWN(e + XEN_IMG_OFFSET);
>>
>> I don't understand the comment: No PTE updates happen before this point
>> afaict. It is just that PTEs pointing above that address are not candidates
>> for relocation. I think the comment should at least mention the overlap
>> scenario your trying to deal with, with the important point being that there
>> may actually be PTEs pointing into [e, e + XEN_IMG_OFFSET).
> 
> What do you think about that:
> 
>   All PTEs pointing above that address are not candidates for relocation.
>   Due to possibility of partial overlap of the end of source image and the
>   beginning of region for destination image some PTEs may point to
>   addresses in range [e, e + XEN_IMG_OFFSET).

SGTM.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2018-04-19 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18 10:26 [PATCH v5] x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image Daniel Kiper
2018-04-18 16:00 ` Jan Beulich
2018-04-19  9:28   ` Daniel Kiper
2018-04-19 12:05     ` 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.