Re: [PATCH 1/3] ipc/msg: increase MSGMNI, remove scaling

2014-08-15 Thread Rafael Aquini
On Tue, Aug 12, 2014 at 09:29:15AM +0200, Manfred Spraul wrote:
> SysV can be abused to allocate locked kernel memory.
> For most systems, a small limit doesn't make sense, see the discussion with
> regards to SHMMAX.
> 
> Therefore: increase MSGMNI to the maximum supported.
> 
> And: If we ignore the risk of locking too much memory, then an automatic
> scaling of MSGMNI doesn't make sense. Therefore the logic can be removed.
> 
> Notes:
> 1) If an administrator must limit the memory allocations, then he can set
> MSGMNI as necessary.
> 
> Or he can disable sysv entirely (as e.g. done by Android).
> 
> 2) MSGMAX and MSGMNB are intentionally not increased, as these values are used
> to control latency vs. throughput:
> If MSGMNB is large, then msgsnd() just returns and more messages can be queued
> before a task switch to a task that calls msgrcv() is forced.
> 
> Signed-off-by: Manfred Spraul 
> ---

Acked-by: Rafael Aquini 


>  include/linux/ipc_namespace.h | 20 --
>  include/uapi/linux/msg.h  | 28 +
>  ipc/Makefile  |  2 +-
>  ipc/ipc_sysctl.c  | 86 +---
>  ipc/ipcns_notifier.c  | 92 
> ---
>  ipc/msg.c | 36 +
>  ipc/namespace.c   | 22 ---
>  ipc/util.c| 40 ---
>  8 files changed, 23 insertions(+), 303 deletions(-)
>  delete mode 100644 ipc/ipcns_notifier.c
> 
> diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
> index 35e7eca..e365d5e 100644
> --- a/include/linux/ipc_namespace.h
> +++ b/include/linux/ipc_namespace.h
> @@ -7,15 +7,6 @@
>  #include 
>  #include 
>  
> -/*
> - * ipc namespace events
> - */
> -#define IPCNS_MEMCHANGED   0x0001   /* Notify lowmem size changed */
> -#define IPCNS_CREATED  0x0002   /* Notify new ipc namespace created */
> -#define IPCNS_REMOVED  0x0003   /* Notify ipc namespace removed */
> -
> -#define IPCNS_CALLBACK_PRI 0
> -
>  struct user_namespace;
>  
>  struct ipc_ids {
> @@ -38,7 +29,6 @@ struct ipc_namespace {
>   unsigned intmsg_ctlmni;
>   atomic_tmsg_bytes;
>   atomic_tmsg_hdrs;
> - int auto_msgmni;
>  
>   size_t  shm_ctlmax;
>   size_t  shm_ctlall;
> @@ -77,18 +67,8 @@ extern atomic_t nr_ipc_ns;
>  extern spinlock_t mq_lock;
>  
>  #ifdef CONFIG_SYSVIPC
> -extern int register_ipcns_notifier(struct ipc_namespace *);
> -extern int cond_register_ipcns_notifier(struct ipc_namespace *);
> -extern void unregister_ipcns_notifier(struct ipc_namespace *);
> -extern int ipcns_notify(unsigned long);
>  extern void shm_destroy_orphaned(struct ipc_namespace *ns);
>  #else /* CONFIG_SYSVIPC */
> -static inline int register_ipcns_notifier(struct ipc_namespace *ns)
> -{ return 0; }
> -static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
> -{ return 0; }
> -static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
> -static inline int ipcns_notify(unsigned long l) { return 0; }
>  static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
>  #endif /* CONFIG_SYSVIPC */
>  
> diff --git a/include/uapi/linux/msg.h b/include/uapi/linux/msg.h
> index a703755..2733ec8 100644
> --- a/include/uapi/linux/msg.h
> +++ b/include/uapi/linux/msg.h
> @@ -51,16 +51,28 @@ struct msginfo {
>  };
>  
>  /*
> - * Scaling factor to compute msgmni:
> - * the memory dedicated to msg queues (msgmni * msgmnb) should occupy
> - * at most 1/MSG_MEM_SCALE of the lowmem (see the formula in ipc/msg.c):
> - * up to 8MB   : msgmni = 16 (MSGMNI)
> - * 4 GB: msgmni = 8K
> - * more than 16 GB : msgmni = 32K (IPCMNI)
> + * MSGMNI, MSGMAX and MSGMNB are default values which can be
> + * modified by sysctl.
> + *
> + * MSGMNI is the upper limit for the number of messages queues per
> + * namespace.
> + * It has been chosen to be as large possible without facilitating
> + * scenarios where userspace causes overflows when adjusting the limits via
> + * operations of the form retrieve current limit; add X; update limit".
> + *
> + * MSGMNB is the default size of a new message queue. Non-root tasks can
> + * decrease the size with msgctl(IPC_SET), root tasks
> + * (actually: CAP_SYS_RESOURCE) can both increase and decrease the queue
> + * size. The optimal value is application dependant.
> + * 16384 is used because it was always used (since 0.99.10)
> + *
> + * MAXMAX is the maximum size of an individual message, it's a global
> + * (per-namespace) limit that applies for all message queues.
> + * It's set to 1/2 of MSGMNB, to ensure that at least two messages fit into
> + * the queue. This is also an arbitrary choice (since 2.6.0).
>   */
> -#define MSG_MEM_SCALE 32
>  
> -#define MSGMNI16   /* <= IPCMNI */ /* max # of msg queue identifiers 
> */
> +#define MSGMNI 32000   /* <= IPCMNI */ /* max # of msg queue 

Re: [PATCH 1/3] ipc/msg: increase MSGMNI, remove scaling

2014-08-15 Thread Rafael Aquini
On Tue, Aug 12, 2014 at 09:29:15AM +0200, Manfred Spraul wrote:
 SysV can be abused to allocate locked kernel memory.
 For most systems, a small limit doesn't make sense, see the discussion with
 regards to SHMMAX.
 
 Therefore: increase MSGMNI to the maximum supported.
 
 And: If we ignore the risk of locking too much memory, then an automatic
 scaling of MSGMNI doesn't make sense. Therefore the logic can be removed.
 
 Notes:
 1) If an administrator must limit the memory allocations, then he can set
 MSGMNI as necessary.
 
 Or he can disable sysv entirely (as e.g. done by Android).
 
 2) MSGMAX and MSGMNB are intentionally not increased, as these values are used
 to control latency vs. throughput:
 If MSGMNB is large, then msgsnd() just returns and more messages can be queued
 before a task switch to a task that calls msgrcv() is forced.
 
 Signed-off-by: Manfred Spraul manf...@colorfullife.com
 ---

