Skip to content

Commit 6546bc4

Browse files
Nadia Derbeytorvalds
authored andcommitted
ipc: re-enable msgmni automatic recomputing msgmni if set to negative
The enhancement as asked for by Yasunori: if msgmni is set to a negative value, register it back into the ipcns notifier chain. A new interface has been added to the notification mechanism: notifier_chain_cond_register() registers a notifier block only if not already registered. With that new interface we avoid taking care of the states changes in procfs. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Mingming Cao <cmm@us.ibm.com> Cc: Pierre Peiffer <pierre.peiffer@bull.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 91cfb2b commit 6546bc4

5 files changed

Lines changed: 87 additions & 10 deletions

File tree

‎include/linux/ipc_namespace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern atomic_t nr_ipc_ns;
5252
#define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
5353

5454
extern int register_ipcns_notifier(struct ipc_namespace *);
55+
extern int cond_register_ipcns_notifier(struct ipc_namespace *);
5556
extern int unregister_ipcns_notifier(struct ipc_namespace *);
5657
extern int ipcns_notify(unsigned long);
5758

‎include/linux/notifier.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ extern int raw_notifier_chain_register(struct raw_notifier_head *nh,
121121
extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
122122
struct notifier_block *nb);
123123

124+
extern int blocking_notifier_chain_cond_register(
125+
struct blocking_notifier_head *nh,
126+
struct notifier_block *nb);
127+
124128
extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
125129
struct notifier_block *nb);
126130
extern int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,

‎ipc/ipc_sysctl.c‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/sysctl.h>
1616
#include <linux/uaccess.h>
1717
#include <linux/ipc_namespace.h>
18+
#include <linux/msg.h>
19+
#include "util.h"
1820

1921
static void *get_ipc(ctl_table *table)
2022
{
@@ -24,6 +26,27 @@ static void *get_ipc(ctl_table *table)
2426
return which;
2527
}
2628

29+
/*
30+
* Routine that is called when a tunable has successfully been changed by
31+
* hand and it has a callback routine registered on the ipc namespace notifier
32+
* chain: we don't want such tunables to be recomputed anymore upon memory
33+
* add/remove or ipc namespace creation/removal.
34+
* They can come back to a recomputable state by being set to a <0 value.
35+
*/
36+
static void tunable_set_callback(int val)
37+
{
38+
if (val >= 0)
39+
unregister_ipcns_notifier(current->nsproxy->ipc_ns);
40+
else {
41+
/*
42+
* Re-enable automatic recomputing only if not already
43+
* enabled.
44+
*/
45+
recompute_msgmni(current->nsproxy->ipc_ns);
46+
cond_register_ipcns_notifier(current->nsproxy->ipc_ns);
47+
}
48+
}
49+
2750
#ifdef CONFIG_PROC_FS
2851
static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2952
void __user *buffer, size_t *lenp, loff_t *ppos)
@@ -38,17 +61,17 @@ static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
3861
static int proc_ipc_callback_dointvec(ctl_table *table, int write,
3962
struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
4063
{
64+
struct ctl_table ipc_table;
4165
size_t lenp_bef = *lenp;
4266
int rc;
4367

44-
rc = proc_ipc_dointvec(table, write, filp, buffer, lenp, ppos);
68+
memcpy(&ipc_table, table, sizeof(ipc_table));
69+
ipc_table.data = get_ipc(table);
70+
71+
rc = proc_dointvec(&ipc_table, write, filp, buffer, lenp, ppos);
4572

4673
if (write && !rc && lenp_bef == *lenp)
47-
/*
48-
* Tunable has successfully been changed from userland:
49-
* disable its automatic recomputing.
50-
*/
51-
unregister_ipcns_notifier(current->nsproxy->ipc_ns);
74+
tunable_set_callback(*((int *)(ipc_table.data)));
5275

5376
return rc;
5477
}
@@ -119,12 +142,14 @@ static int sysctl_ipc_registered_data(ctl_table *table, int __user *name,
119142
rc = sysctl_ipc_data(table, name, nlen, oldval, oldlenp, newval,
120143
newlen);
121144

122-
if (newval && newlen && rc > 0)
145+
if (newval && newlen && rc > 0) {
123146
/*
124-
* Tunable has successfully been changed from userland:
125-
* disable its automatic recomputing.
147+
* Tunable has successfully been changed from userland
126148
*/
127-
unregister_ipcns_notifier(current->nsproxy->ipc_ns);
149+
int *data = get_ipc(table);
150+
151+
tunable_set_callback(*data);
152+
}
128153

129154
return rc;
130155
}

‎ipc/ipcns_notifier.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ int register_ipcns_notifier(struct ipc_namespace *ns)
6161
return blocking_notifier_chain_register(&ipcns_chain, &ns->ipcns_nb);
6262
}
6363

64+
int cond_register_ipcns_notifier(struct ipc_namespace *ns)
65+
{
66+
memset(&ns->ipcns_nb, 0, sizeof(ns->ipcns_nb));
67+
ns->ipcns_nb.notifier_call = ipcns_callback;
68+
ns->ipcns_nb.priority = IPCNS_CALLBACK_PRI;
69+
return blocking_notifier_chain_cond_register(&ipcns_chain,
70+
&ns->ipcns_nb);
71+
}
72+
6473
int unregister_ipcns_notifier(struct ipc_namespace *ns)
6574
{
6675
return blocking_notifier_chain_unregister(&ipcns_chain,

‎kernel/notifier.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ static int notifier_chain_register(struct notifier_block **nl,
3131
return 0;
3232
}
3333

34+
static int notifier_chain_cond_register(struct notifier_block **nl,
35+
struct notifier_block *n)
36+
{
37+
while ((*nl) != NULL) {
38+
if ((*nl) == n)
39+
return 0;
40+
if (n->priority > (*nl)->priority)
41+
break;
42+
nl = &((*nl)->next);
43+
}
44+
n->next = *nl;
45+
rcu_assign_pointer(*nl, n);
46+
return 0;
47+
}
48+
3449
static int notifier_chain_unregister(struct notifier_block **nl,
3550
struct notifier_block *n)
3651
{
@@ -204,6 +219,29 @@ int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
204219
}
205220
EXPORT_SYMBOL_GPL(blocking_notifier_chain_register);
206221

222+
/**
223+
* blocking_notifier_chain_cond_register - Cond add notifier to a blocking notifier chain
224+
* @nh: Pointer to head of the blocking notifier chain
225+
* @n: New entry in notifier chain
226+
*
227+
* Adds a notifier to a blocking notifier chain, only if not already
228+
* present in the chain.
229+
* Must be called in process context.
230+
*
231+
* Currently always returns zero.
232+
*/
233+
int blocking_notifier_chain_cond_register(struct blocking_notifier_head *nh,
234+
struct notifier_block *n)
235+
{
236+
int ret;
237+
238+
down_write(&nh->rwsem);
239+
ret = notifier_chain_cond_register(&nh->head, n);
240+
up_write(&nh->rwsem);
241+
return ret;
242+
}
243+
EXPORT_SYMBOL_GPL(blocking_notifier_chain_cond_register);
244+
207245
/**
208246
* blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain
209247
* @nh: Pointer to head of the blocking notifier chain

0 commit comments

Comments
 (0)