This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Home Products Support Community News


Re: [Xen-devel] [Patch] Allowing PV-OPS kernel to detect whether XSAVE i

To: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Subject: Re: [Xen-devel] [Patch] Allowing PV-OPS kernel to detect whether XSAVE is supported
From: Haitao Shan <maillists.shan@xxxxxxxxx>
Date: Wed, 10 Nov 2010 09:45:51 +0800
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>, Keir Fraser <keir.fraser@xxxxxxxxxxxxx>
Delivery-date: Tue, 09 Nov 2010 17:46:58 -0800
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=urVtnHNRjhWpUdwboXoNOgZuJlzPy95uFfaxn2UEQ5s=; b=qfCvFDer3JkwgRbR4F+ka23Ax5mBTrjv8GbfQCOkx4CVsLDRhKNt0TYNh9tuPlulPb 67uYo3hoo6yvoDhS05NB5ss/Nch1l1VA0FWwhhqL0Ij/OcwSzZAv5Xg6NvL8Y1icbdMz fsUlIDq4rdfor0jrYYiNOnkruM71Z1D7F4cFo=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=a1NbatzZ409Zle/vWJ1yqmPHGhm8ziGLTzNgrSGbalpJyiVtpKS2Nlt6ZhThulCidO F80R5iHzn0NH89fc/KEmJfFoQmsF+OTHdnlUXJxgwdXXwL1+4j2NlnyvqLMMudHN2pXJ E6AwSSgBlKOKqPZfQRNsm6CLWOBYzF8EYSAKM=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4CD9EA4E.2040805@xxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <AANLkTi=dR3b7N5xUa2E=gLnVFdVWYX=S0fXN-g8OaJtP@xxxxxxxxxxxxxx> <4CD9A73B.2070909@xxxxxxxx> <AANLkTimeXpoC08=RLGxsQZSrf4EjR2vvCFHtuhjr+eNb@xxxxxxxxxxxxxx> <4CD9EA4E.2040805@xxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
>> If user mode sees both are set, they can use it actually. So we
>> initially set FP and SSE in XCR0 for guest. If user mode wants to use
>> it, guest kernel still can manage the state using traditional FPU
>> save/restore mechanism. If user mode wants to access more extended
>> states, it has to acquire kernel's support for turning on related bit
>> in XCR0, which is finally controlled by Xen now.
> Are you saying that usermode can use XSAVE, AVX and other instruction
> set extensions successfully if Xen supports them, even if the guest OS
> doesn't?  That sounds unlikely - what happens when, for example, an old
> Linux wants to context switch from one Linux task to another on a VCPU?
> How will the task's context get saved/reloaded properly?
Actually not. I mean user mode can use XSAVE instruction itself but
not AVX or any future instruction extensions. Using the latter would
require setting XCR0 properly, which is owned and managed by Xen
itself. As I said, initially Xen sets XCR0 to be FPU/SSE only for
guest (we do do XCR0 switch when vcpu context switch, this is a
per-vcpu setting). Unless guest kernel requires to enable more
extended states through XSETBV (this is ROOT ring 0 instruction only),
it won't be changed.
And in this case, guest kernel can still use original FXSAVE mechanism
to provide context switching support to its user space apps.
It just means user mode can use XSAVE instruction if it wans to use
this instruction to do save/restore itself.
If user mode wants more, it has to check kernel's SW interface support
for turning on more extended states management (via XSETBV in kernel
finally). But old kernels just do not have such kind of interface.

> Your kernel changes seem fine, and should allow a modern kernel to
> support XSAVE and all the CPU features that go along with it.  But I'm
> really concerned that your Xen changes will cause previously working
> usermode programs to start erroneously using XSAVE when the guest kernel
> cannot support it.
Well, I am concerned too. But I still think the current approach
should be architecturally viable. But there may be bugs in my code

>> I have a few AVX test programs running both inside PV guest and HVM.
>> However, I have to admit that my aim is to test Xen's fpu context
>> switching using Xsave and guest save/restore.
> Could you make them available for testing?
I will return to you later for answer to this question. I needs to
judge the correct Intel policy and channel when doing such a release.

> IanJ: It looks like it would be useful to add some tests to the suite to
> make sure all this extended context is save/restored properly...
> Thanks,
>    J

Xen-devel mailing list