Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp484968pxu; Fri, 11 Dec 2020 07:03:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzTknRhlRjjStfXXUTGhXnZSMymRDLnZ6DlsCyg7FCj5T2RlUDRk0c7zl+ou1KBYsOBkFL X-Received: by 2002:a17:906:9acc:: with SMTP id ah12mr10901941ejc.386.1607699032301; Fri, 11 Dec 2020 07:03:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607699032; cv=none; d=google.com; s=arc-20160816; b=aSAzccn1TXeyiJdHM1SvzJdCAQLTy9zkXLMDiF0Lr16Gza4u7XZkyDEaWx4iv3/aux ETjMjXDRv1f+mAp1N/ujavyt6YX2TpI7GwtiLMPPLuFhu1TUmNGEBgTcJVlgI+Q/m2sb yFO3pYOJH0TReM4t1kBpT3DBQQYbdhQLzK6ydjzhAvFZGYhpgWCm864fbBt3z4bdxcXh yC5kBdIsHSAcH2iqBs5ebIpygI3klc3n+avO1TLwT5ksDK+9RqWORlEdYmSho/V2kPkD V4fwM8Bw1FloEnab0t9IDS5bFQLKLTJjmJ05ZS0kzk1IpPQSaD2m9AgGnV4CkTLWa24j Pl2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=IKiH6OnAUiKTfKunEALIYY1r8tJrHCHMZ6gxnf457hA=; b=HcKYmk2BDYS/1rSht6Rqep/8zBYbkeBzLl8Ym/POXFQsEcZL9whvo88tIhuNa+AatF xz3pXAHHwH0pcF069XQU+CUIXNxOZUGUpt6jBil+yXLygx72AxOz/c/r1QckZ98ppRXC zqJ6wYOIqDFn3tRSc4XDAzZhUmsCuD5IaKkOEb5Jowb8FGjAelJum2xxXaT9vuQpIxQu orrS1eh9fn9RPg5cl2+J4xSiEfuyfNCbkL3/IqYCR2ianO2hJu+Hh4PEBrBqHCR0wO+s EDHOI1kBAWPiYTwIl9Z0IQy7Ut1y4zOAT2ckqYCXAYk7LptBN0OXHPABCMhxD0W1gIED 7Tng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si4583459edf.510.2020.12.11.07.03.23; Fri, 11 Dec 2020 07:03:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391795AbgLJQob (ORCPT + 99 others); Thu, 10 Dec 2020 11:44:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:44704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391115AbgLJOhp (ORCPT ); Thu, 10 Dec 2020 09:37:45 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Masami Hiramatsu , Andrea Righi , "Steven Rostedt (VMware)" Subject: [PATCH 5.9 18/75] ring-buffer: Set the right timestamp in the slow path of __rb_reserve_next() Date: Thu, 10 Dec 2020 15:26:43 +0100 Message-Id: <20201210142606.955620564@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142606.074509102@linuxfoundation.org> References: <20201210142606.074509102@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrea Righi commit 8785f51a17083eee7c37606079c6447afc6ba102 upstream. In the slow path of __rb_reserve_next() a nested event(s) can happen between evaluating the timestamp delta of the current event and updating write_stamp via local_cmpxchg(); in this case the delta is not valid anymore and it should be set to 0 (same timestamp as the interrupting event), since the event that we are currently processing is not the last event in the buffer. Link: https://lkml.kernel.org/r/X8IVJcp1gRE+FJCJ@xps-13-7390 Cc: Ingo Molnar Cc: Masami Hiramatsu Cc: stable@vger.kernel.org Link: https://lwn.net/Articles/831207 Fixes: a389d86f7fd0 ("ring-buffer: Have nested events still record running time stamp") Signed-off-by: Andrea Righi Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ring_buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3287,11 +3287,11 @@ __rb_reserve_next(struct ring_buffer_per ts = rb_time_stamp(cpu_buffer->buffer); barrier(); /*E*/ if (write == (local_read(&tail_page->write) & RB_WRITE_MASK) && - info->after < ts) { + info->after < ts && + rb_time_cmpxchg(&cpu_buffer->write_stamp, + info->after, ts)) { /* Nothing came after this event between C and E */ info->delta = ts - info->after; - (void)rb_time_cmpxchg(&cpu_buffer->write_stamp, - info->after, ts); info->ts = ts; } else { /*