From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [patch 1/8] test: allow functions to execute on non-irq context remotely
Date: Thu, 25 Mar 2010 15:07:27 -0300 [thread overview]
Message-ID: <20100325180727.GA23070@amt.cnet> (raw)
In-Reply-To: <4BAB8E94.5090902@redhat.com>
On Thu, Mar 25, 2010 at 06:25:56PM +0200, Avi Kivity wrote:
> On 03/24/2010 11:24 PM, Marcelo Tosatti wrote:
> >Which allows code to execute on remote cpus while receiving interrupts.
> >
> >Also move late smp initialization to common code, and the smp loop
> >to C code.
>
>
> >+
> >+void smp_loop(void)
> >+{
> >+ void (*fn)(void *data);
> >+ void *data;
> >+
> >+ asm volatile ("hlt");
>
> Racy. The interrupt can happen before the hlt, which will kill the
> cpu.
Why would it kill the cpu? Only miss the event AFAICS. See patch below.
> Needs to be
>
> cli
> while not smp_function():
> sti; hlt
> cli
> sti
> smp_function()(smp_data())
>
> Also need to make sure two on_cpu_noipi()s don't stomp on each other.
Only cpu0 requests this ATM, and the IPIs to set function/data are
protected by a spinlock which serializes between cpu0<->target.
Its responsability of the caller to synchronization with termination.
Are you OK with this:
test: allow functions to execute on non-irq context remotely
Which allows code to execute on remote cpus while receiving interrupts.
Also move late smp initialization to common code, and the smp loop
to C code.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/kvm/user/test/lib/x86/smp.c
===================================================================
--- qemu-kvm.orig/kvm/user/test/lib/x86/smp.c
+++ qemu-kvm/kvm/user/test/lib/x86/smp.c
@@ -114,7 +114,7 @@ void on_cpu_async(int cpu, void (*functi
}
-void smp_init(void)
+void smp_init_ids(void)
{
int i;
void ipi_entry(void);
@@ -125,4 +125,70 @@ void smp_init(void)
for (i = 1; i < cpu_count(); ++i)
on_cpu(i, setup_smp_id, 0);
+ printf("detected %d cpus\n", cpu_count());
+}
+
+static void *smp_function(void)
+{
+ void *fn;
+
+ asm ("mov %%gs:8, %0" : "=r"(fn));
+ return fn;
+}
+
+static void setup_smp_function(void *data)
+{
+ asm ("mov %0, %%gs:8" : : "r"(data) : "memory");
+}
+
+static void *smp_data(void)
+{
+ void *fn;
+
+ asm ("mov %%gs:16, %0" : "=r"(fn));
+ return fn;
+}
+
+static void setup_smp_data(void *data)
+{
+ asm ("mov %0, %%gs:16" : : "r"(data) : "memory");
+}
+
+void on_cpu_noipi(int cpu, void (*function)(void *data), void *data)
+{
+ if (cpu == smp_id())
+ function(data);
+ else {
+ on_cpu(cpu, setup_smp_data, data);
+ on_cpu(cpu, setup_smp_function, function);
+ }
+}
+
+static void irq_disable(void)
+{
+ asm volatile("cli");
+}
+
+static void irq_enable(void)
+{
+ asm volatile("sti");
+}
+
+void smp_loop(void)
+{
+ void (*fn)(void *data);
+
+ irq_disable();
+ fn = smp_function();
+ if (fn) {
+ setup_smp_function(0);
+ irq_enable();
+ fn(smp_data());
+ irq_disable();
+ }
+
+ irq_enable();
+ asm volatile ("hlt");
+ irq_disable();
+
}
Index: qemu-kvm/kvm/user/test/lib/x86/smp.h
===================================================================
--- qemu-kvm.orig/kvm/user/test/lib/x86/smp.h
+++ qemu-kvm/kvm/user/test/lib/x86/smp.h
@@ -5,12 +5,11 @@ struct spinlock {
int v;
};
-void smp_init(void);
-
int cpu_count(void);
int smp_id(void);
void on_cpu(int cpu, void (*function)(void *data), void *data);
void on_cpu_async(int cpu, void (*function)(void *data), void *data);
+void on_cpu_noipi(int cpu, void (*function)(void *data), void *data);
void spin_lock(struct spinlock *lock);
void spin_unlock(struct spinlock *lock);
Index: qemu-kvm/kvm/user/test/x86/cstart64.S
===================================================================
--- qemu-kvm.orig/kvm/user/test/x86/cstart64.S
+++ qemu-kvm/kvm/user/test/x86/cstart64.S
@@ -165,7 +165,7 @@ ap_start64:
nop
lock incw cpu_online_count
-1: hlt
+1: call smp_loop
jmp 1b
start64:
@@ -174,6 +174,7 @@ start64:
call enable_apic
call smp_init
call enable_x2apic
+ call smp_init_ids
call main
mov %eax, %edi
call exit
Index: qemu-kvm/kvm/user/test/x86/smptest.c
===================================================================
--- qemu-kvm.orig/kvm/user/test/x86/smptest.c
+++ qemu-kvm/kvm/user/test/x86/smptest.c
@@ -15,8 +15,6 @@ int main()
int ncpus;
int i;
- smp_init();
-
ncpus = cpu_count();
printf("found %d cpus\n", ncpus);
for (i = 0; i < ncpus; ++i)
Index: qemu-kvm/kvm/user/test/x86/vmexit.c
===================================================================
--- qemu-kvm.orig/kvm/user/test/x86/vmexit.c
+++ qemu-kvm/kvm/user/test/x86/vmexit.c
@@ -155,8 +155,6 @@ int main(void)
{
int i;
- smp_init();
-
for (i = 0; i < ARRAY_SIZE(tests); ++i)
do_test(&tests[i]);
next prev parent reply other threads:[~2010-03-25 18:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-24 21:24 [patch 0/8] add slot deletion, rmap chain tests Marcelo Tosatti
2010-03-24 21:24 ` [patch 1/8] test: allow functions to execute on non-irq context remotely Marcelo Tosatti
2010-03-25 16:25 ` Avi Kivity
2010-03-25 18:07 ` Marcelo Tosatti [this message]
2010-03-28 6:32 ` Avi Kivity
2010-03-24 21:24 ` [patch 2/8] test: add pagefault exception handler Marcelo Tosatti
2010-03-24 21:24 ` [patch 3/8] test: protect fwcfg accesses with lock Marcelo Tosatti
2010-03-24 21:24 ` [patch 4/8] test: export vm helpers Marcelo Tosatti
2010-03-24 21:24 ` [patch 5/8] testdev: add port to create/delete memslots Marcelo Tosatti
2010-03-25 16:27 ` Avi Kivity
2010-03-24 21:24 ` [patch 6/8] test: parallel faults vs slot deletion Marcelo Tosatti
2010-03-24 21:24 ` [patch 7/8] test: bump max vcpus to 64 Marcelo Tosatti
2010-03-24 21:24 ` [patch 8/8] test: long rmap chains Marcelo Tosatti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100325180727.GA23070@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox