From: Tom Lendacky <thomas.lendacky@xxxxxxx> Update the GHCB accessor functions so that some of the macros can be used by KVM when accessing the GHCB via the VMSA accessors. This will avoid duplicating code and make access to the GHCB somewhat transparent. Signed-off-by: Tom Lendacky <thomas.lendacky@xxxxxxx> --- arch/x86/include/asm/svm.h | 15 +++++++++++++-- arch/x86/kernel/cpu/vmware.c | 12 ++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index da38eb195355..c112207c201b 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -349,15 +349,26 @@ struct vmcb { #define DEFINE_GHCB_ACCESSORS(field) \ static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \ { \ + const struct vmcb_save_area *vmsa = &ghcb->save; \ + \ return test_bit(GHCB_BITMAP_IDX(field), \ - (unsigned long *)&ghcb->save.valid_bitmap); \ + (unsigned long *)vmsa->valid_bitmap); \ + } \ + \ + static inline u64 ghcb_get_##field(struct ghcb *ghcb) \ + { \ + const struct vmcb_save_area *vmsa = &ghcb->save; \ + \ + return vmsa->field; \ } \ \ static inline void ghcb_set_##field(struct ghcb *ghcb, u64 value) \ { \ + struct vmcb_save_area *vmsa = &ghcb->save; \ + \ __set_bit(GHCB_BITMAP_IDX(field), \ (unsigned long *)&ghcb->save.valid_bitmap); \ - ghcb->save.field = value; \ + vmsa->field = value; \ } DEFINE_GHCB_ACCESSORS(cpl) diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 924571fe5864..c6ede3b3d302 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -501,12 +501,12 @@ static bool vmware_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs) ghcb_rbp_is_valid(ghcb))) return false; - regs->bx = ghcb->save.rbx; - regs->cx = ghcb->save.rcx; - regs->dx = ghcb->save.rdx; - regs->si = ghcb->save.rsi; - regs->di = ghcb->save.rdi; - regs->bp = ghcb->save.rbp; + regs->bx = ghcb_get_rbx(ghcb); + regs->cx = ghcb_get_rcx(ghcb); + regs->dx = ghcb_get_rdx(ghcb); + regs->si = ghcb_get_rsi(ghcb); + regs->di = ghcb_get_rdi(ghcb); + regs->bp = ghcb_get_rbp(ghcb); return true; } -- 2.28.0