KVM: Reduce kvm stack usage in kvm_arch_vm_ioctl()

Previous thread: KVM: pci device assignment by Linux Kernel Mailing List on Thursday, October 16, 2008 - 4:02 pm. (1 message)

Next thread: KVM: Reduce stack usage in kvm_vcpu_ioctl() by Linux Kernel Mailing List on Thursday, October 16, 2008 - 4:02 pm. (1 message)
From: Linux Kernel Mailing List
Date: Thursday, October 16, 2008 - 4:02 pm

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=f0d662...
Commit:     f0d662759a2465babdba1160749c446648c9d159
Parent:     4d5c5d0fe89c921336b95f5e7e4f529a9df92f53
Author:     Dave Hansen <dave@linux.vnet.ibm.com>
AuthorDate: Mon Aug 11 10:01:45 2008 -0700
Committer:  Avi Kivity <avi@qumranet.com>
CommitDate: Wed Oct 15 10:15:18 2008 +0200

    KVM: Reduce kvm stack usage in kvm_arch_vm_ioctl()
    
    On my machine with gcc 3.4, kvm uses ~2k of stack in a few
    select functions.  This is mostly because gcc fails to
    notice that the different case: statements could have their
    stack usage combined.  It overflows very nicely if interrupts
    happen during one of these large uses.
    
    This patch uses two methods for reducing stack usage.
    1. dynamically allocate large objects instead of putting
       on the stack.
    2. Use a union{} member for all of the case variables. This
       tricks gcc into combining them all into a single stack
       allocation. (There's also a comment on this)
    
    Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
    Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 arch/x86/kvm/x86.c |   72 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a97157c..87d4342 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1869,6 +1869,15 @@ long kvm_arch_vm_ioctl(struct file *filp,
 	struct kvm *kvm = filp->private_data;
 	void __user *argp = (void __user *)arg;
 	int r = -EINVAL;
+	/*
+	 * This union makes it completely explicit to gcc-3.x
+	 * that these two variables' stack usage should be
+	 * combined, not added together.
+	 */
+	union {
+		struct kvm_pit_state ps;
+		struct kvm_memory_alias alias;
+	} u;
 
 	switch (ioctl) {
 	case KVM_SET_TSS_ADDR:
@@ -1900,17 +1909,14 @@ long kvm_arch_vm_ioctl(struct file *filp,
 	case ...
Previous thread: KVM: pci device assignment by Linux Kernel Mailing List on Thursday, October 16, 2008 - 4:02 pm. (1 message)

Next thread: KVM: Reduce stack usage in kvm_vcpu_ioctl() by Linux Kernel Mailing List on Thursday, October 16, 2008 - 4:02 pm. (1 message)