diff mbox

[2/2] kvm tools: Bring SMP back

Message ID 1347462216-18641-2-git-send-email-asias.hejun@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Asias He Sept. 12, 2012, 3:03 p.m. UTC
We have this currently:

   kvm__init()
      kvm__arch_setup_firmware()
         mptable__init()
            using kvm->nrcpus

   kvm_cpu__init()
      kvm->nrcpus = kvm->cfg.nrcpus

kvm->nrcpus is used in mptable__init() before it is initialized, so
mptable__init() will setup a wrong mp table.

Before:
$ ./lkvm -c 4
$ cat /proc/cpuinfo |grep ^processor|wc -l
1

After:
$ ./lkvm -c 4
$ cat /proc/cpuinfo |grep ^processor|wc -l
4

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/builtin-run.c | 7 -------
 tools/kvm/kvm.c         | 6 ++++++
 2 files changed, 6 insertions(+), 7 deletions(-)

Comments

Cyrill Gorcunov Sept. 12, 2012, 3:10 p.m. UTC | #1
On Wed, Sep 12, 2012 at 11:03:36PM +0800, Asias He wrote:
> We have this currently:
> 
>    kvm__init()
>       kvm__arch_setup_firmware()
>          mptable__init()
>             using kvm->nrcpus
> 
>    kvm_cpu__init()
>       kvm->nrcpus = kvm->cfg.nrcpus
> 
> kvm->nrcpus is used in mptable__init() before it is initialized, so
> mptable__init() will setup a wrong mp table.
> 
> Before:
> $ ./lkvm -c 4
> $ cat /proc/cpuinfo |grep ^processor|wc -l
> 1
> 
> After:
> $ ./lkvm -c 4
> $ cat /proc/cpuinfo |grep ^processor|wc -l
> 4
> 
> Signed-off-by: Asias He <asias.hejun@gmail.com>

Good catch!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 5ddffaa..790b496 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -656,19 +656,12 @@  static int kvm_cmd_run_init(int argc, const char **argv)
 		goto fail;
 	}
 
-
 	r = ioeventfd__init(kvm);
 	if (r < 0) {
 		pr_err("ioeventfd__init() failed with error %d\n", r);
 		goto fail;
 	}
 
-	r = kvm_cpu__init(kvm);
-	if (r < 0) {
-		pr_err("kvm_cpu__init() failed with error %d\n", r);
-		goto fail;
-	}
-
 	r = irq__init(kvm);
 	if (r < 0) {
 		pr_err("irq__init() failed with error %d\n", r);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index cca2e93..4fdad92 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -248,6 +248,12 @@  int kvm__init(struct kvm *kvm)
 
 	kvm__init_ram(kvm);
 
+	ret = kvm_cpu__init(kvm);
+	if (ret < 0) {
+		pr_err("kvm_cpu__init() failed with error %d\n", ret);
+		goto err_vm_fd;
+	}
+
 	if (!kvm->cfg.firmware_filename) {
 		if (!kvm__load_kernel(kvm, kvm->cfg.kernel_filename,
 				kvm->cfg.initrd_filename, kvm->cfg.real_cmdline, kvm->cfg.vidmode))