kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ricardo Koller <ricarkol@google.com>
To: Nikos Nikoleris <nikos.nikoleris@arm.com>
Cc: kvm@vger.kernel.org, drjones@redhat.com, pbonzini@redhat.com,
	jade.alglave@arm.com, alexandru.elisei@arm.com,
	Andrew Jones <andrew.jones@linux.dev>
Subject: Re: [kvm-unit-tests PATCH v2 19/23] arm64: Use code from the gnu-efi when booting with EFI
Date: Wed, 29 Jun 2022 22:13:31 -0700	[thread overview]
Message-ID: <Yr0w+69mgp/nDXr2@google.com> (raw)
In-Reply-To: <3c501902-ba3d-209e-b563-a20547c3fe26@arm.com>

Ni Nikos,

On Mon, Jun 27, 2022 at 06:10:20PM +0100, Nikos Nikoleris wrote:
> Hi Ricardo,
> 
> Thanks for this, let me go through the idea I had. Please let me know if I
> am missing something.
> 
> On 21/06/2022 23:32, Ricardo Koller wrote:
> > On Fri, May 06, 2022 at 09:56:01PM +0100, Nikos Nikoleris wrote:
> > > arm/efi/crt0-efi-aarch64.S defines the header and the handover
> > > sequence from EFI to a efi_main. This change includes the whole file
> > > in arm/cstart64.S when we compile with EFI support.
> > > 
> > > In addition, we change the handover code in arm/efi/crt0-efi-aarch64.S
> > > to align the stack pointer. This alignment is necessary because we
> > > make assumptions about cpu0's stack alignment and most importantly we
> > > place its thread_info at the bottom of this stack.
> > > 
> > > Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
> > > ---
> > >   arm/cstart64.S             |  6 ++++++
> > >   arm/efi/crt0-efi-aarch64.S | 17 +++++++++++++++--
> > >   2 files changed, 21 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/arm/cstart64.S b/arm/cstart64.S
> > > index 55b41ea..08cf02f 100644
> > > --- a/arm/cstart64.S
> > > +++ b/arm/cstart64.S
> > > @@ -15,6 +15,10 @@
> > >   #include <asm/thread_info.h>
> > >   #include <asm/sysreg.h>
> > > +#ifdef CONFIG_EFI
> > > +#include "efi/crt0-efi-aarch64.S"
> > > +#else
> > > +
> > >   .macro zero_range, tmp1, tmp2
> > >   9998:	cmp	\tmp1, \tmp2
> > >   	b.eq	9997f
> > > @@ -107,6 +111,8 @@ start:
> > >   	bl	exit
> > >   	b	halt
> > > +#endif
> > > +
> > >   .text
> > >   /*
> > > diff --git a/arm/efi/crt0-efi-aarch64.S b/arm/efi/crt0-efi-aarch64.S
> > > index d50e78d..11a062d 100644
> > > --- a/arm/efi/crt0-efi-aarch64.S
> > > +++ b/arm/efi/crt0-efi-aarch64.S
> > > @@ -111,10 +111,19 @@ section_table:
> > >   	.align		12
> > >   _start:
> > > -	stp		x29, x30, [sp, #-32]!
> > > +	stp		x29, x30, [sp, #-16]!
> > 
> > Is this and the "ldp x29, x30, [sp], #16" change below needed?
> > why is #-32 not good?
> > 
> 
> The stack is full-descending. Here we make space for x29 and x30 in the
> stack (16bytes) and save the two registers
> 

Got it, was thinking mainly in terms of optimizing for less changes.
But I see your point; plus it makes the restoring simpler.

> > > +
> > > +	// Align sp; this is necessary due to way we store cpu0's thread_info
> > 
> > /* */ comment style
> > 
> 
> ack
> 
> > >   	mov		x29, sp
> > > +	and		x29, x29, #THREAD_MASK
> > > +	mov		x30, sp
> > > +	mov		sp, x29
> > > +	str		x30, [sp, #-32]!
> > > +
> 
> Here we're making space in the stack for the old sp (x30), x0 and x1 but we
> have to also ensure that the sp is aligned (32bytes). The we store x30.
> 
> (As a side note, I could also change this to
> 
> +	str		x30, [sp, #-16]!
> 
> and change the next stp to do pre-incrementing mode. This might make things
> simpler.)

Definitely, it would look like two regular pushes.

> 
> > > +	mov             x29, sp
> > >   	stp		x0, x1, [sp, #16]
> > > +
> 
> Here, we use the space we made before to store x0 and x1.
> 
> I think, the stack now should look like:
> 
>        |   ...  |
>        |   x30  |
>        |   x29  |

possibly some more extra space due to #THREAD_MASK

>        |   x1   |
>        |   x0   |
>        |   pad  |
> sp ->  | old_sp |

Thanks for this!

> 
> 
> > >   	mov		x2, x0
> > >   	mov		x3, x1
> > >   	adr		x0, ImageBase
> > > @@ -126,5 +135,9 @@ _start:
> > >   	ldp		x0, x1, [sp, #16]
> > >   	bl		efi_main
> > > -0:	ldp		x29, x30, [sp], #32
> > > +	// Restore sp
> > 
> > /* */ comment style
> 
> ack
> 
> > 
> > > +	ldr		x30, [sp]
> 
> I think this should have been:
> 
> +	ldr		x30, [sp], #32
> 
> Restore x30 from the current sp and free up space in the stack (all
> 32bytes).
> 

Now I get it. That's not needed actually, as you are restoring sp from
old_sp below to this address:

          |   ...  |
          |   x30  |
sp ->     |   x29  |

(old_sp was the sp after pushing x29,x30)

> > 
> > I'm not able to understand this. Is this ldr restoring the value pushed
> > with "str x30, [sp, #-32]!" above? in that case, shouldn't this be at
> > [sp - 32]? But, given that this code is unreachable when efi_main is
> > called, do you even need to restore the sp?
> > 
> > > +	mov             sp, x30
> > > +
> > > +0:	ldp		x29, x30, [sp], #16
> 
> Then, this restores x29 and x30 and frees up the the corresponding space in
> the stack.
> 
> 
> I am not sure we shouldn't get to this point and I wanted to properly save
> and restore the register state. I haven't really found what's the right/best
> way to exit from an EFI app and I wanted to allow for graceful return from
> this point. But I am happy to change all this.

Yes, let's keep it just in case.

> 
> Thanks,
> 
> Nikos
> 
> > >   	ret
> > > -- 
> > > 2.25.1
> > > 

Thanks!
Ricardo

  reply	other threads:[~2022-06-30  5:13 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06 20:55 [kvm-unit-tests PATCH v2 00/23] EFI and ACPI support for arm64 Nikos Nikoleris
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 01/23] lib: Move acpi header and implementation to lib Nikos Nikoleris
2022-05-19 13:21   ` Andrew Jones
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 02/23] lib: Ensure all struct definition for ACPI tables are packed Nikos Nikoleris
2022-05-19 13:17   ` Andrew Jones
2022-05-19 15:52     ` Nikos Nikoleris
2022-05-19 17:14       ` Andrew Jones
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 03/23] lib: Add support for the XSDT ACPI table Nikos Nikoleris
2022-05-19 13:30   ` Andrew Jones
2022-06-18  0:38   ` Ricardo Koller
2022-06-20  8:53     ` Alexandru Elisei
2022-06-20 11:06       ` Nikos Nikoleris
2022-06-21 12:25         ` Alexandru Elisei
2022-06-21 11:26     ` Nikos Nikoleris
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 04/23] lib: Extend the definition of the ACPI table FADT Nikos Nikoleris
2022-05-19 13:42   ` Andrew Jones
2022-06-18  1:00   ` Ricardo Koller
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 05/23] arm/arm64: Add support for setting up the PSCI conduit through ACPI Nikos Nikoleris
2022-05-19 13:54   ` Andrew Jones
2022-06-21 16:06   ` Ricardo Koller
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 06/23] arm/arm64: Add support for discovering the UART " Nikos Nikoleris
2022-05-19 13:59   ` Andrew Jones
2022-06-21 16:07   ` Ricardo Koller
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 07/23] arm/arm64: Add support for timer initialization " Nikos Nikoleris
2022-05-19 14:10   ` Andrew Jones
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 08/23] arm/arm64: Add support for cpu " Nikos Nikoleris
2022-05-19 14:23   ` Andrew Jones
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 09/23] lib/printf: Support for precision modifier in printing strings Nikos Nikoleris
2022-05-19 14:52   ` Andrew Jones
2022-05-19 16:02     ` Andrew Jones
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 10/23] lib/printf: Add support for printing wide strings Nikos Nikoleris
2022-06-21 16:11   ` Ricardo Koller
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 11/23] lib/efi: Add support for getting the cmdline Nikos Nikoleris
2022-06-21 16:33   ` Ricardo Koller
2022-06-27 16:12     ` Nikos Nikoleris
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 12/23] arm/arm64: mmu_disable: Clean and invalidate before disabling Nikos Nikoleris
2022-05-13 13:15   ` Alexandru Elisei
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 13/23] arm/arm64: Rename etext to _etext Nikos Nikoleris
2022-06-21 16:42   ` Ricardo Koller
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 14/23] lib: Avoid ms_abi for calls related to EFI on arm64 Nikos Nikoleris
2022-05-20 14:02   ` Andrew Jones
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 15/23] arm64: Add a new type of memory type flag MR_F_RESERVED Nikos Nikoleris
2022-06-21 16:44   ` Ricardo Koller
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 16/23] arm/arm64: Add a setup sequence for systems that boot through EFI Nikos Nikoleris
2022-05-13 13:31   ` Alexandru Elisei
2022-06-27 16:36     ` Nikos Nikoleris
2022-05-06 20:55 ` [kvm-unit-tests PATCH v2 17/23] arm64: Copy code from GNU-EFI Nikos Nikoleris
2022-06-21 17:59   ` Ricardo Koller
2022-05-06 20:56 ` [kvm-unit-tests PATCH v2 18/23] arm64: Change gnu-efi imported file to use defined types Nikos Nikoleris
2022-05-06 20:56 ` [kvm-unit-tests PATCH v2 19/23] arm64: Use code from the gnu-efi when booting with EFI Nikos Nikoleris
2022-06-21 22:32   ` Ricardo Koller
2022-06-27 17:10     ` Nikos Nikoleris
2022-06-30  5:13       ` Ricardo Koller [this message]
2022-05-06 20:56 ` [kvm-unit-tests PATCH v2 20/23] lib: Avoid external dependency in libelf Nikos Nikoleris
2022-06-21 22:39   ` Ricardo Koller
2022-05-06 20:56 ` [kvm-unit-tests PATCH v2 21/23] x86: Move x86_64-specific EFI CFLAGS to x86_64 Makefile Nikos Nikoleris
2022-06-21 22:45   ` Ricardo Koller
2022-06-22 13:47     ` Nikos Nikoleris
2022-05-06 20:56 ` [kvm-unit-tests PATCH v2 22/23] arm64: Add support for efi in Makefile Nikos Nikoleris
2022-06-21 22:51   ` Ricardo Koller
2022-06-22 13:52     ` Nikos Nikoleris
2022-06-21 22:52   ` Ricardo Koller
2022-05-06 20:56 ` [kvm-unit-tests PATCH v2 23/23] arm64: Add an efi/run script Nikos Nikoleris
2022-06-21 23:09   ` Ricardo Koller
2022-06-22 14:13     ` Nikos Nikoleris
2022-06-30  5:22       ` Ricardo Koller
2022-05-13 14:09 ` [kvm-unit-tests PATCH v2 00/23] EFI and ACPI support for arm64 Alexandru Elisei
2022-05-18  9:00   ` Nikos Nikoleris
2022-05-20  9:58     ` Alexandru Elisei
2022-05-17 17:56 ` Ricardo Koller
2022-05-18 12:44   ` Nikos Nikoleris
2022-05-18 16:10     ` Ricardo Koller

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=Yr0w+69mgp/nDXr2@google.com \
    --to=ricarkol@google.com \
    --cc=alexandru.elisei@arm.com \
    --cc=andrew.jones@linux.dev \
    --cc=drjones@redhat.com \
    --cc=jade.alglave@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=nikos.nikoleris@arm.com \
    --cc=pbonzini@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).