From patchwork Tue Nov 6 22:20:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Orr X-Patchwork-Id: 10671557 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 C633914E2 for ; Tue, 6 Nov 2018 22:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8DB52B29F for ; Tue, 6 Nov 2018 22:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6B3B2B332; Tue, 6 Nov 2018 22:20:26 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37DE72B29F for ; Tue, 6 Nov 2018 22:20:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BD4F6B0499; Tue, 6 Nov 2018 17:20:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 16BB66B049B; Tue, 6 Nov 2018 17:20:25 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0840C6B049C; Tue, 6 Nov 2018 17:20:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id BE5C36B0499 for ; Tue, 6 Nov 2018 17:20:24 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id b15-v6so9050281pfo.3 for ; Tue, 06 Nov 2018 14:20:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=m2iqjlD99uhLk3TcwseOpc1O1utdKyZJoe8g5b3aQf4=; b=dsVPYRjjIEifDlMFit5UWRPdOqDU8RTdYoULN5P9Po1WDA2V4s/l8wvBQmjG8L38/U q7H2j19sBCmndS6srlgPapJJUPffKRaMJOpAFym74detdIQTlbuToxRMmmQ+QsChkhuE gTNZ1sDLUiaBuMLTv6pt42LhsqYyWvo9JnzLzD6uRQZieU5dkrsLyAePgTpN4JFTib6m DNmuDZo7Q1rvWUpPIIk7iW04hMFgMlky2391u+zq0sctMcay7Q7OPr97HFExoPV5knBQ mnYDPilJZeln/awhQSxa3x7YF3K+dUpFxMTgHWPNLh9utYLhIBZwMJr/FjF4Ykniu6tl GnaA== X-Gm-Message-State: AGRZ1gIVI7MK439F34vw6hdoYMGWltAyWJ7pOEfSSzToZlWnO6ZDXlOx inJGfhVKvIELTp8vblHcBJAlYWgyj+ulSg1pgYMfeAAXht13FeGzFt3c2BiN4nLfnVBglgqAav4 ioF/EyxSbKrcoZKIS0f5wxUKIMhVbsn0eSKa21ei1sqizkkVS6DehBIrMjBuiKZHPH6Zt5VAAFE zjOiqAGl0naijE91DmpD2tlnR2UTlulrNgUdRHwbYyji+3l0Gnel2CZKlbvw9R2no07v69tqG+k cFQBNirS0IFI/LcIudNrmWQxHkOMqkounMg1uKoSBd+EHpWUAJy0bK8GPs6sD0CNRQ5Xr/J6ceu 39QPz6vhXekWEnguVhW/pQnxUV8aP5Fw8wZuWmMeRYYMXbL4FBkcPB1AsDo53tB7qnv8egKHr2k j X-Received: by 2002:a17:902:6184:: with SMTP id u4-v6mr28543688plj.291.1541542824432; Tue, 06 Nov 2018 14:20:24 -0800 (PST) X-Received: by 2002:a17:902:6184:: with SMTP id u4-v6mr28543641plj.291.1541542823623; Tue, 06 Nov 2018 14:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541542823; cv=none; d=google.com; s=arc-20160816; b=iL3NJ2TKIlfUVe0eXShWvXdAfn42JNrHeIRoFD7gSCMFOU1Nk8qqzNoC7hba8ejopV gDv1Qc+dCCzDK26PzND1zGv5NqsEaILc6hgIoD92FD00pqxnlMR7LvnwV7m+XfNidRM0 ihJFETQAbCQlCtuISjuRY5GF4hChm3ZMvBvNYbbqssugqBxZQjPmFP4icmKK8/Dm0O5z uREK3YaKz9UGs8RlJElFh1Xb1qg7+28snn+w/jEVTXXZzix0A86TahcZI/SxDI+JqihE AgIIfQsdc+sle7GXvAcbqyNZqLJKYlEOtLvRMP/fcAcMwwXD7MbC1mDtl87dktRDarad whNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=m2iqjlD99uhLk3TcwseOpc1O1utdKyZJoe8g5b3aQf4=; b=R1GDbuFcmlU0BhNIDFC1fPAg/MghReiiEDb68KG5sF/6amEEeO6JPA3MwRm+kkZ618 A3MGAK0j9tmtr4SnCf/iZ6HP1QCHIb0fm6cU9MAQR3VZ5foAiMHO1xYfxpm3xrUBSANJ 4IWLQT19jDD2zmLN4CjxTkIACpJDc0zuXd3SzJz0Xx6JA6hW48FDgeENawKIlDABLcco 0WpWvzlgDqxCD3QJWQYUqQQx5ZGo2fPPK0YLLVpBM6hWjI6UvakUcWI26XDzrVSv7559 ZhOJH0XwR5ENprdutAdiP/qULrjEDOlTNtHft1DRSMcUrq2M+mxWWnutY7JmMCZZxq0g 6djA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Q6PKKVxM; spf=pass (google.com: domain of 3pxpiwwckcdwkypamppemmejc.amkjglsv-kkityai.mpe@flex--marcorr.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3pxPiWwcKCDwkYpamppemmejc.amkjglsv-kkitYai.mpe@flex--marcorr.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id 60-v6sor29001009pla.41.2018.11.06.14.20.23 for (Google Transport Security); Tue, 06 Nov 2018 14:20:23 -0800 (PST) Received-SPF: pass (google.com: domain of 3pxpiwwckcdwkypamppemmejc.amkjglsv-kkityai.mpe@flex--marcorr.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Q6PKKVxM; spf=pass (google.com: domain of 3pxpiwwckcdwkypamppemmejc.amkjglsv-kkityai.mpe@flex--marcorr.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3pxPiWwcKCDwkYpamppemmejc.amkjglsv-kkitYai.mpe@flex--marcorr.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=m2iqjlD99uhLk3TcwseOpc1O1utdKyZJoe8g5b3aQf4=; b=Q6PKKVxMJYGLUvKL7E/LbHiccXDRh+0kDvxS8eJv4xlHpevvl/v9cl9mVdW1uIGvkO BSFsl9WWwH6FV/bASr5jqk+NaGJbXIHWzCY2q3K4XGrlcn0hKMw1I80XmMD5k4d7b3/e 1OncDlTJ2HXOSzfmHECyuK0v1iTlF8N7Qvagjvi4GrFdprPLnEMcI4+aLB9ihh4b8l3m yrMikInWztfVIRTBq/2UtLKSMjUJSxaC5MbiGfWJQ/EItscWu6hBcnm7oPPdjKStsRcH XOjf20fijy9h2RKPUTnqK+gNhEoi7OgKtKWImOLR3WLBJPMc0s2yXG3l8nGXtGnky4AA kdxA== X-Google-Smtp-Source: AJdET5cMYaY8o6gqnYE9E61HX98GXy0M+cR43vucBeBi/1XWdw1wvPbWi4mxAXj5TP5Rz3y9W6jTaU2DWJ48 X-Received: by 2002:a17:902:e08c:: with SMTP id cb12-v6mr400090plb.117.1541542823152; Tue, 06 Nov 2018 14:20:23 -0800 (PST) Date: Tue, 6 Nov 2018 14:20:08 -0800 In-Reply-To: <20181106222009.90833-1-marcorr@google.com> Message-Id: <20181106222009.90833-2-marcorr@google.com> Mime-Version: 1.0 References: <20181106222009.90833-1-marcorr@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog Subject: [kvm PATCH v7 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 , Dave Hansen X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);