Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1312029
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Fredrik Markstrom <fredrik.markstrom@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/1] ipc/mqueue: Obey RLIM_INFINITY for message queues. |
| Date | Tue, 19 Jan 2016 10:20:01 +0100 |
| Message-ID | <qSACd-5IF-3@gated-at.bofh.it> (permalink) |
| X-Original-To | Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ysCB3uSwjSGfSvhJGvuzUGn4rz5HJSekwpDV9Nb8BAA=; b=VKGK7ZcUekQ5sd7rq+FiDQVToUj6jSWrOonjZJAZMfG//DLgHcp0g7wG691MFxfD6V OnJzFtCieCzC8/fBX3kapI1a2+Vr4I2wDu6vn8aNC2RCXrLl0o5B5R+ZVFJqNmxPClwH XZ9O+xXhd7c4r0BsbDa/ynBfGf3YB2Yo/e7jwzQEeD3e98DWNAYH59UH1eQSS2P1oyh2 bb+Sro2jGyI4mY+8sqM4ur6kBbaSszTebJiHl68y8BrIdEErtdcBwSN3mxXAmzMxOxQX +rfHKuPNZ1FO2PhZZLSc1NLafjS1rWfB0c86Iiqw3zC6sli16QPdaTY4hcVJ40+hB2GB QRVQ== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ysCB3uSwjSGfSvhJGvuzUGn4rz5HJSekwpDV9Nb8BAA=; b=KfUKgxV4/kKvz6nSXivjjgNjWDlP6SPYdaGpgIyhpgWv994YgrdBlr2MQ55PdcZ3Pi Bp56paU9HDPQKSab39OLWKj+EKXcj7HWm+ayyO5jzLYP1O1CybEksohKdXXcPCv4B4TC katiiwtmGmBxIC2z4A7IHVY4/ykvXp0fgu6jd9wzcJNIJ9IX9MzHmRk32QDfbbgc7qON J7uY533siy4exPOmLKHv1w+TDOvtgrXqgYPuogW7Z5MvF8aVGF0Su4Phx15Jl2xdsrBi xww3AGaD8YD3V/EZCEQ78FwPkKFTT0Jiji5yoMsGq/qiO5BfMceHUBhMAeEL4TrzlMr0 gE8g== |
| X-Gm-Message-State | ALoCoQmF8GEu0klDFs0KykMWTiiBDLFsXusPNbD212pD0sGbB/YM1phYkC+QjvU4h0h7MSDBFbUYmNWZLfmA5yhIvLOim9HzwA== |
| X-Received | by 10.107.16.27 with SMTP id y27mr26395593ioi.21.1453194881426; Tue, 19 Jan 2016 01:14:41 -0800 (PST) |
| X-Mailer | git-send-email 2.7.0 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 96 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Manfred Spraul <manfred@colorfullife.com>, Davidlohr Bueso <dave@stgolabs.net>, David Howells <dhowells@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>, George Spelvin <linux@horizon.com>, Marcus Gelderie <redmnic@gmail.com>, linux-kernel@vger.kernel.org |
| X-Original-Date | Tue, 19 Jan 2016 10:10:37 +0100 |
| X-Original-Message-ID | <1453194637-13996-1-git-send-email-fredrik.markstrom@gmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1312029 |
Show key headers only | View raw
Even if we set the "POSIX message queues" rlimit to unlimited we might
fail with EMFILE. That happens when the max usage of a user wraps around
on 32 bits.
We fix this by:
- Skipping the test in the case of RLIM_INFINITY
- Changing user->mq_bytes from long to long long
The accounting can't be skipped entierly for this case since rlimit can be
changed from unlimited to something smaller while a message queue is open.
Signed-off-by: Fredrik Markstrom <fredrik.markstrom@gmail.com>
---
/* Compile with: gcc -o mqt mqt.c
*/
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <stdio.h>
int main(void) {
int i;
mqd_t mqs[1000];
struct mq_attr attr;
attr.mq_msgsize = 70000;
attr.mq_maxmsg = 10000;
attr.mq_flags = 0;
attr.mq_curmsgs = 0;
for(i = 0; i < 1000; i++) {
char name[32];
sprintf(name, "/tmq%d", i);
mqs[i] = mq_open(name, O_RDWR|O_CREAT, 0644, &attr);
if(mqs[i] < 0) {
printf("Failed after %d mq_open\n", i);
perror("mq_open");
return -1;
}
}
printf("Success (i=%d)\n", i);
return 0;
}
Before patch:
% ulimit -c unlimited
% ./mqt
Failed after 6 mq_open
mq_open: Too many open files
After patch:
% ulimit -c unlimited
% ./mqt
....
Success (i=1000)
include/linux/sched.h | 2 +-
ipc/mqueue.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index edad7a4..745b7f5 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -827,7 +827,7 @@ struct user_struct {
#endif
#ifdef CONFIG_POSIX_MQUEUE
/* protected by mq_lock */
- unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
+ unsigned long long mq_bytes; /* How many bytes can be allocated to mqueue? */
#endif
unsigned long locked_shm; /* How many pages of mlocked shm ? */
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 161a180..40db042 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -275,8 +275,9 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
info->attr.mq_msgsize);
spin_lock(&mq_lock);
- if (u->mq_bytes + mq_bytes < u->mq_bytes ||
- u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
+ if (rlimit(RLIMIT_MSGQUEUE) != RLIM_INFINITY && (
+ u->mq_bytes + mq_bytes < u->mq_bytes ||
+ u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE))) {
spin_unlock(&mq_lock);
/* mqueue_evict_inode() releases info->messages */
ret = -EMFILE;
--
2.1.4
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH 1/1] ipc/mqueue: Obey RLIM_INFINITY for message queues. Fredrik Markstrom <fredrik.markstrom@gmail.com> - 2016-01-19 10:20 +0100
csiph-web