Skip to content

Commit

Permalink
x86/boot: Introduce helpers for MSR reads/writes
Browse files Browse the repository at this point in the history
The current set of helpers used throughout the run-time kernel have
dependencies on code/facilities outside of the boot kernel, so there
are a number of call-sites throughout the boot kernel where inline
assembly is used instead. More will be added with subsequent patches
that add support for SEV-SNP, so take the opportunity to provide a basic
set of helpers that can be used by the boot kernel to reduce reliance on
inline assembly.

Use boot_* prefix so that it's clear these are helpers specific to the
boot kernel to avoid any confusion with the various other MSR read/write
helpers.

  [ bp: Disambiguate parameter names and trim comment. ]

Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20220307213356.2797205-6-brijesh.singh@amd.com
  • Loading branch information
Michael Roth authored and Borislav Petkov committed Apr 6, 2022
1 parent 6d3b3d3 commit 176db62
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
26 changes: 26 additions & 0 deletions arch/x86/boot/msr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Helpers/definitions related to MSR access.
*/

#ifndef BOOT_MSR_H
#define BOOT_MSR_H

#include <asm/shared/msr.h>

/*
* The kernel proper already defines rdmsr()/wrmsr(), but they are not for the
* boot kernel since they rely on tracepoint/exception handling infrastructure
* that's not available here.
*/
static inline void boot_rdmsr(unsigned int reg, struct msr *m)
{
asm volatile("rdmsr" : "=a" (m->l), "=d" (m->h) : "c" (reg));
}

static inline void boot_wrmsr(unsigned int reg, const struct msr *m)
{
asm volatile("wrmsr" : : "c" (reg), "a"(m->l), "d" (m->h) : "memory");
}

#endif /* BOOT_MSR_H */
11 changes: 1 addition & 10 deletions arch/x86/include/asm/msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@
#include <asm/errno.h>
#include <asm/cpumask.h>
#include <uapi/asm/msr.h>

struct msr {
union {
struct {
u32 l;
u32 h;
};
u64 q;
};
};
#include <asm/shared/msr.h>

struct msr_info {
u32 msr_no;
Expand Down
15 changes: 15 additions & 0 deletions arch/x86/include/asm/shared/msr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_SHARED_MSR_H
#define _ASM_X86_SHARED_MSR_H

struct msr {
union {
struct {
u32 l;
u32 h;
};
u64 q;
};
};

#endif /* _ASM_X86_SHARED_MSR_H */

0 comments on commit 176db62

Please sign in to comment.