From patchwork Wed Oct 31 13:26:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Orr X-Patchwork-Id: 10662675 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 AE98514DE for ; Wed, 31 Oct 2018 13:26:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EBC9284BD for ; Wed, 31 Oct 2018 13:26:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9288628AA4; Wed, 31 Oct 2018 13:26:46 +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 20938284BD for ; Wed, 31 Oct 2018 13:26:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BADFE6B0010; Wed, 31 Oct 2018 09:26:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B5C946B026B; Wed, 31 Oct 2018 09:26:44 -0400 (EDT) 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 A71E26B026C; Wed, 31 Oct 2018 09:26:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id 7609C6B0010 for ; Wed, 31 Oct 2018 09:26:44 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id j69-v6so11380653ywb.19 for ; Wed, 31 Oct 2018 06:26:44 -0700 (PDT) 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=sag5MWmUMVeJlNMpxbgpOCQmQo4Ok3FbocF8rLJTZCg=; b=qan9gnaQ4S0w7OL8dYqsrrzctB8UnucjnyOLdBgVa8HGAlP6n+XtrZclEaGWERkPTF fs7jzmbMXP/TQ6Sn+wm5EMzjcQ2LiH0UcpfwXEdLgZSEi0obnrS+ehJ3koZgYEkGu8jW mPE8aG9tIVxciZkUb0VQ2smz9VQZffV5Q7a9YzQtCC+YCucxD89bn7hNim5/BXjwXT5c isc6jU8lmgTvAR6NeyRjRzsrn9NWTgVkIPmpZs8rUp+BO+N5bcGJuwR6vozJsp06nUCd DMbtenCV2j70RjxcEQK/7Fp11pdi8lZ6ylqm9uJ/Ks2LSVVJ27QHhuZicyJMLmbKVhn2 mZQw== X-Gm-Message-State: AGRZ1gJNKt5FMOKFN+SLJz75AIo6zQP15e3Tn2PXYsQfWl0ilX9gM1Qv l0UafLOd7RstQJbs+X4/Y1FX03ZbHugpYvMhZDueATiRcukinDCRAaIHM8qYW0ICZZ89NFgnIqK 9KV3fkaawkGYPxr6yDRXDXmHw/MBmzJKo47P+sjCuWuljNx5ATGEbg/MqIFVbPhL07JoT0E/DFS 4jZnMQJTpSczWurVaGqZux3ng24GyKCN/PyCXdzxb0c1LjFVPBjzCeFs3LsSsfg2C2Nkisgie2r u6Ha8QR5AF3UgVuB2B43M/In2+X/6AWaS9UoYqHgy7ouzioKjgp+sK0Kw1hKWcGv+BSSOAN9hw2 hUxjkXxIFZtIysQP1u2aMpQbCbWrzg+PKAgfiA2D12p6JmlGHrxzAYp61ku9zg/wyDYIQ7Cm3Io P X-Received: by 2002:a5b:3c2:: with SMTP id t2-v6mr3035259ybp.328.1540992404078; Wed, 31 Oct 2018 06:26:44 -0700 (PDT) X-Received: by 2002:a5b:3c2:: with SMTP id t2-v6mr3035154ybp.328.1540992402491; Wed, 31 Oct 2018 06:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540992402; cv=none; d=google.com; s=arc-20160816; b=0veEt0rfnwCfo4b8+DIH2V0ctJexU9dchOupoF7Eyv6UVUUzYpRtUaqzLNjO/VrHed 1Fa7FYnaqDGNcf4KhfIid0bRmKKmGwhahFepHiSLi/MUR5rczcFKVwOGsaKrElQmbCBo q6Dgoh5d64VZbI2hFwTGLpU548Gw8nIlYLve83RXiCioaq5b2aWfsLx66icF+/tJ02jv E5RY9NIhhmEp7Nk7UZ8BAe3R/fisoSL45QMrSSSCRigTE2P/Isfp1nJFKzFKL7OFXZNQ FSCgId3vVrpC+Cnpf/dAlvCWi+c09sT3TISTOQehiCeCMUhzzNWjnjwuokUITOD6xSwv 0vVw== 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=sag5MWmUMVeJlNMpxbgpOCQmQo4Ok3FbocF8rLJTZCg=; b=Pm3DwC+/IaQuJhZiy2ONqEVp9Jo4Hg+AWz3VRNZeqfiq65JGUN47xkQQEAutZhXUoG wth0w+FirrodgmfLv8mMBk9cu2h5v/7NWzP+ZsDTdMRFIDaks4TZGn++4sEX26Sb2bYq zkPOIgWFZINPU9aeVPPozMFdqRR/KA+HvXbtqH8ocZM8QQQ6M/53oz5eTjjHV7WSihKG C0A/T4WQW3e3l1BPfptiSuhAabpeCYxNTbRqAx6oOmujcTSF/deGEoLrbq/qJ6Fg8Cwh 6oTG3ZJvOLHt6RMweUfsvVhD2Zj67LqtvHMfUsmsrwhCdqHG48kicYaPIy5js9+O1+aC cAeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=klEZe1+Y; spf=pass (google.com: domain of 3kq3zwwckcdkhvmxjmmbjjbgz.xjhgdips-hhfqvxf.jmb@flex--marcorr.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3kq3ZWwcKCDkhVmXjmmbjjbgZ.Xjhgdips-hhfqVXf.jmb@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 m14-v6sor12427754ybp.84.2018.10.31.06.26.42 for (Google Transport Security); Wed, 31 Oct 2018 06:26:42 -0700 (PDT) Received-SPF: pass (google.com: domain of 3kq3zwwckcdkhvmxjmmbjjbgz.xjhgdips-hhfqvxf.jmb@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=klEZe1+Y; spf=pass (google.com: domain of 3kq3zwwckcdkhvmxjmmbjjbgz.xjhgdips-hhfqvxf.jmb@flex--marcorr.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3kq3ZWwcKCDkhVmXjmmbjjbgZ.Xjhgdips-hhfqVXf.jmb@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=sag5MWmUMVeJlNMpxbgpOCQmQo4Ok3FbocF8rLJTZCg=; b=klEZe1+YLFreakUC1NNWYeyOnlaW0ntB3zzqwzbnKOaNr+HjvwFIoPO+mZH+KAwDlZ j+lseImIqnz9dnhMd0IopzDS5+E5z7GC8b1ifKqMksISoeug5GrN82adGqE2ttXDcJHr 9h9IpYHmtTy6cIvoqClSy2yErvilzoRCGC936R0e+woy9EklHZAlZ2zXeyvO449TV7DP FnECVaZ8rWoA5SGl0kzb/l2Kjgtf4oPjArv7bo8AZ5qFCZymZpQPtMzWm+vq867jTIHJ WYP6G9Dua4VPzkl0oURZB8xSwkhWwSCYXNmVeYkpAakTx5Z/wiJ2oezakszw8tHPOlsU Rxjw== X-Google-Smtp-Source: AJdET5c7s7Wrujes1yN28z27Ablc0GtM2SWbbocQ15S6tHRBU9kdq6AxSSMsZhc+s2/n1eNSXZgn2HWdP18m X-Received: by 2002:a25:cb56:: with SMTP id b83-v6mr1485845ybg.72.1540992402222; Wed, 31 Oct 2018 06:26:42 -0700 (PDT) Date: Wed, 31 Oct 2018 06:26:31 -0700 In-Reply-To: <20181031132634.50440-1-marcorr@google.com> Message-Id: <20181031132634.50440-2-marcorr@google.com> Mime-Version: 1.0 References: <20181031132634.50440-1-marcorr@google.com> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [kvm PATCH v5 1/4] 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 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);