RCU: eliminating explicit memory barriers from SysV IPC
PATCH 3/3 RCU: eliminating explicit memory barriers from SysV IPC
This patch uses the rcu_assign_pointer() API to eliminate a number of explicit memory barriers from the SysV IPC code that uses RCU. It also restructures the ipc_ids structure so that the array size is stored in the same memory block as the array itself (see the new struct ipc_id_ary). This prevents the race that the earlier code was subject to, where a reader could see a mismatch between the size and the actual array. With the size stored with the array, the possibility of mismatch is eliminated -- with out the need for careful ordering and explicit memory barriers. This has been tested successfully on i386 and ppc64.
Signed-off-by <[email protected]>
---
msg.c | 2 - sem.c | 2 - util.c | 80 +++++++++++++++++++++++++++++------------------------------------ util.h | 13 +++++----- 4 files changed, 45 insertions(+), 52 deletions(-)
ipc/msg.c +1 -1
@@ -380,7 +380,7 @@ asmlinkage long sys_msgctl (int msqid, iint success_return;if (!buf)return -EFAULT ; -if (cmd ==MSG_STAT && msqid >= msg_ids.size) +if (cmd ==MSG_STAT && msqid >= msg_ids.entries->size)return -EINVAL ;memset (&tbuf,0 ,sizeof (tbuf));
ipc/sem.c +1 -1
@@ -523,7 +523,7 @@ static int semctl_nolock(int semid, intstruct semid64_ds tbuf;int id; -if (semid >= sem_ids.size) +if (semid >= sem_ids.entries->size)return -EINVAL ;memset (&tbuf,0 ,sizeof (tbuf));
ipc/util.c +36 -44
170 lines not on this page · raw message
ipc/util.h +7 -6
@@ -15,18 +15,19 @@ void sem_init (void);void msg_init (void );void shm_init (void ); -struct ipc_ids { +struct ipc_id_ary {int size; +struct kern_ipc_perm *p[0 ]; +}; + +struct ipc_ids {int in_use;int max_id;unsigned short seq;unsigned short seq_max;struct semaphore sem; -struct ipc_id * entries; -}; - -struct ipc_id { -struct kern_ipc_perm * p; +struct ipc_id_ary nullentry; +struct ipc_id_ary * entries; };void __init ipc_init_ids (struct ipc_ids * ids,int size);