Skip to content

Commit

Permalink
x86/pvh: Call C code via the kernel virtual mapping
Browse files Browse the repository at this point in the history
[ Upstream commit e8fbc0d ]

Calling C code via a different mapping than it was linked at is
problematic, because the compiler assumes that RIP-relative and absolute
symbol references are interchangeable. GCC in particular may use
RIP-relative per-CPU variable references even when not using -fpic.

So call xen_prepare_pvh() via its kernel virtual mapping on x86_64, so
that those RIP-relative references produce the correct values. This
matches the pre-existing behavior for i386, which also invokes
xen_prepare_pvh() via the kernel virtual mapping before invoking
startup_32 with paging disabled again.

Fixes: 7243b93 ("xen/pvh: Bootstrap PVH guest")
Tested-by: Jason Andryuk <[email protected]>
Reviewed-by: Jason Andryuk <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Juergen Gross <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
ardbiesheuvel authored and gregkh committed Dec 5, 2024
1 parent a9681f7 commit 9978ff5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion arch/x86/platform/pvh/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ SYM_CODE_START_LOCAL(pvh_start_xen)
movq %rbp, %rbx
subq $_pa(pvh_start_xen), %rbx
movq %rbx, phys_base(%rip)
call xen_prepare_pvh

/* Call xen_prepare_pvh() via the kernel virtual mapping */
leaq xen_prepare_pvh(%rip), %rax
subq phys_base(%rip), %rax
addq $__START_KERNEL_map, %rax
ANNOTATE_RETPOLINE_SAFE
call *%rax

/*
* Clear phys_base. __startup_64 will *add* to its value,
* so reset to 0.
Expand Down

0 comments on commit 9978ff5

Please sign in to comment.