* [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap
@ 2016-09-13 3:28 Chao Gao
[not found] ` <20160913032813.GA11652-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-09-20 5:25 ` Chao Gao
0 siblings, 2 replies; 5+ messages in thread
From: Chao Gao @ 2016-09-13 3:28 UTC (permalink / raw)
To: linux-efi-u79uwXL29TY76Z2rM5mHXA
Cc: Matt Fleming, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
x86-DgEjT+Ai2ygdnm+yROfE0A
Commit 78ce248f (efi: Iterate over efi.memmap in for_each_efi_memory_desc())
replaces the old loop by for_each_efi_memory_desc() which will encounter #PF
when efi.memap are not initialized.
In boot process, xen set EFI_PARAVIRT in xen_efi_init() before setup_arch()
is called. This leads efi_memmap_init() will not initialize structures
related to efi.memmap. However, the following functions e.g.
efi_find_mirror(), efi_print_memmap() and efi_free_boot_services() access
efi.memmap without necessary checks. kernel and xen crash in this case.
After adding these checks, xen and kernel boot up normally.
Signed-off-by: Chao Gao <chao.gao-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
arch/x86/platform/efi/efi.c | 6 ++++++
arch/x86/platform/efi/quirks.c | 3 +++
2 files changed, 9 insertions(+)
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 1fbb408..68966dc 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -102,6 +102,9 @@ void __init efi_find_mirror(void)
efi_memory_desc_t *md;
u64 mirror_size = 0, total_size = 0;
+ if (efi_enabled(EFI_PARAVIRT))
+ return;
+
for_each_efi_memory_desc(md) {
unsigned long long start = md->phys_addr;
unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
@@ -207,6 +210,9 @@ void __init efi_print_memmap(void)
efi_memory_desc_t *md;
int i = 0;
+ if (efi_enabled(EFI_PARAVIRT))
+ return;
+
for_each_efi_memory_desc(md) {
char buf[64];
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 89d1146..4fa1e4d 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -251,6 +251,9 @@ void __init efi_free_boot_services(void)
{
efi_memory_desc_t *md;
+ if (efi_enabled(EFI_PARAVIRT))
+ return;
+
for_each_efi_memory_desc(md) {
unsigned long long start = md->phys_addr;
unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap
[not found] ` <20160913032813.GA11652-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2016-09-13 8:51 ` Ard Biesheuvel
[not found] ` <CAKv+Gu_NrMGSu-9DxyZdurLWNbkHx2D480WS3gupazzC8U67EQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2016-09-13 8:51 UTC (permalink / raw)
To: Chao Gao
Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, x86-DgEjT+Ai2ygdnm+yROfE0A
On 13 September 2016 at 04:28, Chao Gao <chao.gao-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:
> Commit 78ce248f (efi: Iterate over efi.memmap in for_each_efi_memory_desc())
> replaces the old loop by for_each_efi_memory_desc() which will encounter #PF
> when efi.memap are not initialized.
>
> In boot process, xen set EFI_PARAVIRT in xen_efi_init() before setup_arch()
> is called. This leads efi_memmap_init() will not initialize structures
> related to efi.memmap. However, the following functions e.g.
> efi_find_mirror(), efi_print_memmap() and efi_free_boot_services() access
> efi.memmap without necessary checks. kernel and xen crash in this case.
> After adding these checks, xen and kernel boot up normally.
>
OK, so looking at the hunks below, it looks to me like we should
initialize the efi.memmap to sane values in the EFI_PARAVIRT case,
rather than open coding this test each time for_each_efi_memory_desc()
is invoked.
> Signed-off-by: Chao Gao <chao.gao-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
> arch/x86/platform/efi/efi.c | 6 ++++++
> arch/x86/platform/efi/quirks.c | 3 +++
> 2 files changed, 9 insertions(+)
>
> diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
> index 1fbb408..68966dc 100644
> --- a/arch/x86/platform/efi/efi.c
> +++ b/arch/x86/platform/efi/efi.c
> @@ -102,6 +102,9 @@ void __init efi_find_mirror(void)
> efi_memory_desc_t *md;
> u64 mirror_size = 0, total_size = 0;
>
> + if (efi_enabled(EFI_PARAVIRT))
> + return;
> +
> for_each_efi_memory_desc(md) {
> unsigned long long start = md->phys_addr;
> unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
> @@ -207,6 +210,9 @@ void __init efi_print_memmap(void)
> efi_memory_desc_t *md;
> int i = 0;
>
> + if (efi_enabled(EFI_PARAVIRT))
> + return;
> +
> for_each_efi_memory_desc(md) {
> char buf[64];
>
> diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
> index 89d1146..4fa1e4d 100644
> --- a/arch/x86/platform/efi/quirks.c
> +++ b/arch/x86/platform/efi/quirks.c
> @@ -251,6 +251,9 @@ void __init efi_free_boot_services(void)
> {
> efi_memory_desc_t *md;
>
> + if (efi_enabled(EFI_PARAVIRT))
> + return;
> +
> for_each_efi_memory_desc(md) {
> unsigned long long start = md->phys_addr;
> unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
> --
> 1.8.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-efi" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap
[not found] ` <CAKv+Gu_NrMGSu-9DxyZdurLWNbkHx2D480WS3gupazzC8U67EQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-09-13 11:26 ` Chao Gao
0 siblings, 0 replies; 5+ messages in thread
From: Chao Gao @ 2016-09-13 11:26 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA, Matt Fleming, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, x86-DgEjT+Ai2ygdnm+yROfE0A
On Tue, Sep 13, 2016 at 09:51:39AM +0100, Ard Biesheuvel wrote:
>On 13 September 2016 at 04:28, Chao Gao <chao.gao-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:
>> Commit 78ce248f (efi: Iterate over efi.memmap in for_each_efi_memory_desc())
>> replaces the old loop by for_each_efi_memory_desc() which will encounter #PF
>> when efi.memap are not initialized.
>>
>> In boot process, xen set EFI_PARAVIRT in xen_efi_init() before setup_arch()
>> is called. This leads efi_memmap_init() will not initialize structures
>> related to efi.memmap. However, the following functions e.g.
>> efi_find_mirror(), efi_print_memmap() and efi_free_boot_services() access
>> efi.memmap without necessary checks. kernel and xen crash in this case.
>> After adding these checks, xen and kernel boot up normally.
>>
>
>OK, so looking at the hunks below, it looks to me like we should
>initialize the efi.memmap to sane values in the EFI_PARAVIRT case,
>rather than open coding this test each time for_each_efi_memory_desc()
>is invoked.
>
Ard, thanks for you reply.
Yes, I think what you say is also a solution. This patch just uses the same method
using by some existed functions such as efi_memblock_x86_reserve_range() and
efi_runtime_init(). we can handle cases with existed flags correctly and the checks
seems not too much. Maybe we can try what you say when it's really needed.
>> Signed-off-by: Chao Gao <chao.gao-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>> ---
>> arch/x86/platform/efi/efi.c | 6 ++++++
>> arch/x86/platform/efi/quirks.c | 3 +++
>> 2 files changed, 9 insertions(+)
>>
>> diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
>> index 1fbb408..68966dc 100644
>> --- a/arch/x86/platform/efi/efi.c
>> +++ b/arch/x86/platform/efi/efi.c
>> @@ -102,6 +102,9 @@ void __init efi_find_mirror(void)
>> efi_memory_desc_t *md;
>> u64 mirror_size = 0, total_size = 0;
>>
>> + if (efi_enabled(EFI_PARAVIRT))
>> + return;
>> +
>> for_each_efi_memory_desc(md) {
>> unsigned long long start = md->phys_addr;
>> unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
>> @@ -207,6 +210,9 @@ void __init efi_print_memmap(void)
>> efi_memory_desc_t *md;
>> int i = 0;
>>
>> + if (efi_enabled(EFI_PARAVIRT))
>> + return;
>> +
>> for_each_efi_memory_desc(md) {
>> char buf[64];
>>
>> diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
>> index 89d1146..4fa1e4d 100644
>> --- a/arch/x86/platform/efi/quirks.c
>> +++ b/arch/x86/platform/efi/quirks.c
>> @@ -251,6 +251,9 @@ void __init efi_free_boot_services(void)
>> {
>> efi_memory_desc_t *md;
>>
>> + if (efi_enabled(EFI_PARAVIRT))
>> + return;
>> +
>> for_each_efi_memory_desc(md) {
>> unsigned long long start = md->phys_addr;
>> unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
>> --
>> 1.8.3.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-efi" in
>> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap
2016-09-13 3:28 [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap Chao Gao
[not found] ` <20160913032813.GA11652-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2016-09-20 5:25 ` Chao Gao
2016-09-20 9:56 ` Matt Fleming
1 sibling, 1 reply; 5+ messages in thread
From: Chao Gao @ 2016-09-20 5:25 UTC (permalink / raw)
To: linux-efi, Matt Fleming, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, x86, linux-kernel
Sorry for bothering you. There is a regression since commit 78ce248f that if
booting xen in UEFI mode, dom0 will crash and xen reboot constantly.
This patch tries to fix it. Please take a look at it.
On Tue, Sep 13, 2016 at 11:28:15AM +0800, Chao Gao wrote:
>Commit 78ce248f (efi: Iterate over efi.memmap in for_each_efi_memory_desc())
>replaces the old loop by for_each_efi_memory_desc() which will encounter #PF
>when efi.memap are not initialized.
>
>In boot process, xen set EFI_PARAVIRT in xen_efi_init() before setup_arch()
>is called. This leads efi_memmap_init() will not initialize structures
>related to efi.memmap. However, the following functions e.g.
>efi_find_mirror(), efi_print_memmap() and efi_free_boot_services() access
>efi.memmap without necessary checks. kernel and xen crash in this case.
>After adding these checks, xen and kernel boot up normally.
>
>Signed-off-by: Chao Gao <chao.gao@intel.com>
>---
> arch/x86/platform/efi/efi.c | 6 ++++++
> arch/x86/platform/efi/quirks.c | 3 +++
> 2 files changed, 9 insertions(+)
>
>diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
>index 1fbb408..68966dc 100644
>--- a/arch/x86/platform/efi/efi.c
>+++ b/arch/x86/platform/efi/efi.c
>@@ -102,6 +102,9 @@ void __init efi_find_mirror(void)
> efi_memory_desc_t *md;
> u64 mirror_size = 0, total_size = 0;
>
>+ if (efi_enabled(EFI_PARAVIRT))
>+ return;
>+
> for_each_efi_memory_desc(md) {
> unsigned long long start = md->phys_addr;
> unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
>@@ -207,6 +210,9 @@ void __init efi_print_memmap(void)
> efi_memory_desc_t *md;
> int i = 0;
>
>+ if (efi_enabled(EFI_PARAVIRT))
>+ return;
>+
> for_each_efi_memory_desc(md) {
> char buf[64];
>
>diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
>index 89d1146..4fa1e4d 100644
>--- a/arch/x86/platform/efi/quirks.c
>+++ b/arch/x86/platform/efi/quirks.c
>@@ -251,6 +251,9 @@ void __init efi_free_boot_services(void)
> {
> efi_memory_desc_t *md;
>
>+ if (efi_enabled(EFI_PARAVIRT))
>+ return;
>+
> for_each_efi_memory_desc(md) {
> unsigned long long start = md->phys_addr;
> unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
>--
>1.8.3.1
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-efi" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap
2016-09-20 5:25 ` Chao Gao
@ 2016-09-20 9:56 ` Matt Fleming
0 siblings, 0 replies; 5+ messages in thread
From: Matt Fleming @ 2016-09-20 9:56 UTC (permalink / raw)
To: Chao Gao
Cc: linux-efi, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
linux-kernel
On Tue, 20 Sep, at 01:25:14PM, Chao Gao wrote:
> Sorry for bothering you. There is a regression since commit 78ce248f that if
> booting xen in UEFI mode, dom0 will crash and xen reboot constantly.
> This patch tries to fix it. Please take a look at it.
Can you try commit d4c4fed08f31 ("efi: Make
for_each_efi_memory_desc_in_map() cope with running on Xen") and see
if that fixes things for you?
That patch is already in Linus' tree and is included in v4.8-rc7.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-20 9:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-13 3:28 [PATCH] x86/efi: Add necessary checks before iterating over efi.memmap Chao Gao
[not found] ` <20160913032813.GA11652-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-09-13 8:51 ` Ard Biesheuvel
[not found] ` <CAKv+Gu_NrMGSu-9DxyZdurLWNbkHx2D480WS3gupazzC8U67EQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-09-13 11:26 ` Chao Gao
2016-09-20 5:25 ` Chao Gao
2016-09-20 9:56 ` Matt Fleming
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.