Skip to content

Commit

Permalink
ipc: rename ids->rw_mutex
Browse files Browse the repository at this point in the history
Since in some situations the lock can be shared for readers, we shouldn't
be calling it a mutex, rename it to rwsem.

Signed-off-by: Davidlohr Bueso <[email protected]>
Tested-by: Sedat Dilek <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and torvalds committed Sep 11, 2013
1 parent c2c737a commit d9a605e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion include/linux/ipc_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ipc_ids {
int in_use;
unsigned short seq;
unsigned short seq_max;
struct rw_semaphore rw_mutex;
struct rw_semaphore rwsem;
struct idr ipcs_idr;
int next_id;
};
Expand Down
20 changes: 10 additions & 10 deletions ipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s)
* @ns: namespace
* @params: ptr to the structure that contains the key and msgflg
*
* Called with msg_ids.rw_mutex held (writer)
* Called with msg_ids.rwsem held (writer)
*/
static int newque(struct ipc_namespace *ns, struct ipc_params *params)
{
Expand Down Expand Up @@ -259,8 +259,8 @@ static void expunge_all(struct msg_queue *msq, int res)
* removes the message queue from message queue ID IDR, and cleans up all the
* messages associated with this queue.
*
* msg_ids.rw_mutex (writer) and the spinlock for this message queue are held
* before freeque() is called. msg_ids.rw_mutex remains locked on exit.
* msg_ids.rwsem (writer) and the spinlock for this message queue are held
* before freeque() is called. msg_ids.rwsem remains locked on exit.
*/
static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
{
Expand All @@ -282,7 +282,7 @@ static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
}

/*
* Called with msg_ids.rw_mutex and ipcp locked.
* Called with msg_ids.rwsem and ipcp locked.
*/
static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
{
Expand Down Expand Up @@ -386,9 +386,9 @@ copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version)
}

/*
* This function handles some msgctl commands which require the rw_mutex
* This function handles some msgctl commands which require the rwsem
* to be held in write mode.
* NOTE: no locks must be held, the rw_mutex is taken inside this function.
* NOTE: no locks must be held, the rwsem is taken inside this function.
*/
static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
struct msqid_ds __user *buf, int version)
Expand All @@ -403,7 +403,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
return -EFAULT;
}

down_write(&msg_ids(ns).rw_mutex);
down_write(&msg_ids(ns).rwsem);
rcu_read_lock();

ipcp = ipcctl_pre_down_nolock(ns, &msg_ids(ns), msqid, cmd,
Expand Down Expand Up @@ -459,7 +459,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
out_unlock1:
rcu_read_unlock();
out_up:
up_write(&msg_ids(ns).rw_mutex);
up_write(&msg_ids(ns).rwsem);
return err;
}

Expand Down Expand Up @@ -494,7 +494,7 @@ static int msgctl_nolock(struct ipc_namespace *ns, int msqid,
msginfo.msgmnb = ns->msg_ctlmnb;
msginfo.msgssz = MSGSSZ;
msginfo.msgseg = MSGSEG;
down_read(&msg_ids(ns).rw_mutex);
down_read(&msg_ids(ns).rwsem);
if (cmd == MSG_INFO) {
msginfo.msgpool = msg_ids(ns).in_use;
msginfo.msgmap = atomic_read(&ns->msg_hdrs);
Expand All @@ -505,7 +505,7 @@ static int msgctl_nolock(struct ipc_namespace *ns, int msqid,
msginfo.msgtql = MSGTQL;
}
max_id = ipc_get_maxid(&msg_ids(ns));
up_read(&msg_ids(ns).rw_mutex);
up_read(&msg_ids(ns).rwsem);
if (copy_to_user(buf, &msginfo, sizeof(struct msginfo)))
return -EFAULT;
return (max_id < 0) ? 0 : max_id;
Expand Down
4 changes: 2 additions & 2 deletions ipc/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
int next_id;
int total, in_use;

down_write(&ids->rw_mutex);
down_write(&ids->rwsem);

in_use = ids->in_use;

Expand All @@ -93,7 +93,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
free(ns, perm);
total++;
}
up_write(&ids->rw_mutex);
up_write(&ids->rwsem);
}