Acked-by: Rafael Aquini aqu...@redhat.com


  include/linux/ipc_namespace.h | 20 --
  include/uapi/linux/msg.h  | 28 +
  ipc/Makefile  |  2 +-
  ipc/ipc_sysctl.c  | 86 +---
  ipc/ipcns_notifier.c  | 92 
 ---
  ipc/msg.c | 36 +
  ipc/namespace.c   | 22 ---
  ipc/util.c| 40 ---
  8 files changed, 23 insertions(+), 303 deletions(-)
  delete mode 100644 ipc/ipcns_notifier.c
 
 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
 index 35e7eca..e365d5e 100644
 --- a/include/linux/ipc_namespace.h
 +++ b/include/linux/ipc_namespace.h
 @@ -7,15 +7,6 @@
  #include linux/notifier.h
  #include linux/nsproxy.h
  
 -/*
 - * ipc namespace events
 - */
 -#define IPCNS_MEMCHANGED   0x0001   /* Notify lowmem size changed */
 -#define IPCNS_CREATED  0x0002   /* Notify new ipc namespace created */
 -#define IPCNS_REMOVED  0x0003   /* Notify ipc namespace removed */
 -
 -#define IPCNS_CALLBACK_PRI 0
 -
  struct user_namespace;
  
  struct ipc_ids {
 @@ -38,7 +29,6 @@ struct ipc_namespace {
   unsigned intmsg_ctlmni;
   atomic_tmsg_bytes;
   atomic_tmsg_hdrs;
 - int auto_msgmni;
  
   size_t  shm_ctlmax;
   size_t  shm_ctlall;
 @@ -77,18 +67,8 @@ extern atomic_t nr_ipc_ns;
  extern spinlock_t mq_lock;
  
  #ifdef CONFIG_SYSVIPC
 -extern int register_ipcns_notifier(struct ipc_namespace *);
 -extern int cond_register_ipcns_notifier(struct ipc_namespace *);
 -extern void unregister_ipcns_notifier(struct ipc_namespace *);
 -extern int ipcns_notify(unsigned long);
  extern void shm_destroy_orphaned(struct ipc_namespace *ns);
  #else /* CONFIG_SYSVIPC */
 -static inline int register_ipcns_notifier(struct ipc_namespace *ns)
 -{ return 0; }
 -static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
 -{ return 0; }
 -static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
 -static inline int ipcns_notify(unsigned long l) { return 0; }
  static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
  #endif /* CONFIG_SYSVIPC */
  
 diff --git a/include/uapi/linux/msg.h b/include/uapi/linux/msg.h
 index a703755..2733ec8 100644
 --- a/include/uapi/linux/msg.h
 +++ b/include/uapi/linux/msg.h
 @@ -51,16 +51,28 @@ struct msginfo {
  };
  
  /*
 - * Scaling factor to compute msgmni:
 - * the memory dedicated to msg queues (msgmni * msgmnb) should occupy
 - * at most 1/MSG_MEM_SCALE of the lowmem (see the formula in ipc/msg.c):
 - * up to 8MB   : msgmni = 16 (MSGMNI)
 - * 4 GB: msgmni = 8K
 - * more than 16 GB : msgmni = 32K (IPCMNI)
 + * MSGMNI, MSGMAX and MSGMNB are default values which can be
 + * modified by sysctl.
 + *
 + * MSGMNI is the upper limit for the number of messages queues per
 + * namespace.
 + * It has been chosen to be as large possible without facilitating
 + * scenarios where userspace causes overflows when adjusting the limits via
 + * operations of the form retrieve current limit; add X; update limit.
 + *
 + * MSGMNB is the default size of a new message queue. Non-root tasks can
 + * decrease the size with msgctl(IPC_SET), root tasks
 + * (actually: CAP_SYS_RESOURCE) can both increase and decrease the queue
 + * size. The optimal value is application dependant.
 + * 16384 is used because it was always used (since 0.99.10)
 + *
 + * MAXMAX is the maximum size of an individual message, it's a global
 + * (per-namespace) limit that applies for all message queues.
 + * It's set to 1/2 of MSGMNB, to ensure that at least two messages fit into
 + * the queue. This is also an arbitrary choice (since 2.6.0).
   */
 -#define MSG_MEM_SCALE 32
  
 -#define MSGMNI16   /* = IPCMNI */ /* max # of msg queue identifiers 
 */
 +#define MSGMNI 32000   /* = IPCMNI */ /* max # of msg queue identifiers 
 */
  #define MSGMAX  8192   /* = INT_MAX 

[PATCH 1/3] ipc/msg: increase MSGMNI, remove scaling

2014-08-12 Thread Manfred Spraul
SysV can be abused to allocate locked kernel memory.
For most systems, a small limit doesn't make sense, see the discussion with
regards to SHMMAX.

Therefore: increase MSGMNI to the maximum supported.

And: If we ignore the risk of locking too much memory, then an automatic
scaling of MSGMNI doesn't make sense. Therefore the logic can be removed.

Notes:
1) If an administrator must limit the memory allocations, then he can set
MSGMNI as necessary.

Or he can disable sysv entirely (as e.g. done by Android).

2) MSGMAX and MSGMNB are intentionally not increased, as these values are used
to control latency vs. throughput:
If MSGMNB is large, then msgsnd() just returns and more messages can be queued
before a task switch to a task that calls msgrcv() is forced.

