All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] [Mini-OS] Make sure schedule() is called safely
Date: Fri, 23 Nov 2007 17:28:47 +0000	[thread overview]
Message-ID: <20071123172847.GA12402@implementation.uk.xensource.com> (raw)

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>

diff -r dc9246357cdb extras/mini-os/hypervisor.c
--- a/extras/mini-os/hypervisor.c	Fri Nov 23 16:42:44 2007 +0000
+++ b/extras/mini-os/hypervisor.c	Fri Nov 23 17:25:50 2007 +0000
@@ -33,6 +33,8 @@
     ((sh)->evtchn_pending[idx] &                \
      ~(sh)->evtchn_mask[idx])
 
+int in_callback;
+
 void do_hypervisor_callback(struct pt_regs *regs)
 {
     unsigned long  l1, l2, l1i, l2i;
@@ -41,6 +43,7 @@ void do_hypervisor_callback(struct pt_re
     shared_info_t *s = HYPERVISOR_shared_info;
     vcpu_info_t   *vcpu_info = &s->vcpu_info[cpu];
 
+    in_callback = 1;
    
     vcpu_info->evtchn_upcall_pending = 0;
     /* NB. No need for a barrier here -- XCHG is a barrier on x86. */
@@ -59,6 +62,8 @@ void do_hypervisor_callback(struct pt_re
 			do_event(port, regs);
         }
     }
+
+    in_callback = 0;
 }
 
 
diff -r dc9246357cdb extras/mini-os/include/hypervisor.h
--- a/extras/mini-os/include/hypervisor.h	Fri Nov 23 16:42:44 2007 +0000
+++ b/extras/mini-os/include/hypervisor.h	Fri Nov 23 17:25:50 2007 +0000
@@ -42,4 +42,6 @@ void unmask_evtchn(u32 port);
 void unmask_evtchn(u32 port);
 void clear_evtchn(u32 port);
 
+extern int in_callback;
+
 #endif /* __HYPERVISOR_H__ */
diff -r dc9246357cdb extras/mini-os/sched.c
--- a/extras/mini-os/sched.c	Fri Nov 23 16:42:44 2007 +0000
+++ b/extras/mini-os/sched.c	Fri Nov 23 17:25:50 2007 +0000
@@ -125,6 +125,14 @@ void schedule(void)
     unsigned long flags;
     prev = current;
     local_irq_save(flags); 
+    if (in_callback) {
+        printk("Must not call schedule() from a callback\n");
+        BUG();
+    }
+    if (flags) {
+        printk("Must not call schedule() with IRQs disabled\n");
+        BUG();
+    }
     list_for_each(iterator, &exited_threads)
     {
         thread = list_entry(iterator, struct thread, thread_list);

                 reply	other threads:[~2007-11-23 17:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20071123172847.GA12402@implementation.uk.xensource.com \
    --to=samuel.thibault@eu.citrix.com \
    --cc=xen-devel@lists.xensource.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.