Re: [RFC v2-fix 1/1] x86/tdx: Handle in-kernel MMIO

From: Sean Christopherson
Date: Tue May 18 2021 - 14:17:12 EST


On Tue, May 18, 2021, Andi Kleen wrote:
> > Why does this code exist at all? TDX and SEV-ES absolutely must share code for
> > handling MMIO reflection. It will require a fair amount of refactoring to move
> > the guts of vc_handle_mmio() to common code, but there is zero reason to maintain
> > two separate versions of the opcode cracking.
>
> While that's true on the high level, all the low level details are
> different. We looked at unifying at some point, but it would have been a
> callback hell. I don't think unifying would make anything cleaner.

How hard did you look? The only part that _must_ be different between SEV and
TDX is the hypercall itself, which is wholly contained at the very end of
vc_do_mmio().

Despite vc_slow_virt_to_phys() taking a pointer to the ghcb, it's unused and
thus the function is 100% generic.

The ghcb->shared_buffer usage throughout the upper levels can be eliminated by
refactoring the stack to take a "u64 *val", since MMIO accesses are currently
bounded to 8 bytes.

> Besides the bulk of the decoding work is already unified in the common x86
> instruction decoder. The actual actions are different, and the code fetching
> is also different

Huh? What do you mean by "actual actions"? Why is the code fetch different?