Skip to content

Commit

Permalink
x86/boot/64: Use RIP_REL_REF() to assign 'phys_base'
Browse files Browse the repository at this point in the history
'phys_base' is assigned from code that executes from a 1:1 mapping so it
cannot use a plain access from C. Replace the use of fixup_pointer()
with RIP_REL_REF(), which is better and simpler.

While at it, move the assignment to before the addition of the SME mask
so there is no need to subtract it again, and drop the unnecessary
addition ('phys_base' is statically initialized to 0x0)

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240221113506.2565718-20-ardb+git@google.com
  • Loading branch information
Ard Biesheuvel authored and Ingo Molnar committed Feb 26, 2024
1 parent 5da7936 commit d9ec115
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions arch/x86/kernel/head64.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ unsigned long __head __startup_64(unsigned long physaddr,
* and the address I am actually running at.
*/
load_delta = physaddr - (unsigned long)(_text - __START_KERNEL_map);
RIP_REL_REF(phys_base) = load_delta;

/* Is the address not 2M aligned? */
if (load_delta & ~PMD_MASK)
Expand Down Expand Up @@ -301,12 +302,6 @@ unsigned long __head __startup_64(unsigned long physaddr,
for (; i < PTRS_PER_PMD; i++)
pmd[i] &= ~_PAGE_PRESENT;

/*
* Fixup phys_base - remove the memory encryption mask to obtain
* the true physical address.
*/
*fixup_long(&phys_base, physaddr) += load_delta - sme_get_me_mask();

return sme_postprocess_startup(bp, pmd);
}

Expand Down

0 comments on commit d9ec115

Please sign in to comment.