Re: [PATCH] IPC: fix error case when idr-cache is empty in ipcget()

Previous thread: IDE DMA doesn't work with pata_via and compact flash card by Philipp Wollermann on Thursday, October 11, 2007 - 12:05 am. (6 messages)

Next thread: 2.6.23-rc4: oops in evdev_disconnect by Jiri Slaby on Thursday, October 11, 2007 - 5:09 am. (2 messages)
From: Pierre Peiffer
Date: Thursday, October 11, 2007 - 12:32 am

I resend this patch, by taking into account Nadia's remarks.

With the use of idr to store the ipc, the case where the idr cache is
empty, when idr_get_new is called (this may happen even if we call
idr_pre_get() before), is not well handled: it lets semget()/shmget()/msgget()
return ENOSPC when this cache is empty, what 1. does not reflect the facts
and 2. does not conform to the man(s).

This patch fixes this by retrying the whole process of allocation in this case.

This patch applies on top of 2.6.23-rc8-mm2 and should probably be merged
in 2.6.24 if Nadia's patches are included.

Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net>

---
 ipc/msg.c  |    4 ++--
 ipc/sem.c  |    4 ++--
 ipc/shm.c  |    5 +++--
 ipc/util.c |   16 +++++++++++-----
 4 files changed, 18 insertions(+), 11 deletions(-)

Index: b/ipc/msg.c
===================================================================
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -188,10 +188,10 @@ static int newque(struct ipc_namespace *
 	 * ipc_addid() locks msq
 	 */
 	id = ipc_addid(&msg_ids(ns), &msq->q_perm, ns->msg_ctlmni);
-	if (id == -1) {
+	if (id < 0) {
 		security_msg_queue_free(msq);
 		ipc_rcu_putref(msq);
-		return -ENOSPC;
+		return id;
 	}
 
 	msq->q_perm.id = msg_buildid(ns, id, msq->q_perm.seq);
Index: b/ipc/sem.c
===================================================================
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -269,10 +269,10 @@ static int newary(struct ipc_namespace *
 	}
 
 	id = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni);
-	if(id == -1) {
+	if (id < 0) {
 		security_sem_free(sma);
 		ipc_rcu_putref(sma);
-		return -ENOSPC;
+		return id;
 	}
 	ns->used_sems += nsems;
 
Index: b/ipc/shm.c
===================================================================
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -409,10 +409,11 @@ static int newseg(struct ipc_namespace *
 	if (IS_ERR(file))
 		goto no_file;
 
-	error = -ENOSPC;
 	id = shm_addid(ns, shp);
-	if(id == -1) 
+	if (id < 0) ...
From: Andrew Morton
Date: Monday, October 15, 2007 - 1:13 pm

On Thu, 11 Oct 2007 09:32:22 +0200

Not pretty, is it?  The idr interface isn't a good one.  But then, any
storage library (aka container class) which allocates memory at insertion
time is a pain to handle in the kernel.

btw, idr_pre_get() should return 0 on success, else an errno - the current
interface is silly.

-

Previous thread: IDE DMA doesn't work with pata_via and compact flash card by Philipp Wollermann on Thursday, October 11, 2007 - 12:05 am. (6 messages)

Next thread: 2.6.23-rc4: oops in evdev_disconnect by Jiri Slaby on Thursday, October 11, 2007 - 5:09 am. (2 messages)