Commit eb84c72b authored by Aleksa Sarai's avatar Aleksa Sarai Committed by Kleber Sacilotto de Souza

cgroup: pids: use atomic64_t for pids->limit

BugLink: https://bugs.launchpad.net/bugs/1858489

commit a713af39 upstream.

Because pids->limit can be changed concurrently (but we don't want to
take a lock because it would be needlessly expensive), use atomic64_ts
instead.

Fixes: commit 49b786ea ("cgroup: implement the PIDs subsystem")
Cc: stable@vger.kernel.org # v4.3+
Signed-off-by: default avatarAleksa Sarai <cyphar@cyphar.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 1926a2f8
...@@ -48,7 +48,7 @@ struct pids_cgroup { ...@@ -48,7 +48,7 @@ struct pids_cgroup {
* %PIDS_MAX = (%PID_MAX_LIMIT + 1). * %PIDS_MAX = (%PID_MAX_LIMIT + 1).
*/ */
atomic64_t counter; atomic64_t counter;
int64_t limit; atomic64_t limit;
}; };
static struct pids_cgroup *css_pids(struct cgroup_subsys_state *css) static struct pids_cgroup *css_pids(struct cgroup_subsys_state *css)
...@@ -70,8 +70,8 @@ pids_css_alloc(struct cgroup_subsys_state *parent) ...@@ -70,8 +70,8 @@ pids_css_alloc(struct cgroup_subsys_state *parent)
if (!pids) if (!pids)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
pids->limit = PIDS_MAX;
atomic64_set(&pids->counter, 0); atomic64_set(&pids->counter, 0);
atomic64_set(&pids->limit, PIDS_MAX);
return &pids->css; return &pids->css;
} }
...@@ -142,13 +142,14 @@ static int pids_try_charge(struct pids_cgroup *pids, int num) ...@@ -142,13 +142,14 @@ static int pids_try_charge(struct pids_cgroup *pids, int num)
for (p = pids; parent_pids(p); p = parent_pids(p)) { for (p = pids; parent_pids(p); p = parent_pids(p)) {
int64_t new = atomic64_add_return(num, &p->counter); int64_t new = atomic64_add_return(num, &p->counter);
int64_t limit = atomic64_read(&p->limit);
/* /*
* Since new is capped to the maximum number of pid_t, if * Since new is capped to the maximum number of pid_t, if
* p->limit is %PIDS_MAX then we know that this test will never * p->limit is %PIDS_MAX then we know that this test will never
* fail. * fail.
*/ */
if (new > p->limit) if (new > limit)
goto revert; goto revert;
} }
...@@ -262,7 +263,7 @@ static ssize_t pids_max_write(struct kernfs_open_file *of, char *buf, ...@@ -262,7 +263,7 @@ static ssize_t pids_max_write(struct kernfs_open_file *of, char *buf,
* Limit updates don't need to be mutex'd, since it isn't * Limit updates don't need to be mutex'd, since it isn't
* critical that any racing fork()s follow the new limit. * critical that any racing fork()s follow the new limit.
*/ */
pids->limit = limit; atomic64_set(&pids->limit, limit);
return nbytes; return nbytes;
} }
...@@ -270,7 +271,7 @@ static int pids_max_show(struct seq_file *sf, void *v) ...@@ -270,7 +271,7 @@ static int pids_max_show(struct seq_file *sf, void *v)
{ {
struct cgroup_subsys_state *css = seq_css(sf); struct cgroup_subsys_state *css = seq_css(sf);
struct pids_cgroup *pids = css_pids(css); struct pids_cgroup *pids = css_pids(css);
int64_t limit = pids->limit; int64_t limit = atomic64_read(&pids->limit);
if (limit >= PIDS_MAX) if (limit >= PIDS_MAX)
seq_printf(sf, "%s\n", PIDS_MAX_STR); seq_printf(sf, "%s\n", PIDS_MAX_STR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment