Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2157408ybi; Sun, 9 Jun 2019 05:13:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqT7pIa6jjkYWZyeZbriLx+YsdGI3UhvxwiAOwAMfkXurYP3TmUPD7pjArNgie0vP3P2zX X-Received: by 2002:a17:902:a982:: with SMTP id bh2mr64418862plb.224.1560082414358; Sun, 09 Jun 2019 05:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560082414; cv=none; d=google.com; s=arc-20160816; b=LET4DybGbmN2uAHoSbZfNsFfnIbTUkNCyrJkrKrydSA8h30EPYQOeSodMKKh7CZdvr 8WaZ8NrGr8X4/uhPj3oFqyJqUnJHc6sbZG27b5yYah8+w2/bc+H4zUayrA1p9tvjcKpP of3VdOqjEtkrkv3Ljw+6RNKz6QXeXJIO/9wcHJMSVs+izYvcyTgMK9aiYHbTJQgJ2WSM MZFq4DR58zgbql2JvCPT0tutIEV7jVNGLpPsu7O55pKMpIPN9JuR3Tc7Z5CHaI0XK07F 1ZDHoIepNmlHlmXh4n5oHmoL+cmDUl/QR2AHNbMaKQcMo03eow4rdCzuO4CAhT0MNJj7 6nXg== 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=MGnWlXcEZlsDllQ1p+dLiYMxOQG545jMz4NgSBC9Y94=; b=q0ign9i/H5lMIx+0dTWSHK7WhRtYrv5uGoBci0AHec5oIKctecNOB1xZnNQhW/H8wJ 6AlKO1TyN8UgXhwLLIE07MU1MRSNquOmtzedJZR4iEt3+5AVpowJqqIt+zciQzKgb698 UIUwCG22kYNGPYUhXQSIICLjhxD6373fI2tmJyIMXFsB25B5Y+i94a5Ekv6uo8ZtaYy4 KrWFE4WyZJUPnjBB4SZgdMxYk/QIN/umuVQqLKwuysaQKdB5lzvGHV20vHMPkfe2pvck fbCem4hYqz+K8tNhDAmO4CVhEhYlw8F1O5cSAHG3AF8JemtZ3BjhUlZN8fafbm1dLzNN 9zdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nRmn0YNw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13si6790694ply.311.2019.06.09.05.13.15; Sun, 09 Jun 2019 05:13:34 -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=@gmail.com header.s=20161025 header.b=nRmn0YNw; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728345AbfFIMK5 (ORCPT + 99 others); Sun, 9 Jun 2019 08:10:57 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37663 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbfFIMK5 (ORCPT ); Sun, 9 Jun 2019 08:10:57 -0400 Received: by mail-lj1-f196.google.com with SMTP id 131so5466208ljf.4 for ; Sun, 09 Jun 2019 05:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MGnWlXcEZlsDllQ1p+dLiYMxOQG545jMz4NgSBC9Y94=; b=nRmn0YNw8W+QR/WXpFQLQvxWieu7tL/WNi0q3+UMLXv1nXW9gwzTkCv8SY1aRpJeat ilJLCQYmFDEiyA3lldq0wUtt9f85fPZGz+jdQ/hHsk01cnqc6AUXcRN1GNDaWLJV14jX ngoF5Y2eJ4ywcfSSrZxnYcfyh8zCFxI53rHruVBiZnb1KSQtkRgLJIGZ6DOctY72Hm8S 5TbducFcWoCXLn2GTEd21oqtCp0N4r2+WEB+zmjhox+Yi53x81DvSYRbVf4NWSZqbe/P 0aiDUGPE3KavdxykFJkQrksAtAEmmw5rxLRm30FYIRBidXHsQ1OR0t18qhaGuetsxAZY TQNg== 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=MGnWlXcEZlsDllQ1p+dLiYMxOQG545jMz4NgSBC9Y94=; b=drz2dYTJX/XoMr0xFxwQ2T21XmTnPlf6wqbQFpl7svaIhyrhq6brw1gjxnGMU7imgc HLThBODfAzH/Ibll7sGn4J90ge4BpeXVbQ1FHLz8SyrVb/y+oZjP9I2AtKiGMibw0SHk Rfrbh9HyXnufalQNhOZoJfETsKyScZobjqwsN7Cjykkum2GcyI6Lmrbf1kN5yGfqN8DI UqrwPFk2AbhgbfiyE9gKfsTmLhGPXodK0UHf4ywZX2hmeOVi+5qgnYuG7CLZABfhgZKc RYnsM51Nf3HHE21PBAW/Lo08wQoTqnABGD1ujizRS4xcGthMjAVIOE/BaEFwiQfeyzK7 iykw== X-Gm-Message-State: APjAAAVYRn4vJIozbzsB9JEOG+XTAytCppg4pGfOChda/J68PkX03eSn 0k/Wg+p0sFs/qlUS08+e9T4= X-Received: by 2002:a2e:9692:: with SMTP id q18mr34382352lji.89.1560082255174; Sun, 09 Jun 2019 05:10:55 -0700 (PDT) Received: from esperanza ([176.120.239.149]) by smtp.gmail.com with ESMTPSA id t3sm1423097lfk.59.2019.06.09.05.10.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jun 2019 05:10:54 -0700 (PDT) Date: Sun, 9 Jun 2019 15:10:52 +0300 From: Vladimir Davydov To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Johannes Weiner , Shakeel Butt , Waiman Long Subject: Re: [PATCH v6 01/10] mm: add missing smp read barrier on getting memcg kmem_cache pointer Message-ID: <20190609121052.kge3w3hv3t5u5bb3@esperanza> References: <20190605024454.1393507-1-guro@fb.com> <20190605024454.1393507-2-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190605024454.1393507-2-guro@fb.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. commit 506458efaf153c1ea480591c5602a5a3ba5a3b76 Author: Will Deacon Date: Tue Oct 24 11:22:48 2017 +0100 locking/barriers: Convert users of lockless_dereference() to READ_ONCE() READ_ONCE() now has an implicit smp_read_barrier_depends() call, so it can be used instead of lockless_dereference() without any change in semantics. Signed-off-by: Will Deacon Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1508840570-22169-4-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar commit 76ebbe78f7390aee075a7f3768af197ded1bdfbb Author: Will Deacon Date: Tue Oct 24 11:22:47 2017 +0100 locking/barriers: Add implicit smp_read_barrier_depends() to READ_ONCE() In preparation for the removal of lockless_dereference(), which is the same as READ_ONCE() on all architectures other than Alpha, add an implicit smp_read_barrier_depends() to READ_ONCE() so that it can be used to head dependency chains on all architectures. Signed-off-by: Will Deacon Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1508840570-22169-3-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar