Skip to content

Commit

Permalink
*use rd_msr/wr_msr helpers for boot kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
mdroth committed Feb 2, 2022
1 parent 982c6c5 commit a16e11f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
24 changes: 10 additions & 14 deletions arch/x86/boot/compressed/sev.c
Expand Up @@ -23,6 +23,7 @@
#include <asm/cpuid.h>

#include "error.h"
#include "../msr.h"

struct ghcb boot_ghcb_page __aligned(PAGE_SIZE);
struct ghcb *boot_ghcb;
Expand Down Expand Up @@ -57,23 +58,19 @@ static unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx)

static inline u64 sev_es_rd_ghcb_msr(void)
{
unsigned long low, high;
struct msr m;

asm volatile("rdmsr" : "=a" (low), "=d" (high) :
"c" (MSR_AMD64_SEV_ES_GHCB));
rd_msr(MSR_AMD64_SEV_ES_GHCB, &m);

return ((high << 32) | low);
return m.q;
}

static inline void sev_es_wr_ghcb_msr(u64 val)
{
u32 low, high;
struct msr m;

low = val & 0xffffffffUL;
high = val >> 32;

asm volatile("wrmsr" : : "c" (MSR_AMD64_SEV_ES_GHCB),
"a"(low), "d" (high) : "memory");
m.q = val;
wr_msr(MSR_AMD64_SEV_ES_GHCB, &m);
}

static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)
Expand Down Expand Up @@ -255,12 +252,11 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)

static inline u64 rd_sev_status_msr(void)
{
unsigned long low, high;
struct msr m;

asm volatile("rdmsr" : "=a" (low), "=d" (high) :
"c" (MSR_AMD64_SEV));
rd_msr(MSR_AMD64_SEV, &m);

return ((high << 32) | low);
return m.q;
}

static void enforce_vmpl0(void)
Expand Down
30 changes: 15 additions & 15 deletions arch/x86/boot/cpucheck.c
Expand Up @@ -27,6 +27,7 @@
#include <asm/required-features.h>
#include <asm/msr-index.h>
#include "string.h"
#include "msr.h"

static u32 err_flags[NCAPINTS];

Expand Down Expand Up @@ -130,12 +131,11 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
/* If this is an AMD and we're only missing SSE+SSE2, try to
turn them on */

u32 ecx = MSR_K7_HWCR;
u32 eax, edx;
struct msr m;

asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
eax &= ~(1 << 15);
asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
rd_msr(MSR_K7_HWCR, &m);
m.l &= ~(1 << 15);
wr_msr(MSR_K7_HWCR, &m);

get_cpuflags(); /* Make sure it really did something */
err = check_cpuflags();
Expand All @@ -145,28 +145,28 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
/* If this is a VIA C3, we might have to enable CX8
explicitly */

u32 ecx = MSR_VIA_FCR;
u32 eax, edx;
struct msr m;

asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
eax |= (1<<1)|(1<<7);
asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
rd_msr(MSR_VIA_FCR, &m);
m.l |= (1<<1)|(1<<7);
wr_msr(MSR_VIA_FCR, &m);

set_bit(X86_FEATURE_CX8, cpu.flags);
err = check_cpuflags();
} else if (err == 0x01 && is_transmeta()) {
/* Transmeta might have masked feature bits in word 0 */

u32 ecx = 0x80860004;
u32 eax, edx;
struct msr m, m_tmp;
u32 level = 1;

asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
rd_msr(0x80860004, &m);
m_tmp = m;
m_tmp.l = ~0;
wr_msr(0x80860004, &m_tmp);
asm("cpuid"
: "+a" (level), "=d" (cpu.flags[0])
: : "ecx", "ebx");
asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
wr_msr(0x80860004, &m);

err = check_cpuflags();
} else if (err == 0x01 &&
Expand Down

0 comments on commit a16e11f

Please sign in to comment.