Signed-off-by: Manfred Spraul 
---
 include/linux/ipc_namespace.h | 20 --
 include/uapi/linux/msg.h  | 28 +
 ipc/Makefile  |  2 +-
 ipc/ipc_sysctl.c  | 86 +---
 ipc/ipcns_notifier.c  | 92 ---
 ipc/msg.c | 36 +
 ipc/namespace.c   | 22 ---
 ipc/util.c| 40 ---
 8 files changed, 23 insertions(+), 303 deletions(-)
 delete mode 100644 ipc/ipcns_notifier.c

diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 35e7eca..e365d5e 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -7,15 +7,6 @@
 #include 
 #include 
 
-/*
- * ipc namespace events
- */
-#define IPCNS_MEMCHANGED   0x0001   /* Notify lowmem size changed */
-#define IPCNS_CREATED  0x0002   /* Notify new ipc namespace created */
-#define IPCNS_REMOVED  0x0003   /* Notify ipc namespace removed */
-
-#define IPCNS_CALLBACK_PRI 0
-
 struct user_namespace;
 
 struct ipc_ids {
@@ -38,7 +29,6 @@ struct ipc_namespace {
unsigned intmsg_ctlmni;
atomic_tmsg_bytes;
atomic_tmsg_hdrs;
-   int auto_msgmni;
 
size_t  shm_ctlmax;
size_t  shm_ctlall;
@@ -77,18 +67,8 @@ extern atomic_t nr_ipc_ns;
 extern spinlock_t mq_lock;
 
 #ifdef CONFIG_SYSVIPC
-extern int register_ipcns_notifier(struct ipc_namespace *);
-extern int cond_register_ipcns_notifier(struct ipc_namespace *);
-extern void unregister_ipcns_notifier(struct ipc_namespace *);
-extern int ipcns_notify(unsigned long);
 extern void shm_destroy_orphaned(struct ipc_namespace *ns);
 #else /* CONFIG_SYSVIPC */
-static inline int register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
-static inline int ipcns_notify(unsigned long l) { return 0; }
 static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
 #endif /* CONFIG_SYSVIPC */
 
diff --git a/include/uapi/linux/msg.h b/include/uapi/linux/msg.h
index a703755..2733ec8 100644
--- a/include/uapi/linux/msg.h
+++ b/include/uapi/linux/msg.h
@@ -51,16 +51,28 @@ struct msginfo {
 };
 
 /*
- * Scaling factor to compute msgmni:
- * the memory dedicated to msg queues (msgmni * msgmnb) should occupy
- * at most 1/MSG_MEM_SCALE of the lowmem (see the formula in ipc/msg.c):
- * up to 8MB   : msgmni = 16 (MSGMNI)
- * 4 GB: msgmni = 8K
- * more than 16 GB : msgmni = 32K (IPCMNI)
+ * MSGMNI, MSGMAX and MSGMNB are default values which can be
+ * modified by sysctl.
+ *
+ * MSGMNI is the upper limit for the number of messages queues per
+ * namespace.
+ * It has been chosen to be as large possible without facilitating
+ * scenarios where userspace causes overflows when adjusting the limits via
+ * operations of the form retrieve current limit; add X; update limit".
+ *
+ * MSGMNB is the default size of a new message queue. Non-root tasks can
+ * decrease the size with msgctl(IPC_SET), root tasks
+ * (actually: CAP_SYS_RESOURCE) can both increase and decrease the queue
+ * size. The optimal value is application dependant.
+ * 16384 is used because it was always used (since 0.99.10)
+ *
+ * MAXMAX is the maximum size of an individual message, it's a global
+ * (per-namespace) limit that applies for all message queues.
+ * It's set to 1/2 of MSGMNB, to ensure that at least two messages fit into
+ * the queue. This is also an arbitrary choice (since 2.6.0).
  */
-#define MSG_MEM_SCALE 32
 
-#define MSGMNI16   /* <= IPCMNI */ /* max # of msg queue identifiers */
+#define MSGMNI 32000   /* <= IPCMNI */ /* max # of msg queue identifiers */
 #define MSGMAX  8192   /* <= INT_MAX */   /* max size of message (bytes) */
 #define MSGMNB 16384   /* <= INT_MAX */   /* default max size of a message 
queue */
 
diff --git a/ipc/Makefile b/ipc/Makefile
index 9075e17..86c7300 100644
--- a/ipc/Makefile
+++ b/ipc/Makefile
@@ -3,7 +3,7 @@
 #
 
 

[PATCH 1/3] ipc/msg: increase MSGMNI, remove scaling

2014-08-12 Thread Manfred Spraul
SysV can be abused to allocate locked kernel memory.
For most systems, a small limit doesn't make sense, see the discussion with
regards to SHMMAX.

Therefore: increase MSGMNI to the maximum supported.

And: If we ignore the risk of locking too much memory, then an automatic
scaling of MSGMNI doesn't make sense. Therefore the logic can be removed.

Notes:
1) If an administrator must limit the memory allocations, then he can set
MSGMNI as necessary.

Or he can disable sysv entirely (as e.g. done by Android).

2) MSGMAX and MSGMNB are intentionally not increased, as these values are used
to control latency vs. throughput:
If MSGMNB is large, then msgsnd() just returns and more messages can be queued
before a task switch to a task that calls msgrcv() is forced.

