Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3622859ybi; Mon, 10 Jun 2019 13:35:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN3yACh7N9EqQYiF6G1azgCCjKBUOuZrJ+mucbgIQbtzqbc7XWk0LLlqzQJGIBh538Ritj X-Received: by 2002:a17:902:7897:: with SMTP id q23mr71505132pll.21.1560198925201; Mon, 10 Jun 2019 13:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560198925; cv=none; d=google.com; s=arc-20160816; b=nRVi5h7+E4yYQ6DWr4vfSAVIQepP9NXLOWpSxAIrIg4oDypInK30NUXk0qM0dChbIe kByxlY8Vzf032b/Bkz7jGHZjGQKsz1hAeR+Vg7cXST78nHa+4zGJbAQ7DGF0aHf4+RcB Y3Ja1flFVz0h2b/QVhVO9elkBh25emaMsdVGMPJEbSY/CKXzH9iqyRLxhgo4xTh+r+zc Uc/7hSbWyfLjuE5RB0F3B8JhGncjK6h/qhskg6B2F2xw3o6MAqune2a7Cgeko7mgd8e8 8+EnYIhY6xS/XeyiyehL6FwgFQoPImE8GWXFEF76IWDANRTBUx0aOJFOVcbXXhK5xwSw OhMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QntknNlUMZ8JI/1goGczbuHi72H8zQ1C3B8XCCIqc74=; b=Rz0pS55CUs+Sl82YYZc2kHJP/bSRyTjt9hpr3A9rFkoAvY8xXDfZj1r+v9yuwbrd93 LZ8o9pi0wRzIPFKq1I+RzM57Nt9xks/DWYitLTRd1aMvxhLSu+QOv36XypVupQSQRKeO I9iRZnoGAW8nxkA3+oBPMdXz/piUi8hiwe5hhOOiPgdoKQ5487lDzYj7cV7wNlPSoLb6 qMm2EuMA5FmohjkAqfsZVuRJsxCqZC+C9JAeqW5wVTUpB1F9Szp3n5i7g5edvQ5VFU/u lCofxfqOq6uJRJNpJDajeI0BD2vqKDBx2vsG5NyT66BWbJGNEMn5SZwp++zmMpnyhheB 2LlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=xzuzhYxw; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n7si9889954plk.435.2019.06.10.13.35.10; Mon, 10 Jun 2019 13:35:25 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=xzuzhYxw; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389440AbfFJUdu (ORCPT + 99 others); Mon, 10 Jun 2019 16:33:50 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37237 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389331AbfFJUdu (ORCPT ); Mon, 10 Jun 2019 16:33:50 -0400 Received: by mail-pf1-f195.google.com with SMTP id 19so5113607pfa.4 for ; Mon, 10 Jun 2019 13:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QntknNlUMZ8JI/1goGczbuHi72H8zQ1C3B8XCCIqc74=; b=xzuzhYxwoNBu8erHlLCrxSF6MyfWGF1hKTX+tKC7Hnyu/qw9Tj+eRX3C62ggnJnCN4 tg1sy2avRP+ogUk9rkB6oxWVwW96l1plZ/wS2FgBg9ov5ZHfQD01osPiIMw9+s45gWyY GGXQZoJP/K2EQ4oq1dCL3nRh6zdkvZtN3sDwEjTz28wEzhHh0solkY3gANj5poClnBQT XSIBZ/r7EK9XzaDLWHwvHR99AFFP1HcBQWTc/qlpPiE93EVyQJHzrAVsG5nJX8onEPlp pOyyL1FTk0PCBlHw5ymm1gYsRTCXcT0eaXT0qFfdhfKjR67fqwACSYKwOZWVE2hRWy1F wgxg== 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:user-agent; bh=QntknNlUMZ8JI/1goGczbuHi72H8zQ1C3B8XCCIqc74=; b=ZscyPCt4HdlWfF7D0FSYl8XsaUlxA247TEWZ/FUFunWHwoVJWiDU7fG5beOJnk6p85 q0U+mPNpyqnmwf6gqwpTpdqp7kkrY3UkgZWc7MsEDfDS8gRrwM0ZxEG2Y8DEoyJW1/MZ Vgn3sVUR3CAWn9JbZUBNhpIUCyPgLwBu8+yRPcGFxEaZmYtdcwUaAkyf4l8EbSlM5Zey jBDdGgpnHCud3D61kxi4IlnkyOwSvdbOHOrlSmFlNsNIUkVQIl4rrQri5SlQfihamOFS jsKa2aO6a0f3rzJrZ+1XZD3wabHQzDFIJyD7FrpfUtbGG0HhtyvbVbjyvc1/a4SsroP2 QhXg== X-Gm-Message-State: APjAAAUlN8XeLrbI+TwJGG+1QbinVfPaAjg/T1Lt5Ma7xKX8gSbj3Cpq vF7SftFhcH/KBGs7TQM2hsb0Hq3QExM= X-Received: by 2002:a62:6145:: with SMTP id v66mr75694199pfb.144.1560198827276; Mon, 10 Jun 2019 13:33:47 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::2:8cbd]) by smtp.gmail.com with ESMTPSA id v4sm14441747pff.45.2019.06.10.13.33.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 10 Jun 2019 13:33:46 -0700 (PDT) Date: Mon, 10 Jun 2019 16:33:44 -0400 From: Johannes Weiner To: Vladimir Davydov Cc: Roman Gushchin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Shakeel Butt , Waiman Long Subject: Re: [PATCH v6 01/10] mm: add missing smp read barrier on getting memcg kmem_cache pointer Message-ID: <20190610203344.GA7789@cmpxchg.org> References: <20190605024454.1393507-1-guro@fb.com> <20190605024454.1393507-2-guro@fb.com> <20190609121052.kge3w3hv3t5u5bb3@esperanza> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190609121052.kge3w3hv3t5u5bb3@esperanza> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 09, 2019 at 03:10:52PM +0300, Vladimir Davydov wrote: > On Tue, Jun 04, 2019 at 07:44:45PM -0700, Roman Gushchin wrote: > > Johannes noticed that reading the memcg kmem_cache pointer in > > cache_from_memcg_idx() is performed using READ_ONCE() macro, > > which doesn't implement a SMP barrier, which is required > > by the logic. > > > > Add a proper smp_rmb() to be paired with smp_wmb() in > > memcg_create_kmem_cache(). > > > > The same applies to memcg_create_kmem_cache() itself, > > which reads the same value without barriers and READ_ONCE(). > > > > Suggested-by: Johannes Weiner > > Signed-off-by: Roman Gushchin > > --- > > mm/slab.h | 1 + > > mm/slab_common.c | 3 ++- > > 2 files changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/mm/slab.h b/mm/slab.h > > index 739099af6cbb..1176b61bb8fc 100644 > > --- a/mm/slab.h > > +++ b/mm/slab.h > > @@ -260,6 +260,7 @@ cache_from_memcg_idx(struct kmem_cache *s, int idx) > > * memcg_caches issues a write barrier to match this (see > > * memcg_create_kmem_cache()). > > */ > > + smp_rmb(); > > cachep = READ_ONCE(arr->entries[idx]); > > Hmm, we used to have lockless_dereference() here, but it was replaced > with READ_ONCE some time ago. The commit message claims that READ_ONCE > has an implicit read barrier in it. Thanks for catching this Vladimir. I wasn't aware of this change to the memory model. Indeed, we don't need to change anything here.