kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: dynamically allocate large struct in em_fxrstor
@ 2017-05-24  6:24 Nick Desaulniers
  2017-05-24 14:19 ` Radim Krčmář
  0 siblings, 1 reply; 19+ messages in thread
From: Nick Desaulniers @ 2017-05-24  6:24 UTC (permalink / raw)
  Cc: Nick Desaulniers, Paolo Bonzini, Radim Krčmář,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
	linux-kernel

Fixes the warning:

arch/x86/kvm/emulate.c:4018:12: warning: stack frame size of 1080 bytes in
function
      'em_fxrstor' [-Wframe-larger-than=]
static int em_fxrstor(struct x86_emulate_ctxt *ctxt)
           ^

Found with CONFIG_FRAME_WARN set to 1024.

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
 arch/x86/kvm/emulate.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 0816ab2e8adc..1d7c9ceeff56 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -4017,30 +4017,38 @@ static int fxrstor_fixup(struct x86_emulate_ctxt *ctxt,
 
 static int em_fxrstor(struct x86_emulate_ctxt *ctxt)
 {
-	struct fxregs_state fx_state;
+	struct fxregs_state *fx_state;
 	int rc;
 
 	rc = check_fxsr(ctxt);
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
 
-	rc = segmented_read_std(ctxt, ctxt->memop.addr.mem, &fx_state, 512);
+	fx_state = kmalloc(sizeof(*fx_state), GFP_KERNEL);
+	if (!fx_state)
+		return -ENOMEM;
+
+	rc = segmented_read_std(ctxt, ctxt->memop.addr.mem, fx_state, 512);
 	if (rc != X86EMUL_CONTINUE)
-		return rc;
+		goto out;
 
-	if (fx_state.mxcsr >> 16)
-		return emulate_gp(ctxt, 0);
+	if (fx_state->mxcsr >> 16) {
+		rc = emulate_gp(ctxt, 0);
+		goto out;
+	}
 
 	ctxt->ops->get_fpu(ctxt);
 
 	if (ctxt->mode < X86EMUL_MODE_PROT64)
-		rc = fxrstor_fixup(ctxt, &fx_state);
+		rc = fxrstor_fixup(ctxt, fx_state);
 
 	if (rc == X86EMUL_CONTINUE)
-		rc = asm_safe("fxrstor %[fx]", : [fx] "m"(fx_state));
+		rc = asm_safe("fxrstor %[fx]", : [fx] "m"(*fx_state));
 
 	ctxt->ops->put_fpu(ctxt);
 
+out:
+	kfree(fx_state);
 	return rc;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-06-02  2:10 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24  6:24 [PATCH] KVM: x86: dynamically allocate large struct in em_fxrstor Nick Desaulniers
2017-05-24 14:19 ` Radim Krčmář
2017-05-25  1:36   ` Nick Desaulniers
2017-05-25 14:07     ` Paolo Bonzini
2017-05-26  4:13       ` Nick Desaulniers
2017-05-26  7:18         ` Paolo Bonzini
2017-05-29 19:55           ` [PATCH v2] KVM: x86: avoid large stack allocations " Nick Desaulniers
2017-05-29 20:14             ` kbuild test robot
2017-05-29 20:29               ` Nick Desaulniers
2017-05-29 20:39             ` [PATCH v3] " Nick Desaulniers
2017-05-29 22:40               ` Nick Desaulniers
2017-05-29 22:48               ` [PATCH v4] " Nick Desaulniers
2017-05-30 10:15                 ` Paolo Bonzini
2017-05-30 14:05                   ` Radim Krčmář
2017-05-31  3:08                 ` [PATCH v5] " Nick Desaulniers
2017-05-31 11:01                   ` Paolo Bonzini
2017-06-01  1:05                     ` Nick Desaulniers
2017-06-01  7:36                       ` Paolo Bonzini
2017-06-02  2:10                         ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).