All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <guangrong.xiao@linux.intel.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: pbonzini@redhat.com, imammedo@redhat.com, kvm@vger.kernel.org,
	mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com,
	qemu-devel@nongnu.org, stefanha@redhat.com,
	dan.j.williams@intel.com, rth@twiddle.net,
	Dave Hansen <dave.hansen@intel.com>,
	"Yu, Yu-cheng" <yu-cheng.yu@intel.com>,
	"Wang, Yong Y" <yong.y.wang@intel.com>,
	"virt-intel-list@redhat.com" <virt-intel-list@redhat.com>,
	"Kasten, Robert A" <robert.a.kasten@intel.com>,
	"Lai, Paul C" <paul.c.lai@intel.com>,
	"Xiao, Guangrong" <guangrong.xiao@intel.com>,
	"ruwang@redhat.com" <ruwang@redhat.com>,
	"Shankar, Ravi V" <ravi.v.shankar@intel.com>,
	"Yu, Fenghua" <fenghua.yu@intel.com>
Subject: Re: XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] [PATCH] target-i386: add Skylake-Client cpu mode)
Date: Wed, 4 May 2016 01:44:20 +0800	[thread overview]
Message-ID: <5728E374.4020809@linux.intel.com> (raw)
In-Reply-To: <20160503161131.GN4457@thinpad.lan.raisama.net>



On 05/04/2016 12:11 AM, Eduardo Habkost wrote:
> (CCing KVM mailing list)
>
> On Tue, May 03, 2016 at 02:38:44PM +0800, Xiao Guangrong wrote:
>> On 04/29/2016 01:34 AM, Eduardo Habkost wrote:
>>> On Wed, Apr 27, 2016 at 04:13:06PM +0800, Xiao Guangrong wrote:
> [...]
>>>> 1. As XSAVES is disabled in upstream linux kernel by commit e88221c50
>>>> (x86/fpu: Disable XSAVES* support for now), QEMU will complain about
>>>> "warning: host doesn't support requested feature: CPUID.0DH:EAX.xsaves [bit 3]"
>>>
>>> I have been looking at the GET_SUPPORTED_CPUID code and I am not
>>> sure if commit e88221c50 is supposed to be affecting
>>> GET_SUPPORTED_CPUID, or not. It looks like it shouldn't, so I
>>> don't know why QEMU is reporting xsaves as unsupported.
>>>
>>> For reference, GET_SUPPORTED_CPUID code for function == 0xd &&
>>> idx == 1 will run:
>>>
>>>    unsigned f_xsaves = kvm_x86_ops->xsaves_supported() ? F(XSAVES) : 0;
>>>    const u32 kvm_cpuid_D_1_eax_x86_features =
>>>            F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | f_xsaves;
>>>    /* [...] */
>>>    do_cpuid_1_ent(&entry[i], function, idx);
>>>    entry[i].eax &= kvm_cpuid_D_1_eax_x86_features;
>>>
>>> do_cpuid_1_ent() just executes the CPUID instruction.
>>>
>>> kvm_x86_ops->xsaves_supported is:
>>>
>>>    static bool vmx_xsaves_supported(void)
>>>    {
>>>            return vmcs_config.cpu_based_2nd_exec_ctrl &
>>>                    SECONDARY_EXEC_XSAVES;
>>>    }
>>>
>>> Is GET_SUPPORTED_CPUID returning XSAVES as unsupported in the
>>> system where you are running tests?
>>
>> No, it returns that XSAVES is supported.
>
> You mean it returns it as unsupported, right?

Sorry for the typo. GET_SUPPORTED_CPUID returns XSAVES is not supported if the feature
is cleared by host.

>
>>
>> Actually F(SAVES) bit is cleared later, in __do_cpuid_ent():
>> 536                                 entry[i].eax &= kvm_cpuid_D_1_eax_x86_features;
>> 537                                 cpuid_mask(&entry[i].eax, CPUID_D_1_EAX);
>>
>> The bits unsupported by boot_cpu_data.x86_capability[CPUID_D_1_EAX] will be cleared.
>
> Oh, I didn't notice the cpuid_mask() call. You're right.
>
>>
>> During boot, the capability is adjusted by cpu_caps_cleared, in arch/x86/kernel/cpu/common.c:
>>   971         /* Clear/Set all flags overriden by options, after probe */
>>   972         for (i = 0; i < NCAPINTS; i++) {
>>   973                 c->x86_capability[i] &= ~cpu_caps_cleared[i];
>>   974                 c->x86_capability[i] |= cpu_caps_set[i];
>>   975         }
>>
>> Actually, setup_clear_cpu_cap() exactly acts on cpu_caps_cleared():
>> 112 #define setup_clear_cpu_cap(bit) do { \
>> 113         clear_cpu_cap(&boot_cpu_data, bit);     \
>> 114         set_bit(bit, (unsigned long *)cpu_caps_cleared); \
>> 115 } while (0)
>>
>> This is the reason why setup_clear_cpu_cap(X86_FEATURE_XSAVES) introduced by commit e88221c50
>> caused XSAVES unreported by KVM.
>
> So, is this the right behavior, or KVM can support exposing
> XSAVES to guests even if the cpu_cap bit is cleared? I don't know
> if exposing XSAVES to KVM guests depend on reworking kernel xsave
> code or not.
>

I think current behavior is right. KVM uses kernel's APIs to save/restore FPU context that may
cause XSAVE not properly switched if XSAVES is used in VM but host does not see it.



WARNING: multiple messages have this Message-ID (diff)
From: Xiao Guangrong <guangrong.xiao@linux.intel.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: pbonzini@redhat.com, imammedo@redhat.com, kvm@vger.kernel.org,
	mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com,
	qemu-devel@nongnu.org, stefanha@redhat.com,
	dan.j.williams@intel.com, rth@twiddle.net,
	Dave Hansen <dave.hansen@intel.com>,
	"Yu, Yu-cheng" <yu-cheng.yu@intel.com>,
	"Wang, Yong Y" <yong.y.wang@intel.com>,
	"virt-intel-list@redhat.com" <virt-intel-list@redhat.com>,
	"Kasten, Robert A" <robert.a.kasten@intel.com>,
	"Lai, Paul C" <paul.c.lai@intel.com>,
	"Xiao, Guangrong" <guangrong.xiao@intel.com>,
	"ruwang@redhat.com" <ruwang@redhat.com>,
	"Shankar, Ravi V" <ravi.v.shankar@intel.com>,
	"Yu, Fenghua" <fenghua.yu@intel.com>
Subject: Re: [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was Re: [PATCH] target-i386: add Skylake-Client cpu mode)
Date: Wed, 4 May 2016 01:44:20 +0800	[thread overview]
Message-ID: <5728E374.4020809@linux.intel.com> (raw)
In-Reply-To: <20160503161131.GN4457@thinpad.lan.raisama.net>



On 05/04/2016 12:11 AM, Eduardo Habkost wrote:
> (CCing KVM mailing list)
>
> On Tue, May 03, 2016 at 02:38:44PM +0800, Xiao Guangrong wrote:
>> On 04/29/2016 01:34 AM, Eduardo Habkost wrote:
>>> On Wed, Apr 27, 2016 at 04:13:06PM +0800, Xiao Guangrong wrote:
> [...]
>>>> 1. As XSAVES is disabled in upstream linux kernel by commit e88221c50
>>>> (x86/fpu: Disable XSAVES* support for now), QEMU will complain about
>>>> "warning: host doesn't support requested feature: CPUID.0DH:EAX.xsaves [bit 3]"
>>>
>>> I have been looking at the GET_SUPPORTED_CPUID code and I am not
>>> sure if commit e88221c50 is supposed to be affecting
>>> GET_SUPPORTED_CPUID, or not. It looks like it shouldn't, so I
>>> don't know why QEMU is reporting xsaves as unsupported.
>>>
>>> For reference, GET_SUPPORTED_CPUID code for function == 0xd &&
>>> idx == 1 will run:
>>>
>>>    unsigned f_xsaves = kvm_x86_ops->xsaves_supported() ? F(XSAVES) : 0;
>>>    const u32 kvm_cpuid_D_1_eax_x86_features =
>>>            F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | f_xsaves;
>>>    /* [...] */
>>>    do_cpuid_1_ent(&entry[i], function, idx);
>>>    entry[i].eax &= kvm_cpuid_D_1_eax_x86_features;
>>>
>>> do_cpuid_1_ent() just executes the CPUID instruction.
>>>
>>> kvm_x86_ops->xsaves_supported is:
>>>
>>>    static bool vmx_xsaves_supported(void)
>>>    {
>>>            return vmcs_config.cpu_based_2nd_exec_ctrl &
>>>                    SECONDARY_EXEC_XSAVES;
>>>    }
>>>
>>> Is GET_SUPPORTED_CPUID returning XSAVES as unsupported in the
>>> system where you are running tests?
>>
>> No, it returns that XSAVES is supported.
>
> You mean it returns it as unsupported, right?

Sorry for the typo. GET_SUPPORTED_CPUID returns XSAVES is not supported if the feature
is cleared by host.

