提交 fa3795a7 编写于 作者: D Dave Hansen 提交者: Avi Kivity

KVM: Reduce stack usage in kvm_vcpu_ioctl()

Signed-off-by: NDave Hansen <dave@linux.vnet.ibm.com>
Signed-off-by: NAvi Kivity <avi@qumranet.com>
上级 f0d66275
...@@ -1126,6 +1126,8 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -1126,6 +1126,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
struct kvm_vcpu *vcpu = filp->private_data; struct kvm_vcpu *vcpu = filp->private_data;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int r; int r;
struct kvm_fpu *fpu = NULL;
struct kvm_sregs *kvm_sregs = NULL;
if (vcpu->kvm->mm != current->mm) if (vcpu->kvm->mm != current->mm)
return -EIO; return -EIO;
...@@ -1173,25 +1175,28 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -1173,25 +1175,28 @@ static long kvm_vcpu_ioctl(struct file *filp,
break; break;
} }
case KVM_GET_SREGS: { case KVM_GET_SREGS: {
struct kvm_sregs kvm_sregs; kvm_sregs = kzalloc(sizeof(struct kvm_sregs), GFP_KERNEL);
r = -ENOMEM;
memset(&kvm_sregs, 0, sizeof kvm_sregs); if (!kvm_sregs)
r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, &kvm_sregs); goto out;
r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, kvm_sregs);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
if (copy_to_user(argp, &kvm_sregs, sizeof kvm_sregs)) if (copy_to_user(argp, kvm_sregs, sizeof(struct kvm_sregs)))
goto out; goto out;
r = 0; r = 0;
break; break;
} }
case KVM_SET_SREGS: { case KVM_SET_SREGS: {
struct kvm_sregs kvm_sregs; kvm_sregs = kmalloc(sizeof(struct kvm_sregs), GFP_KERNEL);
r = -ENOMEM;
if (!kvm_sregs)
goto out;
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&kvm_sregs, argp, sizeof kvm_sregs)) if (copy_from_user(kvm_sregs, argp, sizeof(struct kvm_sregs)))
goto out; goto out;
r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, &kvm_sregs); r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs);
if (r) if (r)
goto out; goto out;
r = 0; r = 0;
...@@ -1272,25 +1277,28 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -1272,25 +1277,28 @@ static long kvm_vcpu_ioctl(struct file *filp,
break; break;
} }
case KVM_GET_FPU: { case KVM_GET_FPU: {
struct kvm_fpu fpu; fpu = kzalloc(sizeof(struct kvm_fpu), GFP_KERNEL);
r = -ENOMEM;
memset(&fpu, 0, sizeof fpu); if (!fpu)
r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, &fpu); goto out;
r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
if (copy_to_user(argp, &fpu, sizeof fpu)) if (copy_to_user(argp, fpu, sizeof(struct kvm_fpu)))
goto out; goto out;
r = 0; r = 0;
break; break;
} }
case KVM_SET_FPU: { case KVM_SET_FPU: {
struct kvm_fpu fpu; fpu = kmalloc(sizeof(struct kvm_fpu), GFP_KERNEL);
r = -ENOMEM;
if (!fpu)
goto out;
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&fpu, argp, sizeof fpu)) if (copy_from_user(fpu, argp, sizeof(struct kvm_fpu)))
goto out; goto out;
r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, &fpu); r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
if (r) if (r)
goto out; goto out;
r = 0; r = 0;
...@@ -1300,6 +1308,8 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -1300,6 +1308,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = kvm_arch_vcpu_ioctl(filp, ioctl, arg); r = kvm_arch_vcpu_ioctl(filp, ioctl, arg);
} }
out: out:
kfree(fpu);
kfree(kvm_sregs);
return r; return r;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册