aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hansen <dave@linux.vnet.ibm.com>2008-08-11 13:01:46 -0400
committerAvi Kivity <avi@qumranet.com>2008-10-15 04:15:18 -0400
commitfa3795a7308df099f0f2c9e5ca2c20a5ff65bdc4 (patch)
tree5adec83a7a6348f4e99a76fc0dbfccaa80484647
parentf0d662759a2465babdba1160749c446648c9d159 (diff)
KVM: Reduce stack usage in kvm_vcpu_ioctl()
Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r--virt/kvm/kvm_main.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 5eb96c7c8d7a..0309571fcb20 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1126,6 +1126,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
1126 struct kvm_vcpu *vcpu = filp->private_data; 1126 struct kvm_vcpu *vcpu = filp->private_data;
1127 void __user *argp = (void __user *)arg; 1127 void __user *argp = (void __user *)arg;
1128 int r; 1128 int r;
1129 struct kvm_fpu *fpu = NULL;
1130 struct kvm_sregs *kvm_sregs = NULL;
1129 1131
1130 if (vcpu->kvm->mm != current->mm) 1132 if (vcpu->kvm->mm != current->mm)
1131 return -EIO; 1133 return -EIO;
@@ -1173,25 +1175,28 @@ out_free2:
1173 break; 1175 break;
1174 } 1176 }
1175 case KVM_GET_SREGS: { 1177 case KVM_GET_SREGS: {
1176 struct kvm_sregs kvm_sregs; 1178 kvm_sregs = kzalloc(sizeof(struct kvm_sregs), GFP_KERNEL);
1177 1179 r = -ENOMEM;
1178 memset(&kvm_sregs, 0, sizeof kvm_sregs); 1180 if (!kvm_sregs)
1179 r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, &kvm_sregs); 1181 goto out;
1182 r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, kvm_sregs);
1180 if (r) 1183 if (r)
1181 goto out; 1184 goto out;
1182 r = -EFAULT; 1185 r = -EFAULT;
1183 if (copy_to_user(argp, &kvm_sregs, sizeof kvm_sregs)) 1186 if (copy_to_user(argp, kvm_sregs, sizeof(struct kvm_sregs)))
1184 goto out; 1187 goto out;
1185 r = 0; 1188 r = 0;
1186 break; 1189 break;
1187 } 1190 }
1188 case KVM_SET_SREGS: { 1191 case KVM_SET_SREGS: {
1189 struct kvm_sregs kvm_sregs; 1192 kvm_sregs = kmalloc(sizeof(struct kvm_sregs), GFP_KERNEL);
1190 1193 r = -ENOMEM;
1194 if (!kvm_sregs)
1195 goto out;
1191 r = -EFAULT; 1196 r = -EFAULT;
1192 if (copy_from_user(&kvm_sregs, argp, sizeof kvm_sregs)) 1197 if (copy_from_user(kvm_sregs, argp, sizeof(struct kvm_sregs)))
1193 goto out; 1198 goto out;
1194 r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, &kvm_sregs); 1199 r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs);
1195 if (r) 1200 if (r)
1196 goto out; 1201 goto out;
1197 r = 0; 1202 r = 0;
@@ -1272,25 +1277,28 @@ out_free2:
1272 break; 1277 break;
1273 } 1278 }
1274 case KVM_GET_FPU: { 1279 case KVM_GET_FPU: {
1275 struct kvm_fpu fpu; 1280 fpu = kzalloc(sizeof(struct kvm_fpu), GFP_KERNEL);
1276 1281 r = -ENOMEM;
1277 memset(&fpu, 0, sizeof fpu); 1282 if (!fpu)
1278 r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, &fpu); 1283 goto out;
1284 r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu);
1279 if (r) 1285 if (r)
1280 goto out; 1286 goto out;
1281 r = -EFAULT; 1287 r = -EFAULT;
1282 if (copy_to_user(argp, &fpu, sizeof fpu)) 1288 if (copy_to_user(argp, fpu, sizeof(struct kvm_fpu)))
1283 goto out; 1289 goto out;
1284 r = 0; 1290 r = 0;
1285 break; 1291 break;
1286 } 1292 }
1287 case KVM_SET_FPU: { 1293 case KVM_SET_FPU: {
1288 struct kvm_fpu fpu; 1294 fpu = kmalloc(sizeof(struct kvm_fpu), GFP_KERNEL);
1289 1295 r = -ENOMEM;
1296 if (!fpu)
1297 goto out;
1290 r = -EFAULT; 1298 r = -EFAULT;
1291 if (copy_from_user(&fpu, argp, sizeof fpu)) 1299 if (copy_from_user(fpu, argp, sizeof(struct kvm_fpu)))
1292 goto out; 1300 goto out;
1293 r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, &fpu); 1301 r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
1294 if (r) 1302 if (r)
1295 goto out; 1303 goto out;
1296 r = 0; 1304 r = 0;
@@ -1300,6 +1308,8 @@ out_free2:
1300 r = kvm_arch_vcpu_ioctl(filp, ioctl, arg); 1308 r = kvm_arch_vcpu_ioctl(filp, ioctl, arg);
1301 } 1309 }
1302out: 1310out:
1311 kfree(fpu);
1312 kfree(kvm_sregs);
1303 return r; 1313 return r;
1304} 1314}
1305 1315