Received: by 10.223.164.202 with SMTP id h10csp2041448wrb; Thu, 16 Nov 2017 08:26:32 -0800 (PST) X-Google-Smtp-Source: AGs4zMY7BGLNa6r9KwuUPJiAPFmIvN5UIHNKsMFypvODzko9BnUbRoK0o6AJuEKl9mR8+p2nKaj/ X-Received: by 10.84.235.3 with SMTP id o3mr2274372plk.30.1510849592319; Thu, 16 Nov 2017 08:26:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510849592; cv=none; d=google.com; s=arc-20160816; b=CrJZ97KWccpmctZXRxds9OcpAUDyff9v7Eemd9XZlaOYBVGnIjjzBZpCHADF2rPews ABTN1XY1B5EgyQV3vvrapdhEL5Ud0Rwx4gWpWo8l0oqJgrOMLcg/yEIfmu6o/g3khMb6 iOBO4refNQD2wC1cxUVlGn+a7451aymc1oK6IvpBIgaLKuBMNLYufDi1bbBIK9Nxe+h9 3odrRzD+eul3kN4Of8Xx4M0uFYGXpQCg5yksaRmBPtL11eJEKbZRUsN3ctTEWsPp4HFr qgjSO/QHmOK3zgJhiUb+zdU32UxESOwWpDVzjvPizwhndz1HOHt33w0ef78YwkUfGVVf yWKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=ZhVEyVfG2WqcmfffLdwf/nP8/boif0kGcE9xdBkZVc4=; b=bieuh/9H7bllQ6APmuH0FjW/SXhY3gbey0XyYhZdvXfUfNcOw23DpSJdpWvqyMIgF6 THbZjDeu0rbdyGNOekYVcyrITnTp2mvqjW+BHyGaoFKWvdgHf2c2gE+VhdHKoLmixYVF aDWwxYtVGoenaxBwWSof2DKFOiXt1vBd5rFIAtydtqCnvb9+AbDd734zb2TMWbxmT0+c vbZrgwlDLOxlaellWlvgTz0njyDdrVc6h/gVVHekf3+W9xfYHyEBTCzk0lt6ZVcwlmwA Dfcdy5hp7QwhgkUGRL/v0upTZvZgs0b3pHQasyay5hlzAt4Voj+oQfcOnnARFmqnBv24 Koig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iyyB1SAp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q8si1216108pfa.310.2017.11.16.08.26.05; Thu, 16 Nov 2017 08:26:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iyyB1SAp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934917AbdKPNgN (ORCPT + 91 others); Thu, 16 Nov 2017 08:36:13 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:47173 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759696AbdKPNgC (ORCPT ); Thu, 16 Nov 2017 08:36:02 -0500 Received: by mail-ot0-f194.google.com with SMTP id s4so13281232ote.4; Thu, 16 Nov 2017 05:36:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=ZhVEyVfG2WqcmfffLdwf/nP8/boif0kGcE9xdBkZVc4=; b=iyyB1SApls6qAWzG2S9wLjhAROpCBh75V8SV0d5J6VUEYG7HKEOi/TJtVmSXRi6bYi EFW3Z0ULWi/dXcgtu2x+wWRDijFLJKwXmPqanPkwOeay9bdkf2b/ymRftW6f2pERlEW0 Kr5/0CNQKHDbwLoeACMD6SikBnrKREyb0yQinc6GxyxD1MrzAHDIjmdPUHNv/Lxj+Tfv 1qjepJAj3F+jo5Das0wXFyRnoBDCykLh74jCr+HmHFD2oMGVIfHyhXY6IdzRw6lzOT7P rs4ZH+N/P2ASYju1tfMofdrLVsm+cxx/nVzfiHr37RJAX7pPylhjqMX7P/SSUHt7KOqn sGyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ZhVEyVfG2WqcmfffLdwf/nP8/boif0kGcE9xdBkZVc4=; b=LfRpgzFGTtAMnGw/i4HIpDMJgT/C2OoiYw+VSlmMQLspxqSNqFwCK4+Tbma/iGh7zK FwD/ftVnsMEDytnSlHKC0Wv1JR8L5b5sm5DLJ2oeyFnvDxSLrZNmltfrVw1LsIp1q6dS KMPUTFh/UOkuEE1SjCcux2kQfMOpcIfArAcVtfeGXb4SGoEr4eFR0WDn2YBaB7yssTw7 Huv0ROL9AlwBsXlgXcxNaNPHqMBP6e7YoDG1A9+wv7CzGcXAgcK4DeE1gKnAcEfUP4xk +RZU1pOV49GzqQzmjp+m/+DX++rNZxCRN2o7DMJhTrlI+eL3IVh8Wb/6RCX/WL1FPuU0 OUrQ== X-Gm-Message-State: AJaThX7CUVIqzfehtK1MhDkm858N5PiztztXVNpNaTU7VitWprThiSgM wWgU/5yIwO/BKjIjIbXFH7Y= X-Received: by 10.157.17.80 with SMTP id p16mr1273746otp.371.1510839361840; Thu, 16 Nov 2017 05:36:01 -0800 (PST) Received: from [0.0.0.0] ([47.89.242.186]) by smtp.gmail.com with ESMTPSA id 80sm435944otj.75.2017.11.16.05.35.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 05:36:01 -0800 (PST) Subject: Re: [PATCH 1/2] x86,kvm: move qemu/guest FPU switching out to vcpu_run To: Paolo Bonzini , Rik van Riel , "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 References: <20171114215424.32214-1-riel@redhat.com> <20171114215424.32214-2-riel@redhat.com> <2e83dd3f-8f03-03ac-45e0-f2fae1d17013@gmail.com> <1510756981.21121.291.camel@redhat.com> <1510806094.21121.303.camel@redhat.com> <0fc15536-0b34-51b6-cc14-00989825b0bc@gmail.com> <9ba2d4c1-0781-419e-ddeb-77e0494583d2@redhat.com> <00231a24-f1a2-324e-1c32-0a5a7a3995f1@redhat.com> From: Quan Xu Message-ID: Date: Thu, 16 Nov 2017 21:35:53 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <00231a24-f1a2-324e-1c32-0a5a7a3995f1@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.. > From 1584237323722403554@xxx Thu Nov 16 15:34:06 +0000 2017 X-GM-THRID: 1584017174910331026 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread