From patchwork Wed Oct 31 23:49:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Orr X-Patchwork-Id: 10663359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EC1A13A4 for ; Wed, 31 Oct 2018 23:49:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 795A12B943 for ; Wed, 31 Oct 2018 23:49:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CF982B9C2; Wed, 31 Oct 2018 23:49:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085E02B943 for ; Wed, 31 Oct 2018 23:49:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728489AbeKAIuD (ORCPT ); Thu, 1 Nov 2018 04:50:03 -0400 Received: from mail-io1-f74.google.com ([209.85.166.74]:54296 "EHLO mail-io1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725755AbeKAIuC (ORCPT ); Thu, 1 Nov 2018 04:50:02 -0400 Received: by mail-io1-f74.google.com with SMTP id q26-v6so15837721ioi.21 for ; Wed, 31 Oct 2018 16:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sag5MWmUMVeJlNMpxbgpOCQmQo4Ok3FbocF8rLJTZCg=; b=rqTZMcavNyyovzMSxcAu4EhLXbC9QzFt8tV/BXPWZL+RZIpxT5xlT7Of078dzGWhLz uoFQiXGyj3ZH/ifAt0o5iT0klxRvip96jBej7PRQcldWXZ9fWWpEkHdOXSrRine4DhHB W7ozWF+PT6mt1UgsM0GzhGGDVkLwPtFInebqB6DrzW1PVFu9ERTj4NdqAs6Ar1REbW4W KGXweL1v5a9gIhf2QZB0li/KYj+nY8pJ6upsnTFMzfCB24M6AJ3kSrU33jwl+cGbZ7Hn BoKB+4MWRNEv69cneVnU4PnoXP4QkOt1O4dcuc3vM4m+vyaa31uF0Q+TTG93RC5MNXaz TRvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sag5MWmUMVeJlNMpxbgpOCQmQo4Ok3FbocF8rLJTZCg=; b=FfOz56+j9nfrEdf6fSxb3mDLfxpdvYPy+b/l/F3z28pnyhXHMBFlLAlbwVT+0cjVtY EwSOXTrw2k2SMXQw97CbH/aprmh9drd05VfT1QaBwq5QW7Nwn6nNdDBeUUHfOmhhKlsE 9mYSE/KosgUGi5alTUahvM/+v8NnZYx0aVfxTQQyvcWnrhMTumyF3cJbFUA30xxSuq3j 19tCSLsgtQTHDQEzyD3XUcvec63RU9lNDYb3lwxl+QU64fVKh5EVyU4y4wL3oWcSqrl+ GUdKFnWWoDMiiT8htlA33c1KirJ1+Zhtyc2ZfQafQ4tSx3OdvoZJ+bKMnnlbm1lleQY+ X4oQ== X-Gm-Message-State: AGRZ1gIHZe2faFaN8jK9g2uw9/Q8M33KdE2xEsTq6obpGS+e+6OhrKm8 2b1OBnPRfLLl9LwKQ5qzybQMorEwybk7zPqDwBgAfNXlir/qnPxWPvoMaG+tquMx7dpHYOdPJs+ GWwzU8aHaaVJMJ6R6Al19+XdO1ewswnFNjVTiLlD/EKVFogJMIEfDtMtEmJWu X-Google-Smtp-Source: AJdET5flk7ooqaejTMsXXqjIwACRiUCqESKS/OHGre4mffs1Ve/56ZxSoyJK3Tdl6GTp4Hs9n+94pKlke+af X-Received: by 2002:a05:660c:145:: with SMTP id r5mr1666008itk.25.1541029777968; Wed, 31 Oct 2018 16:49:37 -0700 (PDT) Date: Wed, 31 Oct 2018 16:49:27 -0700 In-Reply-To: <20181031234928.144206-1-marcorr@google.com> Message-Id: <20181031234928.144206-2-marcorr@google.com> Mime-Version: 1.0 References: <20181031234928.144206-1-marcorr@google.com> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [kvm PATCH v6 1/2] kvm: x86: Use task structs fpu field for user From: Marc Orr To: kvm@vger.kernel.org, jmattson@google.com, rientjes@google.com, konrad.wilk@oracle.com, linux-mm@kvack.org, akpm@linux-foundation.org, pbonzini@redhat.com, rkrcmar@redhat.com, willy@infradead.org, sean.j.christopherson@intel.com, dave.hansen@linux.intel.com, kernellwp@gmail.com Cc: Marc Orr Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously, x86's instantiation of 'struct kvm_vcpu_arch' added an fpu field to save/restore fpu-related architectural state, which will differ from kvm's fpu state. However, this is redundant to the 'struct fpu' field, called fpu, embedded in the task struct, via the thread field. Thus, this patch removes the user_fpu field from the kvm_vcpu_arch struct and replaces it with the task struct's fpu field. This change is significant because the fpu struct is actually quite large. For example, on the system used to develop this patch, this change reduces the size of the vcpu_vmx struct from 23680 bytes down to 19520 bytes, when building the kernel with kvmconfig. This reduction in the size of the vcpu_vmx struct moves us closer to being able to allocate the struct at order 2, rather than order 3. Suggested-by: Dave Hansen Signed-off-by: Marc Orr --- arch/x86/include/asm/kvm_host.h | 7 +++---- arch/x86/kvm/x86.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 55e51ff7e421..ebb1d7a755d4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -601,16 +601,15 @@ struct kvm_vcpu_arch { /* * QEMU userspace and the guest each have their own FPU state. - * In vcpu_run, we switch between the user and guest FPU contexts. - * While running a VCPU, the VCPU thread will have the guest FPU - * context. + * In vcpu_run, we switch between the user, maintained in the + * task_struct struct, and guest FPU contexts. While running a VCPU, + * the VCPU thread will have the guest FPU context. * * Note that while the PKRU state lives inside the fpu registers, * it is switched out separately at VMENTER and VMEXIT time. The * "guest_fpu" state here contains the guest FPU context, with the * host PRKU bits. */ - struct fpu user_fpu; struct fpu guest_fpu; u64 xcr0; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bdcb5babfb68..ff77514f7367 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7999,7 +7999,7 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu) static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu) { preempt_disable(); - copy_fpregs_to_fpstate(&vcpu->arch.user_fpu); + copy_fpregs_to_fpstate(¤t->thread.fpu); /* PKRU is separately restored in kvm_x86_ops->run. */ __copy_kernel_to_fpregs(&vcpu->arch.guest_fpu.state, ~XFEATURE_MASK_PKRU); @@ -8012,7 +8012,7 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) { preempt_disable(); copy_fpregs_to_fpstate(&vcpu->arch.guest_fpu); - copy_kernel_to_fpregs(&vcpu->arch.user_fpu.state); + copy_kernel_to_fpregs(¤t->thread.fpu.state); preempt_enable(); ++vcpu->stat.fpu_reload; trace_kvm_fpu(0);