public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Nikos Nikoleris <nikos.nikoleris@arm.com>
To: Andrew Jones <andrew.jones@linux.dev>
Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev,
	alexandru.elisei@arm.com, eric.auger@redhat.com,
	shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com
Subject: Re: [kvm-unit-tests PATCH v2 13/18] arm64: Simplify efi_mem_init
Date: Mon, 4 Mar 2024 10:01:51 +0000	[thread overview]
Message-ID: <cc7ed07d-d08f-4b0d-b642-bfaf4fbafdb1@arm.com> (raw)
In-Reply-To: <20240304-9cc10a0c64d1723d3c203cf2@orel>

On 04/03/2024 09:55, Andrew Jones wrote:
> On Mon, Mar 04, 2024 at 08:10:40AM +0000, Nikos Nikoleris wrote:
>> On 27/02/2024 19:21, Andrew Jones wrote:
>>> Reduce the EFI mem_map loop to only setting flags and finding the
>>> largest free memory region. Then, apply memregions_split() for
>>> the code/data region split and do the rest of the things that
>>> used to be done in the EFI mem_map loop in a separate mem_region
>>> loop.
>>>
>>> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
>>
>> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
> 
> Thanks. While skimming this patch now to remind myself about it for v3,
> I see the etext = ALIGN() below which I forgot to consider. We certainly
> need the end of the text section to be on a page boundary, but that
> doesn't seem to be the case right now. I think we need to add this
> change

I missed and it didn't manifest in any of the runs I did. However, it 
makes sense.

Thanks,

Nikos

