Skip to content

Commit 0cbc025

Browse files
tlendackybp3tk0v
authored andcommitted
x86/sev: Add support for the RMPREAD instruction
The RMPREAD instruction returns an architecture defined format of an RMP table entry. This is the preferred method for examining RMP entries. The instruction is advertised in CPUID 0x8000001f_EAX[21]. Use this instruction when available. Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Nikunj A Dadhania <[email protected]> Reviewed-by: Neeraj Upadhyay <[email protected]> Reviewed-by: Ashish Kalra <[email protected]> Link: https://lore.kernel.org/r/72c734ac8b324bbc0c839b2c093a11af4a8881fa.1733172653.git.thomas.lendacky@amd.com
1 parent 3e43c60 commit 0cbc025

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@
451451
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* Virtual TSC_AUX */
452452
#define X86_FEATURE_SME_COHERENT (19*32+10) /* AMD hardware-enforced cache coherency */
453453
#define X86_FEATURE_DEBUG_SWAP (19*32+14) /* "debug_swap" AMD SEV-ES full debug state swap support */
454+
#define X86_FEATURE_RMPREAD (19*32+21) /* RMPREAD instruction */
454455
#define X86_FEATURE_SVSM (19*32+28) /* "svsm" SVSM present */
455456

456457
/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */

arch/x86/virt/svm/sev.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ static int get_rmpentry(u64 pfn, struct rmpentry *e)
306306
{
307307
struct rmpentry_raw *e_raw;
308308

309+
if (cpu_feature_enabled(X86_FEATURE_RMPREAD)) {
310+
int ret;
311+
312+
/* Binutils version 2.44 supports the RMPREAD mnemonic. */
313+
asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfd"
314+
: "=a" (ret)
315+
: "a" (pfn << PAGE_SHIFT), "c" (e)
316+
: "memory", "cc");
317+
318+
return ret;
319+
}
320+
309321
e_raw = get_raw_rmpentry(pfn);
310322
if (IS_ERR(e_raw))
311323
return PTR_ERR(e_raw);

0 commit comments

Comments
 (0)