Skip to contentSkip to conversation

x86_64/efi: Use all 64 bit of efi_memmap in setup_e820()

PATCH Superseded Dmitry Skorodumov 2 participants 5 messages Jul 22, 2015 – Jul 28, 2015 3 messages not in the archive

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86_64/efi: Use all 64 bit of efi_memmap in setup_e820()

The efi_info structure stores low 32 bits of memory map in efi_memmap and high 32 bits in efi_memmap_hi.

While constructing pointer in the setup_e820(), need to take into account all 64 bits of the pointer.

It is because on 64bit machine the function efi_get_memory_map() may return full 64bit pointer and before the patch that pointer was truncated.

tested in Parallels virtual machine with more then 3GB of memory

---
 arch/x86/boot/compressed/eboot.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/boot/compressed/eboot.c +6 -1
index 2c82bd1..9108fe5 100644
@@ -1184,6 +1184,12 @@ static efi_status_t setup_e820(struct boot_params *params,
 	u32 nr_entries;
 	u32 nr_desc;
 	int i;
+	unsigned long m;
+
+	m = efi->efi_memmap;
+#ifdef CONFIG_X86_64
+	m |= (u64)efi->efi_memmap_hi << 32;
+#endif
 
 	nr_entries = 0;
 	nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size;
@@ -1191,7 +1197,6 @@ static efi_status_t setup_e820(struct boot_params *params,
 	for (i = 0; i < nr_desc; i++) {
 		efi_memory_desc_t *d;
 		unsigned int e820_type = 0;
-		unsigned long m = efi->efi_memmap;
 
 		d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
 		switch (d->type) {
Signature · 1 line
1.7.9.1
#2 lore raw
In reply to a message not in the archive
Quoted 6 lines · Dmitry Skorodumov

The efi_info structure stores low 32 bits of memory map in efi_memmap and high 32 bits in efi_memmap_hi.

While constructing pointer in the setup_e820(), need to take into account all 64 bits of the pointer.

Quoted 7 lines

It is because on 64bit machine the function efi_get_memory_map() may return full 64bit pointer and before the patch that pointer was truncated.

tested in Parallels virtual machine with more then 3GB of memory

When you say "tested", you mean that it doesn't boot correctly without your patch but does boot correctly with it applied? What I'm really asking is: are we sure that your setup triggered this new code?

Quoted 18 lines
arch/x86/boot/compressed/eboot.c +6 -0
index 2c82bd1..9108fe5 100644
@@ -1184,6 +1184,12 @@ static efi_status_t setup_e820(struct boot_params *params,
 	u32 nr_entries;
 	u32 nr_desc;
 	int i;
+	unsigned long m;
+
+	m = efi->efi_memmap;
+#ifdef CONFIG_X86_64
+	m |= (u64)efi->efi_memmap_hi << 32;
+#endif
 
 	nr_entries = 0;
 	nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size;

arch/x86/boot/compressed/eboot.c static efi_status_t setup_e820(struct boot_params *params, · line 1202

Quoted 7 lines
arch/x86/boot/compressed/eboot.c +0 -1
@@ -1191,7 +1197,6 @@ static efi_status_t setup_e820(struct boot_params *params,
 	for (i = 0; i < nr_desc; i++) {
 		efi_memory_desc_t *d;
 		unsigned int e820_type = 0;
-		unsigned long m = efi->efi_memmap;
 
 		d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
 		switch (d->type) {

Is there a reason that adding efi->efi_memmap_hi can't be done inside this for loop? Gcc should be smart enough to hoist this calculation out of the loop.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#4 lore raw
In reply to a message not in the archive
Quoted 4 lines · Matt Fleming
Quoted 3 lines · Dmitry Skorodumov

The efi_info structure stores low 32 bits of memory map in efi_memmap and high 32 bits in efi_memmap_hi.

Quoted 8 lines
Quoted 4 lines

While constructing pointer in the setup_e820(), need to take into account all 64 bits of the pointer.

tested in Parallels virtual machine with more then 3GB of memory

When you say "tested", you mean that it doesn't boot correctly without your patch but does boot correctly with it applied? What I'm really asking is: are we sure that your setup triggered this new code?

Yes, while debugging I added a lot of logging to trace the problem. Parallels VM doesn't boot correctly without the patch.

I believe that any EDK2-based efi-bios will not work also, though I heard that OVMF uses own linux boot loader..
It is because the memory for memmap was allocated from EFI_LOADER_DATA pool - efi_call_early(allocate_pool, EFI_LOADER_DATA, map_size... );

It is possible to kludge the problem by patching EFI-bios of the machine to allocate EFI_LOADER_DATA-memory below the 4GB space,
but I think that fixing setup_e820() is the right thing.

Quoted 4 lines
Quoted 4 lines
arch/x86/boot/compressed/eboot.c +4 -0
+	m = efi->efi_memmap;
+#ifdef CONFIG_X86_64
+	m |= (u64)efi->efi_memmap_hi << 32;
+#endif

..

Quoted 7 lines

arch/x86/boot/compressed/eboot.c static efi_status_t setup_e820(struct boot_params *params, · line 1201

Quoted 3 lines
arch/x86/boot/compressed/eboot.c +0 -1
 	for (i = 0; i < nr_desc; i++) {
-		unsigned long m = efi->efi_memmap;
 		d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));

Is there a reason that adding efi->efi_memmap_hi can't be done inside this for loop? Gcc should be smart enough to hoist this calculation out of the loop.

Smart from its side.. I'll correct this and resend the patch.-- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to Matt Fleming
Quoted 12 lines · Dmitry Skorodumov
Quoted 7 lines

The efi_info structure stores low 32 bits of memory map in efi_memmap and high 32 bits in efi_memmap_hi.

While constructing pointer in the setup_e820(), need to take into account all 64 bits of the pointer.

tested in Parallels virtual machine with more then 3GB of memory

When you say "tested", you mean that it doesn't boot correctly without your patch but does boot correctly with it applied? What I'm really asking is: are we sure that your setup triggered this new code?

Yes, while debugging I added a lot of logging to trace the problem. Parallels VM doesn't boot correctly without the patch.

I believe that any EDK2-based efi-bios will not work also, though I heard that OVMF uses own linux boot loader..
It is because the memory for memmap was allocated from EFI_LOADER_DATA pool - efi_call_early(allocate_pool, EFI_LOADER_DATA, map_size... );

It is possible to kludge the problem by patching EFI-bios of the machine to allocate EFI_LOADER_DATA-memory below the 4GB space,
but I think that fixing setup_e820() is the right thing.

Quoted 4 lines
Quoted 4 lines
arch/x86/boot/compressed/eboot.c +4 -0
+   m = efi->efi_memmap;
+#ifdef CONFIG_X86_64
+   m |= (u64)efi->efi_memmap_hi << 32;
+#endif

..

Quoted 7 lines
Quoted 3 lines
     for (i = 0; i < nr_desc; i++) {
-           unsigned long m = efi->efi_memmap;
             d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));

Is there a reason that adding efi->efi_memmap_hi can't be done inside this for loop? Gcc should be smart enough to hoist this calculation out of the loop.

Smart from its side.. I'll correct this and resend the patch.

PS: Looks my mailer have not sent the message to the list. Resending via gmane-web, sorry for potential duplicate

#6 lore raw
In reply to a message not in the archive
Quoted 9 lines · Dmitry Skorodumov
Quoted 6 lines · Matt Fleming
Quoted 5 lines · Dmitry Skorodumov

The efi_info structure stores low 32 bits of memory map in efi_memmap and high 32 bits in efi_memmap_hi.

While constructing pointer in the setup_e820(), need to take into account all 64 bits of the pointer.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

tested in Parallels virtual machine with more then 3GB of memory

When you say "tested", you mean that it doesn't boot correctly without your patch but does boot correctly with it applied? What I'm really asking is: are we sure that your setup triggered this new code?

Yes, while debugging I added a lot of logging to trace the problem. Parallels VM doesn't boot correctly without the patch.

OK cool, I would definitely include this in the patch commit message.

Quoted 8 lines

I believe that any EDK2-based efi-bios will not work also, though I heard that OVMF uses own linux boot loader..
It is because the memory for memmap was allocated from EFI_LOADER_DATA pool - efi_call_early(allocate_pool, EFI_LOADER_DATA, map_size... );

It is possible to kludge the problem by patching EFI-bios of the machine to allocate EFI_LOADER_DATA-memory below the 4GB space,
but I think that fixing setup_e820() is the right thing.

Yes your fix looks correct to me, I just wanted to know whether you hit the bug with a real workload or via code inspection.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
arch/x86/boot/compressed/eboot.c +4 -0
+	m = efi->efi_memmap;
+#ifdef CONFIG_X86_64
+	m |= (u64)efi->efi_memmap_hi << 32;
+#endif

..

Quoted 7 lines

arch/x86/boot/compressed/eboot.c static efi_status_t setup_e820(struct boot_params *params, · line 1201

Quoted 3 lines
arch/x86/boot/compressed/eboot.c +0 -1
 	for (i = 0; i < nr_desc; i++) {
-		unsigned long m = efi->efi_memmap;
 		d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));

Is there a reason that adding efi->efi_memmap_hi can't be done inside this for loop? Gcc should be smart enough to hoist this calculation out of the loop.

Quoted 1 line

Smart from its side.. I'll correct this and resend the patch.

Great, thanks.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center