Received: by 10.223.164.202 with SMTP id h10csp1568453wrb; Wed, 15 Nov 2017 23:59:17 -0800 (PST) X-Google-Smtp-Source: AGs4zMbQlj+OEXWxkPd6k9CGjmcVSieravECPauVr4Oc7aHEA/zUMuAbaFjDOHNKw02+bl8hI4wT X-Received: by 10.99.124.24 with SMTP id x24mr857381pgc.196.1510819157677; Wed, 15 Nov 2017 23:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510819157; cv=none; d=google.com; s=arc-20160816; b=vd7X7T005xelH+3Fz0T6vTmip8KW8poUShqVzjAnWXusxY/WCGW1GCgpbLEc8wXnAt 18ztNKFIIH56txPRmG8T/ifSRq/926Nep0pmLwiuz3J72H4qRLmXGJYstmSWH9fvu9zw FGh5TmGq5/+PLwlG/raQMasrUsePgmdVlZpzZ8kgQmBSzzgIykBUh2kp1MoSY+j0+U+3 nLmbBzomsFNcqslCyT2hLE2/UsCtMBzvhztpKfX8OuDZUaphNjfj8sXLLwqVdmb3Dswr Eab7YgIiAk/7HHI/8k3i1xbnoo4NbE3wI27vGKV+v0MKdKInDWTur1mHzktPcs4jIVnl 9Qjg== 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=femrivKBNR8f3I8PTMe6b0ajjGOPRufX1S22PPuFmnY=; b=iJb3BTuAwECk6PpMf8WChp72B6l/qxpVca+VIhcL7dXsq5Db8HrtxgJc7T5jP4MRSK fb9QdsnCrPksJ1hSYsrbH1J/aF+iCvKU/wx/dBkHxEIGzxZfS18my0KM8Vobrkaj1FQ/ y+gcB/cyBaUIqRnEVBz4cC9Vyt6L8FcwLP8nhs0fpcXS8wcynJsB0yrLZDkMoJd55gLb dAn+HJPOHF7Lu/BRRyQu04VlY3LsvObFnrkqKKHFywDg2e/nuhNgplJDEvRCAP3TuQXs xo429ZP06OaY5ZhD95zWzkVMgRSlZI6ktiCjTGmOgfEZR/sSvPORdmcFesml+niwDLjX /FlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=paincVbT; 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 f3si471453plf.106.2017.11.15.23.59.05; Wed, 15 Nov 2017 23:59:17 -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=paincVbT; 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 S1751632AbdKPFGh (ORCPT + 90 others); Thu, 16 Nov 2017 00:06:37 -0500 Received: from mail-ot0-f175.google.com ([74.125.82.175]:52810 "EHLO mail-ot0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbdKPFG1 (ORCPT ); Thu, 16 Nov 2017 00:06:27 -0500 Received: by mail-ot0-f175.google.com with SMTP id 18so21545142oty.9; Wed, 15 Nov 2017 21:06:26 -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=femrivKBNR8f3I8PTMe6b0ajjGOPRufX1S22PPuFmnY=; b=paincVbTocCY/AKdKSPLWK8wO281sSFYmK6lrkEJLWEhEIhuS6Cv38NxkQIntd7qum vl6XmGy5YMbxnWREepvpP3WvCtEIkkRiedQjEQ3umGtK8iSzLJ5X3dRSzm//2X9pL5qG HPVppM5oOgMgA81Q93wI9FMY74TGuzKIIRlhuuIf6oB84+V9AlfsF9RrkFoaPFVUAMvn f0laL8PHu0dPsfrw2whDayEPYQlL9K2qkq9WGcel/RYqKXE+XUkFoWtSLORWPXhb6iz/ YJB7u8PvxmYa06WTNp+vlbEmRRnTPFt4SDSCtE/VoG+P0a46HOx9kYwpGkR5aAXLW1Uy +B1g== 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=femrivKBNR8f3I8PTMe6b0ajjGOPRufX1S22PPuFmnY=; b=piB7UW79VGR5CS/MIfsz/LJkm52z5DmnzpaLZByHRAjje4Q1Njge0AJpabLpQ1B3n8 2Q2x6chQ+ezfnWuj4lz+A3ZO1hYof/JtHXbUDzrh2BS56ufAsX5F55qEzjrtNt0jV1iH /Pf33qGg79cR/l4AOBe0VeoUnfnaqBbfYaBU86xXMZiSsGjdZQR4fWBSsgqbvBJSDiq4 Xuq+4zAvu0ZEOTavZ4F0gE6el2uO2fC+xpp5l3nq6QsqRHcreu4b6qvzRFwR0GuhGNFO chAM51tyQIQretun/3ZIeIlJyroWv8UsY6BSxc+QDlgoKWc7494/FIr6r7TtdKtn36hO tSUw== X-Gm-Message-State: AJaThX6ZVzZ77PWtOgpfPvdFPjajAvuW4B67lYFfvQ4Wwq3tJ5gqGtcm h+WfanCP+QKWMK6PJqZ83tw= X-Received: by 10.157.37.61 with SMTP id k58mr306495otb.110.1510808786378; Wed, 15 Nov 2017 21:06:26 -0800 (PST) Received: from [0.0.0.0] ([47.89.242.186]) by smtp.gmail.com with ESMTPSA id u20sm141319oie.10.2017.11.15.21.06.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 21:06:25 -0800 (PST) Subject: Re: [PATCH 1/2] x86,kvm: move qemu/guest FPU switching out to vcpu_run To: Rik van Riel , "quan.xu04@gmail.com" , pbonzini@redhat.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> From: Quan Xu Message-ID: <0fc15536-0b34-51b6-cc14-00989825b0bc@gmail.com> Date: Thu, 16 Nov 2017 13:06:18 +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: <1510806094.21121.303.camel@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 12:21, Rik van Riel wrote: > On Thu, 2017-11-16 at 10:50 +0800, Quan Xu wrote: >> On 2017-11-15 22:43, Rik van Riel wrote: >>> Can you explain why you believe that? >> for example, a vcpu thread is running in kvm mode under cretical >> condition to stop. QEMU send an IPI to cause a VM-exit to happen >> immediately, and this IPI doesn't make vcpu return to QEMU. IIUC >> this vcpu thread will still continue to run in kvm mode when is >> waked up at targer machine. with your patch, I don't see a chance >> to load guest FPU or XSTATE, until return to QEMU and run kvm mode >> again. >> >> then the FPU or XSTATE status is inconsistent for a small window, >> what's >> even >> worse is that the vcpu is running. >> >> Did I misunderstand? > 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. > > When the VCPU thread is scheduled back in, the context > switch code will restore current->thread.fpu to the FPU > registers. good catch! Also as your comment, PKRU is switched out separately at VMENTER and VMEXIT time, but with a lots of IF conditions.. the pkru may be restored with host pkru after VMEXIT. when vcpu thread is scheduled out, the pkru value in current->thread.fpu.state may be the host pkru value, instead of guest pkru value (of course, this _assumes_ that the pkru is in current->thread.fpu.state as well). in this way, the pkru may be a coner case. 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.. Quan Alibaba Cloud > The VCPU thread will never run with anything else than > the guest FPU state, while inside the KVM_RUN code. > From 1584206039967104450@xxx Thu Nov 16 07:16:52 +0000 2017 X-GM-THRID: 1584017174910331026 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread