mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yingjie Wang <x-professor@outlook.com>
To: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	Manfred Spraul <manfred@colorfullife.com>,
	Alexey Gladkov <legion@kernel.org>,
	"Eric W . Biederman" <ebiederm@xmission.com>
Cc: "Yingjie Wang" <x-professor@outlook.com>,
	"Vasily Averin" <vasily.averin@linux.dev>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Alejandro Colomar" <alx@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>,
	"linux-man@vger.kernel.org" <linux-man@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH v3 1/3] ipc/sem: account enlarged sops arrays to memcg
Date: Sat, 24 Oct 2026 12:21:41 +0000	[thread overview]
Message-ID: <edbb4aa04440205874d8a02a7f18e82d8188b937.1792808260.git.x-professor@outlook.com> (raw)
In-Reply-To: <cover.1792808260.git.x-professor@outlook.com>

Commit 6a4746ba0619 ("ipc: remove memcg accounting for sops objects in
do_semtimedop()") removed accounting based on the assumption that sops
arrays would remain small, describing a maximum cost of two pages.

SEMOPM is a UAPI default that can be changed when rebuilding the kernel.
It must not also define the accounting policy, since changing that default
would enlarge the unaccounted range.

Keep the historical small-array range unaccounted with a fixed internal
threshold of 1000 operations, and use GFP_KERNEL_ACCOUNT when the actual
nsops exceeds it. Requests within that range retain the existing allocation
behavior, while larger user-controlled arrays are charged to the caller's
memory cgroup.

Commit 50ec499b9a43 ("sysctl: allow change system v ipc sysctls inside ipc
namespace") later made the per-namespace limit tunable by IPC namespace
owners without capabilities in the initial user namespace.

Link: https://lore.kernel.org/r/20261016152609.2528805-1-x-professor@outlook.com
Fixes: 6a4746ba0619 ("ipc: remove memcg accounting for sops objects in do_semtimedop()")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
 ipc/sem.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ipc/sem.c b/ipc/sem.c
index 5ec41de7e85b2..a8c9807175520 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -176,6 +176,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
 
 #define SEMMSL_FAST	256 /* 512 bytes on stack */
 #define SEMOPM_FAST	64  /* ~ 372 bytes on stack */
+#define SEMOPM_NOACCOUNT	1000 /* ~ 2 pages for struct sembuf */
 
 /*
  * Switching from the mode suitable for simple ops
@@ -2234,7 +2235,10 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops,
 		return -EINVAL;
 
 	if (nsops > SEMOPM_FAST) {
-		sops = kvmalloc_objs(*sops, nsops);
+		gfp_t gfp = nsops > SEMOPM_NOACCOUNT ?
+			GFP_KERNEL_ACCOUNT : GFP_KERNEL;
+
+		sops = kvmalloc_objs(*sops, nsops, gfp);
 		if (sops == NULL)
 			return -ENOMEM;
 	}
-- 
2.43.0


  reply	other threads:[~2026-10-24 12:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24 12:21 [PATCH v3 0/3] ipc/sem: account enlarged sops arrays and validate SEMOPM Yingjie Wang
2026-10-24 12:21 ` Yingjie Wang [this message]
2026-10-24 12:21 ` [PATCH v3 2/3] ipc/sem: reject negative SEMOPM values Yingjie Wang
2026-10-24 13:23   ` Alejandro Colomar
2026-10-24 12:21 ` [PATCH v3 3/3] ipc/sem: remove obsolete SEMOPM fragmentation warning Yingjie Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=edbb4aa04440205874d8a02a7f18e82d8188b937.1792808260.git.x-professor@outlook.com \
    --to=x-professor@outlook.com \
    --cc=akpm@linux-foundation.org \
    --cc=alx@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=hannes@cmpxchg.org \
    --cc=legion@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=manfred@colorfullife.com \
    --cc=mhocko@suse.com \
    --cc=mkoutny@suse.com \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=vasily.averin@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®