Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3973108imm; Mon, 14 May 2018 00:14:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr+Q80e+tKdovrkwwsBOSbuYwAQtIgvTcyc0mzcerrCm4q3magIeeDdlG0lFPv353etl44s X-Received: by 2002:a62:cf43:: with SMTP id b64-v6mr9169985pfg.248.1526282051741; Mon, 14 May 2018 00:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526282051; cv=none; d=google.com; s=arc-20160816; b=dR41vIB0O3IXvXwnoxQvqLMfeOGgSnA6H9fdHrCoy44x6e/j6OAROC4wv7+1TbFqZ6 APxtteHuwkX/+fnXVTz8IkBITuIFVuvaggCOAm/Ke7CtL1BcCM75WXBv6Yq5uDozulX1 0nAgrGYcndmFK2tsM3nmd4SsL/3A75w57geYIV9BLG2eHqa7eCuSPb4issr8elroU4V6 96i5J4/j8WRrnq/+Rqdwb8kc2pPecrvhsG4+kESm7/bTi+KiC7eOWq7Wxv8AIYNemaNq sXtax1HMPV9kE74s4Ej4yObIQBLuhluJZtPUY1Fag8MYw2o8GQSuQb8spuxc0p4F+zwi hoMg== 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:arc-authentication-results; bh=Jdnx/4/Ltqxm2O7IQH8AT2nY69DPA1QP8O6V745G5yQ=; b=mPdWdCvbJbqzyQc/FYbVt8P4qGLWBk9K6m6ZNENIvMdOZUQ50mmEoW6UYT0DX/rSYo OWUlFi8YB9FcchmxlnyWYyGtbqfwrqWR4KgPE6ZI5sC/j0DXzArAKoN8uE/C0obPWcn4 KzgyfCsYnsKDRrhS8dUMj82Fqbnas03++HdiXP3vgsr48fE14aeDFA1kayqWKIuN8nri /1JLnlp98znXpuzhKz59LM7Ez60opMVs69xGLSdq+/1MRoWBGk/Y/ReR7WFYU6YgDG/I UxAxV1R7w16d/EpFYvEjyOsN8HMuWnW7C6gPtHsTqN0Ka4vzlGQ9Q7g9TG7UQ7xpcWOe 9VOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=c+4p3OcO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l36-v6si5773515plg.82.2018.05.14.00.13.57; Mon, 14 May 2018 00:14:11 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=c+4p3OcO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753816AbeENG6J (ORCPT + 99 others); Mon, 14 May 2018 02:58:09 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55388 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753782AbeENG6C (ORCPT ); Mon, 14 May 2018 02:58:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Jdnx/4/Ltqxm2O7IQH8AT2nY69DPA1QP8O6V745G5yQ=; b=c+4p3OcODLfnuSrzivCVjjLRp kgWXvEZDAOdym/NegrcuFYRJ2W1y8cq1KumFF9S9PCNdKPqIE4ebZdSFYk/LikFMMjBbH2dHSkN1a /BQ3AbAubzNLQ1Q1UdHcyrsQ2zzmkGm5EULmZ8MGyc80GMiP63m/XqvxjeSobCHCB1hUilo8TFA5D jbD7hRMZ9y8JPm5jX8G8gbdSv8dx6miXRpAwxNWGP7VM9zEOVzodWdAPfVufkzmQOKfGySWxh3oV7 +vuOH67IXPVVi7cTj0BWSXH888c5ObmWbGJUclhh4lFe0vpPWVnDudT6seuoiYoIYbprwHGjfQmnC 0yQ9slBqA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fI7Qj-0003qg-Jj; Mon, 14 May 2018 06:57:57 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 43D0D2029FA13; Mon, 14 May 2018 08:57:55 +0200 (CEST) Date: Mon, 14 May 2018 08:57:55 +0200 From: Peter Zijlstra To: "Paul E. McKenney" Cc: Xiao Guangrong , rostedt@goodmis.org, Lai Jiangshan , stefani@seibold.net, "linux-kernel@vger.kernel.org" Subject: Re: Is read barrier missed in kfifo? Message-ID: <20180514065755.GM12217@hirez.programming.kicks-ass.net> References: <5382d3a8-08e0-5429-0cd3-36f9c69197e1@gmail.com> <20180511083242.GJ12217@hirez.programming.kicks-ass.net> <20180511162053.GY26088@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180511162053.GY26088@linux.vnet.ibm.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 09:20:53AM -0700, Paul E. McKenney wrote: > On Fri, May 11, 2018 at 10:32:42AM +0200, Peter Zijlstra wrote: > > On Fri, May 11, 2018 at 03:25:18PM +0800, Xiao Guangrong wrote: > > > > > > Hi, > > > > > > Currently, there is no read barrier between reading the index > > > (kfifo.in) and fetching the real data from the fifo. > > > > > > I am afraid that will cause the vfifo is observed as not empty > > > however the data is not actually ready for read. Right? > > > > That code is decidedly dodgy indeed. I can only see smp_wmb() but no > > matching barriers at all -- therefore the code is almost certainly as > > good as not having any barriers at all. > > > > I would suggest you try and convert the code to smp_store_release() and > > smp_load_acquire() while you're at it. > > Isn't this one of the places where we rely on control dependencies? Then it bloody well should have a comment. But at least one side of the fifo needs a read barrier I think. We can rely on a ctrl-dep on the write side, where we read the head/tail values, compute space and then conditionally allow writes to happen. But on the read side it's all reads and ctrl-dep doesn't help anything.