Commit 54924ea3 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

ipc: convert to idr_alloc()

Convert to the much saner new idr interface.

The new interface doesn't directly translate to the way idr_pre_get()
was used around ipc_addid() as preloading disables preemption.  From
my cursory reading, it seems like we should be able to do all
allocation from ipc_addid(), so I moved it there.  Can you please
check whether this would be okay?  If this is wrong and ipc_addid()
should be allowed to be called from non-sleepable context, I'd suggest
allocating id itself in the outer functions and later install the
pointer using idr_replace().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reported-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
Tested-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
Cc: Stanislav Kinsbursky <skinsbursky@parallels.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6b207ba3
...@@ -252,7 +252,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) ...@@ -252,7 +252,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
{ {
kuid_t euid; kuid_t euid;
kgid_t egid; kgid_t egid;
int id, err; int id;
int next_id = ids->next_id; int next_id = ids->next_id;
if (size > IPCMNI) if (size > IPCMNI)
...@@ -261,17 +261,21 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) ...@@ -261,17 +261,21 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
if (ids->in_use >= size) if (ids->in_use >= size)
return -ENOSPC; return -ENOSPC;
idr_preload(GFP_KERNEL);
spin_lock_init(&new->lock); spin_lock_init(&new->lock);
new->deleted = 0; new->deleted = 0;
rcu_read_lock(); rcu_read_lock();
spin_lock(&new->lock); spin_lock(&new->lock);
err = idr_get_new_above(&ids->ipcs_idr, new, id = idr_alloc(&ids->ipcs_idr, new,
(next_id < 0) ? 0 : ipcid_to_idx(next_id), &id); (next_id < 0) ? 0 : ipcid_to_idx(next_id), 0,
if (err) { GFP_NOWAIT);
idr_preload_end();
if (id < 0) {
spin_unlock(&new->lock); spin_unlock(&new->lock);
rcu_read_unlock(); rcu_read_unlock();
return err; return id;
} }
ids->in_use++; ids->in_use++;
...@@ -307,19 +311,10 @@ static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids, ...@@ -307,19 +311,10 @@ static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
struct ipc_ops *ops, struct ipc_params *params) struct ipc_ops *ops, struct ipc_params *params)
{ {
int err; int err;
retry:
err = idr_pre_get(&ids->ipcs_idr, GFP_KERNEL);
if (!err)
return -ENOMEM;
down_write(&ids->rw_mutex); down_write(&ids->rw_mutex);
err = ops->getnew(ns, params); err = ops->getnew(ns, params);
up_write(&ids->rw_mutex); up_write(&ids->rw_mutex);
if (err == -EAGAIN)
goto retry;
return err; return err;
} }
...@@ -376,8 +371,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids, ...@@ -376,8 +371,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
struct kern_ipc_perm *ipcp; struct kern_ipc_perm *ipcp;
int flg = params->flg; int flg = params->flg;
int err; int err;
retry:
err = idr_pre_get(&ids->ipcs_idr, GFP_KERNEL);
/* /*
* Take the lock as a writer since we are potentially going to add * Take the lock as a writer since we are potentially going to add
...@@ -389,8 +382,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids, ...@@ -389,8 +382,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
/* key not used */ /* key not used */
if (!(flg & IPC_CREAT)) if (!(flg & IPC_CREAT))
err = -ENOENT; err = -ENOENT;
else if (!err)
err = -ENOMEM;
else else
err = ops->getnew(ns, params); err = ops->getnew(ns, params);
} else { } else {
...@@ -413,9 +404,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids, ...@@ -413,9 +404,6 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
} }
up_write(&ids->rw_mutex); up_write(&ids->rw_mutex);
if (err == -EAGAIN)
goto retry;
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment