Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2432759pxu; Sat, 28 Nov 2020 13:59:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8VfkpBW6ahHKCfwBs2kEgVIjEEdCGecWvr8gwuv6GdViQVSNfUwd1SLcA70MpNe1BJydG X-Received: by 2002:a17:906:27d1:: with SMTP id k17mr13630635ejc.325.1606600762764; Sat, 28 Nov 2020 13:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606600762; cv=none; d=google.com; s=arc-20160816; b=Uh6+ptX4TkHu1eUpOjixB0rMS9bsmKqb/krXR7ZBTrrRvUh17sUSqQGJtzWpm1fyXt cHY88sXiUdtlwT4PIWcq9Jh5RxJK9k0Rs5thYFoZUo7QOWbSC3u+iqAfXTjC2rBIkQiM s99sWdbNhwOffdUamV9LcPDpCTsjuDItIfdMxclZEeYyKnViV6kpSuax7KsePAkF5i8u ymLTa2YjV4IObVMfKCBKly679mzu6i/o1OLC7uBcYFW2pCoyzHDvoxfCm7eg1WtHaVT9 ndQnFomH8yLELZOceSFGsFn4Nl3cyJmFLKCKzONP+of7ErNHxPt1SrSA+9W17FiAz173 Bk7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=L1ZVOdz/CkW3cEUwY2qKMVfD+NLZGHncisYT77s+qT8=; b=Ohlp6WlWJjikqjSfx/g9GZGKVmkua6EccCSxR5CHyuaFZXEjZ5iFZsnFPnoKfGwfq7 CCVncxiq2JIBQggtNxQranozXWhjfmHdaZN2Hj60No9kHIkBnEhH6cOS3TrocA9R9tpn IxaEDFJusGDoVdv2UY6y6m5vip13iUZE5+xE/4Il0DPDkR7X7p8MEDkFS7MyN3ewF4qr 0sGX3q5PWt7cP3r861tfwUfKQ0sVCVzJT4SDrMGBBDX5SatPJTqpD6uuW0HV7Vx/klKA ByP/tFsv61abDwO/BoapuH2xuQU6QdY3BB1Z4x/iDAjOG8Lw+r84hmUE2K9UUn7Ta2kC h0wQ== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si9127453ejm.496.2020.11.28.13.59.00; Sat, 28 Nov 2020 13:59:22 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391249AbgK1V4R (ORCPT + 99 others); Sat, 28 Nov 2020 16:56:17 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:52857 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387745AbgK1U5d (ORCPT ); Sat, 28 Nov 2020 15:57:33 -0500 Received: from mail-wr1-f71.google.com ([209.85.221.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kiwK8-0007lg-OT for linux-kernel@vger.kernel.org; Sat, 28 Nov 2020 09:15:20 +0000 Received: by mail-wr1-f71.google.com with SMTP id u8so2696551wrq.6 for ; Sat, 28 Nov 2020 01:15:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=L1ZVOdz/CkW3cEUwY2qKMVfD+NLZGHncisYT77s+qT8=; b=oVYRQuWltJcTTmumydnIY27G1Jv5lZtBHd+byVayls/ztLJo2MYbz/gRB94lPMskyh wVkvGnmYoENThOlwtUWh+rdqeV2xFevaAFFfLzYKHBvHtPF+UTC+BPXHKEYxSG8oLAda mn9kmh9nIrK8bIPHkthPEyviXufy0Ljnt20uGU/Hn/Rjalslygqnr8/cj5dLapUxC0xY jZ7/MB2OoIiReI7ELCXY9NqtomFHPPECqjbI/xLhx7v27KSVmZWIaZNqfqTo95HzBDta kL1aqgOdflH1wHzbeXvhE584xz22/UIxKZ01+9xD77gzp/OkTWRwc8sDMSmQxBXOSpNS 8Jbw== X-Gm-Message-State: AOAM530/rAslLfHFhJRKSbCv8reMVzVMr8Rl8D/coY/xj2DGWHxCETgU JnidtR+b6lvs81A8lSskFjFUdqS3Fx4w40XbKtMg64VfRSIk7Bs7tQ40tZ2XqrW/Sgj1AiVlWaJ 648opJIM6zgwz3pj20UUMWdM6Cbe+QnUXl6h9GWa1nw== X-Received: by 2002:adf:a451:: with SMTP id e17mr15976269wra.99.1606554920349; Sat, 28 Nov 2020 01:15:20 -0800 (PST) X-Received: by 2002:adf:a451:: with SMTP id e17mr15976260wra.99.1606554920140; Sat, 28 Nov 2020 01:15:20 -0800 (PST) Received: from localhost (host-79-35-122-236.retail.telecomitalia.it. [79.35.122.236]) by smtp.gmail.com with ESMTPSA id d16sm20573195wrw.17.2020.11.28.01.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 01:15:19 -0800 (PST) Date: Sat, 28 Nov 2020 10:15:17 +0100 From: Andrea Righi To: Steven Rostedt Cc: Ingo Molnar , Masami Hiramatsu , linux-kernel@vger.kernel.org Subject: [PATCH] ring-buffer: set the right timestamp in the slow path of __rb_reserve_next() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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://lwn.net/Articles/831207 Fixes: a389d86f7fd0 ("ring-buffer: Have nested events still record running time stamp") Signed-off-by: Andrea Righi --- kernel/trace/ring_buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index dc83b3fa9fe7..5e30e0cdb6ce 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3287,11 +3287,11 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, 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, info->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, info->ts); info->ts = ts; } else { /* -- 2.29.2