Skip to contentSkip to conversation

2.6.5-rc2-mm2 ipc hang fix

PATCH badari 2 participants 4 messages Mar 26, 2004

lore
Share & tools
lore

badari

author
#0 lore raw

Hi Andrew,

I ran into ipc hang while trying to shutdown database. Problem seems to be due to missing sem_unlock() in find_undo(). Here is the patch to fix the problem.

Please apply.

Thanks,
Badari

ipc/sem.c 2004-03-26 05:19:57.047757872 -0800 renamed from ipc/sem.c 2004-03-26 05:19:22.833959160 -0800 +3 -1
@@ -972,8 +972,10 @@ static struct sem_undo *find_undo(int se
        if(sma==NULL)
                goto out;
        un = ERR_PTR(-EIDRM);
-       if (sem_checkid(sma,semid))
+       if (sem_checkid(sma,semid)) {
+               sem_unlock(sma);
                goto out_unlock;
+       }
        nsems = sma->sem_nsems;
        sem_unlock(sma);
 
#1 lore raw
Quoted 15 lines · badari
ipc/sem.c 2004-03-26 05:19:57.047757872 -0800 renamed from ipc/sem.c 2004-03-26 05:19:22.833959160 -0800 +3 -1
@@ -972,8 +972,10 @@ static struct sem_undo *find_undo(int se
       if(sma==NULL)
               goto out;
       un = ERR_PTR(-EIDRM);
-       if (sem_checkid(sma,semid))
+       if (sem_checkid(sma,semid)) {
+               sem_unlock(sma);
               goto out_unlock;
+       }
       nsems = sma->sem_nsems;
       sem_unlock(sma);
 

[snip]

Quoted 5 lines

out_unlock:

        unlock_semundo();
out:
        return un;
}

Thanks for finding the bug - out_unlock unlocks the wrong spinlock, that's why I didn't notice it while searching for the bug. But I think your fix is wrong: the "goto out_unlock" must be replaced with "goto out": the semundo spinlock is not held.

--
Manfred

#2 lore raw
Quoted 23 lines · Manfred Spraul
Quoted 13 lines · badari
ipc/sem.c 2004-03-26 05:19:57.047757872 -0800 renamed from ipc/sem.c 2004-03-26 05:19:22.833959160 -0800 +3 -1
@@ -972,8 +972,10 @@ static struct sem_undo *find_undo(int se
       if(sma==NULL)
               goto out;
       un = ERR_PTR(-EIDRM);
-       if (sem_checkid(sma,semid))
+       if (sem_checkid(sma,semid)) {
+               sem_unlock(sma);
               goto out_unlock;
+       }
       nsems = sma->sem_nsems;
       sem_unlock(sma);

[snip]

Quoted 5 lines

out_unlock:

        unlock_semundo();
out:
        return un;
}
Quoted 4 lines

Thanks for finding the bug - out_unlock unlocks the wrong spinlock, that's why I didn't notice it while searching for the bug. But I think your fix is wrong: the "goto out_unlock" must be replaced with "goto out": the semundo spinlock is not held.

Yes. You are correct. semundo lock is not held.
Here is the updated patch.

Thanks,
Badari

ipc/sem.c +4 -2
@@ -972,8 +972,10 @@ static struct sem_undo *find_undo(int se
 	if(sma==NULL)
 		goto out;
 	un = ERR_PTR(-EIDRM);
-	if (sem_checkid(sma,semid))
-		goto out_unlock;
+	if (sem_checkid(sma,semid)) {
+		sem_unlock(sma);
+		goto out;
+	}
 	nsems = sma->sem_nsems;
 	sem_unlock(sma);
 
#3 lore raw

Re: 2.6.5-rc2-mm2 ipc hang fix (final version)

In reply to Manfred Spraul

Hi,

Here is the final version. I missed a compile warning before. out_unlock label is no longer needed.

Thanks,
Badari

ipc/sem.c +4 -3
@@ -972,8 +972,10 @@ static struct sem_undo *find_undo(int se
 	if(sma==NULL)
 		goto out;
 	un = ERR_PTR(-EIDRM);
-	if (sem_checkid(sma,semid))
-		goto out_unlock;
+	if (sem_checkid(sma,semid)) {
+		sem_unlock(sma);
+		goto out;
+	}
 	nsems = sma->sem_nsems;
 	sem_unlock(sma);
 
@@ -1004,7 +1006,6 @@ static struct sem_undo *find_undo(int se
 	sma->undo = new;
 	sem_unlock(sma);
 	un = new;
-out_unlock:
 	unlock_semundo();
 out:
 	return un;