summaryrefslogtreecommitdiff
path: root/sys/src/9/port/devdtracy.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-03-30 09:17:46 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2019-03-30 09:17:46 +0100
commit4f0bfe0fb8dc608a94fe429c5ddb12e58997e1ce (patch)
treefc81407d959370278dfdb53da69c5ab8b3fef55c /sys/src/9/port/devdtracy.c
parentac3147a9c58f339f9b978ab087464912c16bc8f8 (diff)
dtracy: avoid dmachlock() race
between being commited to a machno and having acquired the lock, the scheduler could come in an schedule us on a different processor. the solution is to have dtmachlock() take a special -1 argument to mean "current mach" and return the actual mach number after the lock has been acquired and interrupts being disabled.
Diffstat (limited to 'sys/src/9/port/devdtracy.c')
-rw-r--r--sys/src/9/port/devdtracy.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/src/9/port/devdtracy.c b/sys/src/9/port/devdtracy.c
index 018bad624..19a321cc5 100644
--- a/sys/src/9/port/devdtracy.c
+++ b/sys/src/9/port/devdtracy.c
@@ -512,10 +512,18 @@ dtrealloc(void *v, ulong n)
return v;
}
-void
+int
dtmachlock(int i)
{
+ while(i < 0) {
+ i = dtmachlock(m->machno);
+ if(i == m->machno)
+ return i;
+ dtmachunlock(i);
+ i = -1;
+ }
ilock(&machlocks[i]);
+ return i;
}
void