From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v3] KVM: x86: XSAVE/XRSTOR live migration support Date: Sun, 13 Jun 2010 11:26:18 +0300 Message-ID: <4C14962A.9030608@redhat.com> References: <1276230971-5990-1-git-send-email-sheng@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , kvm@vger.kernel.org To: Sheng Yang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:64622 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753084Ab0FMI4d (ORCPT ); Sun, 13 Jun 2010 04:56:33 -0400 In-Reply-To: <1276230971-5990-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/11/2010 07:36 AM, Sheng Yang wrote: > This patch enable save/restore of xsave state. > > +static int kvm_vcpu_ioctl_x86_set_xsave(struct kvm_vcpu *vcpu, > + struct kvm_xsave *guest_xsave) > +{ > + u64 xstate_bv = > + *(u64 *)&guest_xsave->region[XSAVE_HDR_OFFSET / sizeof(u32)]; > + int size; > + > + if (cpu_has_xsave) { > + if (xstate_bv& XSTATE_YMM) > + size = XSAVE_YMM_OFFSET + XSAVE_YMM_SIZE; > + else > + size = XSAVE_HDR_OFFSET + XSAVE_HDR_SIZE; > + memcpy(&vcpu->arch.guest_fpu.state->xsave, > + guest_xsave->region, size); > This allows userspace to overflow host memory by specifying XSTATE_YMM on a host that doesn't support it. Better to just use the host's size of the structure. > + } else { > + if (xstate_bv& ~XSTATE_FPSSE) > + return -EINVAL; > + size = sizeof(struct i387_fxsave_struct); > + memcpy(&vcpu->arch.guest_fpu.state->fxsave, > + guest_xsave->region, size); > + } > + return 0; > +} > + > > + > +static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu, > + struct kvm_xcrs *guest_xcrs) > +{ > + int i, r = 0; > + > + if (!cpu_has_xsave) > + return -EINVAL; > Too strict? > + > + if (guest_xcrs->nr_xcrs> KVM_MAX_XCRS) > + return -EFAULT; > EFAULT is for faults during access to userspace. EINVAL or E2BIG. Need to ensure flags is 0 for forward compatibility. > + > + for (i = 0; i< guest_xcrs->nr_xcrs; i++) > + /* Only support XCR0 currently */ > + if (guest_xcrs->xcrs[0].xcr == XCR_XFEATURE_ENABLED_MASK) { > + r = __kvm_set_xcr(vcpu, XCR_XFEATURE_ENABLED_MASK, > + guest_xcrs->xcrs[0].value); > + break; > + } > + if (r) > + r = -EFAULT; > EINVAL > + return r; > +} > + > -- error compiling committee.c: too many arguments to function