Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2693773ybh; Mon, 16 Mar 2020 08:01:05 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtAoTE0j4GB9f0vtOMNpINd67AgTvHii00C9T3nWLQ1ywuXeeD37boLC6xOtbNWkt0iiTGs X-Received: by 2002:aca:1201:: with SMTP id 1mr18162171ois.172.1584370865197; Mon, 16 Mar 2020 08:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584370865; cv=none; d=google.com; s=arc-20160816; b=JRMzuoAi4DAW9OYrqV7r6Cj4tdWIEfo5uMfzW+6trtCU09JZ0sL2aKCtdXnVIbG212 wcMCeMlLu2vgqYeDrj+V3WzSHzBWBUti8kQsLcRDRKvLxJQGu7wl1nUzmSw62OgmN9yB K0q0GfxesCbKa3UXN+RgT5CzDYxZujg+XTG63PO1o3toyxBafFuvUeuFg5YUkvbin5MD eH4bsAzoZaMjAlCmekhrbTbUpAVnV6dFOojaGVGccIRAlbCDnJsD/F6ZilWqramTAvYc h5WAoZ3b2rLAZCXJS/ryg5Dh4WMT2mnoVFMZ9u57Tdi6m9A/ysPzoylXXjaI3kPD7ICS RVSA== 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; bh=4FvxAgszQ++g/zBJBmYryRtulzv92eq2k64hW2XTxyI=; b=zqsvdy4R1ExdFH+RlSsXDKjM3llTyedHemfhYYjqQVOD3ml09muB6EB3k1rCas8Cl/ B/SS9dU8DiOWBNHkjiYPUDA1nMuJjE3a0NwCS9Zp9jwUxjmSIpwtsun76scUNHkoOYzf 6QPG6iEUEYV9ZR/L7KsAU0iM9GcyzUdR1BmWnq02+aiEbbaKgPO61gIGkQnzO0MHLRcI BVp0PZzUubbbqFYrKC6QHtFvy82Ai7rzPXPLWmOIqr4HgeSmdlwR5FRXAfduWUi3vJXO 93RE9YckV/xbrZgJaeCNY5XAz/JJE8H6ru1de6kzad+LTRMoTb2TN+0O6lQWvHdBHS5Z YdTg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f129si99039oia.243.2020.03.16.08.00.50; Mon, 16 Mar 2020 08:01:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731703AbgCPO71 (ORCPT + 99 others); Mon, 16 Mar 2020 10:59:27 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50341 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731629AbgCPO71 (ORCPT ); Mon, 16 Mar 2020 10:59:27 -0400 Received: by mail-wm1-f65.google.com with SMTP id z13so1971913wml.0; Mon, 16 Mar 2020 07:59:25 -0700 (PDT) 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=4FvxAgszQ++g/zBJBmYryRtulzv92eq2k64hW2XTxyI=; b=KJ8dn3BzFIyRA9SGk+20C70HQStvMy0R6edJhIefx0BKO6p40F9Odbb6/uK3VZGdWi gMXr5hFNeJ9gFLQIFMaI5DI1X8eskmWZ4q5ySvDKSB/dp+mZQ8ezXTU3qDC/Agq64pFJ MEBT4pIJo4ebRc4lLVKSV5AATOR19zBpQdHcgYFsVFZS0eE5SYuM1yZnEgWy9Yj7Rb3O j/2JbOz0s6Mnyuj6+K0C+DDptrSZmQuTlBQeiH5dAJ/Nh7xXZvVVa7/x0pwjCJFgfpyW TC+sdTNkRQ1azPgzVcasNShQnW3BZNtOu2pjMtLhq+eQuVSTklUNhSaCCkQTj6iljOY+ 1ClA== X-Gm-Message-State: ANhLgQ1mAU7FCjSvuAWuxkvOCMAEDvkj+IzexIveITSPjXbJdT7DGV4q pETQgri0MYMN2CpXmXE67+M= X-Received: by 2002:a7b:c75a:: with SMTP id w26mr10572063wmk.2.1584370765264; Mon, 16 Mar 2020 07:59:25 -0700 (PDT) Received: from localhost ([37.188.132.163]) by smtp.gmail.com with ESMTPSA id i67sm256021wri.50.2020.03.16.07.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 07:59:24 -0700 (PDT) Date: Mon, 16 Mar 2020 15:59:23 +0100 From: Michal Hocko To: Chris Down Cc: Andrew Morton , Johannes Weiner , Tejun Heo , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 6/6] mm, memcg: Prevent mem_cgroup_protected store tearing Message-ID: <20200316145923.GR11482@dhcp22.suse.cz> 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 On Thu 12-03-20 17:33:16, Chris Down wrote: > 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; > -- > 2.25.1 -- Michal Hocko SUSE Labs