[Solved] QEMU: Booting x86_64 kernel via PVH

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
lukecreator
Posts: 2
Joined: Tue Jul 27, 2021 3:09 pm

[Solved] QEMU: Booting x86_64 kernel via PVH

Post by lukecreator »

After getting a basic 32-bit i386 kernel emulating through QEMU, I figured I would go ahead and get one fired up on x86_64. I am still completely in the "Let's make sure this actually works before doing anything else" phase. Running "qemu-system-x86_64 -kernel out.bin" results in QEMU spitting out "Error loading uncompressed kernel without PVH ELF Note." The binary file has been verified with grub-file as well.

I've read around that QEMU does not support multiboot2 so I figured I would just give it what it wants and include the elf note. My only issue here is figuring out how to do this correctly. As of now I have

Code: Select all

section .note
align 4
	dd 3 ; name size
	dd 4 ; data size
	dd 18 ; type (0x12)
align 4
	db 'Xen' ; name
align 4
	dd _start ; data
and my linker puts the section at the right spot in the file.

Code: Select all

	.note : 
	{
		*(.note)
	}
Running readelf does show that the elfnote is present and contains what I thought was the correct information (see below). QEMU still tells me that it wants its PVH elfnote despite this. I have exhausted every resource trying to get it to work over the past week and I'm about at the end of my ropes; Thinking I misunderstood something big-time. Would love if someone could point me in the right direction here on where I went wrong.

Note data:

Code: Select all

Displaying notes found in: .note
  Owner                Data size        Description
  Xen                  0x00000004       Unknown note type: (0x00000012)
   description data: 00 20 00 00
https://xenbits.xen.org/docs/unstable/misc/pvh.html
Last edited by lukecreator on Wed Jul 28, 2021 11:05 am, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: QEMU: Booting x86_64 kernel via PVH

Post by Octocontrabass »

I'm no PVH expert, but I think you might run into trouble if you tell QEMU your kernel supports paravirtualization when it actually doesn't.

Code: Select all

section .note
I'm not sure if it makes a difference, but Xen uses the section name ".note.Xen" in the ELFNOTE macro.

Code: Select all

	dd 3 ; name size
This should be 4.

Code: Select all

	db 'Xen' ; name
The missing 4th byte is a null terminator.
lukecreator
Posts: 2
Joined: Tue Jul 27, 2021 3:09 pm

Re: QEMU: Booting x86_64 kernel via PVH

Post by lukecreator »

Octocontrabass wrote:I'm no PVH expert, but I think you might run into trouble if you tell QEMU your kernel supports paravirtualization when it actually doesn't.

Code: Select all

section .note
I'm not sure if it makes a difference, but Xen uses the section name ".note.Xen" in the ELFNOTE macro.

Code: Select all

	dd 3 ; name size
This should be 4.

Code: Select all

	db 'Xen' ; name
The missing 4th byte is a null terminator.
Thank you! You're probably right on the first part but I'm going to give it a shot anyway and see if everything doesn't blow up. Good to know that the name field absolutely requires null termination at the end; I have tried that already but I haven't tried putting the labeled note section so I'll give it a go and let you know what comes out of it.

EDIT: The section naming was it! Words cannot explain how ecstatic I am to see something so mediocre working right now haha
Post Reply