Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp519938yba; Wed, 15 May 2019 05:33:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZRPz3bJd7fEuWA0nIqG000KvoZLMAC4dAWCTj2ZX6+AJEWd2tuMBvWheKNnQkicwgAgSO X-Received: by 2002:a63:8149:: with SMTP id t70mr44480918pgd.134.1557923627716; Wed, 15 May 2019 05:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557923627; cv=none; d=google.com; s=arc-20160816; b=XxXeLSYcRYFo19IWgdybiLidioaiu4Se6EjDGIHWiKVAoStYd5PCq24DMbBmPGlYBS Etfdl2bUNEga2qiiobhYfx+l5sAPeRK0ck66tB+MrN43DTHH+9M4TQiwUYxSMI8llFRT je7Kuzcd7vKfBm82qjp7aFJ6VvdsOQTTmhBTxFyINtYPxHH4rXUPGwNVCv8eagI1ghoz 9k7YvQlsv7hVnbJhh21vqfJbVrhT7RAm0QF3ENBzHmdW9+CBnlqCgJBKimc7gZaGYllm J5tQu925qfh3e7xd3EWFX/LKsc1hIbIHJPkuuNpOxXf+mdkEH9FGr4a0jJ1vewHOCtFl IXxg== 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=zCCfi2VVHEha3dpNjP34AHH7pIAgmLH8/4Yn0qNp2cA=; b=QK5p4ooxuYgwgpi4VlWQv32PQtC4U/elnXuIfiZL54BE+/fCFXFiyc50n051JUmoxR cKT67hXTbhC0iJ79IXJozB9lFZoE7EX4sCDjmkSZeUS6Fej4W21d6vjXjgAgAd3xcRKm C+Pa3iqPnwlCT2X21sHqpxmSSzdo8TfZmrngm394e1sgKcNDfBPpdrvFLqpFbIVa4uLl u5DEOuUhyDLa955NgGaJ/EsBfm6FS4qRK/qrgWRTMV7sizVFlMcx56jtBMQ7kXmBi2Gk lnnW/ax0aJUr8Sxq7uas4+tFDQSGDdhA3Lwzolc3Awpi0Iu79vckl499+cQWs7luBmeE D0ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="HtoY5G3/"; 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 g191si1652534pgc.197.2019.05.15.05.33.32; Wed, 15 May 2019 05:33:47 -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="HtoY5G3/"; 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 S1726422AbfEOKv2 (ORCPT + 99 others); Wed, 15 May 2019 06:51:28 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:44530 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbfEOKv2 (ORCPT ); Wed, 15 May 2019 06:51:28 -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=zCCfi2VVHEha3dpNjP34AHH7pIAgmLH8/4Yn0qNp2cA=; b=HtoY5G3/FWVdXgniTqYpme5Ka DcSIU+uWGaLpCYVUM7c9mv+Ww1N1vheD0mYXA19Lq6fuTtcxy3CjNlFnWb66dLd8erhV0f4GMQ81C 24H9VBJC6Rn1pPW59PN0JcJcnjE79H9wW0TFzVJbGTps8twV3/8P2lcMWwoUCeA1QTMgA9WC7sT2B 6AcV4/lX31mw8rZlvFSuM7zhsmgUQ+Ro0hyUcWmnPE62ChDRO2ulzVAacGe1VnHxBkR2PplrvVbRX y6u81NQw7QR0yhwNxAu7zS/0SThlMxBB82B1ZLF/miNpgO+qkxByS1bZwH1Yq8i6wB3wgRMua5rv1 n3lMlB4/w==; 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 1hQrVO-0005HH-A0; Wed, 15 May 2019 10:51:26 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id ACBAF2029F888; Wed, 15 May 2019 12:51:24 +0200 (CEST) Date: Wed, 15 May 2019 12:51:24 +0200 From: Peter Zijlstra To: Alexander Shishkin Cc: Yabin Cui , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf/ring_buffer: Fix exposing a temporarily decreased data_head. Message-ID: <20190515105124.GE2623@hirez.programming.kicks-ass.net> References: <20190515003059.23920-1-yabinc@google.com> <87ef50xlb8.fsf@ashishki-desk.ger.corp.intel.com> <20190515094352.GC2623@hirez.programming.kicks-ass.net> <87bm04xcdb.fsf@ashishki-desk.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87bm04xcdb.fsf@ashishki-desk.ger.corp.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 15, 2019 at 01:04:16PM +0300, Alexander Shishkin wrote: > Peter Zijlstra writes: > > > On Wed, May 15, 2019 at 09:51:07AM +0300, Alexander Shishkin wrote: > >> Yabin Cui writes: > >> > >> > diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c > >> > index 674b35383491..0b9aefe13b04 100644 > >> > --- a/kernel/events/ring_buffer.c > >> > +++ b/kernel/events/ring_buffer.c > >> > @@ -54,8 +54,10 @@ static void perf_output_put_handle(struct perf_output_handle *handle) > >> > * IRQ/NMI can happen here, which means we can miss a head update. > >> > */ > >> > > >> > - if (!local_dec_and_test(&rb->nest)) > >> > + if (local_read(&rb->nest) > 1) { > >> > + local_dec(&rb->nest); > >> > >> What stops rb->nest changing between local_read() and local_dec()? > > > > Nothing, however it must remain the same :-) > > > > That is the cryptic way of saying that since these buffers are strictly > > per-cpu, the only change can come from interrupts, and they must have a > > net 0 change. Or rather, an equal amount of decrements to increments. > > > > So if it changes, it must also change back to where it was. > > Ah that's true. So the whole ->nest thing can be done with > READ_ONCE()/WRITE_ONCE() instead? > Because the use of local_dec_and_test() creates an impression that we > rely on atomicity of it, which in actuality we don't. Yes, I think we can get away with that. And that might be a worth-while optimization for !x86.