Received: by 10.223.164.202 with SMTP id h10csp1927838wrb; Thu, 16 Nov 2017 06:42:04 -0800 (PST) X-Google-Smtp-Source: AGs4zMb1vOKFpLRI7xT5QBSzc4naCIPvkQ/RcBHIR0s4Bdk/v0ymPoql1JSpm320Qe+wyB4A+x3N X-Received: by 10.159.252.11 with SMTP id n11mr1913414pls.207.1510843324810; Thu, 16 Nov 2017 06:42:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510843324; cv=none; d=google.com; s=arc-20160816; b=iyuY3oUafbgMw2y1FdiC/vK/5B7teWeYymS4uPHQTKKu+46qJCZrSzNUAeG5Ev7nuX qz3jVFW7+/oG1ooICzHV/IYl7hpSUdFHwySzfhSX8jhVUtEKObX1OsmtePnFnHJf/W9D 3qL3QS+A3YGG0RLUC6U0vWKXvWyS0kHc/c1rw4Y/PKuJFW5wUVhFNuCEKGCQn3tapPqk iIrOdBAq9ftOvc0m3zl4cqYj/Evgy0xSrvfG11bHUl+EkTAoA5enjECHAFwOc48pFDHX 6Wp9ObPo0qu0mlvAdf1xozfbEeDPzfwFbg8Q3Omjdyku27w4vSy1gvoOVtk/OSPBMMpH 4NqQ== 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=O2e7UyjyefKro51KUufXcfmnO7NWpbdSMCgyjZqmCcc=; b=QEZeMJLNy2tx945JN0hU+IbzLA1vReq070JWPjIApIXhQmDS63QVwXVsU2ivLpTHUr tMRxQG5YFV19ZygJuaeXA/6wDs0QupMSHCqBEJJi6XYXWHfVJ9v4oww1lAolgUleTzfi ZH02hISSvZqqp7+TjFuxEEWB7AshK7G/XCGo2QKtxpWo/rWEXMlgqtc+Ro5IsgIPfyGf xz1oaWtWotnfOGy2IHKFZgUi6WuEnystHLhACPjhiBx9gpZshM/nqVBJiGTiKi53umiY zpo5U+9o7ilkwbAbJjOYpsP2ETkXePdy8CvjlfiF+HXBoS4jus+Y4oZtlKZeC/ZK/saj lLJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PFQN4TvR; 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 x66si1099546pfa.129.2017.11.16.06.41.52; Thu, 16 Nov 2017 06:42:04 -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=PFQN4TvR; 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 S934616AbdKPMNN (ORCPT + 91 others); Thu, 16 Nov 2017 07:13:13 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:49632 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934437AbdKPMNH (ORCPT ); Thu, 16 Nov 2017 07:13:07 -0500 Received: by mail-oi0-f65.google.com with SMTP id r190so9202242oie.6; Thu, 16 Nov 2017 04:13:07 -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=O2e7UyjyefKro51KUufXcfmnO7NWpbdSMCgyjZqmCcc=; b=PFQN4TvRD78zis0V+pa/B3meXqC7cKQgI7ILRZNtmD/zzqoX5MAEv8iQZBN+CCwTmu S7AdGisZDUL11AGHmTQmz3TnekJNs2fvtNdlssgh0HElBv8aPqbvj4foZTvIup5L/FIR 5gPHh67oxR7L+5qPKo/8vm6aQBFAmPQgcKY1LRKWhtiKfjM1JcGjgilVn1zKVJM96/TZ EdH0nn9SHsl5afv7cTblOwyLwd9CCnCh5wbi6Ps9fCHo/nHNxTKJaU62g0ho/YEzrwov OJY28OAx4NL811TEAmr4Y7X2kNPmCljQUidHc1NEXrIXkl55Otl31Z0NacN8A7CYRH9o TPAw== 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=O2e7UyjyefKro51KUufXcfmnO7NWpbdSMCgyjZqmCcc=; b=ZQ+MTsl+KoD7qcrPU6404nev7y8EK9Lyrn1dK2xov6UbeOmnsTFWh2I4zec9nlB+3Q 6XJUxdbGKP9EVS7LtBoTwec/sUjGFX6aq/PzIdbbflT6SYJxAMzY1vSvGg2eBWDQZwKZ /DnAkh/jvcOasz86ocCesic2ekUQk6qcukgLc5aj3dFYK5FFTMpqI/RAh/8vKD9j4KpE irxX201p5Rqk27QuT7xk0MojXM0cTbylnx9eugSojPtq0uXT2FTwI7McBIqaIl3sZF8p TMOGJ349v/IKeWAL6vNhH13ndkhDRnypOQC9NcB/CTAuP3m3CNym+iX8L+kl3ZOD0U+T cILg== X-Gm-Message-State: AJaThX4X0U8Tsz2t8pKnMRSFSViE7gm/JZoxFVbmm9Ao8MCr6+g1aSY9 Q0JAlV0NWEuQ58ZYg8Q5V3M= X-Received: by 10.202.67.65 with SMTP id q62mr797508oia.280.1510834386873; Thu, 16 Nov 2017 04:13:06 -0800 (PST) Received: from [0.0.0.0] ([47.89.242.186]) by smtp.gmail.com with ESMTPSA id e20sm329219oib.53.2017.11.16.04.13.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 04:13:06 -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> From: Quan Xu Message-ID: Date: Thu, 16 Nov 2017 20:12:58 +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: <9ba2d4c1-0781-419e-ddeb-77e0494583d2@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 18:21, Paolo Bonzini wrote: > On 16/11/2017 06:06, Quan Xu wrote: >> 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. > Rik may correct me, but I think this is not possible. Preemption is > disabled all the time while PKRU = guest_pkru (which is only during > vmx_vcpu_run). refer to the following code, vcpu_enter_guest() {     ...     preempt_disable()        ...        kvm_x86_ops->run(vcpu);  (actually it is vmx_vcpu_run())        ...     ...     preempt_enable(); } when preempt_disable before to run kvm_x86_ops->run.. in kvm_x86_ops->run, the pkru is restored with host_pkru (IF guest_pkru != host_pkru). all this happened under preempt_disable(). it's not true that preemtion is disable all the time while PKRU  = guest_pkru.. 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." 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 1584225337503196489@xxx Thu Nov 16 12:23:35 +0000 2017 X-GM-THRID: 1584017174910331026 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread