Re: [PATCHv4 17/30] x86/tdx: Add port I/O emulation

Dave Hansen
2022-02-25T04:00:00Z

On 2/24/22 07:56, Kirill A. Shutemov wrote:
> @@ -347,6 +399,8 @@ static bool virt_exception_kernel(struct pt_regs *regs, struct ve_info *ve)
> return handle_cpuid(regs);
> case EXIT_REASON_EPT_VIOLATION:
> return handle_mmio(regs, ve);
> + case EXIT_REASON_IO_INSTRUCTION:
> + return handle_io(regs, ve->exit_qual);

Sorry to keep throwing random new things at this patch set. Thanks for
bearing with me.

Is there anything to keep these port I/O #VE's from occurring in
userspace? It's not how things are normally done, but is there
something fundamental to keep ioperm() and friends from working in TDX
guests?

As it stands with this set, userspace would probably
1. Succeed with the ioperm()
2. Do a port I/O instruction
3. Trigger a #VE
4. Get killed by the SIGSEGV that came from the #VE handler

That's not a horrible state of affairs. But, if this *can* happen, it
might be nice to just refuse the ioperm() in the first place.