Re: [PATCH v2 10/13] KVM: x86: Shrink the usercopy region of the emulation context

From: Sean Christopherson
Date: Mon Mar 02 2020 - 14:19:45 EST


On Mon, Mar 02, 2020 at 07:40:27PM +0100, Paolo Bonzini wrote:
> On 26/02/20 18:51, Vitaly Kuznetsov wrote:
> >> +
> >> + /* Here begins the usercopy section. */
> >> + struct operand src;
> >> + struct operand src2;
> >> + struct operand dst;
> > Out of pure curiosity, how certain are we that this is going to be
> > enough for userspaces?
> >
>
> And also, where exactly are the user copies done?

Anything that funnels into ctxt->ops->read_std() or ctxt->ops->write_std(),
e.g.

if (ctxt->src2.type == OP_MEM) {
rc = segmented_read(ctxt, ctxt->src2.addr.mem,
&ctxt->src2.val, ctxt->src2.bytes);
if (rc != X86EMUL_CONTINUE)
goto done;
}


segmented_read() : @data = &ctxt->src2.val
|
|-> read_emulated()
|
|-> ctxt->ops->read_emulated() / emulator_read_emulated()
|
|-> emulator_read_write()
|
|-> emulator_read_write_onepage()
|
|-> ops->read_write_emulate() / read_emulate()
|
|-> kvm_vcpu_read_guest()
|
...
|-> __kvm_read_guest_page()
|
|-> __copy_from_user(data, ...)