Skip to content

Commit 00c2bf8

Browse files
Nadia Derbeytorvalds
authored andcommitted
ipc: get rid of ipc_lock_down()
Remove the ipc_lock_down() routines: they used to call idr_find() locklessly (given that the ipc ids lock was already held), so they are not needed anymore. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> Acked-by: "Paul E. McKenney" <paulmck@us.ibm.com> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: Jim Houston <jim.houston@comcast.net> Cc: Pierre Peiffer <peifferp@gmail.com> Acked-by: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 983bfb7 commit 00c2bf8

3 files changed

Lines changed: 4 additions & 75 deletions

File tree

‎ipc/shm.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,9 @@ void __init shm_init (void)
111111
IPC_SHM_IDS, sysvipc_shm_proc_show);
112112
}
113113

114-
/*
115-
* shm_lock_(check_)down routines are called in the paths where the rw_mutex
116-
* is held to protect access to the idr tree.
117-
*/
118-
static inline struct shmid_kernel *shm_lock_down(struct ipc_namespace *ns,
119-
int id)
120-
{
121-
struct kern_ipc_perm *ipcp = ipc_lock_down(&shm_ids(ns), id);
122-
123-
if (IS_ERR(ipcp))
124-
return (struct shmid_kernel *)ipcp;
125-
126-
return container_of(ipcp, struct shmid_kernel, shm_perm);
127-
}
128-
129114
/*
130115
* shm_lock_(check_) routines are called in the paths where the rw_mutex
131-
* is not held.
116+
* is not necessarily held.
132117
*/
133118
static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
134119
{
@@ -211,7 +196,7 @@ static void shm_close(struct vm_area_struct *vma)
211196

212197
down_write(&shm_ids(ns).rw_mutex);
213198
/* remove from the list of attaches of the shm segment */
214-
shp = shm_lock_down(ns, sfd->id);
199+
shp = shm_lock(ns, sfd->id);
215200
BUG_ON(IS_ERR(shp));
216201
shp->shm_lprid = task_tgid_vnr(current);
217202
shp->shm_dtim = get_seconds();
@@ -932,7 +917,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
932917

933918
out_nattch:
934919
down_write(&shm_ids(ns).rw_mutex);
935-
shp = shm_lock_down(ns, shmid);
920+
shp = shm_lock(ns, shmid);
936921
BUG_ON(IS_ERR(shp));
937922
shp->shm_nattch--;
938923
if(shp->shm_nattch == 0 &&

‎ipc/util.c‎

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -716,56 +716,6 @@ struct kern_ipc_perm *ipc_lock(struct ipc_ids *ids, int id)
716716
return out;
717717
}
718718

719-
/**
720-
* ipc_lock_down - Lock an ipc structure with rw_sem held
721-
* @ids: IPC identifier set
722-
* @id: ipc id to look for
723-
*
724-
* Look for an id in the ipc ids idr and lock the associated ipc object.
725-
*
726-
* The ipc object is locked on exit.
727-
*
728-
* This is the routine that should be called when the rw_mutex is already
729-
* held, i.e. idr tree protected.
730-
*/
731-
732-
struct kern_ipc_perm *ipc_lock_down(struct ipc_ids *ids, int id)
733-
{
734-
struct kern_ipc_perm *out;
735-
int lid = ipcid_to_idx(id);
736-
737-
rcu_read_lock();
738-
out = idr_find(&ids->ipcs_idr, lid);
739-
if (out == NULL) {
740-
rcu_read_unlock();
741-
return ERR_PTR(-EINVAL);
742-
}
743-
744-
spin_lock(&out->lock);
745-
746-
/*
747-
* No need to verify that the structure is still valid since the
748-
* rw_mutex is held.
749-
*/
750-
return out;
751-
}
752-
753-
struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, int id)
754-
{
755-
struct kern_ipc_perm *out;
756-
757-
out = ipc_lock_down(ids, id);
758-
if (IS_ERR(out))
759-
return out;
760-
761-
if (ipc_checkid(out, id)) {
762-
ipc_unlock(out);
763-
return ERR_PTR(-EIDRM);
764-
}
765-
766-
return out;
767-
}
768-
769719
struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id)
770720
{
771721
struct kern_ipc_perm *out;
@@ -837,7 +787,7 @@ struct kern_ipc_perm *ipcctl_pre_down(struct ipc_ids *ids, int id, int cmd,
837787
int err;
838788

839789
down_write(&ids->rw_mutex);
840-
ipcp = ipc_lock_check_down(ids, id);
790+
ipcp = ipc_lock_check(ids, id);
841791
if (IS_ERR(ipcp)) {
842792
err = PTR_ERR(ipcp);
843793
goto out_up;

‎ipc/util.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ void* ipc_rcu_alloc(int size);
102102
void ipc_rcu_getref(void *ptr);
103103
void ipc_rcu_putref(void *ptr);
104104

105-
/*
106-
* ipc_lock_down: called with rw_mutex held
107-
* ipc_lock: called without that lock held
108-
*/
109-
struct kern_ipc_perm *ipc_lock_down(struct ipc_ids *, int);
110105
struct kern_ipc_perm *ipc_lock(struct ipc_ids *, int);
111106

112107
void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
@@ -155,7 +150,6 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)
155150
rcu_read_unlock();
156151
}
157152

158-
struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, int id);
159153
struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id);
160154
int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
161155
struct ipc_ops *ops, struct ipc_params *params);

0 commit comments

Comments
 (0)