From patchwork Thu Mar 12 17:33:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Down X-Patchwork-Id: 11435139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5163E6CA for ; Thu, 12 Mar 2020 17:33:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1DE982073E for ; Thu, 12 Mar 2020 17:33:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="qaWsULht" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DE982073E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chrisdown.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D93BB6B0075; Thu, 12 Mar 2020 13:33:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D444F6B0078; Thu, 12 Mar 2020 13:33:18 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C80736B007B; Thu, 12 Mar 2020 13:33:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id B0C546B0075 for ; Thu, 12 Mar 2020 13:33:18 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7216E180ACC54 for ; Thu, 12 Mar 2020 17:33:18 +0000 (UTC) X-FDA: 76587406476.02.bait69_39f0e08541115 X-Spam-Summary: 2,0,0,4ef3e5ba0e233619,d41d8cd98f00b204,chris@chrisdown.name,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1312:1313:1314:1345:1359:1431:1437:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3870:3871:5007:6261:6653:10004:10400:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12895:13069:13161:13229:13311:13357:13439:13846:13895:14096:14097:14181:14394:14721:21080:21444:21451:21627:21990:30054:30064,0,RBL:209.85.221.67:@chrisdown.name:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: bait69_39f0e08541115 X-Filterd-Recvd-Size: 3939 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Mar 2020 17:33:17 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id 6so8569902wre.4 for ; Thu, 12 Mar 2020 10:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NoiaqPMaLbyoL7WcV9VE9eKkmobOKnQ4L0s3bngIbSs=; b=qaWsULht3bWoY5iXQLEcDGdBTFV6hjN7lpV33RTCtB3xWc1PLX/WRxZQohX8Xrl/9w UmohlrmtFgTmdaoEpFrPYYLSu55234z8uvo9TnjcyiBJbYmm2fJpmw10ZPHUC3T9G4Z3 CvKX3yFDACoE48iNQsDgNcSOYv8fqeVuxR4Rk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NoiaqPMaLbyoL7WcV9VE9eKkmobOKnQ4L0s3bngIbSs=; b=FRSrdXgOUCNXbtUR35y3q5FSKj5D3kvHvyj9oObDFt4pipgDsYjHpQnBz/MzTJvg/I 6OQjoeG88Z3qU2lvDH7/yyBaEE24DwT1FXfveY+CXsLk0RFJUJA5X+MpaTcb40E9qXB/ NelVIGC+nCOs/XCmiLsVhncQ90n2ABKL+wbxTz5D+qAAdMRM0n27Jc/A+tgAlUbNcGGL iXKpVU7OPB+MJThF4dRwxzo98TiF7f0iOSmGiR9ATe0mGlE1fNZOW0rcwAev45dJK1ip shjGpRiO0RDR830YzKlO8MlZUZfC8i06skQ2sP6brq+RcLcOHlXSHNQ9z5qc7krKlVhI 49HQ== X-Gm-Message-State: ANhLgQ1f6570FTBnZmNSMXIbSU+9FmsUdEVOasgTotpSBtaWXEeFrvCd hiice0aSLcSeoR+v15Qv4L7Cjg== X-Google-Smtp-Source: ADFU+vvYbyeKzXBtFBZm5+Qqw3wXcJUdTLliut8wUu0quaYaNk9IXP08ecLQIM8cttCro0Cmn5Mn+Q== X-Received: by 2002:a5d:63c7:: with SMTP id c7mr11956491wrw.384.1584034396977; Thu, 12 Mar 2020 10:33:16 -0700 (PDT) Received: from localhost ([89.32.122.5]) by smtp.gmail.com with ESMTPSA id o3sm14396506wme.36.2020.03.12.10.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 10:33:16 -0700 (PDT) Date: Thu, 12 Mar 2020 17:33:16 +0000 From: Chris Down To: Andrew Morton Cc: Johannes Weiner , Tejun Heo , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 6/6] mm, memcg: Prevent mem_cgroup_protected store tearing Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000073, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The read side of this is all protected, but we can still tear if multiple iterations of mem_cgroup_protected are going at the same time. There's some intentional racing in mem_cgroup_protected which is ok, but load/store tearing should be avoided. Signed-off-by: Chris Down Cc: Andrew Morton Cc: Johannes Weiner Cc: Roman Gushchin Cc: Tejun Heo Cc: linux-mm@kvack.org Cc: cgroups@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com Acked-by: Michal Hocko --- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 57048a38c75d..e9af606238ab 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6301,8 +6301,8 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, } exit: - memcg->memory.emin = emin; - memcg->memory.elow = elow; + WRITE_ONCE(memcg->memory.emin, emin); + WRITE_ONCE(memcg->memory.elow, elow); if (usage <= emin) return MEMCG_PROT_MIN;