From: Avi Kivity <avi@redhat.com>
To: Sheng Yang <sheng@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: x86: XSAVE/XRSTOR live migration support
Date: Thu, 10 Jun 2010 12:19:25 +0300 [thread overview]
Message-ID: <4C10AE1D.40604@redhat.com> (raw)
In-Reply-To: <1276140433-29570-2-git-send-email-sheng@linux.intel.com>
On 06/10/2010 06:27 AM, Sheng Yang wrote:
> This patch enable save/restore of xsave state.
>
> Signed-off-by: Sheng Yang<sheng@linux.intel.com>
> ---
> Documentation/kvm/api.txt | 76 ++++++++++++++++++++++++++++++
> arch/x86/include/asm/kvm.h | 24 ++++++++++
> arch/x86/kvm/x86.c | 110 ++++++++++++++++++++++++++++++++++++++++++++
> include/linux/kvm.h | 12 +++++
> 4 files changed, 222 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/kvm/api.txt b/Documentation/kvm/api.txt
> index 159b4ef..cb0afa2 100644
> --- a/Documentation/kvm/api.txt
> +++ b/Documentation/kvm/api.txt
> @@ -922,6 +922,82 @@ Define which vcpu is the Bootstrap Processor (BSP). Values are the same
> as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
> is vcpu 0.
>
> +4.41 KVM_GET_XSAVE
> +
> +Capability: KVM_CAP_XSAVE
> +Architectures: x86
> +Type: vcpu ioctl
> +Parameters: struct kvm_xsave (out)
> +Returns: 0 on success, -1 on error
> +
> +struct kvm_xsave {
> + __u32 size;
> + __u32 region[1000];
> +};
> +
> +This ioctl would copy current vcpu's xsave struct to the userspace.
>
How is size interpreted?
I think we can leave it out since it is implied by the xsave header.
>
> +/* for KVM_CAP_XSAVE */
> +struct kvm_xsave {
> + __u32 size;
> + __u32 reserved[3];
> + __u32 region[1020];
> +};
>
That's different from the documentation.
> +
> +#define KVM_MAX_XCRS 1
>
Needs to be much bigger for future compatibility, since it's part of the
ABI.
> @@ -2373,6 +2375,60 @@ static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu,
> return 0;
> }
>
> +static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu,
> + struct kvm_xsave *guest_xsave)
> +{
> + u32 size;
> +
> + if (cpu_has_xsave)
> + size = sizeof(struct xsave_struct);
> + else
> + size = sizeof(struct i387_fxsave_struct);
> +
> + guest_xsave->size = size;
> + memcpy(guest_xsave->region,&vcpu->arch.guest_fpu.state->xsave, size);
>
If !cpu_has_xsave, we can create a fake xsave header that says we have
the fpu and sse, so userspace doesn't have to look at size.
You're memcpy()ing state->xsave unconditionally, even if
!cpu_has_xsave. That works, but it's cleaner to access the ->fxsave member.
> +
> +static void kvm_vcpu_ioctl_x86_get_xcrs(struct kvm_vcpu *vcpu,
> + struct kvm_xcrs *guest_xcrs)
> +{
> + guest_xcrs->nr_xcrs = 1;
> + guest_xcrs->flags = 0;
> + guest_xcrs->xcrs[0].value = vcpu->arch.xcr0;
> +}
>
guest_xcrs[0].xcr = ...
What if !cpu_has_xsave? Probably should set nr_xcrs = 0.
> +
> +static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
> + struct kvm_xcrs *guest_xcrs)
> +{
> + if (guest_xcrs->nr_xcrs< 1)
> + return 1;
>
Not really needed.
> +
> + /* Userspace may override the initial value of xcr0... */
> + if (guest_xcrs->xcrs[0].value != 0) {
>
Why check the value? What about checking the xcrs[].xcr?
> + vcpu->arch.xcr0 = guest_xcrs->xcrs[0].value;
> + vcpu->guest_xcr0_loaded = 0;
> + }
>
Need to loop over the array. Also, call kvm_set_xcr() to get checks to
be performed.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2010-06-10 9:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-10 3:27 [PATCH v8 1/2] KVM: VMX: Enable XSAVE/XRSTOR for guest Sheng Yang
2010-06-10 3:27 ` [PATCH 2/2] KVM: x86: XSAVE/XRSTOR live migration support Sheng Yang
2010-06-10 9:19 ` Avi Kivity [this message]
2010-06-10 9:05 ` [PATCH v8 1/2] KVM: VMX: Enable XSAVE/XRSTOR for guest Avi Kivity
2010-06-10 18:27 ` Marcelo Tosatti
2010-06-11 5:15 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C10AE1D.40604@redhat.com \
--to=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=sheng@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.