kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Fix segfault when failing to initialize KVM
@ 2012-02-01  2:07 Sasha Levin
  2012-02-01  7:05 ` Pekka Enberg
  0 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2012-02-01  2:07 UTC (permalink / raw)
  To: penberg; +Cc: mingo, gorcunov, asias.hejun, kvm, Sasha Levin

Might happen when hardware virtualization is not supported.

Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-run.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 6ded1d2..a67faf8 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -997,6 +997,10 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 	}
 
 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
+	if (IS_ERR_OR_NULL(kvm)) {
+		r = PTR_ERR(kvm);
+		goto fail;
+	}
 
 	kvm->single_step = single_step;
 
-- 
1.7.8.4


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

* Re: [PATCH] kvm tools: Fix segfault when failing to initialize KVM
  2012-02-01  2:07 [PATCH] kvm tools: Fix segfault when failing to initialize KVM Sasha Levin
@ 2012-02-01  7:05 ` Pekka Enberg
  2012-02-01  7:19   ` Cyrill Gorcunov
  2012-02-01 12:48   ` Sasha Levin
  0 siblings, 2 replies; 6+ messages in thread
From: Pekka Enberg @ 2012-02-01  7:05 UTC (permalink / raw)
  To: Sasha Levin; +Cc: mingo, gorcunov, asias.hejun, kvm

On Tue, 31 Jan 2012, Sasha Levin wrote:
> Might happen when hardware virtualization is not supported.
>
> Reported-by: Ingo Molnar <mingo@elte.hu>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> tools/kvm/builtin-run.c |    4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> index 6ded1d2..a67faf8 100644
> --- a/tools/kvm/builtin-run.c
> +++ b/tools/kvm/builtin-run.c
> @@ -997,6 +997,10 @@ static int kvm_cmd_run_init(int argc, const char **argv)
> 	}
>
> 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> +	if (IS_ERR_OR_NULL(kvm)) {
> +		r = PTR_ERR(kvm);

How is this going to work when 'kvm' is NULL? It'd be best if kvm_init() 
never returned NULL on error.

> +		goto fail;
> +	}
>
> 	kvm->single_step = single_step;
>
> -- 
> 1.7.8.4
>
>

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

* Re: [PATCH] kvm tools: Fix segfault when failing to initialize KVM
  2012-02-01  7:05 ` Pekka Enberg
@ 2012-02-01  7:19   ` Cyrill Gorcunov
  2012-02-01  7:26     ` Pekka Enberg
  2012-02-01 12:48   ` Sasha Levin
  1 sibling, 1 reply; 6+ messages in thread
From: Cyrill Gorcunov @ 2012-02-01  7:19 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Sasha Levin, mingo, asias.hejun, kvm

On Wed, Feb 01, 2012 at 09:05:34AM +0200, Pekka Enberg wrote:
> On Tue, 31 Jan 2012, Sasha Levin wrote:
> >Might happen when hardware virtualization is not supported.
> >
> >Reported-by: Ingo Molnar <mingo@elte.hu>
> >Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> >---
> >tools/kvm/builtin-run.c |    4 ++++
> >1 files changed, 4 insertions(+), 0 deletions(-)
> >
> >diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> >index 6ded1d2..a67faf8 100644
> >--- a/tools/kvm/builtin-run.c
> >+++ b/tools/kvm/builtin-run.c
> >@@ -997,6 +997,10 @@ static int kvm_cmd_run_init(int argc, const char **argv)
> >	}
> >
> >	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> >+	if (IS_ERR_OR_NULL(kvm)) {
> >+		r = PTR_ERR(kvm);
> 
> How is this going to work when 'kvm' is NULL? It'd be best if
> kvm_init() never returned NULL on error.
> 
> >+		goto fail;
> >+	}
> >
> >	kvm->single_step = single_step;
> >

I suspect we need something like
---
 tools/kvm/builtin-run.c |    5 +++++
 tools/kvm/kvm.c         |    2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6.git/tools/kvm/builtin-run.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/builtin-run.c
+++ linux-2.6.git/tools/kvm/builtin-run.c
@@ -997,6 +997,11 @@ static int kvm_cmd_run_init(int argc, co
 	}
 
 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
+	if (IS_ERR(kvm)) {
+		r = (int)PTR_ERR(kvm);
+		pr_err("Can't initialize KVM, failed with error %d\n", r);
+		goto fail;
+	}
 
 	kvm->single_step = single_step;
 
Index: linux-2.6.git/tools/kvm/kvm.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/kvm.c
+++ linux-2.6.git/tools/kvm/kvm.c
@@ -340,7 +340,7 @@ struct kvm *kvm__init(const char *kvm_de
 	}
 
 	kvm = kvm__new();
-	if (IS_ERR_OR_NULL(kvm))
+	if (IS_ERR(kvm))
 		return kvm;
 
 	kvm->sys_fd = open(kvm_dev, O_RDWR);

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

* Re: [PATCH] kvm tools: Fix segfault when failing to initialize KVM
  2012-02-01  7:19   ` Cyrill Gorcunov
@ 2012-02-01  7:26     ` Pekka Enberg
  2012-02-01  7:28       ` Cyrill Gorcunov
  0 siblings, 1 reply; 6+ messages in thread
From: Pekka Enberg @ 2012-02-01  7:26 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: Sasha Levin, mingo, asias.hejun, kvm

On Wed, 1 Feb 2012, Cyrill Gorcunov wrote:
> I suspect we need something like
> ---
> tools/kvm/builtin-run.c |    5 +++++
> tools/kvm/kvm.c         |    2 +-
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> Index: linux-2.6.git/tools/kvm/builtin-run.c
> ===================================================================
> --- linux-2.6.git.orig/tools/kvm/builtin-run.c
> +++ linux-2.6.git/tools/kvm/builtin-run.c
> @@ -997,6 +997,11 @@ static int kvm_cmd_run_init(int argc, co
> 	}
>
> 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> +	if (IS_ERR(kvm)) {
> +		r = (int)PTR_ERR(kvm);

The cast is not needed.

> +		pr_err("Can't initialize KVM, failed with error %d\n", r);
> +		goto fail;
> +	}

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

* Re: [PATCH] kvm tools: Fix segfault when failing to initialize KVM
  2012-02-01  7:26     ` Pekka Enberg
@ 2012-02-01  7:28       ` Cyrill Gorcunov
  0 siblings, 0 replies; 6+ messages in thread
From: Cyrill Gorcunov @ 2012-02-01  7:28 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Sasha Levin, mingo, asias.hejun, kvm

On Wed, Feb 01, 2012 at 09:26:00AM +0200, Pekka Enberg wrote:
> On Wed, 1 Feb 2012, Cyrill Gorcunov wrote:
> >I suspect we need something like
> >---
> >tools/kvm/builtin-run.c |    5 +++++
> >tools/kvm/kvm.c         |    2 +-
> >2 files changed, 6 insertions(+), 1 deletion(-)
> >
> >Index: linux-2.6.git/tools/kvm/builtin-run.c
> >===================================================================
> >--- linux-2.6.git.orig/tools/kvm/builtin-run.c
> >+++ linux-2.6.git/tools/kvm/builtin-run.c
> >@@ -997,6 +997,11 @@ static int kvm_cmd_run_init(int argc, co
> >	}
> >
> >	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> >+	if (IS_ERR(kvm)) {
> >+		r = (int)PTR_ERR(kvm);
> 
> The cast is not needed.
> 

Yeah, it's leftover from draft patch ;) Sasha, would you make
some new version or I should create new patch?

	Cyrill

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

* Re: [PATCH] kvm tools: Fix segfault when failing to initialize KVM
  2012-02-01  7:05 ` Pekka Enberg
  2012-02-01  7:19   ` Cyrill Gorcunov
@ 2012-02-01 12:48   ` Sasha Levin
  1 sibling, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2012-02-01 12:48 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: mingo, gorcunov, asias.hejun, kvm

On Wed, 2012-02-01 at 09:05 +0200, Pekka Enberg wrote:
> On Tue, 31 Jan 2012, Sasha Levin wrote:
> > Might happen when hardware virtualization is not supported.
> >
> > Reported-by: Ingo Molnar <mingo@elte.hu>
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> > ---
> > tools/kvm/builtin-run.c |    4 ++++
> > 1 files changed, 4 insertions(+), 0 deletions(-)
> >
> > diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> > index 6ded1d2..a67faf8 100644
> > --- a/tools/kvm/builtin-run.c
> > +++ b/tools/kvm/builtin-run.c
> > @@ -997,6 +997,10 @@ static int kvm_cmd_run_init(int argc, const char **argv)
> > 	}
> >
> > 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> > +	if (IS_ERR_OR_NULL(kvm)) {
> > +		r = PTR_ERR(kvm);
> 
> How is this going to work when 'kvm' is NULL? It'd be best if kvm_init() 
> never returned NULL on error.

Actually, it never does, I'm not sure why I put IS_ERR_OR_NULL there.

I'll resend that one.

-- 

Sasha.


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

end of thread, other threads:[~2012-02-01 12:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-01  2:07 [PATCH] kvm tools: Fix segfault when failing to initialize KVM Sasha Levin
2012-02-01  7:05 ` Pekka Enberg
2012-02-01  7:19   ` Cyrill Gorcunov
2012-02-01  7:26     ` Pekka Enberg
2012-02-01  7:28       ` Cyrill Gorcunov
2012-02-01 12:48   ` Sasha Levin

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).