ia64/xen-unstable

changeset 16447:ee519207734f

[Mini-OS] Make sure schedule() is called safely

If a thread tries to sleep from a callback or with callbacks disabled,
Mini-OS will completely lock, so make sure this never happens.

Signed-off-by: Samuel Thibault <samuel.thibault@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Sat Nov 24 13:29:20 2007 +0000 (2007-11-24)
parents 7eea09b18839
children 2c52520f3284
files extras/mini-os/hypervisor.c extras/mini-os/include/hypervisor.h extras/mini-os/sched.c
line diff
     1.1 --- a/extras/mini-os/hypervisor.c	Sat Nov 24 13:28:54 2007 +0000
     1.2 +++ b/extras/mini-os/hypervisor.c	Sat Nov 24 13:29:20 2007 +0000
     1.3 @@ -33,6 +33,8 @@
     1.4      ((sh)->evtchn_pending[idx] &                \
     1.5       ~(sh)->evtchn_mask[idx])
     1.6  
     1.7 +int in_callback;
     1.8 +
     1.9  void do_hypervisor_callback(struct pt_regs *regs)
    1.10  {
    1.11      unsigned long  l1, l2, l1i, l2i;
    1.12 @@ -41,6 +43,7 @@ void do_hypervisor_callback(struct pt_re
    1.13      shared_info_t *s = HYPERVISOR_shared_info;
    1.14      vcpu_info_t   *vcpu_info = &s->vcpu_info[cpu];
    1.15  
    1.16 +    in_callback = 1;
    1.17     
    1.18      vcpu_info->evtchn_upcall_pending = 0;
    1.19      /* NB. No need for a barrier here -- XCHG is a barrier on x86. */
    1.20 @@ -59,6 +62,8 @@ void do_hypervisor_callback(struct pt_re
    1.21  			do_event(port, regs);
    1.22          }
    1.23      }
    1.24 +
    1.25 +    in_callback = 0;
    1.26  }
    1.27  
    1.28  
     2.1 --- a/extras/mini-os/include/hypervisor.h	Sat Nov 24 13:28:54 2007 +0000
     2.2 +++ b/extras/mini-os/include/hypervisor.h	Sat Nov 24 13:29:20 2007 +0000
     2.3 @@ -42,4 +42,6 @@ void mask_evtchn(u32 port);
     2.4  void unmask_evtchn(u32 port);
     2.5  void clear_evtchn(u32 port);
     2.6  
     2.7 +extern int in_callback;
     2.8 +
     2.9  #endif /* __HYPERVISOR_H__ */
     3.1 --- a/extras/mini-os/sched.c	Sat Nov 24 13:28:54 2007 +0000
     3.2 +++ b/extras/mini-os/sched.c	Sat Nov 24 13:29:20 2007 +0000
     3.3 @@ -125,6 +125,14 @@ void schedule(void)
     3.4      unsigned long flags;
     3.5      prev = current;
     3.6      local_irq_save(flags); 
     3.7 +    if (in_callback) {
     3.8 +        printk("Must not call schedule() from a callback\n");
     3.9 +        BUG();
    3.10 +    }
    3.11 +    if (flags) {
    3.12 +        printk("Must not call schedule() with IRQs disabled\n");
    3.13 +        BUG();
    3.14 +    }
    3.15      list_for_each(iterator, &exited_threads)
    3.16      {
    3.17          thread = list_entry(iterator, struct thread, thread_list);