public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Using kzalloc to avoid allocating kvm_regs from kernel stack
@ 2008-02-25  9:34 Zhang, Xiantao
  2008-02-25 16:38 ` Hollis Blanchard
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang, Xiantao @ 2008-02-25  9:34 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, kvm-ia64-devel

[-- Attachment #1: Type: text/plain, Size: 1688 bytes --]

From: Xiantao Zhang <xiantao.zhang@intel.com>
Date: Mon, 25 Feb 2008 17:11:43 +0800
Subject: [PATCH] kvm: Using kzalloc to avoid allocating kvm_regs from
kernel stack.

Since the size of struct kvm_regs maybe too big to allocate from kernel
stack,
here use kzalloc to allocate it.
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
---
 virt/kvm/kvm_main.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf6df51..5348538 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -806,25 +806,26 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
 		break;
 	case KVM_GET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
-		memset(&kvm_regs, 0, sizeof kvm_regs);
-		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = -EFAULT;
-		if (copy_to_user(argp, &kvm_regs, sizeof kvm_regs))
+		if (copy_to_user(argp, kvm_regs, sizeof(struct
kvm_regs)))
 			goto out;
 		r = 0;
 		break;
 	}
 	case KVM_SET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
 		r = -EFAULT;
-		if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
+		if (copy_from_user(kvm_regs, argp, sizeof(struct
kvm_regs)))
 			goto out;
-		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
+		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = 0;
-- 
1.5.2

[-- Attachment #2: 0001-kvm-Using-kzalloc-to-avoid-allocating-kvm_regs-from.patch --]
[-- Type: application/octet-stream, Size: 1698 bytes --]

From 23a274a5e40e80b9eb4b92d8a29fe81373de4407 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <xiantao.zhang@intel.com>
Date: Mon, 25 Feb 2008 17:11:43 +0800
Subject: [PATCH] kvm: Using kzalloc to avoid allocating kvm_regs from kernel stack.

Since the size of kvm_regs maybe too big to allocate from kernel stack,
here use kzalloc to allocate it.
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
---
 virt/kvm/kvm_main.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf6df51..5348538 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -806,25 +806,26 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
 		break;
 	case KVM_GET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
-		memset(&kvm_regs, 0, sizeof kvm_regs);
-		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = -EFAULT;
-		if (copy_to_user(argp, &kvm_regs, sizeof kvm_regs))
+		if (copy_to_user(argp, kvm_regs, sizeof(struct kvm_regs)))
 			goto out;
 		r = 0;
 		break;
 	}
 	case KVM_SET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
 		r = -EFAULT;
-		if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
+		if (copy_from_user(kvm_regs, argp, sizeof(struct kvm_regs)))
 			goto out;
-		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
+		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = 0;
-- 
1.5.2


[-- Attachment #3: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* Re: [PATCH] Using kzalloc to avoid allocating kvm_regs from kernel stack
@ 2008-02-25  9:43 Zhang, Xiantao
  0 siblings, 0 replies; 4+ messages in thread
From: Zhang, Xiantao @ 2008-02-25  9:43 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, kvm-ia64-devel

[-- Attachment #1: Type: text/plain, Size: 1854 bytes --]

Please use the new one. Add the check for failed allocation.
 
From: Xiantao Zhang <xiantao.zhang@intel.com>
Date: Mon, 25 Feb 2008 17:25:07 +0800
Subject: [PATCH] kvm: Using kzalloc to avoid allocating kvm_regs from
kernel stack.

Since the size of kvm_regs maybe too big to allocate from kernel stack,
here use kzalloc to allocate it.
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
---
 virt/kvm/kvm_main.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf6df51..8d4326f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -806,25 +806,32 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
 		break;
 	case KVM_GET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
-		memset(&kvm_regs, 0, sizeof kvm_regs);
-		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
+		r = -ENOMEM;
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		if (!kvm_regs)
+			goto out;
+		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = -EFAULT;
-		if (copy_to_user(argp, &kvm_regs, sizeof kvm_regs))
+		if (copy_to_user(argp, kvm_regs, sizeof(struct
kvm_regs)))
 			goto out;
 		r = 0;
 		break;
 	}
 	case KVM_SET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
+		r = -ENOMEM;
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		if (!kvm_regs)
+			goto out;
 		r = -EFAULT;
-		if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
+		if (copy_from_user(kvm_regs, argp, sizeof(struct
kvm_regs)))
 			goto out;
-		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
+		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = 0;
-- 
1.5.2

[-- Attachment #2: 0001-kvm-Using-kzalloc-to-avoid-allocating-kvm_regs-from.patch --]
[-- Type: application/octet-stream, Size: 1801 bytes --]

From ea8d2422c93c1a386b732a34505bb040bda52b6e Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <xiantao.zhang@intel.com>
Date: Mon, 25 Feb 2008 17:25:07 +0800
Subject: [PATCH] kvm: Using kzalloc to avoid allocating kvm_regs from kernel stack.

Since the size of kvm_regs maybe too big to allocate from kernel stack,
here use kzalloc to allocate it.
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
---
 virt/kvm/kvm_main.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf6df51..8d4326f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -806,25 +806,32 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
 		break;
 	case KVM_GET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
-		memset(&kvm_regs, 0, sizeof kvm_regs);
-		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
+		r = -ENOMEM;
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		if (!kvm_regs)
+			goto out;
+		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = -EFAULT;
-		if (copy_to_user(argp, &kvm_regs, sizeof kvm_regs))
+		if (copy_to_user(argp, kvm_regs, sizeof(struct kvm_regs)))
 			goto out;
 		r = 0;
 		break;
 	}
 	case KVM_SET_REGS: {
-		struct kvm_regs kvm_regs;
+		struct kvm_regs *kvm_regs;
 
+		r = -ENOMEM;
+		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+		if (!kvm_regs)
+			goto out;
 		r = -EFAULT;
-		if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
+		if (copy_from_user(kvm_regs, argp, sizeof(struct kvm_regs)))
 			goto out;
-		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
+		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
 		if (r)
 			goto out;
 		r = 0;
-- 
1.5.2


[-- Attachment #3: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* Re: [PATCH] Using kzalloc to avoid allocating kvm_regs from kernel stack
  2008-02-25  9:34 [PATCH] Using kzalloc to avoid allocating kvm_regs from kernel stack Zhang, Xiantao
@ 2008-02-25 16:38 ` Hollis Blanchard
  2008-02-25 16:39   ` Hollis Blanchard
  0 siblings, 1 reply; 4+ messages in thread
From: Hollis Blanchard @ 2008-02-25 16:38 UTC (permalink / raw)
  To: Zhang, Xiantao; +Cc: kvm-devel, kvm-ia64-devel, Avi Kivity

On Mon, 2008-02-25 at 17:34 +0800, Zhang, Xiantao wrote:
> From: Xiantao Zhang <xiantao.zhang@intel.com>
> Date: Mon, 25 Feb 2008 17:11:43 +0800
> Subject: [PATCH] kvm: Using kzalloc to avoid allocating kvm_regs from
> kernel stack.
> 
> Since the size of struct kvm_regs maybe too big to allocate from kernel
> stack,
> here use kzalloc to allocate it.
> Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
> ---
>  virt/kvm/kvm_main.c |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index cf6df51..5348538 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -806,25 +806,26 @@ static long kvm_vcpu_ioctl(struct file *filp,
>  		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
>  		break;
>  	case KVM_GET_REGS: {
> -		struct kvm_regs kvm_regs;
> +		struct kvm_regs *kvm_regs;
>  
> -		memset(&kvm_regs, 0, sizeof kvm_regs);
> -		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
> +		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
> +		r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
>  		if (r)
>  			goto out;
>  		r = -EFAULT;
> -		if (copy_to_user(argp, &kvm_regs, sizeof kvm_regs))
> +		if (copy_to_user(argp, kvm_regs, sizeof(struct
> kvm_regs)))
>  			goto out;
>  		r = 0;
>  		break;
>  	}
>  	case KVM_SET_REGS: {
> -		struct kvm_regs kvm_regs;
> +		struct kvm_regs *kvm_regs;
>  
> +		kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
>  		r = -EFAULT;
> -		if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
> +		if (copy_from_user(kvm_regs, argp, sizeof(struct
> kvm_regs)))
>  			goto out;
> -		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
> +		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
>  		if (r)
>  			goto out;
>  		r = 0;

Where is this freed?

-- 
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

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

* Re: [PATCH] Using kzalloc to avoid allocating kvm_regs from kernel stack
  2008-02-25 16:38 ` Hollis Blanchard
