All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alejandro Vallejo" <alejandro.vallejo@cloud.com>
To: "Frediano Ziglio" <frediano.ziglio@cloud.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>
Cc: xen-devel@lists.xenproject.org, "Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [PATCH v3 5/5] x86/boot: Clarify comment
Date: Fri, 11 Oct 2024 16:06:25 +0100	[thread overview]
Message-ID: <D4T2JEKDK7KE.6N9GUPZMAVPC@cloud.com> (raw)
In-Reply-To: <CACHz=ZgRPEWYK8hh-mi+308gYEBbzq=aUE6ic8O1ONeV29-5mQ@mail.gmail.com>

On Fri Oct 11, 2024 at 2:58 PM BST, Frediano Ziglio wrote:
> On Fri, Oct 11, 2024 at 2:38 PM Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> >
> > On 11/10/2024 2:28 pm, Alejandro Vallejo wrote:
> > > On Fri, Oct 11, 2024 at 02:08:37PM +0100, Frediano Ziglio wrote:
> > >> On Fri, Oct 11, 2024 at 1:56 PM Alejandro Vallejo
> > >> <alejandro.vallejo@cloud.com> wrote:
> > >>> On Fri, Oct 11, 2024 at 09:52:44AM +0100, Frediano Ziglio wrote:
> > >>>> Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
> > >>>> ---
> > >>>>  xen/arch/x86/boot/reloc.c | 2 +-
> > >>>>  1 file changed, 1 insertion(+), 1 deletion(-)
> > >>>>
> > >>>> diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
> > >>>> index e50e161b27..e725cfb6eb 100644
> > >>>> --- a/xen/arch/x86/boot/reloc.c
> > >>>> +++ b/xen/arch/x86/boot/reloc.c
> > >>>> @@ -65,7 +65,7 @@ typedef struct memctx {
> > >>>>      /*
> > >>>>       * Simple bump allocator.
> > >>>>       *
> > >>>> -     * It starts from the base of the trampoline and allocates downwards.
> > >>>> +     * It starts on top of space reserved for the trampoline and allocates downwards.
> > >>> nit: Not sure this is much clearer. The trampoline is not a stack (and even if
> > >>> it was, I personally find "top" and "bottom" quite ambiguous when it grows
> > >>> backwards), so calling top to its lowest address seems more confusing than not.
> > >>>
> > >>> If anything clarification ought to go in the which direction it takes. Leaving
> > >>> "base" instead of "top" and replacing "downwards" by "backwards" to make it
> > >>> crystal clear that it's a pointer that starts where the trampoline starts, but
> > >>> moves in the opposite direction.
> > >>>
> > >> Base looks confusing to me, but surely that comment could be confusing.
> > >> For the trampoline 64 KB are reserved. Last 4 KB are used as a normal
> > >> stack (push/pop/call/whatever), first part gets a copy of the
> > >> trampoline code/data (about 6 Kb) the rest (so 64 - 4 - ~6 = ~54 kb)
> > >> is used for the copy of MBI information. That "rest" is what we are
> > >> talking about here.
> > > Last? From what I looked at it seems to be the first 12K.
> > >
> > >    #define TRAMPOLINE_STACK_SPACE  PAGE_SIZE
> > >    #define TRAMPOLINE_SPACE        (KB(64) - TRAMPOLINE_STACK_SPACE)
> > >
> > > To put it another way, with left=lo-addr and right=hi-addr. The code seems to
> > > do this...
> > >
> > >  |<--------------64K-------------->|
> > >  |<-----12K--->|                   |

s/12K/4K/

My brain merged the 12bits in the wrong place. Too much bit twiddling.

> > >  +-------------+-----+-------------+
> > >  | stack-space | mbi | trampoline  |
> > >  +-------------+-----+-------------+
> > >                ^  ^
> > >                |  |
> > >                |  +-- copied Multiboot info + modules
> > >                +----- initial memctx.ptr
> > >
> > > ... with the stack growing backwards to avoid overflowing onto mbi.
> > >
> > > Or am I missing something?
> >
> > So I was hoping for some kind of diagram like this, to live in
> > arch/x86/include/asm/trampoline.h with the other notes about the trampoline.
> >
> > But, is that diagram accurate?  Looking at
>
>        /* Switch to low-memory stack which lives at the end of
> trampoline region. */
>        mov     sym_esi(trampoline_phys), %edi
>        lea     TRAMPOLINE_SPACE+TRAMPOLINE_STACK_SPACE(%edi),%esp
>        lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax
>        pushl   $BOOT_CS32
>        push    %eax
>
>        /* Copy bootstrap trampoline to low memory, below 1MB. */
>        lea     sym_esi(trampoline_start), %esi
>        mov     $((trampoline_end - trampoline_start) / 4),%ecx
>        rep movsl
>
> So, from low to high
> - trampoline code/data (%edi at beginning of copy is trampoline_phys,
> %esi is trampoline_start)
> - space (used for MBI copy)
> - stack (%esp is set to trampoline_phys + TRAMPOLINE_SPACE +
> TRAMPOLINE_STACK_SPACE)
>
> Frediano

So it's reversed from what I thought

 |<--------------64K-------------->|
 |                   |<-----4K---->|
 +-------------+-----+-------------+
 |  text-(ish) | mbi | stack-space |
 +-------------+-----+-------------+
                  ^                ^
                  |                |
                  |                +-- initial memctx.ptr
                  +------------------- copied Multiboot info + modules


Your version of the comment is a definite improvement over the nonsense that
was there before. Sorry for the noise :)

Cheers,
Alejandro


  reply	other threads:[~2024-10-11 15:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11  8:52 [PATCH v3 0/5] Reuse 32 bit C code more safely Frediano Ziglio
2024-10-11  8:52 ` [PATCH v3 1/5] x86/boot: create a C bundle for 32 bit boot code and use it Frediano Ziglio
2024-10-11 10:57   ` [Makefile only] " Andrew Cooper
2024-10-11 13:17   ` [python] " Andrew Cooper
2024-10-11 13:53     ` Frediano Ziglio
2024-10-11 13:20   ` Jan Beulich
2024-10-11 13:21     ` Andrew Cooper
2024-10-11  8:52 ` [PATCH v3 2/5] x86/boot: Reuse code to relocate trampoline Frediano Ziglio
2024-10-11 12:02   ` Andrew Cooper
2024-10-11 12:50   ` Jan Beulich
2024-10-11  8:52 ` [PATCH v3 3/5] x86/boot: Use boot_vid_info variable directly from C code Frediano Ziglio
2024-10-11 12:07   ` Andrew Cooper
2024-10-11  8:52 ` [PATCH v3 4/5] x86/boot: Use trampoline_phys " Frediano Ziglio
2024-10-11 12:05   ` Andrew Cooper
2024-10-11  8:52 ` [PATCH v3 5/5] x86/boot: Clarify comment Frediano Ziglio
2024-10-11 12:56   ` Alejandro Vallejo
2024-10-11 13:08     ` Frediano Ziglio
2024-10-11 13:28       ` Alejandro Vallejo
2024-10-11 13:38         ` Andrew Cooper
2024-10-11 13:58           ` Frediano Ziglio
2024-10-11 15:06             ` Alejandro Vallejo [this message]
2024-10-11 16:07               ` Andrew Cooper
2024-10-11 14:06           ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D4T2JEKDK7KE.6N9GUPZMAVPC@cloud.com \
    --to=alejandro.vallejo@cloud.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=frediano.ziglio@cloud.com \
    --cc=jbeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.