static void free_ipc_ns(struct ipc_namespace *ns)
Expand Down
24 changes: 12 additions & 12 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static inline void sem_unlock(struct sem_array *sma, int locknum)
}

/*
* sem_lock_(check_) routines are called in the paths where the rw_mutex
* sem_lock_(check_) routines are called in the paths where the rwsem
* is not held.
*
* The caller holds the RCU read lock.
Expand Down Expand Up @@ -426,7 +426,7 @@ static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s)
* @ns: namespace
* @params: ptr to the structure that contains key, semflg and nsems
*
* Called with sem_ids.rw_mutex held (as a writer)
* Called with sem_ids.rwsem held (as a writer)
*/

static int newary(struct ipc_namespace *ns, struct ipc_params *params)
Expand Down Expand Up @@ -492,7 +492,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)


/*
* Called with sem_ids.rw_mutex and ipcp locked.
* Called with sem_ids.rwsem and ipcp locked.
*/
static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg)
{
Expand All @@ -503,7 +503,7 @@ static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg)
}

/*
* Called with sem_ids.rw_mutex and ipcp locked.
* Called with sem_ids.rwsem and ipcp locked.
*/
static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
struct ipc_params *params)
Expand Down Expand Up @@ -994,8 +994,8 @@ static int count_semzcnt (struct sem_array * sma, ushort semnum)
return semzcnt;
}

/* Free a semaphore set. freeary() is called with sem_ids.rw_mutex locked
* as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex
/* Free a semaphore set. freeary() is called with sem_ids.rwsem locked
* as a writer and the spinlock for this semaphore set hold. sem_ids.rwsem
* remains locked on exit.
*/
static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
Expand Down Expand Up @@ -1116,7 +1116,7 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid,
seminfo.semmnu = SEMMNU;
seminfo.semmap = SEMMAP;
seminfo.semume = SEMUME;
down_read(&sem_ids(ns).rw_mutex);
down_read(&sem_ids(ns).rwsem);
if (cmd == SEM_INFO) {
seminfo.semusz = sem_ids(ns).in_use;
seminfo.semaem = ns->used_sems;
Expand All @@ -1125,7 +1125,7 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid,
seminfo.semaem = SEMAEM;
}
max_id = ipc_get_maxid(&sem_ids(ns));
up_read(&sem_ids(ns).rw_mutex);
up_read(&sem_ids(ns).rwsem);
if (copy_to_user(p, &seminfo, sizeof(struct seminfo)))
return -EFAULT;
return (max_id < 0) ? 0: max_id;
Expand Down Expand Up @@ -1431,9 +1431,9 @@ copy_semid_from_user(struct semid64_ds *out, void __user *buf, int version)
}

/*
* This function handles some semctl commands which require the rw_mutex
* This function handles some semctl commands which require the rwsem
* to be held in write mode.
* NOTE: no locks must be held, the rw_mutex is taken inside this function.
* NOTE: no locks must be held, the rwsem is taken inside this function.
*/
static int semctl_down(struct ipc_namespace *ns, int semid,
int cmd, int version, void __user *p)
Expand All @@ -1448,7 +1448,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,
return -EFAULT;
}

down_write(&sem_ids(ns).rw_mutex);
down_write(&sem_ids(ns).rwsem);
rcu_read_lock();

ipcp = ipcctl_pre_down_nolock(ns, &sem_ids(ns), semid, cmd,
Expand Down Expand Up @@ -1487,7 +1487,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,
out_unlock1:
rcu_read_unlock();
out_up:
up_write(&sem_ids(ns).rw_mutex);
up_write(&sem_ids(ns).rwsem);
return err;
}

Expand Down
Loading

0 comments on commit d9a605e

Please sign in to comment.