From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969592AbdEYOHW (ORCPT ); Thu, 25 May 2017 10:07:22 -0400 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 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A2528C05973F Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A2528C05973F Subject: Re: [PATCH] KVM: x86: dynamically allocate large struct in em_fxrstor To: Nick Desaulniers , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20170524062433.20680-1-nick.desaulniers@gmail.com> <20170524141957.GA8174@potion> <20170525013653.dvxpczik77l6ogp7@lostoracle.net> From: Paolo Bonzini Message-ID: <52f0d4a8-aacf-dc64-8117-2ba33bbfd928@redhat.com> Date: Thu, 25 May 2017 16:07:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <20170525013653.dvxpczik77l6ogp7@lostoracle.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 25 May 2017 14:07:12 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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