fix possible mm_context wrap-around race
Tony, since I can't test the patch on anything but a UP machine at this time (which is uninteresting, since the race doesn't trigger there), I'd suggest to put this into the "testing" tree. Hopefully, somebody could run some tests which involve multi-threaded apps doing a lot of fork/exec'ing.
Thanks,
--david
Signature · 3 lines
Mosberger Consulting LLC, voice/fax: 510-744-9372, http://www.mosberger-consulting.com/ 35706 Runckel Lane, Fremont, CA 94536
Argh, some day I'll hopefully remember to attach the actual patch...
--david
Quoted 14 lines · david mosberger
Tony, since I can't test the patch on anything but a UP machine at this time (which is uninteresting, since the race doesn't trigger there), I'd suggest to put this into the "testing" tree. Hopefully, somebody could run some tests which involve multi-threaded apps doing a lot of fork/exec'ing.
Thanks,
--david
--
Mosberger Consulting LLC, voice/fax: 510-744-9372,
http://www.mosberger-consulting.com/
35706 Runckel Lane, Fremont, CA 94536
Signature · 3 lines
Mosberger Consulting LLC, voice/fax: 510-744-9372, http://www.mosberger-consulting.com/ 35706 Runckel Lane, Fremont, CA 94536
[IA64] Fix race in mm-context wrap-around logic.
The patch below should fix a race which could cause stale TLB entries. Specifically, when 2 CPUs ended up racing for entrance to wrap_mmu_context(). The losing CPU would find that by the time it acquired ctx.lock, mm->context already had a valid value, but then it failed to (re-)check the delayed TLB flushing logic and hence could end up using a context number when there were still stale entries in its TLB. The fix is to check for delayed TLB flushes only after mm->context is valid (non-zero). The patch also makes GCC v4.x happier by defining a non-volatile variant of mm_context_t called nv_mm_context_t.
include/asm-ia64/mmu.h +5 -3
@@ -2,10 +2,12 @@#define __MMU_H/* -* Type for a context number. We declare it volatile to ensure proper ordering when it's -* accessed outside of spinlock'd critical sections (e.g., as done in activate_mm() and -* init_new_context()). +* Type for a context number. We declare it volatile to ensure proper +* ordering when it's accessed outside of spinlock'd critical sections +* (e.g., as done in activate_mm() and init_new_context()). */ typedef volatile unsigned long mm_context_t ; +typedef unsigned long nv_mm_context_t ; +#endif
include/asm-ia64/mmu_context.h +31 -21
87 lines not on this page · raw message
Here is a program that exposes the issue on a 2.4 and 2.6 kernel. It pretty easy to reproduce on an 8-way - takes about 1 or 2 minutes on a 2-way it has not been reproduced or tried on a 4-way (i.e. no available system).
- mario
----------------------------
gcc -g -pthread foo.cpp -o foo -lpthread
#include <stdio.h>
#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
void * worker(void *self) {
int x = -1;
FILE *pp = 0;
long junk[8192];
char buf[1024];
x = -1;
errno = 0;
pp = popen("ls", "r");
x = errno;
if(pp) {
memset(buf, 0, sizeof(buf));
while(fgets(buf, sizeof(buf)-1, pp) != 0) {
;
}
pclose(pp);
}
else printf("popen failed: %s\n", strerror(errno));
pthread_exit(NULL);
}int main(void) {
pthread_t pt[128];
pthread_t pthr;
int x = 0;
while(1) {
for (x = 0; x < 5; x++)
pthread_create(&(pt[x]), 0, worker, (void *)&x);
for (x = 0; x < 5; x++)
pthread_join( pt[x], NULL);
usleep(5000);
} return 0;
}
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of david mosberger
Sent: Tuesday, July 26, 2005 12:23 AM
To: Luck, Tony
Cc: [email protected]
Subject: Re: fix possible mm_context wrap-around race
Argh, some day I'll hopefully remember to attach the actual patch...
--david
Quoted 14 lines · david mosberger
Tony, since I can't test the patch on anything but a UP machine at this time (which is uninteresting, since the race doesn't trigger there), I'd suggest to put this into the "testing" tree. Hopefully, somebody could run some tests which involve multi-threaded apps doing a lot of fork/exec'ing.
Thanks,
--david
--
Mosberger Consulting LLC, voice/fax: 510-744-9372,
http://www.mosberger-consulting.com/
35706 Runckel Lane, Fremont, CA 94536
Signature · 2 lines
Mosberger Consulting LLC, voice/fax: 510-744-9372, http://www.mosberger-consulting.com/ 35706 Runckel Lane, Fremont, CA 94536