Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1641500ybp; Fri, 11 Oct 2019 18:07:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQEmhNtN3RK0VigfEmGFlI6gEPmQ0TWaF9jqdHVMdwOrb6i4oTgFdcmfmPuBToS3aeYlB2 X-Received: by 2002:a50:f744:: with SMTP id j4mr9093637edn.73.1570842433999; Fri, 11 Oct 2019 18:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570842433; cv=none; d=google.com; s=arc-20160816; b=HaWcfkmKeiqkKbUhXSyFihjeZW601kfq5lKm5nh6I3UliwFjIpZtQy9X+9nQOdlggr O6OCy4qCMfeZ562ukPwI1eRZv7KNe9lSmWh+IEQ9BKHKy0Q3jyRWJOLpIcboTA56gA6L Bs4yT80O6vRzX2LcdODoC5QoSaaSj0JDgOo2esOMwIYK90QHHaUScczPAEcjavi6YDbX bAb1+iyq2YP1gZGXhy3/xxMEsXHGL7QQNj8kck1xULa1iMxRBUcZ7ujqoh3iE/8sAQWv UtDOzPXiiDPQxgBKXeqE/5Zs+d2mjxMaWqpmpIOAD/it1702IGwJOVxxDsejknmR9Rxj O+nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=eSNro/zACwxkmWzJyjBpuOegnDY2zdvrTlf+uwWXIO8=; b=RShVlHucLw58+77ih0YdIXaOVs3/dgg3coTLUGcoXuJo9zCpljdZ2RUR2HdNk6T/21 yOYb35NBvOjjq2fn19KWDUa/FocEZGdHpAZZDz17YKBU5RS+CudQm1RcPisimeIBf1kg EJv2aIXmjV/WCvhFgYgY8YyPHnsEzD8dYKU7letxKDDbWrU0gm9Lezdk2tm4u8CkKtot NGwjH78F5Sqscfodb/Oz+ib/6Oy6C9so+sS40ZXUyUR4+WeSvj9C/5/fWXP+YBNe6jnJ KToXkDqaw4vs3C5zvYVIjlYoub1HvNpKKlL1Lx6THO8N2hJPY9/s/y3osmNuxBzgWbeB jBUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o49si6899111edc.261.2019.10.11.18.06.50; Fri, 11 Oct 2019 18:07:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728520AbfJLBGR (ORCPT + 99 others); Fri, 11 Oct 2019 21:06:17 -0400 Received: from mx2a.mailbox.org ([80.241.60.219]:57995 "EHLO mx2a.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbfJLBGR (ORCPT ); Fri, 11 Oct 2019 21:06:17 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2a.mailbox.org (Postfix) with ESMTPS id B4EABA1585; Sat, 12 Oct 2019 03:06:14 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id HpnuEwOz63oE; Sat, 12 Oct 2019 03:06:11 +0200 (CEST) From: Aleksa Sarai To: Tejun Heo , Li Zefan , Johannes Weiner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksa Sarai , stable@vger.kernel.org Subject: [PATCH] cgroup: pids: use {READ,WRITE}_ONCE for pids->limit operations Date: Sat, 12 Oct 2019 12:05:39 +1100 Message-Id: <20191012010539.6131-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because pids->limit can be changed concurrently (but we don't want to take a lock because it would be needlessly expensive), use the appropriate memory barriers. Fixes: commit 49b786ea146f ("cgroup: implement the PIDs subsystem") Cc: stable@vger.kernel.org # v4.3+ Signed-off-by: Aleksa Sarai --- kernel/cgroup/pids.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c index 8e513a573fe9..a726e4a20177 100644 --- a/kernel/cgroup/pids.c +++ b/kernel/cgroup/pids.c @@ -152,7 +152,7 @@ static int pids_try_charge(struct pids_cgroup *pids, int num) * p->limit is %PIDS_MAX then we know that this test will never * fail. */ - if (new > p->limit) + if (new > READ_ONCE(p->limit)) goto revert; } @@ -277,7 +277,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 * critical that any racing fork()s follow the new limit. */ - pids->limit = limit; + WRITE_ONCE(pids->limit, limit); return nbytes; } @@ -285,7 +285,7 @@ static int pids_max_show(struct seq_file *sf, void *v) { struct cgroup_subsys_state *css = seq_css(sf); struct pids_cgroup *pids = css_pids(css); - int64_t limit = pids->limit; + int64_t limit = READ_ONCE(pids->limit); if (limit >= PIDS_MAX) seq_printf(sf, "%s\n", PIDS_MAX_STR); -- 2.23.0