From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756497AbdKODEL (ORCPT ); Tue, 14 Nov 2017 22:04:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53308 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753074AbdKODDy (ORCPT ); Tue, 14 Nov 2017 22:03:54 -0500 Message-ID: <1510715030.21121.287.camel@redhat.com> Subject: Re: [PATCH 1/2] x86,kvm: move qemu/guest FPU switching out to vcpu_run From: Rik van Riel To: Wanpeng Li Cc: Paolo Bonzini , kvm , "linux-kernel@vger.kernel.org" , David Hildenbrand , Christian Borntraeger , Thomas Gleixner , Radim Krcmar Date: Tue, 14 Nov 2017 22:03:50 -0500 In-Reply-To: References: <20171114215424.32214-1-riel@redhat.com> <20171114215424.32214-2-riel@redhat.com> Organization: Red Hat, Inc Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 15 Nov 2017 03:03:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-11-15 at 08:47 +0800, Wanpeng Li wrote: > 2017-11-15 5:54 GMT+08:00  : > > From: Rik van Riel > > > > Currently, every time a VCPU is scheduled out, the host kernel will > > first save the guest FPU/xstate context, then load the qemu > > userspace > > FPU context, only to then immediately save the qemu userspace FPU > > context back to memory. When scheduling in a VCPU, the same > > extraneous > > FPU loads and saves are done. > > > > This could be avoided by moving from a model where the guest FPU is > > loaded and stored with preemption disabled, to a model where the > > qemu userspace FPU is swapped out for the guest FPU context for > > the duration of the KVM_RUN ioctl. > > What will happen if CONFIG_PREEMPT is enabled? The scheduler will save the guest FPU context when a VCPU thread is preempted, and restore it when it is scheduled back in. While inside kvm_arch_vcpu_ioctl_run, the task FPU context will be the guest FPU context, instead of the qemu userspace FPU context.