Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp759115ybh; Thu, 12 Mar 2020 10:34:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuZlzLz+nMUgoQVtGLYSKkAfYCfIx2PhO3CyZP7QyhE8T7XrSPSqmuG2qi9ml5IovRPu7Z4 X-Received: by 2002:a05:6830:118d:: with SMTP id u13mr846001otq.41.1584034476221; Thu, 12 Mar 2020 10:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584034476; cv=none; d=google.com; s=arc-20160816; b=h1K+9RAr6nPsXomKEnz3ObCPvFD6NqTpROOv676fW9C9gtiAZJln2eYhRipqOsuMpp zGJUB4ZIHr09qlIH0NFadJsANPf3k2RslA1Ub/NFoEL2hbSz1taVpIWjTSrwu7y9mf/6 sCb9vMdZOjkCRfKtVPLmEMTftKajPMqFRuVug6IcFJPTE96h014LS9RbkSKgE/N8qphE w/aKdcGbgNUPGWT1kV6qV5s8IN8N4IjgFZpgV6xAEvnUMqB9o9lAxRpYwVTvcl74xc8R cZSsDocbveFAn4Ink0RBSgw7OK0EcBtRuc5MrGdCWsywQBKp7rJfPqOYXrexNAjHL1xv LVTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=NoiaqPMaLbyoL7WcV9VE9eKkmobOKnQ4L0s3bngIbSs=; b=nCYMj0EaebJrPdOni7+fAHo9kPGru0eq7jhyG3ZISlgAJ1oPftiV/ISaa9IouLG/Se k4rm/guFnHMXNveJQze6ipa1nTY/yTZOcbyKJaRx7EGO5FrwKncCavuj7RmTGh9MMgcT IM/+CdpuNDrIq4SVa4poLbp8RLYL4cDMBju0an9JYgR8N8fhJRaJtyXKVuxgoJy3UaXG Ae5M/oisHYF0RPt1NzlzsK7VO/C+WwB/06NrBkyQCqYWIYST6MX5lcy2uHylpIqp8ujI j9Uw2lhc7AU5IKLoJ5fPlc8ygqJTmdhTYW/3Ycz7nlkw2Z/2UtWYkQPhsjQCvCG1c0ir Jk2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=qaWsULht; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n198si2935153oig.37.2020.03.12.10.34.23; Thu, 12 Mar 2020 10:34:36 -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; dkim=pass header.i=@chrisdown.name header.s=google header.b=qaWsULht; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726822AbgCLRdT (ORCPT + 99 others); Thu, 12 Mar 2020 13:33:19 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37103 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgCLRdS (ORCPT ); Thu, 12 Mar 2020 13:33:18 -0400 Received: by mail-wr1-f65.google.com with SMTP id 6so8569901wre.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=ibI9CdG6yv3Q0RXmYAewOoaejTfVNoN1evjlZL8tMFC4JHyLWtL9xP1+odwNZT1bzf 9CBahXpXC9uV9ENeazj91BgRB/mYmZqbKLXhoaA3hJBEQ+rqE9A/ZN24GBZ2p+e8jV9F gHz7rtsKOSG2ACE7bil62Y8R3y6g9aCbGgCFeSRdwM12Me6UBtiIRmM1fnxCDf9sRGb9 TV3t2y6FG+5fX/H1GRyWYcGjlhqzsbOc9uXSt6BC9TkmKUnA4u9YJ1rTmH+0D8DsP7WO pQUH1lpSKc0kByKBFToh6SbviNRUC7FfU5Y0SbXuQh60yJe9K5lsvJvOnXmFZEzjO4Tk enxw== X-Gm-Message-State: ANhLgQ3qJ44MqJ4RKXINhFmp7XDwtwfud/65UBz2Aphj8OjlkDiVSmyY en2AVKIB5By8WJ2BAaiD6KR4cg== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.25.1