Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1709677pxb; Mon, 8 Mar 2021 04:37:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE/jKlAfy5rh4WzzwFpVFMOhwTZ8ZOCzWBpFvNccn7XM0ZfnX2CExTrZ4x3GMK4aHJ51Zb X-Received: by 2002:a17:906:a099:: with SMTP id q25mr14760720ejy.549.1615207029335; Mon, 08 Mar 2021 04:37:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615207029; cv=none; d=google.com; s=arc-20160816; b=DnUSgvounvZ7PpuaJJfTqWrSDzDG8esFf6xPdPghBVkEGVXd+4hlsiduViAszAwd0S GLl+NW6bWLOsXi3jeOmrZYchrxoZQB5NcbcvtNPaXyoNUERKd2TH1OCNEiloNnwuOoD8 3FtpTZsKCsqgnoDLxAk63bknPDh1rYD5bc2EPcTGmMdQpMLUTsHXj1wtzqxvbaS2KObO EWKhDQjNGPx/282bclM9wrS68Ik2+pLU01XeacXaX/xWePZjcx/zAxU+968UOHKOUs9y yqkliML50nvkcSpMTCQojZ4WoiyBZzNaZd5+IIXjFDm7+6unMlv5cG0nmwyMeZrbGALX FkOA== 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:dkim-signature; bh=Ful0IzpVmj47foxXWNDIkyOgWUHbfo6p7RDW89mJG88=; b=hgeZyftEfe5TDkrv8TuTjPWM00jG1PNL74K+8sm8FeNApPTNWiYH1hYGJy7NKz1H+8 E6XC5htEtrpWKpmghZn4sK1DL105rnZ0jcVf8UYi2+V9focFhWosOYj1bZ0xB/1SnhUv 3DSDKCPwC1sMvRdHnAxo6Ngw1WcRh6EYCxIPxugZB5cD1aT16kj2yZ0l+/uG0q961jsj LqeU2vK9yZDdLTKLDdYLlS0vdV4MlvahTNcnyX5KXvq8ZEcYatPyCF844C2mVNfOosPR vv4FN09uurYbaQbqXGS17NFTjzTwF1bAlbBzWs42cnq8k6ZoSZop97YovjoEUCmTmT35 d4vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oEAiYSKI; 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=pass (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 n20si6817535ejx.104.2021.03.08.04.36.46; Mon, 08 Mar 2021 04:37:09 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oEAiYSKI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231426AbhCHMfZ (ORCPT + 99 others); Mon, 8 Mar 2021 07:35:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:44124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbhCHMe4 (ORCPT ); Mon, 8 Mar 2021 07:34:56 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48BA3651C3; Mon, 8 Mar 2021 12:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615206896; bh=vIWiUThsyHZCHLlaNKeEPRiQlG72POJDl/1ZuOqmxKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oEAiYSKITurem+3OmIcviNjsXK7itcTMrt53wCtsJjCMiuVToHRIIAzD9HvIVP5fp VgH8Hm4o0rHcYXwhvAQkYFtFtiCwcZk/rAcN0wgA5fC5gfK8D5vD/GEgin4isBkQeB HM5E/32smx8kucFE8MpXEkI8r5qRv0/im972Y57I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" Subject: [PATCH 5.10 17/42] ring-buffer: Force before_stamp and write_stamp to be different on discard Date: Mon, 8 Mar 2021 13:30:43 +0100 Message-Id: <20210308122718.982124945@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210308122718.120213856@linuxfoundation.org> References: <20210308122718.120213856@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: Steven Rostedt (VMware) commit 6f6be606e763f2da9fc21de00538c97fe4ca1492 upstream. Part of the logic of the new time stamp code depends on the before_stamp and the write_stamp to be different if the write_stamp does not match the last event on the buffer, as it will be used to calculate the delta of the next event written on the buffer. The discard logic depends on this, as the next event to come in needs to inject a full timestamp as it can not rely on the last event timestamp in the buffer because it is unknown due to events after it being discarded. But by changing the write_stamp back to the time before it, it forces the next event to use a full time stamp, instead of relying on it. The issue came when a full time stamp was used for the event, and rb_time_delta() returns zero in that case. The update to the write_stamp (which subtracts delta) made it not change. Then when the event is removed from the buffer, because the before_stamp and write_stamp still match, the next event written would calculate its delta from the write_stamp, but that would be wrong as the write_stamp is of the time of the event that was discarded. In the case that the delta change being made to write_stamp is zero, set the before_stamp to zero as well, and this will force the next event to inject a full timestamp and not use the current write_stamp. Cc: stable@vger.kernel.org Fixes: a389d86f7fd09 ("ring-buffer: Have nested events still record running time stamp") Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ring_buffer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -2837,6 +2837,17 @@ rb_try_to_discard(struct ring_buffer_per return 0; /* + * It's possible that the event time delta is zero + * (has the same time stamp as the previous event) + * in which case write_stamp and before_stamp could + * be the same. In such a case, force before_stamp + * to be different than write_stamp. It doesn't + * matter what it is, as long as its different. + */ + if (!delta) + rb_time_set(&cpu_buffer->before_stamp, 0); + + /* * If an event were to come in now, it would see that the * write_stamp and the before_stamp are different, and assume * that this event just added itself before updating