LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH -next,v2] efi/libstub: arm32: Use "align" for the size alignment
@ 2021-11-02 2:05 Gaosheng Cui
2021-11-04 9:26 ` Ard Biesheuvel
0 siblings, 1 reply; 4+ messages in thread
From: Gaosheng Cui @ 2021-11-02 2:05 UTC (permalink / raw)
To: ardb, cuigaosheng1; +Cc: linux-efi, linux-kernel, wangweiyang2
We are doing page-based allocations, and both the address
and size must meet alignment constraints, so using "align"
for the size alignment is a better choice.
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
drivers/firmware/efi/libstub/randomalloc.c | 2 +-
drivers/firmware/efi/libstub/relocate.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
index 724155b9e10d..7b7159bb035d 100644
--- a/drivers/firmware/efi/libstub/randomalloc.c
+++ b/drivers/firmware/efi/libstub/randomalloc.c
@@ -76,7 +76,7 @@ efi_status_t efi_random_alloc(unsigned long size,
if (align < EFI_ALLOC_ALIGN)
align = EFI_ALLOC_ALIGN;
- size = round_up(size, EFI_ALLOC_ALIGN);
+ size = round_up(size, align);
/* count the suitable slots in each memory map entry */
for (map_offset = 0; map_offset < map_size; map_offset += desc_size) {
diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c
index 8ee9eb2b9039..d6d27e8c23f8 100644
--- a/drivers/firmware/efi/libstub/relocate.c
+++ b/drivers/firmware/efi/libstub/relocate.c
@@ -50,7 +50,7 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
if (align < EFI_ALLOC_ALIGN)
align = EFI_ALLOC_ALIGN;
- size = round_up(size, EFI_ALLOC_ALIGN);
+ size = round_up(size, align);
nr_pages = size / EFI_PAGE_SIZE;
for (i = 0; i < map_size / desc_size; i++) {
efi_memory_desc_t *desc;
--
2.30.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next,v2] efi/libstub: arm32: Use "align" for the size alignment
2021-11-02 2:05 [PATCH -next,v2] efi/libstub: arm32: Use "align" for the size alignment Gaosheng Cui
@ 2021-11-04 9:26 ` Ard Biesheuvel
2021-11-08 12:48 ` cuigaosheng
2021-11-08 12:56 ` cuigaosheng
0 siblings, 2 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2021-11-04 9:26 UTC (permalink / raw)
To: Gaosheng Cui; +Cc: linux-efi, Linux Kernel Mailing List, wangweiyang2
On Tue, 2 Nov 2021 at 03:04, Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
>
> We are doing page-based allocations, and both the address
> and size must meet alignment constraints, so using "align"
> for the size alignment is a better choice.
>
Why is it a better choice? If I allocate a 2 MB aligned block of
memory, why is it better to align the size to a multiple of 2 MB as
well?
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
> drivers/firmware/efi/libstub/randomalloc.c | 2 +-
> drivers/firmware/efi/libstub/relocate.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
> index 724155b9e10d..7b7159bb035d 100644
> --- a/drivers/firmware/efi/libstub/randomalloc.c
> +++ b/drivers/firmware/efi/libstub/randomalloc.c
> @@ -76,7 +76,7 @@ efi_status_t efi_random_alloc(unsigned long size,
> if (align < EFI_ALLOC_ALIGN)
> align = EFI_ALLOC_ALIGN;
>
> - size = round_up(size, EFI_ALLOC_ALIGN);
> + size = round_up(size, align);
>
> /* count the suitable slots in each memory map entry */
> for (map_offset = 0; map_offset < map_size; map_offset += desc_size) {
> diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c
> index 8ee9eb2b9039..d6d27e8c23f8 100644
> --- a/drivers/firmware/efi/libstub/relocate.c
> +++ b/drivers/firmware/efi/libstub/relocate.c
> @@ -50,7 +50,7 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
> if (align < EFI_ALLOC_ALIGN)
> align = EFI_ALLOC_ALIGN;
>
> - size = round_up(size, EFI_ALLOC_ALIGN);
> + size = round_up(size, align);
> nr_pages = size / EFI_PAGE_SIZE;
> for (i = 0; i < map_size / desc_size; i++) {
> efi_memory_desc_t *desc;
> --
> 2.30.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next,v2] efi/libstub: arm32: Use "align" for the size alignment
2021-11-04 9:26 ` Ard Biesheuvel
@ 2021-11-08 12:48 ` cuigaosheng
2021-11-08 12:56 ` cuigaosheng
1 sibling, 0 replies; 4+ messages in thread
From: cuigaosheng @ 2021-11-08 12:48 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: linux-efi, Linux Kernel Mailing List, wangweiyang2
Hi Ard,
Thanks for your reply.
In my understanding address and size need to meet consistent alignment
constraints,If I understand wrong, please reject this patch.
Best,
GaoSheng.
在 2021/11/4 17:26, Ard Biesheuvel 写道:
> On Tue, 2 Nov 2021 at 03:04, Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
>> We are doing page-based allocations, and both the address
>> and size must meet alignment constraints, so using "align"
>> for the size alignment is a better choice.
>>
> Why is it a better choice? If I allocate a 2 MB aligned block of
> memory, why is it better to align the size to a multiple of 2 MB as
> well?
>
>
>> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
>> ---
>> drivers/firmware/efi/libstub/randomalloc.c | 2 +-
>> drivers/firmware/efi/libstub/relocate.c | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
>> index 724155b9e10d..7b7159bb035d 100644
>> --- a/drivers/firmware/efi/libstub/randomalloc.c
>> +++ b/drivers/firmware/efi/libstub/randomalloc.c
>> @@ -76,7 +76,7 @@ efi_status_t efi_random_alloc(unsigned long size,
>> if (align < EFI_ALLOC_ALIGN)
>> align = EFI_ALLOC_ALIGN;
>>
>> - size = round_up(size, EFI_ALLOC_ALIGN);
>> + size = round_up(size, align);
>>
>> /* count the suitable slots in each memory map entry */
>> for (map_offset = 0; map_offset < map_size; map_offset += desc_size) {
>> diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c
>> index 8ee9eb2b9039..d6d27e8c23f8 100644
>> --- a/drivers/firmware/efi/libstub/relocate.c
>> +++ b/drivers/firmware/efi/libstub/relocate.c
>> @@ -50,7 +50,7 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
>> if (align < EFI_ALLOC_ALIGN)
>> align = EFI_ALLOC_ALIGN;
>>
>> - size = round_up(size, EFI_ALLOC_ALIGN);
>> + size = round_up(size, align);
>> nr_pages = size / EFI_PAGE_SIZE;
>> for (i = 0; i < map_size / desc_size; i++) {
>> efi_memory_desc_t *desc;
>> --
>> 2.30.0
>>
> .
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next,v2] efi/libstub: arm32: Use "align" for the size alignment
2021-11-04 9:26 ` Ard Biesheuvel
2021-11-08 12:48 ` cuigaosheng
@ 2021-11-08 12:56 ` cuigaosheng
1 sibling, 0 replies; 4+ messages in thread
From: cuigaosheng @ 2021-11-08 12:56 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: linux-efi, Linux Kernel Mailing List, wangweiyang2
Hi Ard,
Thanks for your reply.
In my understanding address and size need to meet consistent alignment
constraints,If I understand wrong, please reject this patch.
Best,
GaoSheng.
在 2021/11/4 17:26, Ard Biesheuvel 写道:
> On Tue, 2 Nov 2021 at 03:04, Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
>> We are doing page-based allocations, and both the address
>> and size must meet alignment constraints, so using "align"
>> for the size alignment is a better choice.
>>
> Why is it a better choice? If I allocate a 2 MB aligned block of
> memory, why is it better to align the size to a multiple of 2 MB as
> well?
>
>
>> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
>> ---
>> drivers/firmware/efi/libstub/randomalloc.c | 2 +-
>> drivers/firmware/efi/libstub/relocate.c | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
>> index 724155b9e10d..7b7159bb035d 100644
>> --- a/drivers/firmware/efi/libstub/randomalloc.c
>> +++ b/drivers/firmware/efi/libstub/randomalloc.c
>> @@ -76,7 +76,7 @@ efi_status_t efi_random_alloc(unsigned long size,
>> if (align < EFI_ALLOC_ALIGN)
>> align = EFI_ALLOC_ALIGN;
>>
>> - size = round_up(size, EFI_ALLOC_ALIGN);
>> + size = round_up(size, align);
>>
>> /* count the suitable slots in each memory map entry */
>> for (map_offset = 0; map_offset < map_size; map_offset += desc_size) {
>> diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c
>> index 8ee9eb2b9039..d6d27e8c23f8 100644
>> --- a/drivers/firmware/efi/libstub/relocate.c
>> +++ b/drivers/firmware/efi/libstub/relocate.c
>> @@ -50,7 +50,7 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
>> if (align < EFI_ALLOC_ALIGN)
>> align = EFI_ALLOC_ALIGN;
>>
>> - size = round_up(size, EFI_ALLOC_ALIGN);
>> + size = round_up(size, align);
>> nr_pages = size / EFI_PAGE_SIZE;
>> for (i = 0; i < map_size / desc_size; i++) {
>> efi_memory_desc_t *desc;
>> --
>> 2.30.0
>>
> .
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-08 12:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 2:05 [PATCH -next,v2] efi/libstub: arm32: Use "align" for the size alignment Gaosheng Cui
2021-11-04 9:26 ` Ard Biesheuvel
2021-11-08 12:48 ` cuigaosheng
2021-11-08 12:56 ` cuigaosheng
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).