Re: [PATCHv3 4/4] x86/sev-es: Use insn_decode_mmio() for MMIO implementation

Tom Lendacky
2021-11-29T21:33:58Z

On 11/3/21 10:45 AM, Kirill A. Shutemov wrote:
> From: "Kirill A. Shutemov" <kirill@shutemov.name>
>
> Switch SEV implementation to insn_decode_mmio(). The helper is going
> to be used by TDX too.
>
> No functional changes. It is only build-tested.
>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Joerg Roedel <jroedel@suse.de>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Reviewed-by: Andi Kleen <ak@linux.intel.com>
> Reviewed-by: Tony Luck <tony.luck@intel.com>
> ---
> arch/x86/kernel/sev.c | 171 ++++++++++--------------------------------
> 1 file changed, 40 insertions(+), 131 deletions(-)
>
> diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c
> index a6895e440bc3..8fea7ea67c67 100644
> --- a/arch/x86/kernel/sev.c
> +++ b/arch/x86/kernel/sev.c

...

> break;
> + case MMIO_READ_ZERO_EXTEND:
> + ret = vc_do_mmio(ghcb, ctxt, bytes, true);
> + if (ret)
> + break;
> +

Can you keep the "/* Zero extend based on operand size */" comment here
much like you do below with the sign extended operation below.

Thanks,
Tom

> + memset(reg_data, 0, insn->opnd_bytes);
> + memcpy(reg_data, ghcb->shared_buffer, bytes);
> + break;
> + case MMIO_READ_SIGN_EXTEND:
> + ret = vc_do_mmio(ghcb, ctxt, bytes, true);
> + if (ret)
> + break;
>
> - /* MOVS instruction */
> - case 0xa4:
> - bytes = 1;
> - fallthrough;
> - case 0xa5:
> - if (!bytes)
> - bytes = insn->opnd_bytes;
> + if (bytes == 1) {
> + u8 *val = (u8 *)ghcb->shared_buffer;
>
> - ret = vc_handle_mmio_movs(ctxt, bytes);
> + sign_byte = (*val & 0x80) ? 0xff : 0x00;
> + } else {
> + u16 *val = (u16 *)ghcb->shared_buffer;
> +
> + sign_byte = (*val & 0x8000) ? 0xff : 0x00;
> + }
> +
> + /* Sign extend based on operand size */
> + memset(reg_data, sign_byte, insn->opnd_bytes);
> + memcpy(reg_data, ghcb->shared_buffer, bytes);
> break;
> - /* Two-Byte Opcodes */
> - case 0x0f:
> - ret = vc_handle_mmio_twobyte_ops(ghcb, ctxt);
> + case MMIO_MOVS:
> + ret = vc_handle_mmio_movs(ctxt, bytes);
> break;
> default:
> ret = ES_UNSUPPORTED;
> + break;
> }
>
> return ret;
>