From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] KVM: x86: dynamically allocate large struct in em_fxrstor Date: Thu, 25 May 2017 16:07:08 +0200 Message-ID: <52f0d4a8-aacf-dc64-8117-2ba33bbfd928@redhat.com> References: <20170524062433.20680-1-nick.desaulniers@gmail.com> <20170524141957.GA8174@potion> <20170525013653.dvxpczik77l6ogp7@lostoracle.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org To: Nick Desaulniers , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Return-path: Received: from mx1.redhat.com ([209.132.183.28]:39304 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934669AbdEYOHN (ORCPT ); Thu, 25 May 2017 10:07:13 -0400 In-Reply-To: <20170525013653.dvxpczik77l6ogp7@lostoracle.net> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 25/05/2017 03:36, Nick Desaulniers wrote: >>> if (ctxt->mode < X86EMUL_MODE_PROT64) >>> - rc = fxrstor_fixup(ctxt, &fx_state); >>> + rc = fxrstor_fixup(ctxt, fx_state); >> Ah, fxrstor_fixup most likely got inlined and both of them put ~512 byte >> fxregs_state on the stack ... noinline attribute should solve the >> warning too. > While that would change fewer lines, doesn't the problem still exist in > the case of `ctxt->mode < X86EMUL_MODE_PROT64`, just split across two > stack frames? As in shouldn't we still dynamically allocate fx_state? I think we should do the fixup backwards. That is: - first do get_fpu - if the fixup is necessary, i.e. ctxt->mode < X86EMUL_MODE_PROT64, do fxsave into &fxstate. - then do segmented_read_std with the correct size, which is - offsetof(struct fxregs_state, xmm_space[16]), i.e. 416 if ctxt->mode == X86EMUL_MODE_PROT64 - offsetof(struct fxregs_state, xmm_space[8]), i.e. 288 if ctxt->mode < X86EMUL_MODE_PROT64 and CR4.OSFXSR=1 - offsetof(struct fxregs_state, xmm_space[0]), i.e. 160 if ctxt->mode < X86EMUL_MODE_PROT64 and CR4.OSFXSR=0 - then check fx_state.mxcsr - then do fxrstor - finally do put_fpu This will remove one of the two fxregs_state structs. Paolo