Re: [RFC PATCH] x86/sev: x86/sev: enforce PC-relative addressing in clang
From: Andi Kleen
Date: Wed Jan 10 2024 - 06:51:36 EST
On Wed, Jan 10, 2024 at 01:26:39AM +0000, Kevin Loughlin wrote:
> SEV/SME code can execute prior to page table fixups for kernel
That seems to be fundamental problem.
> relocation. However, as with global variables accessed in
> __startup_64(), clang does not currently generate PC-relative accesses
> for SEV/SME global variables, causing certain flavors of SEV hosts and
> guests to crash.
And that's a hack to work around it.
>
> While an attempt was made to force PC-relative addressing for certain
> global SEV/SME variables via inline assembly (see snp_cpuid_get_table()
> for example), PC-relative addressing must be pervasively-enforced for
> SEV/SME global variables that can be accessed prior to page table
> fixups.
>
> To avoid the error-prone approach of manually referencing each SEV/SME
> global variable via a general form of snp_cpuid_get_table(), it is
> preferable to use compiler flags for position-independent code (ex:
But if gcc doesn't support it then it doesn't work.
It seems your approach with incompatible execution models between
the compilers is just a recipe for future patches only working
on one of the compilers because most code submitters probably
won't test both.
It would be better to at least use a unified execution model, if you want
to extend the hack and not fix the underlying issue.
-Andi