Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2233788ybi; Thu, 20 Jun 2019 11:19:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+hL6dseHFpj8dm+QSM9tl7nn4wKX4MR+ohn1ChJeJb38OG4xX1pwkM4QDU9zKgjt0PXS2 X-Received: by 2002:a17:902:d915:: with SMTP id c21mr60418422plz.335.1561054741256; Thu, 20 Jun 2019 11:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561054741; cv=none; d=google.com; s=arc-20160816; b=venrC73x6bc2PfeCXzb2X+dwCqN+6unpSR5KnA0JgYcrp3qZcFIlpOMglsRJs+MxUr aeV6P3mTSViW+xN8dJ671sSOIQzOMELxHoyaog/uHGzJg9PbK+kpuRZD3AC5kWomE1q7 RqpFOyD8HzwQEl1Tdwt2xirQJD3HNG35g/XA6Ojo7hBFZh1YzZl6aUXYquYO1Lj2OkyJ 7guqrvLh1fyS919vx+NZ7sIgGXj/7dc13tQ6A8NechdxK0xWsgy/SD4mhPkqCaugxkhW 3Ea0I/6/Sda2gxEC2/N52Oy3apICrGgY3J0vg7B8t3lOgLiuY5tKXyedsqXWDXe0Y7ce wv4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ccGG5nCqxvbr1t2c+eikA4SljKjXiH81GbDUjFNgyaU=; b=Hq6ktBTjaTdcp70nlk0G/CYzFh7Hy96n7zY64BrVzunSaXm6dhGr3IH6gKKcUBuCG1 dKCdXn1GqsgcQvdG1uhmHU63W311EiZMLyaqknkMNCT10twQ0n86s42oYYUX8zbCBRyy AS2hgVS5q+ayJHfyJN8sSFgqp3EEng6CaAueBsT4/NKa7gUC+03H5XYkWJWOSABAxZc+ 1BDSr6rqD6jgvfkzchPGepZpVRi73W6whloq0kERFoypAPqthzvleFO44T3rIOcaGaSl CtN/0g8dWwLZvOwOUplevaVK+ydHDm0V4ukAOiRQqqJvTo6kuzzO6l/Wic2n47FPUejN dZ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lbkzAY9t; 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 d39si363036pla.371.2019.06.20.11.18.46; Thu, 20 Jun 2019 11:19:01 -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=@kernel.org header.s=default header.b=lbkzAY9t; 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 S1729500AbfFTSSf (ORCPT + 99 others); Thu, 20 Jun 2019 14:18:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:45436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729419AbfFTSQU (ORCPT ); Thu, 20 Jun 2019 14:16:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3DC752089C; Thu, 20 Jun 2019 18:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054579; bh=d0gosAX3r3C3qaB0cccEa/Bre6+woGl0mD5ROsE6eKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lbkzAY9tKPF8HXBrlPJeG+9H4FCyl1bUstHmPCOlKWwlnP4cpWy8oiqGpTK16FA3Q lIKIHVsVxYMzMoIcpNeu0Cij2oWeGP80bgqKiD3CufcFB5jxJTYRzZcykhVvHI7SO+ Ij0pYLIZCQhVHrIQJquNEk8LUzQYWmgZ92JLZYLk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yabin Cui , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , acme@kernel.org, mark.rutland@arm.com, namhyung@kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.1 49/98] perf/ring_buffer: Add ordering to rb->nest increment Date: Thu, 20 Jun 2019 19:57:16 +0200 Message-Id: <20190620174351.467871924@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174349.443386789@linuxfoundation.org> References: <20190620174349.443386789@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 3f9fbe9bd86c534eba2faf5d840fd44c6049f50e ] Similar to how decrementing rb->next too early can cause data_head to (temporarily) be observed to go backward, so too can this happen when we increment too late. This barrier() ensures the rb->head load happens after the increment, both the one in the 'goto again' path, as the one from perf_output_get_handle() -- albeit very unlikely to matter for the latter. Suggested-by: Yabin Cui Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: acme@kernel.org Cc: mark.rutland@arm.com Cc: namhyung@kernel.org Fixes: ef60777c9abd ("perf: Optimize the perf_output() path by removing IRQ-disables") Link: http://lkml.kernel.org/r/20190517115418.309516009@infradead.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/events/ring_buffer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 009467a60578..4b5f8d932400 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -48,6 +48,15 @@ static void perf_output_put_handle(struct perf_output_handle *handle) unsigned long head; again: + /* + * In order to avoid publishing a head value that goes backwards, + * we must ensure the load of @rb->head happens after we've + * incremented @rb->nest. + * + * Otherwise we can observe a @rb->head value before one published + * by an IRQ/NMI happening between the load and the increment. + */ + barrier(); head = local_read(&rb->head); /* -- 2.20.1