Signed-off-by: Manfred Spraul manf...@colorfullife.com
---
 include/linux/ipc_namespace.h | 20 --
 include/uapi/linux/msg.h  | 28 +
 ipc/Makefile  |  2 +-
 ipc/ipc_sysctl.c  | 86 +---
 ipc/ipcns_notifier.c  | 92 ---
 ipc/msg.c | 36 +
 ipc/namespace.c   | 22 ---
 ipc/util.c| 40 ---
 8 files changed, 23 insertions(+), 303 deletions(-)
 delete mode 100644 ipc/ipcns_notifier.c

diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 35e7eca..e365d5e 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -7,15 +7,6 @@
 #include linux/notifier.h
 #include linux/nsproxy.h
 
-/*
- * ipc namespace events
- */
-#define IPCNS_MEMCHANGED   0x0001   /* Notify lowmem size changed */
-#define IPCNS_CREATED  0x0002   /* Notify new ipc namespace created */
-#define IPCNS_REMOVED  0x0003   /* Notify ipc namespace removed */
-
-#define IPCNS_CALLBACK_PRI 0
-
 struct user_namespace;
 
 struct ipc_ids {
@@ -38,7 +29,6 @@ struct ipc_namespace {
unsigned intmsg_ctlmni;
atomic_tmsg_bytes;
atomic_tmsg_hdrs;
-   int auto_msgmni;
 
size_t  shm_ctlmax;
size_t  shm_ctlall;
@@ -77,18 +67,8 @@ extern atomic_t nr_ipc_ns;
 extern spinlock_t mq_lock;
 
 #ifdef CONFIG_SYSVIPC
-extern int register_ipcns_notifier(struct ipc_namespace *);
-extern int cond_register_ipcns_notifier(struct ipc_namespace *);
-extern void unregister_ipcns_notifier(struct ipc_namespace *);
-extern int ipcns_notify(unsigned long);
 extern void shm_destroy_orphaned(struct ipc_namespace *ns);
 #else /* CONFIG_SYSVIPC */
-static inline int register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
-static inline int ipcns_notify(unsigned long l) { return 0; }
 static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
 #endif /* CONFIG_SYSVIPC */
 
diff --git a/include/uapi/linux/msg.h b/include/uapi/linux/msg.h
index a703755..2733ec8 100644
--- a/include/uapi/linux/msg.h
+++ b/include/uapi/linux/msg.h
@@ -51,16 +51,28 @@ struct msginfo {
 };
 
 /*
- * Scaling factor to compute msgmni:
- * the memory dedicated to msg queues (msgmni * msgmnb) should occupy
- * at most 1/MSG_MEM_SCALE of the lowmem (see the formula in ipc/msg.c):
- * up to 8MB   : msgmni = 16 (MSGMNI)
- * 4 GB: msgmni = 8K
- * more than 16 GB : msgmni = 32K (IPCMNI)
+ * MSGMNI, MSGMAX and MSGMNB are default values which can be
+ * modified by sysctl.
+ *
+ * MSGMNI is the upper limit for the number of messages queues per
+ * namespace.
+ * It has been chosen to be as large possible without facilitating
+ * scenarios where userspace causes overflows when adjusting the limits via
+ * operations of the form retrieve current limit; add X; update limit.
+ *
+ * MSGMNB is the default size of a new message queue. Non-root tasks can
+ * decrease the size with msgctl(IPC_SET), root tasks
+ * (actually: CAP_SYS_RESOURCE) can both increase and decrease the queue
+ * size. The optimal value is application dependant.
+ * 16384 is used because it was always used (since 0.99.10)
+ *
+ * MAXMAX is the maximum size of an individual message, it's a global
+ * (per-namespace) limit that applies for all message queues.
+ * It's set to 1/2 of MSGMNB, to ensure that at least two messages fit into
+ * the queue. This is also an arbitrary choice (since 2.6.0).
  */
-#define MSG_MEM_SCALE 32
 
-#define MSGMNI16   /* = IPCMNI */ /* max # of msg queue identifiers */
+#define MSGMNI 32000   /* = IPCMNI */ /* max # of msg queue identifiers */
 #define MSGMAX  8192   /* = INT_MAX */   /* max size of message (bytes) */
 #define MSGMNB 16384   /* = INT_MAX */   /* default max size of a message 
queue */
 
diff --git a/ipc/Makefile b/ipc/Makefile
index 9075e17..86c7300 100644
--- a/ipc/Makefile
+++ 

[PATCH 1/3] ipc/msg: increase MSGMNI, remove scaling

2014-05-29 Thread Manfred Spraul
SysV can be abused to allocated locked kernel memory.
For most systems, a small limit doesn't make sense,
see the discussion with regards to SHMMAX.

Therefore: increase MSGMNI to the maximum supported.

And: if we ignore the risk of locking too much memory, then
an automatic scaling of MSGMNI doesn't make sense.

Therefore: remove the whole logic.

Note:
If an administrator must limit the memory allocations, then
he can set MSGMNI as necessary.

Or he can disable sysv entirely (as e.g. done with Android).
---
 include/linux/ipc_namespace.h | 20 --
 include/uapi/linux/msg.h  | 12 +-
 ipc/Makefile  |  2 +-
 ipc/ipc_sysctl.c  | 87 +---
 ipc/ipcns_notifier.c  | 92 ---
 ipc/msg.c | 36 +
 ipc/namespace.c   | 22 ---
 ipc/util.c| 40 ---
 8 files changed, 4 insertions(+), 307 deletions(-)
 delete mode 100644 ipc/ipcns_notifier.c

diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 35e7eca..e365d5e 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -7,15 +7,6 @@
 #include 
 #include 
 
-/*
- * ipc namespace events
- */
-#define IPCNS_MEMCHANGED   0x0001   /* Notify lowmem size changed */
-#define IPCNS_CREATED  0x0002   /* Notify new ipc namespace created */
-#define IPCNS_REMOVED  0x0003   /* Notify ipc namespace removed */
-
-#define IPCNS_CALLBACK_PRI 0
-
 struct user_namespace;
 
 struct ipc_ids {
@@ -38,7 +29,6 @@ struct ipc_namespace {
unsigned intmsg_ctlmni;
atomic_tmsg_bytes;
atomic_tmsg_hdrs;
-   int auto_msgmni;
 
size_t  shm_ctlmax;
size_t  shm_ctlall;
@@ -77,18 +67,8 @@ extern atomic_t nr_ipc_ns;
 extern spinlock_t mq_lock;
 
 #ifdef CONFIG_SYSVIPC
-extern int register_ipcns_notifier(struct ipc_namespace *);
-extern int cond_register_ipcns_notifier(struct ipc_namespace *);
-extern void unregister_ipcns_notifier(struct ipc_namespace *);
-extern int ipcns_notify(unsigned long);
 extern void shm_destroy_orphaned(struct ipc_namespace *ns);
 #else /* CONFIG_SYSVIPC */
-static inline int register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
-static inline int ipcns_notify(unsigned long l) { return 0; }
 static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
 #endif /* CONFIG_SYSVIPC */
 
diff --git a/include/uapi/linux/msg.h b/include/uapi/linux/msg.h
index a703755..ae9ddd2 100644
--- a/include/uapi/linux/msg.h
+++ b/include/uapi/linux/msg.h
@@ -50,17 +50,7 @@ struct msginfo {
unsigned short  msgseg; 
 };
 
-/*
- * Scaling factor to compute msgmni:
- * the memory dedicated to msg queues (msgmni * msgmnb) should occupy
- * at most 1/MSG_MEM_SCALE of the lowmem (see the formula in ipc/msg.c):
- * up to 8MB   : msgmni = 16 (MSGMNI)
- * 4 GB: msgmni = 8K
- * more than 16 GB : msgmni = 32K (IPCMNI)
- */
-#define MSG_MEM_SCALE 32
-
-#define MSGMNI16   /* <= IPCMNI */ /* max # of msg queue identifiers */
+#define MSGMNI 32000   /* <= IPCMNI */ /* max # of msg queue identifiers */
 #define MSGMAX  8192   /* <= INT_MAX */   /* max size of message (bytes) */
 #define MSGMNB 16384   /* <= INT_MAX */   /* default max size of a message 
queue */
 
diff --git a/ipc/Makefile b/ipc/Makefile
index 9075e17..86c7300 100644
--- a/ipc/Makefile
+++ b/ipc/Makefile
@@ -3,7 +3,7 @@
 #
 
 obj-$(CONFIG_SYSVIPC_COMPAT) += compat.o
-obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o ipcns_notifier.o 
syscall.o
+obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o syscall.o
 obj-$(CONFIG_SYSVIPC_SYSCTL) += ipc_sysctl.o
 obj_mq-$(CONFIG_COMPAT) += compat_mq.o
 obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y)
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 998d31b..cc34646 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -62,29 +62,6 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table 
*table, int write,
return err;
 }
 
-static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
-   void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-   struct ctl_table ipc_table;
-   size_t lenp_bef = *lenp;
-   int rc;
-
-   memcpy(_table, table, sizeof(ipc_table));
-   ipc_table.data = get_ipc(table);
-
-   rc = proc_dointvec_minmax(_table, write, buffer, lenp, ppos);
-
-   if (write && !rc && lenp_bef == *lenp)
-   /*
-* Tunable has successfully been changed by hand. Disable its
-* automatic adjustment. This simply requires unregistering
-* the notifiers that trigger recalculation.
-   

[PATCH 1/3] ipc/msg: increase MSGMNI, remove scaling

2014-05-29 Thread Manfred Spraul
SysV can be abused to allocated locked kernel memory.
For most systems, a small limit doesn't make sense,
see the discussion with regards to SHMMAX.

Therefore: increase MSGMNI to the maximum supported.

And: if we ignore the risk of locking too much memory, then
an automatic scaling of MSGMNI doesn't make sense.

Therefore: remove the whole logic.

Note:
If an administrator must limit the memory allocations, then
he can set MSGMNI as necessary.

Or he can disable sysv entirely (as e.g. done with Android).
---
 include/linux/ipc_namespace.h | 20 --
 include/uapi/linux/msg.h  | 12 +-
 ipc/Makefile  |  2 +-
 ipc/ipc_sysctl.c  | 87 +---
 ipc/ipcns_notifier.c  | 92 ---
 ipc/msg.c | 36 +
 ipc/namespace.c   | 22 ---
 ipc/util.c| 40 ---
 8 files changed, 4 insertions(+), 307 deletions(-)
 delete mode 100644 ipc/ipcns_notifier.c

diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 35e7eca..e365d5e 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -7,15 +7,6 @@
 #include linux/notifier.h
 #include linux/nsproxy.h
 
-/*
- * ipc namespace events
- */
-#define IPCNS_MEMCHANGED   0x0001   /* Notify lowmem size changed */
-#define IPCNS_CREATED  0x0002   /* Notify new ipc namespace created */
-#define IPCNS_REMOVED  0x0003   /* Notify ipc namespace removed */
-
-#define IPCNS_CALLBACK_PRI 0
-
 struct user_namespace;
 
 struct ipc_ids {
@@ -38,7 +29,6 @@ struct ipc_namespace {
unsigned intmsg_ctlmni;
atomic_tmsg_bytes;
atomic_tmsg_hdrs;
-   int auto_msgmni;
 
size_t  shm_ctlmax;
size_t  shm_ctlall;
@@ -77,18 +67,8 @@ extern atomic_t nr_ipc_ns;
 extern spinlock_t mq_lock;
 
 #ifdef CONFIG_SYSVIPC
-extern int register_ipcns_notifier(struct ipc_namespace *);
-extern int cond_register_ipcns_notifier(struct ipc_namespace *);
-extern void unregister_ipcns_notifier(struct ipc_namespace *);
-extern int ipcns_notify(unsigned long);
 extern void shm_destroy_orphaned(struct ipc_namespace *ns);
 #else /* CONFIG_SYSVIPC */
-static inline int register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
-{ return 0; }
-static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
-static inline int ipcns_notify(unsigned long l) { return 0; }
 static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
 #endif /* CONFIG_SYSVIPC */
 
diff --git a/include/uapi/linux/msg.h b/include/uapi/linux/msg.h
index a703755..ae9ddd2 100644
--- a/include/uapi/linux/msg.h
+++ b/include/uapi/linux/msg.h
@@ -50,17 +50,7 @@ struct msginfo {
unsigned short  msgseg; 
 };
 
-/*
- * Scaling factor to compute msgmni:
- * the memory dedicated to msg queues (msgmni * msgmnb) should occupy
- * at most 1/MSG_MEM_SCALE of the lowmem (see the formula in ipc/msg.c):
- * up to 8MB   : msgmni = 16 (MSGMNI)
- * 4 GB: msgmni = 8K
- * more than 16 GB : msgmni = 32K (IPCMNI)
- */
-#define MSG_MEM_SCALE 32
-
-#define MSGMNI16   /* = IPCMNI */ /* max # of msg queue identifiers */
+#define MSGMNI 32000   /* = IPCMNI */ /* max # of msg queue identifiers */
 #define MSGMAX  8192   /* = INT_MAX */   /* max size of message (bytes) */
 #define MSGMNB 16384   /* = INT_MAX */   /* default max size of a message 
queue */
 
diff --git a/ipc/Makefile b/ipc/Makefile
index 9075e17..86c7300 100644
--- a/ipc/Makefile
+++ b/ipc/Makefile
@@ -3,7 +3,7 @@
 #
 
 obj-$(CONFIG_SYSVIPC_COMPAT) += compat.o
-obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o ipcns_notifier.o 
syscall.o
+obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o syscall.o
 obj-$(CONFIG_SYSVIPC_SYSCTL) += ipc_sysctl.o
 obj_mq-$(CONFIG_COMPAT) += compat_mq.o
 obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y)
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 998d31b..cc34646 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -62,29 +62,6 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table 
*table, int write,
return err;
 }
 
-static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
-   void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-   struct ctl_table ipc_table;
-   size_t lenp_bef = *lenp;
-   int rc;
-
-   memcpy(ipc_table, table, sizeof(ipc_table));
-   ipc_table.data = get_ipc(table);
-
-   rc = proc_dointvec_minmax(ipc_table, write, buffer, lenp, ppos);
-
-   if (write  !rc  lenp_bef == *lenp)
-   /*
-* Tunable has successfully been changed by hand. Disable its
-* automatic adjustment. This simply requires unregistering
-* the notifiers that