All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [patch 1/8] test: allow functions to execute on non-irq context remotely
Date: Sun, 28 Mar 2010 09:32:04 +0300	[thread overview]
Message-ID: <4BAEF7E4.6060504@redhat.com> (raw)
In-Reply-To: <20100325180727.GA23070@amt.cnet>

On 03/25/2010 08:07 PM, Marcelo Tosatti wrote:
> 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.
>    

If the other cpu won't send it a new event until this one is completed.


>> 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:
>    

> +
> +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();
>    

sti; hlt need to be in one asm statement so the compiler does't insert 
anything (for example a call insn) or the race window opens again.

Even then, can't two cpus overwrite a third cpu's smp_function()?

The most worrying bit is that this follows no known model so the reader 
doesn't know what to expect.  on_cpu() follows Linux, but on_cpu_noipi 
has no parallel.

What about switching to a thread model?  Have a single global runqueue, 
round robin threads (no preemption, only on calls to schedule()), use 
cpus_allowed to pin a thread to a cpu.


-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


  reply	other threads:[~2010-03-28  6:32 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
2010-03-28  6:32       ` Avi Kivity [this message]
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=4BAEF7E4.6060504@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.