>
>>
>> Actually F(SAVES) bit is cleared later, in __do_cpuid_ent():
>> 536                                 entry[i].eax &= kvm_cpuid_D_1_eax_x86_features;
>> 537                                 cpuid_mask(&entry[i].eax, CPUID_D_1_EAX);
>>
>> The bits unsupported by boot_cpu_data.x86_capability[CPUID_D_1_EAX] will be cleared.
>
> Oh, I didn't notice the cpuid_mask() call. You're right.
>
>>
>> During boot, the capability is adjusted by cpu_caps_cleared, in arch/x86/kernel/cpu/common.c:
>>   971         /* Clear/Set all flags overriden by options, after probe */
>>   972         for (i = 0; i < NCAPINTS; i++) {
>>   973                 c->x86_capability[i] &= ~cpu_caps_cleared[i];
>>   974                 c->x86_capability[i] |= cpu_caps_set[i];
>>   975         }
>>
>> Actually, setup_clear_cpu_cap() exactly acts on cpu_caps_cleared():
>> 112 #define setup_clear_cpu_cap(bit) do { \
>> 113         clear_cpu_cap(&boot_cpu_data, bit);     \
>> 114         set_bit(bit, (unsigned long *)cpu_caps_cleared); \
>> 115 } while (0)
>>
>> This is the reason why setup_clear_cpu_cap(X86_FEATURE_XSAVES) introduced by commit e88221c50
>> caused XSAVES unreported by KVM.
>
> So, is this the right behavior, or KVM can support exposing
> XSAVES to guests even if the cpu_cap bit is cleared? I don't know
> if exposing XSAVES to KVM guests depend on reworking kernel xsave
> code or not.
>

I think current behavior is right. KVM uses kernel's APIs to save/restore FPU context that may
cause XSAVE not properly switched if XSAVES is used in VM but host does not see it.

  reply	other threads:[~2016-05-03 17:46 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27  8:13 [PATCH] target-i386: add Skylake-Client cpu mode Xiao Guangrong
2016-04-27  8:13 ` [Qemu-devel] " Xiao Guangrong
2016-04-27 11:56 ` Eduardo Habkost
2016-04-27 11:56   ` [Qemu-devel] " Eduardo Habkost
2016-04-28 17:34 ` Eduardo Habkost
2016-05-03  6:38   ` Xiao Guangrong
2016-05-03 16:11     ` XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] [PATCH] target-i386: add Skylake-Client cpu mode) Eduardo Habkost
2016-05-03 16:11       ` [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was " Eduardo Habkost
2016-05-03 17:44       ` Xiao Guangrong [this message]
2016-05-03 17:44         ` Xiao Guangrong
2016-05-03 17:53         ` XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] " Dave Hansen
2016-05-03 17:53           ` [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was " Dave Hansen
2016-05-03 18:23           ` XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] " Eduardo Habkost
2016-05-03 18:23             ` [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was " Eduardo Habkost
2016-05-03 18:29             ` XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] " Dave Hansen
2016-05-03 18:29               ` [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was " Dave Hansen
2016-05-09 13:44           ` XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] " Paolo Bonzini
2016-05-09 13:44             ` [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was " Paolo Bonzini
2016-05-12 12:03             ` Eduardo Habkost
2016-05-12 12:03               ` [Qemu-devel] " Eduardo Habkost
2016-05-12 12:06               ` XSAVES in GET_SUPPORTED_CPUID (was Re: [Qemu-devel] " Paolo Bonzini
2016-05-12 12:06                 ` [Qemu-devel] XSAVES in GET_SUPPORTED_CPUID (was " Paolo Bonzini
2016-05-20 21:39                 ` [QEMU PATCH v2] target-i386: Add Skylake-Client CPU model Eduardo Habkost
2016-05-20 21:39                   ` [Qemu-devel] " Eduardo Habkost
2016-05-23 13:46                   ` Paolo Bonzini
2016-05-23 13:46                     ` [Qemu-devel] " Paolo Bonzini
2016-06-03  3:50                     ` Xiao Guangrong
2016-06-03  3:50                       ` [Qemu-devel] " Xiao Guangrong
2016-06-03 17:27                       ` Eduardo Habkost
2016-06-03 17:27                         ` [Qemu-devel] " Eduardo Habkost
2016-04-29  3:11 ` [PATCH] target-i386: add Skylake-Client cpu mode Huang, Kai
2016-04-29  3:11   ` [Qemu-devel] " Huang, Kai
2016-04-29  3:28   ` Xiao Guangrong
2016-04-29  3:28     ` [Qemu-devel] " Xiao Guangrong

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=5728E374.4020809@linux.intel.com \
    --to=guangrong.xiao@linux.intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=ehabkost@redhat.com \
    --cc=fenghua.yu@intel.com \
    --cc=gleb@kernel.org \
    --cc=guangrong.xiao@intel.com \
    --cc=imammedo@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=paul.c.lai@intel.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=robert.a.kasten@intel.com \
    --cc=rth@twiddle.net \
    --cc=ruwang@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virt-intel-list@redhat.com \
    --cc=yong.y.wang@intel.com \
    --cc=yu-cheng.yu@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.