On Wed, Oct 13, 2021, Paolo Bonzini wrote: > Patches 2 to 7 are a bunch of cleanups to emulator_pio_in and > emulator_pio_in_out, so that the final SEV code is a little easier > to reason on. Just a little, no big promises. IMO, this series goes in the wrong direction and doesn't make the mess any better, just different. The underlying issue is that kernel_pio() does the completely horrendous thing of consuming vcpu->arch.pio. That leads to the juggling that this series tries to clean up, but it's essentially an impossible problem to solve because the approach itself is broken. The _only_ reason vcpu->arch.pio (the structure) exists is to snapshot a port I/O operation that didn't originate from the emulator before exiting to userspace, i.e. "fast" I/O and now SEV-ES. Ignoring those two, all info comes from the emulator and a single flag or even the cui pointer would suffice. Ditto for pio_data, it's purely needed to let userspace read/write values, its use directly in any code except those specific paths is just bad code. So instead of juggling vcpu->arch.pio.count in weird places, just don't set the damn thing in the first place. Untested patches attached that frame in where I think we should go with this. I'll be offline until Monday, apologies for the inconvenience.