> 
> diff --git a/arm/efi/elf_aarch64_efi.lds b/arm/efi/elf_aarch64_efi.lds
> index 836d98255d88..7a4192b77900 100644
> --- a/arm/efi/elf_aarch64_efi.lds
> +++ b/arm/efi/elf_aarch64_efi.lds
> @@ -13,6 +13,7 @@ SECTIONS
>       *(.rodata*)
>       . = ALIGN(16);
>     }
> +  . = ALIGN(4096);
>     _etext = .;
>     _text_size = . - _text;
>     .dynamic  : { *(.dynamic) }
> 
> Thanks,
> drew
> 
>>
>> Thanks,
>>
>> Nikos
>>
>>> ---
>>>    lib/arm/setup.c | 45 ++++++++++++++++++++-------------------------
>>>    1 file changed, 20 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/lib/arm/setup.c b/lib/arm/setup.c
>>> index d0be4c437708..631597b343f1 100644
>>> --- a/lib/arm/setup.c
>>> +++ b/lib/arm/setup.c
>>> @@ -301,9 +301,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
>>>    	struct efi_boot_memmap *map = &(efi_bootinfo->mem_map);
>>>    	efi_memory_desc_t *buffer = *map->map;
>>>    	efi_memory_desc_t *d = NULL;
>>> -	struct mem_region r;
>>> -	uintptr_t text = (uintptr_t)&_text, etext = ALIGN((uintptr_t)&_etext, 4096);
>>> -	uintptr_t data = (uintptr_t)&_data, edata = ALIGN((uintptr_t)&_edata, 4096);
>>> +	struct mem_region r, *code, *data;
>>>    	const void *fdt = efi_bootinfo->fdt;
>>>    	/*
>>> @@ -337,21 +335,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
>>>    			r.flags = MR_F_IO;
>>>    			break;
>>>    		case EFI_LOADER_CODE:
>>> -			if (r.start <= text && r.end > text) {
>>> -				/* This is the unit test region. Flag the code separately. */
>>> -				phys_addr_t tmp = r.end;
>>> -
>>> -				assert(etext <= data);
>>> -				assert(edata <= r.end);
>>> -				r.flags = MR_F_CODE;
>>> -				r.end = data;
>>> -				memregions_add(&r);
>>> -				r.start = data;
>>> -				r.end = tmp;
>>> -				r.flags = 0;
>>> -			} else {
>>> -				r.flags = MR_F_RESERVED;
>>> -			}
>>> +			r.flags = MR_F_CODE;
>>>    			break;
>>>    		case EFI_CONVENTIONAL_MEMORY:
>>>    			if (free_mem_pages < d->num_pages) {
>>> @@ -361,15 +345,27 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
>>>    			break;
>>>    		}
>>> -		if (!(r.flags & MR_F_IO)) {
>>> -			if (r.start < __phys_offset)
>>> -				__phys_offset = r.start;
>>> -			if (r.end > __phys_end)
>>> -				__phys_end = r.end;
>>> -		}
>>>    		memregions_add(&r);
>>>    	}
>>> +	memregions_split((unsigned long)&_etext, &code, &data);
>>> +	assert(code && (code->flags & MR_F_CODE));
>>> +	if (data)
>>> +		data->flags &= ~MR_F_CODE;
>>> +
>>> +	for (struct mem_region *m = mem_regions; m->end; ++m) {
>>> +		if (m != code && (m->flags & MR_F_CODE))
>>> +			m->flags = MR_F_RESERVED;
>>> +
>>> +		if (!(m->flags & MR_F_IO)) {
>>> +			if (m->start < __phys_offset)
>>> +				__phys_offset = m->start;
>>> +			if (m->end > __phys_end)
>>> +				__phys_end = m->end;
>>> +		}
>>> +	}
>>> +	__phys_end &= PHYS_MASK;
>>> +
>>>    	if (efi_bootinfo->fdt_valid) {
>>>    		unsigned long old_start = free_mem_start;
>>>    		void *freemem = (void *)free_mem_start;
>>> @@ -380,7 +376,6 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
>>>    		free_mem_pages = (free_mem_start - old_start) >> EFI_PAGE_SHIFT;
>>>    	}
>>> -	__phys_end &= PHYS_MASK;
>>>    	asm_mmu_disable();
>>>    	if (free_mem_pages == 0)

  reply	other threads:[~2024-03-04 10:01 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 19:21 [kvm-unit-tests PATCH v2 00/18] arm64: EFI improvements Andrew Jones
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 01/18] runtime: Update MAX_SMP probe Andrew Jones
2024-03-03 21:43   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 02/18] runtime: Add yet another 'no kernel' error message Andrew Jones
2024-03-03 21:50   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 03/18] arm64: efi: Don't create dummy test Andrew Jones
2024-03-03 21:57   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 04/18] arm64: efi: Make running tests on EFI can be parallel Andrew Jones
2024-03-03 22:06   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 05/18] arm64: efi: Remove redundant dtb generation Andrew Jones
2024-03-04  7:16   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 06/18] arm64: efi: Move run code into a function Andrew Jones
2024-03-04  7:19   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 07/18] arm64: efi: Remove EFI_USE_DTB Andrew Jones
2024-03-04  7:20   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 08/18] arm64: efi: Improve device tree discovery Andrew Jones
2024-03-04  7:34   ` Nikos Nikoleris
2024-03-04  9:35     ` Andrew Jones
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 09/18] lib/efi: Add support for loading the initrd Andrew Jones
2024-03-04  7:44   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 10/18] arm64: efi: Allow running tests directly Andrew Jones
2024-03-04  7:52   ` Nikos Nikoleris
2024-03-04  9:43     ` Andrew Jones
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 11/18] arm/arm64: Factor out some initial setup Andrew Jones
2024-03-04  7:59   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 12/18] arm/arm64: Factor out allocator init from mem_init Andrew Jones
2024-03-04  8:01   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 13/18] arm64: Simplify efi_mem_init Andrew Jones
2024-03-04  8:10   ` Nikos Nikoleris
2024-03-04  9:55     ` Andrew Jones
2024-03-04 10:01       ` Nikos Nikoleris [this message]
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 14/18] arm64: Add memregions_efi_init Andrew Jones
2024-03-04  8:16   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 15/18] arm64: efi: Don't map reserved regions Andrew Jones
2024-03-04  8:18   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 16/18] arm64: efi: Fix _start returns from failed _relocate Andrew Jones
2024-03-04  8:58   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 17/18] arm64: efi: Switch to our own stack Andrew Jones
2024-03-04  9:03   ` Nikos Nikoleris
2024-02-27 19:21 ` [kvm-unit-tests PATCH v2 18/18] arm64: efi: Add gitlab CI Andrew Jones
2024-03-04  9:06   ` Nikos Nikoleris

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=cc7ed07d-d08f-4b0d-b642-bfaf4fbafdb1@arm.com \
    --to=nikos.nikoleris@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=andrew.jones@linux.dev \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=shahuang@redhat.com \
    --cc=thuth@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