mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Quan Xu <quan.xu0@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Rik van Riel <riel@redhat.com>,
	"quan.xu04@gmail.com" <quan.xu04@gmail.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	david@redhat.com, borntraeger@de.ibm.com, tglx@linutronix.de,
	rkrcmar@redhat.com
Subject: Re: [PATCH 1/2] x86,kvm: move qemu/guest FPU switching out to vcpu_run
Date: Thu, 16 Nov 2017 21:35:53 +0800	[thread overview]
Message-ID: <e3cf353c-a62f-8e1c-685d-3a971605590a@gmail.com> (raw)
In-Reply-To: <00231a24-f1a2-324e-1c32-0a5a7a3995f1@redhat.com>



On 2017-11-16 20:18, Paolo Bonzini wrote:
> On 16/11/2017 13:12, Quan Xu wrote:
>> However it seems there is still some gap..
>>
>> as Rik said, "at context switch time, the context switch code will save
>> the guest FPU state to current->thread.fpu when the VCPU thread is scheduled out."
> By "guest FPU state" Rik means "guest FPU with host PKRU".
   :( actually it is host_pkru, just with different names..

> Guest PKRU is always stored in vcpu->arch.pkru rather than in the guest
> FPU state, so guest PKRU will never be in current->thread.fpu.state either.
>
> KVM_GET_XSAVE will the guest FPU state with vcpu->arch.pkru and
> migration will work properly.
   agreed, I fix it.. that's why I concern.. there are so much methods to
   write PKRU with host_pkru/guest_pkru..

  after migration, KVM_GET|SET_XSAVE restore the right pkru.. but we 
introduce
  another method:

       -- When the VCPU thread is scheduled back in, the context
          switch code will restore current->thread.fpu to the FPU
          registers.


there is still a window to restore current->thread.fpu to the FPU 
registers before enter guest mode and

preempt_disable().

on target machine, after migration, the pkru value is source_host_pkru 
in current->thread.fpu.

in case,

             source_host_pkru_value != guest_pkru_value,
             target_host_pkru_value == guest_pkru_value..

source_host_pkru_value may be restored to PKRU.. make pkru status inconsistent..


thanks

Quan
Alibaba Cloud
> Thanks,
>
> Paolo
>
>> after preempt_enable() in vcpu_enter_guest(), the vcpu thread is
>> scheduled out,
>> in kvm_x86_ops->run, the PKRU has been restored with host_pkru (IF
>> guest_pkru != host_pkru)..
>> instead of guest_pkru..
>>
>> then the PKRU is host_pkru, how to save guest_pkru current->thread.fpu?
>>
>> as mentioned, all this _assumes_ that the pkru is in
>> current->thread.fpu.state as well.
>>
>>
>> thanks,
>>
>> Quan
>> Alibaba Cloud
>>
>>> Context switching will only happen in vcpu_enter_guest() after
>>> preempt_enable() for a preemptible kernel, or in vcpu_run via
>>> cond_resched() for a non-preemptible kernel.
>>>
>>> Thanks,
>>>
>>> Paolo
>>>
>>>> VM migration again, in case,
>>>>              source_host_pkru_value != guest_pkru_value,
>>>>              target_host_pkru_value == guest_pkru_value..
>>>>
>>>> the pkru status would be inconsistent..
>

  reply	other threads:[~2017-11-16 13:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-14 21:54 [PATCH v2 0/2] x86,kvm: move qemu/guest FPU switching out to kvm_arch_vcpu_ioctl_run riel
2017-11-14 21:54 ` [PATCH 1/2] x86,kvm: move qemu/guest FPU switching out to vcpu_run riel
2017-11-15  0:47   ` Wanpeng Li
2017-11-15  3:03     ` Rik van Riel
2017-11-15  4:33       ` Wanpeng Li
2017-11-15 14:40         ` Rik van Riel
2017-11-16  5:54           ` Wanpeng Li
2017-11-15  6:53   ` quan.xu04
2017-11-15 14:43     ` Rik van Riel
2017-11-15 15:09       ` Paolo Bonzini
2017-11-16  2:50       ` Quan Xu
2017-11-16  4:21         ` Rik van Riel
2017-11-16  5:06           ` Quan Xu
2017-11-16 10:21             ` Paolo Bonzini
2017-11-16 12:12               ` Quan Xu
2017-11-16 12:18                 ` Paolo Bonzini
2017-11-16 13:35                   ` Quan Xu [this message]
2017-11-16 13:39                     ` Paolo Bonzini
     [not found]                       ` <d67cef62-3165-50cd-36e8-be7c555dc79e@gmail.com>
2017-11-16 17:50                         ` Paolo Bonzini
2017-11-17  2:54                           ` Quan Xu
2017-11-14 21:54 ` [PATCH 2/2] x86,kvm: remove KVM emulator get_fpu / put_fpu riel

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=e3cf353c-a62f-8e1c-685d-3a971605590a@gmail.com \
    --to=quan.xu0@gmail.com \
    --cc=borntraeger@de.ibm.com \
    --cc=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=quan.xu04@gmail.com \
    --cc=riel@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®