From: Baoquan He <bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
Cc: mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org,
hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org,
izumi.taku-+CUm20s59erQFUHtdCDX3A@public.gmane.org,
fanc.fnst-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org,
thgarnie-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
n-horiguchi-PaJj6Psr51x8UrSeD/g0lQ@public.gmane.org,
ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Subject: Re: [PATCH v9 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor
Date: Wed, 16 Aug 2017 21:18:41 +0800 [thread overview]
Message-ID: <20170816131841.GE21273@x1> (raw)
In-Reply-To: <20170816113726.GA3384-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
On 08/16/17 at 12:37pm, Matt Fleming wrote:
> On Mon, 14 Aug, at 10:54:23PM, Baoquan He wrote:
> > The existing map iteration helper for_each_efi_memory_desc_in_map can
> > only be used after OS initializes EFI to fill data of struct efi_memory_map.
>
> Should this say "EFI subsystem"? The firmware doesn't care about the
> kernel's internal data structures.
Sounds reasonable. Let me update and maybe repost to this thread
directly. Thanks!
>
> > Before that we also need iterate map descriptors which are stored in several
> > intermediate structures, like struct efi_boot_memmap for arch independent
> > usage and struct efi_info for x86 arch only.
> >
> > Introduce efi_early_memdesc_ptr to get pointer to a map descriptor, and
> > replace several places of open code with it.
> >
> > Suggested-by: Ingo Molnar <mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > Signed-off-by: Baoquan He <bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> > ---
> > arch/x86/boot/compressed/eboot.c | 2 +-
> > drivers/firmware/efi/libstub/efi-stub-helper.c | 4 ++--
> > include/linux/efi.h | 21 +++++++++++++++++++++
> > 3 files changed, 24 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
> > index c3e869eaef0c..e007887a33b0 100644
> > --- a/arch/x86/boot/compressed/eboot.c
> > +++ b/arch/x86/boot/compressed/eboot.c
> > @@ -767,7 +767,7 @@ static efi_status_t setup_e820(struct boot_params *params,
> > m |= (u64)efi->efi_memmap_hi << 32;
> > #endif
> >
> > - d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
> > + d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
> > switch (d->type) {
> > case EFI_RESERVED_TYPE:
> > case EFI_RUNTIME_SERVICES_CODE:
> > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > index b0184360efc6..50a9cab5a834 100644
> > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > @@ -205,7 +205,7 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
> > unsigned long m = (unsigned long)map;
> > u64 start, end;
> >
> > - desc = (efi_memory_desc_t *)(m + (i * desc_size));
> > + desc = efi_early_memdesc_ptr(m, desc_size, i);
> > if (desc->type != EFI_CONVENTIONAL_MEMORY)
> > continue;
> >
> > @@ -298,7 +298,7 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
> > unsigned long m = (unsigned long)map;
> > u64 start, end;
> >
> > - desc = (efi_memory_desc_t *)(m + (i * desc_size));
> > + desc = efi_early_memdesc_ptr(m, desc_size, i);
> >
> > if (desc->type != EFI_CONVENTIONAL_MEMORY)
> > continue;
> > diff --git a/include/linux/efi.h b/include/linux/efi.h
> > index 8269bcb8ccf7..9783d9e4a4b2 100644
> > --- a/include/linux/efi.h
> > +++ b/include/linux/efi.h
> > @@ -1020,6 +1020,27 @@ extern int efi_memattr_init(void);
> > extern int efi_memattr_apply_permissions(struct mm_struct *mm,
> > efi_memattr_perm_setter fn);
> >
> > +/*
> > + * efi_early_memdesc_ptr - get the n-th efi memmap descriptor
> > + * @map: the start of efi memmap
> > + * @desc_size: the size of space for each efi memmap descriptor
> > + * @n: the index of efi memmap descriptor
> > + *
> > + * EFI boot service provides function GetMemoryMap() to get a copy of the
> > + * current memory map which is an array of memory descriptors, each of
> > + * which describes a contiguous block of memory. And also get the size of
> > + * map, and the size of each descriptor, etc. Note that per section 6.2 of
> > + * UEFI Spec 2.6 Errata A, the returned size of each descriptor might not
> > + * be equal to sizeof(efi_memory_memdesc_t) since efi_memory_memdesc_t may
> > + * be extended in the future in response to hardware innovation. Thus OS
> > + * MUST use the returned size of descriptor to find the start of each
> > + * efi_memory_memdesc_t in the memory map array. This should only be used
> > + * during bootup since for_each_efi_memory_desc_xxx is suggested after OS
> > + * initializes EFI to fill data of struct efi_memory_map.
> > + */
>
> Again, please use "EFI subsystem" here.
Sure, will do.
>
> > +#define efi_early_memdesc_ptr(map, desc_size, n) \
> > + (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
> > +
> > /* Iterate through an efi_memory_map */
> > #define for_each_efi_memory_desc_in_map(m, md) \
> > for ((md) = (m)->map; \
>
> Otherwise, this looks OK to me.
Thanks for reviewing!
WARNING: multiple messages have this Message-ID (diff)
From: Baoquan He <bhe@redhat.com>
To: Matt Fleming <matt@codeblueprint.co.uk>
Cc: mingo@kernel.org, linux-kernel@vger.kernel.org,
keescook@chromium.org, tglx@linutronix.de, hpa@zytor.com,
izumi.taku@jp.fujitsu.com, fanc.fnst@cn.fujitsu.com,
thgarnie@google.com, n-horiguchi@ah.jp.nec.com,
ard.biesheuvel@linaro.org, linux-efi@vger.kernel.org,
x86@kernel.org
Subject: Re: [PATCH v9 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor
Date: Wed, 16 Aug 2017 21:18:41 +0800 [thread overview]
Message-ID: <20170816131841.GE21273@x1> (raw)
In-Reply-To: <20170816113726.GA3384@codeblueprint.co.uk>
On 08/16/17 at 12:37pm, Matt Fleming wrote:
> On Mon, 14 Aug, at 10:54:23PM, Baoquan He wrote:
> > The existing map iteration helper for_each_efi_memory_desc_in_map can
> > only be used after OS initializes EFI to fill data of struct efi_memory_map.
>
> Should this say "EFI subsystem"? The firmware doesn't care about the
> kernel's internal data structures.
Sounds reasonable. Let me update and maybe repost to this thread
directly. Thanks!
>
> > Before that we also need iterate map descriptors which are stored in several
> > intermediate structures, like struct efi_boot_memmap for arch independent
> > usage and struct efi_info for x86 arch only.
> >
> > Introduce efi_early_memdesc_ptr to get pointer to a map descriptor, and
> > replace several places of open code with it.
> >
> > Suggested-by: Ingo Molnar <mingo@kernel.org>
> > Signed-off-by: Baoquan He <bhe@redhat.com>
> > ---
> > arch/x86/boot/compressed/eboot.c | 2 +-
> > drivers/firmware/efi/libstub/efi-stub-helper.c | 4 ++--
> > include/linux/efi.h | 21 +++++++++++++++++++++
> > 3 files changed, 24 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
> > index c3e869eaef0c..e007887a33b0 100644
> > --- a/arch/x86/boot/compressed/eboot.c
> > +++ b/arch/x86/boot/compressed/eboot.c
> > @@ -767,7 +767,7 @@ static efi_status_t setup_e820(struct boot_params *params,
> > m |= (u64)efi->efi_memmap_hi << 32;
> > #endif
> >
> > - d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
> > + d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
> > switch (d->type) {
> > case EFI_RESERVED_TYPE:
> > case EFI_RUNTIME_SERVICES_CODE:
> > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > index b0184360efc6..50a9cab5a834 100644
> > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > @@ -205,7 +205,7 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
> > unsigned long m = (unsigned long)map;
> > u64 start, end;
> >
> > - desc = (efi_memory_desc_t *)(m + (i * desc_size));
> > + desc = efi_early_memdesc_ptr(m, desc_size, i);
> > if (desc->type != EFI_CONVENTIONAL_MEMORY)
> > continue;
> >
> > @@ -298,7 +298,7 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
> > unsigned long m = (unsigned long)map;
> > u64 start, end;
> >
> > - desc = (efi_memory_desc_t *)(m + (i * desc_size));
> > + desc = efi_early_memdesc_ptr(m, desc_size, i);
> >
> > if (desc->type != EFI_CONVENTIONAL_MEMORY)
> > continue;
> > diff --git a/include/linux/efi.h b/include/linux/efi.h
> > index 8269bcb8ccf7..9783d9e4a4b2 100644
> > --- a/include/linux/efi.h
> > +++ b/include/linux/efi.h
> > @@ -1020,6 +1020,27 @@ extern int efi_memattr_init(void);
> > extern int efi_memattr_apply_permissions(struct mm_struct *mm,
> > efi_memattr_perm_setter fn);
> >
> > +/*
> > + * efi_early_memdesc_ptr - get the n-th efi memmap descriptor
> > + * @map: the start of efi memmap
> > + * @desc_size: the size of space for each efi memmap descriptor
> > + * @n: the index of efi memmap descriptor
> > + *
> > + * EFI boot service provides function GetMemoryMap() to get a copy of the
> > + * current memory map which is an array of memory descriptors, each of
> > + * which describes a contiguous block of memory. And also get the size of
> > + * map, and the size of each descriptor, etc. Note that per section 6.2 of
> > + * UEFI Spec 2.6 Errata A, the returned size of each descriptor might not
> > + * be equal to sizeof(efi_memory_memdesc_t) since efi_memory_memdesc_t may
> > + * be extended in the future in response to hardware innovation. Thus OS
> > + * MUST use the returned size of descriptor to find the start of each
> > + * efi_memory_memdesc_t in the memory map array. This should only be used
> > + * during bootup since for_each_efi_memory_desc_xxx is suggested after OS
> > + * initializes EFI to fill data of struct efi_memory_map.
> > + */
>
> Again, please use "EFI subsystem" here.
Sure, will do.
>
> > +#define efi_early_memdesc_ptr(map, desc_size, n) \
> > + (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
> > +
> > /* Iterate through an efi_memory_map */
> > #define for_each_efi_memory_desc_in_map(m, md) \
> > for ((md) = (m)->map; \
>
> Otherwise, this looks OK to me.
Thanks for reviewing!
next prev parent reply other threads:[~2017-08-16 13:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-14 14:54 [PATCH v9 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He
2017-08-14 14:54 ` [PATCH v9 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor Baoquan He
[not found] ` <1502722464-20614-2-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-08-16 11:37 ` Matt Fleming
2017-08-16 11:37 ` Matt Fleming
[not found] ` <20170816113726.GA3384-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2017-08-16 13:18 ` Baoquan He [this message]
2017-08-16 13:18 ` Baoquan He
2017-08-16 13:46 ` [PATCH v10 " Baoquan He
2017-08-17 10:20 ` [tip:x86/boot] " tip-bot for Baoquan He
2017-08-14 14:54 ` [PATCH v9 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He
2017-08-17 10:21 ` [tip:x86/boot] x86/boot/KASLR: Prefer mirrored memory regions for the kernel physical address tip-bot for Baoquan He
2017-08-17 13:04 ` [PATCH v9 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He
2017-08-18 15:10 ` Ard Biesheuvel
2017-08-18 15:10 ` Ard Biesheuvel
2017-08-19 1:22 ` Baoquan He
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=20170816131841.GE21273@x1 \
--to=bhe-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=fanc.fnst-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org \
--cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
--cc=izumi.taku-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org \
--cc=mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=n-horiguchi-PaJj6Psr51x8UrSeD/g0lQ@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=thgarnie-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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.