Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 71506
b: refs/heads/master
c: c530c6a
h: refs/heads/master
v: v3
  • Loading branch information
Pierre Peiffer authored and Linus Torvalds committed Oct 19, 2007
1 parent ac457e9 commit 90e5568
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1b531f213661657d6e1c55cf5c97f649d630c227
refs/heads/master: c530c6ac7eb1d4ae1ff6b382d9211be446ee82c6
46 changes: 6 additions & 40 deletions trunk/ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,36 +999,6 @@ asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
}
}

static inline void lock_semundo(void)
{
struct sem_undo_list *undo_list;

undo_list = current->sysvsem.undo_list;
if (undo_list)
spin_lock(&undo_list->lock);
}

/* This code has an interaction with copy_semundo().
* Consider; two tasks are sharing the undo_list. task1
* acquires the undo_list lock in lock_semundo(). If task2 now
* exits before task1 releases the lock (by calling
* unlock_semundo()), then task1 will never call spin_unlock().
* This leave the sem_undo_list in a locked state. If task1 now creats task3
* and once again shares the sem_undo_list, the sem_undo_list will still be
* locked, and future SEM_UNDO operations will deadlock. This case is
* dealt with in copy_semundo() by having it reinitialize the spin lock when
* the refcnt goes from 1 to 2.
*/
static inline void unlock_semundo(void)
{
struct sem_undo_list *undo_list;

undo_list = current->sysvsem.undo_list;
if (undo_list)
spin_unlock(&undo_list->lock);
}


/* If the task doesn't already have a undo_list, then allocate one
* here. We guarantee there is only one thread using this undo list,
* and current is THE ONE
Expand Down Expand Up @@ -1089,9 +1059,9 @@ static struct sem_undo *find_undo(struct ipc_namespace *ns, int semid)
if (error)
return ERR_PTR(error);

lock_semundo();
spin_lock(&ulp->lock);
un = lookup_undo(ulp, semid);
unlock_semundo();
spin_unlock(&ulp->lock);
if (likely(un!=NULL))
goto out;

Expand All @@ -1114,10 +1084,10 @@ static struct sem_undo *find_undo(struct ipc_namespace *ns, int semid)
new->semadj = (short *) &new[1];
new->semid = semid;

lock_semundo();
spin_lock(&ulp->lock);
un = lookup_undo(ulp, semid);
if (un) {
unlock_semundo();
spin_unlock(&ulp->lock);
kfree(new);
ipc_lock_by_ptr(&sma->sem_perm);
ipc_rcu_putref(sma);
Expand All @@ -1128,7 +1098,7 @@ static struct sem_undo *find_undo(struct ipc_namespace *ns, int semid)
ipc_rcu_putref(sma);
if (sma->sem_perm.deleted) {
sem_unlock(sma);
unlock_semundo();
spin_unlock(&ulp->lock);
kfree(new);
un = ERR_PTR(-EIDRM);
goto out;
Expand All @@ -1139,7 +1109,7 @@ static struct sem_undo *find_undo(struct ipc_namespace *ns, int semid)
sma->undo = new;
sem_unlock(sma);
un = new;
unlock_semundo();
spin_unlock(&ulp->lock);
out:
return un;
}
Expand Down Expand Up @@ -1315,10 +1285,6 @@ asmlinkage long sys_semop (int semid, struct sembuf __user *tsops, unsigned nsop

/* If CLONE_SYSVSEM is set, establish sharing of SEM_UNDO state between
* parent and child tasks.
*
* See the notes above unlock_semundo() regarding the spin_lock_init()
* in this code. Initialize the undo_list->lock here instead of get_undo_list()
* because of the reasoning in the comment above unlock_semundo.
*/

int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
Expand Down

0 comments on commit 90e5568

Please sign in to comment.