Julian Andres Klode <julian.kl...@canonical.com> writes:

> On Thu, Apr 25, 2024 at 06:30:52PM +0100, Alex Bennée wrote:
>> 
>> Continuing to debug on QEMU it seems there is an incompatibility with
>> the images and the peloader (which overrides the normal efi loader):
>> 
>>   Thread 1 hit Breakpoint 3.2, grub_load_normal_mode () at 
>> ../../../grub-core/kern/main.c:241                            
>>   241     in ../../../grub-core/kern/main.c                                  
>>                                                                              
>>                      
>>   (grub gdb) hbreak do_load_image                                            
>>                                                                              
>>                      
>>   Hardware assisted breakpoint 4 at 0x23bdf0e00: do_load_image. (2 
>> locations)                                                                   
>>                                
>>   (grub gdb) c                                                               
>>                                                                              
>>                      
>>   Continuing.                                                                
>>                                                                              
>>                      
>>   add symbol table from file "bli.module" at                                 
>>                                                                              
>>                      
>>           .text_addr = 0x23ba772e0                                           
>>                                                                              
>>                      
>>           .bss_addr = 0x0                                                    
>>                                                                              
>>                      
>>           .module_license_addr = 0x23ba7764a 
>>           .data_addr = 0x0                                                   
>>                                                                              
>>                      
>>           .rodata.str1.1_addr = 0x23ba77560                                  
>>                                                                              
>>                      
>>           .rodata_addr = 0x23ba77550                                         
>>                                                                              
>>                      
>>   add symbol table from file "xen_boot.module" at                            
>>                                                                              
>>                      
>>           .text_addr = 0x23bcef3c0                                           
>>                                                                              
>>                      
>>           .bss_addr = 0x23bcf0370                                            
>>                                                                              
>>                      
>>           .module_license_addr = 0x23bcf035e                                 
>>            
>>           .data_addr = 0x0                                                   
>>            
>>           .rodata.str1.1_addr = 0x23bcefff8
>> 
>>   Thread 1 hit Breakpoint 4.1, do_load_image (boot_policy=0 '\000', 
>> parent_image_handle=0x23e889f18, file_path=0x237d1bce0, 
>> source_buffer=0x239f00000, source_size=1081352, 
>>       image_handle=0x4766c498) at ../../../grub-core/loader/efi/peimage.c:745
>>   warning: 745    ../../../grub-core/loader/efi/peimage.c: No such file or 
>> directory
>>   (grub gdb) hbreak grub_error
>>   Hardware assisted breakpoint 5 at 0x6db0: grub_error. (2 locations)
>>   (grub gdb) c
>>   Continuing.
>> 
>>   Thread 1 hit Breakpoint 4.2, 0x000000023bdf0e4c in do_load_image 
>> (boot_policy=<optimized out>, parent_image_handle=<optimized out>, 
>> image_handle=<optimized out>, 
>>       source_size=<optimized out>, source_buffer=<optimized out>, 
>> file_path=<optimized out>) at ../../../grub-core/loader/efi/peimage.c:751
>>   751     in ../../../grub-core/loader/efi/peimage.c
>>   (grub gdb) c
>>   Continuing.
>> 
>>   Thread 1 hit Breakpoint 5.2, grub_error (n=GRUB_ERR_BAD_OS, 
>> fmt=0x23bdf1703 "section inside header") at ../../../grub-core/kern/err.c:41
>>   warning: 41     ../../../grub-core/kern/err.c: No such file or directory
>>   (grub gdb) bt
>>   #0  grub_error (n=GRUB_ERR_BAD_OS, fmt=0x23bdf1703 "section inside 
>> header") at ../../../grub-core/kern/err.c:41
>>   #1  0x000000023bdf0e34 in do_load_image (boot_policy=<optimized out>, 
>> parent_image_handle=<optimized out>, file_path=<optimized out>, 
>> source_buffer=<optimized out>, 
>>       source_size=<optimized out>, image_handle=<optimized out>) at 
>> ../../../grub-core/loader/efi/peimage.c:747
>>   #2  0x000000023bedabdc in grub_arch_efi_linux_boot_image (addr=9561964544, 
>> size=1081352, 
>>       args=0x23bbb8b00 "placeholder dom0_mem=4G,max:4G loglvl=all 
>> guest_loglvl=all no-real-mode edd=off") at 
>> ../../../grub-core/loader/efi/linux.c:210
>>   #3  0x000000023bff41bc in grub_loader_boot () at 
>> ../../../grub-core/commands/boot.c:211
>>   #4  grub_loader_boot () at ../../../grub-core/commands/boot.c:190
>>   #5  0x000000023bf42158 in grub_command_execute (name=0x23bf4e72c "boot", 
>> argc=0, argv=0x0 <_start>) at ../../../include/grub/command.h:126
>>   #6  grub_menu_execute_entry (entry=entry@entry=0x23bd17660, 
>> auto_boot=auto_boot@entry=0) at ../../../grub-core/normal/menu.c:306
>>   #7  0x000000023bf41e2c in show_menu (autobooted=<optimized out>, 
>> nested=<optimized out>, menu=<optimized out>) at 
>> ../../../grub-core/normal/menu.c:925
>>   #8  grub_show_menu (menu=menu@entry=0x23bd1a940, nested=nested@entry=1, 
>> autoboot=autoboot@entry=0) at ../../../grub-core/normal/menu.c:940
>>   #9  0x000000023bf408a8 in grub_normal_execute (config=<optimized out>, 
>> nested=nested@entry=1, batch=batch@entry=0) at 
>> ../../../grub-core/normal/main.c:291
>>   #10 0x000000023bf32260 in grub_cmd_source (cmd=<optimized out>, argc=1, 
>> args=0x23bd1fcc8) at ../../../grub-core/commands/configfile.c:48
>>   #11 grub_cmd_source (cmd=<optimized out>, argc=<optimized out>, 
>> args=0x23bd1fcc8) at ../../../grub-core/commands/configfile.c:30
>>   #12 0x000000023bf48d0c in grub_script_execute_cmdline (cmd=<optimized 
>> out>) at ../../../grub-core/script/execute.c:1034
>>   #13 0x000000023bf478c0 in grub_script_execute_cmd 
>> (cmd=cmd@entry=0x23bd190c8) at ../../../grub-core/script/execute.c:819
>>   #14 0x000000023bf4874c in grub_script_execute_cmdlist (list=<optimized 
>> out>) at ../../../grub-core/script/execute.c:1079
>>   #15 0x000000023bf478c0 in grub_script_execute_cmd (cmd=<optimized out>) at 
>> ../../../grub-core/script/execute.c:819
>>   #16 0x000000023bf489b4 in grub_script_execute (script=<optimized out>) at 
>> ../../../grub-core/script/execute.c:1191
>>   #17 0x000000023bf497fc in grub_normal_parse_line 
>> (line=line@entry=0x23bd20060 "configfile $prefix/grub.cfg", 
>> getline=getline@entry=0x23bf40430 <read_config_file_getline>, 
>>       getline_data=getline_data@entry=0x23bd20380) at 
>> ../../../grub-core/script/main.c:36
>>   #18 0x000000023bf409a0 in read_config_file (config=0x23bd20780 
>> "(hd0,gpt1)/EFI/debian/grub.cfg") at ../../../grub-core/normal/main.c:179
>>   #19 grub_normal_execute (config=config@entry=0x23bd20780 
>> "(hd0,gpt1)/EFI/debian/grub.cfg", nested=nested@entry=0, batch=batch@entry=0)
>>       at ../../../grub-core/normal/main.c:277
>>   #20 0x000000023bf40ca4 in grub_enter_normal_mode 
>> (config=config@entry=0x23bd20780 "(hd0,gpt1)/EFI/debian/grub.cfg") at 
>> ../../../grub-core/normal/main.c:304
>>   #21 0x000000023bf40da0 in grub_try_normal_prefix (prefix=0x23bd209a0 
>> "(hd0,gpt1)/EFI/debian") at ../../../grub-core/normal/main.c:356
>>   #22 0x000000023bf40ea0 in grub_try_normal (variable=0x23bf4e492 "fw_path") 
>> at ../../../grub-core/normal/main.c:407
>>   #23 grub_cmd_normal (cmd=<optimized out>, argc=0, argv=<optimized out>) at 
>> ../../../grub-core/normal/main.c:421
>>   #24 grub_cmd_normal (cmd=<optimized out>, argc=<optimized out>, 
>> argv=<optimized out>) at ../../../grub-core/normal/main.c:412
>>   #25 0x000000023c018fb8 in grub_command_execute (name=0x23c01ec6e ")", 
>> argc=0, argv=0x0 <_start>) at ../../../include/grub/command.h:126
>>   #26 grub_load_normal_mode () at ../../../grub-core/kern/main.c:247
>>   #27 grub_main () at ../../../grub-core/kern/main.c:339
>>   #28 0x000000023c5c02c8 in ?? ()
>>   #29 0x000000023c62a000 in ?? ()
>>   #30 0xafafafaf6c617470 in ?? ()
>>   Backtrace stopped: previous frame identical to this frame (corrupt stack?)
>> 
>> Is it possible to override the peloader or does the Xen image need to be
>> prepared a certain way?
>
> Well it needs to be a proper UEFI binary. The loader works for Linux
> and for chainloading the Windows boot loader, we haven't tested other
> binaries (except some small test binaries I suppose).

I'm able to load the hypervisor directly (it appears as a Linux kernel
ARM64 boot executable Image, little-endian, 4K pages). Also using the
upstream grub its able to load the hypervisor with the direct EFI
load_image boot service.

> Personally, I'm surprised Xen still exists in 2024, so don't expect
> me to be very helpful here.

There are still use cases for a "traditional" lowvisor type hypervisor
that isn't entangled with a whole kernel. In our case there are
automotive use cases which benefit from Xen's ability to partition and
pin vCPUs to different domains.

I don't know what Debian's policy is towards Xen but it did at least use
to work.

> In the error case you can see though, that one of the section
> addresses in the Xen binary to be relocated points into the (PE)
> header of the binary, which obviously seems wrong.
>
> So go check your PE sections and check which one is wrong?

Is there any tooling for examining PE sections?

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro

Reply via email to