@ 2008-02-25 16:39   ` Hollis Blanchard
  0 siblings, 0 replies; 4+ messages in thread
From: Hollis Blanchard @ 2008-02-25 16:39 UTC (permalink / raw)
  To: Zhang, Xiantao; +Cc: kvm-devel, kvm-ia64-devel, Avi Kivity

On Mon, 2008-02-25 at 10:38 -0600, Hollis Blanchard wrote:
> On Mon, 2008-02-25 at 17:34 +0800, Zhang, Xiantao wrote:
> > From: Xiantao Zhang <xiantao.zhang@intel.com>
> > Date: Mon, 25 Feb 2008 17:11:43 +0800
> > Subject: [PATCH] kvm: Using kzalloc to avoid allocating kvm_regs from
> > kernel stack.
> > 
> > Since the size of struct kvm_regs maybe too big to allocate from kernel
> > stack,
> > here use kzalloc to allocate it.
> 
> Where is this freed?

Never mind; I see it now in rev #3. :)

-- 
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

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

end of thread, other threads:[~2008-02-25 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-25  9:34 [PATCH] Using kzalloc to avoid allocating kvm_regs from kernel stack Zhang, Xiantao
2008-02-25 16:38 ` Hollis Blanchard
2008-02-25 16:39   ` Hollis Blanchard
  -- strict thread matches above, loose matches on Subject: below --
2008-02-25  9:43 Zhang, Xiantao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox