lkml.org 
[lkml]   [2021]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v8 09/11] x86/tdx: Add MSR support for TDX guest
On Mon, Oct 04, 2021 at 07:52:03PM -0700, Kuppuswamy Sathyanarayanan wrote:
> diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c
> index 3d0416515506..062ac4720434 100644
> --- a/arch/x86/kernel/tdx.c
> +++ b/arch/x86/kernel/tdx.c
> @@ -110,6 +110,41 @@ static __cpuidle void tdx_safe_halt(void)
> _tdx_halt(irq_disabled, do_sti);
> }
>
> +static u64 tdx_read_msr_safe(unsigned int msr, int *err)

Here the kernel convention would probably be to return the error and
make 'val' an argument:

static int tdx_read_msr_safe(unsigned int msr, u64 *val)


> +{
> + struct tdx_hypercall_output out = {0};
> + u64 ret;
> +
> + /*
> + * Emulate the MSR read via hypercall. More info about ABI
> + * can be found in TDX Guest-Host-Communication Interface
> + * (GHCI), sec titled "TDG.VP.VMCALL<Instruction.RDMSR>".
> + */
> + ret = _tdx_hypercall(EXIT_REASON_MSR_READ, msr, 0, 0, 0, &out);
> +
> + *err = ret ? -EIO : 0;
> +
> + return out.r11;
> +}
> +
> +static int tdx_write_msr_safe(unsigned int msr, unsigned int low,
> + unsigned int high)
> +{
> + u64 ret;
> +
> + WARN_ON_ONCE(tdx_is_context_switched_msr(msr));

This fails to build, tdx_is_context_switched_msr() is missing.

> @@ -136,19 +171,33 @@ unsigned long tdx_get_ve_info(struct ve_info *ve)
> int tdx_handle_virtualization_exception(struct pt_regs *regs,
> struct ve_info *ve)
> {
> + unsigned long val;
> + int ret = 0;
> +
> switch (ve->exit_reason) {
> case EXIT_REASON_HLT:
> tdx_halt();
> break;
> + case EXIT_REASON_MSR_READ:
> + val = tdx_read_msr_safe(regs->cx, (unsigned int *)&ret);

Why the 'unsigned int *' cast?

Also, 'val' should have the same type as the one returned by
tdx_read_msr_safe(). (Though it technically doesn't matter here.)

--
Josh

\
 
 \ /
  Last update: 2021-10-06 21:50    [W:0.394 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site