Received: by 10.223.185.116 with SMTP id b49csp3556134wrg; Tue, 13 Feb 2018 04:16:23 -0800 (PST) X-Google-Smtp-Source: AH8x2264XJY+V/IA4FdUo2H/YRKTsHDc25NEUTKRue+jmrSg37F+1t5c7wKHJoZ5JEcoLp9lio4Y X-Received: by 10.101.77.140 with SMTP id p12mr838765pgq.195.1518524182970; Tue, 13 Feb 2018 04:16:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518524182; cv=none; d=google.com; s=arc-20160816; b=m6Ym2y5+zlsI6GnH2DjTt98ny19LgJly2n7FF5ckbHzQB3GOdSUaG62MLs4vViSwr8 /HvmFhGctI8p2fi8YKIbK1hxXnlMw4UazcTaYyLNzK0zyra4imNrL3xVkwyt0h2HXloX NtCql86/C94dEE0+/cKwDxl7fnBF8GLYVavJzUQqecXVxbU7/Fh3L/gJYhtuII5Ize1H v2ztOB2iOyKM8pwDFQg7WHDjq/UVAvLAVpkamMrsrWmmcUa8kVqvfCmZz1UkqrRbQhOI cdVuaDOow8FEFXSnVdeCqjxB8qDw4P8c4VylqJjwS/ccMO5eb+SSmwswrJnet/kUY4sk i1wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=0jUOEVmOiJFM3+BDN9OZCQFXPmQDfV/A7FH6lMqn1Ro=; b=bchq6hnlMUgWTTkW8TZLV2YrwXQHhnmuHLAmiIkuwZHPEqhxIqftdVX7OEoLkmC+rv RwkuUUaqugbKdUxXHDm1gt+j/7ooawuGjhhodi2VXP32QEmB4m1+0+sSYWuZzQRzm2nX C8h6c0N/ox5WeeG9jpFw4JnZHZRvQT8Um9PDgtB0Uylp0zAIQyrpcrLDYRiNMS+ZolFt WUQEMc20q6jqjHFiQu0ddjVsfjrIXAr/CpyTWiYrEblIkhB3klrZ4pokVQxyjhXagifH Ybp6X/U9w7IWgWs/uHjsmydmbNDq5J4+pqqGEMHY6EyAc/PE1ljN7SKQmUzqfo4ZSGpC MnIA== ARC-Authentication-Results: i=1; mx.google.com; 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 j198si2020727pgc.703.2018.02.13.04.16.08; Tue, 13 Feb 2018 04:16:22 -0800 (PST) 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; 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 S935022AbeBMMPO (ORCPT + 99 others); Tue, 13 Feb 2018 07:15:14 -0500 Received: from terminus.zytor.com ([198.137.202.136]:53197 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934806AbeBMMPM (ORCPT ); Tue, 13 Feb 2018 07:15:12 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1DC4lO1028129; Tue, 13 Feb 2018 04:04:47 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1DC4lUF028126; Tue, 13 Feb 2018 04:04:47 -0800 Date: Tue, 13 Feb 2018 04:04:47 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kan Liang Message-ID: Cc: tglx@linutronix.de, wangnan0@huawei.com, peterz@infradead.org, namhyung@kernel.org, hpa@zytor.com, ak@linux.intel.com, mingo@kernel.org, linux-kernel@vger.kernel.org, jolsa@kernel.org, yao.jin@linux.intel.com, acme@redhat.com, kan.liang@intel.com Reply-To: namhyung@kernel.org, tglx@linutronix.de, wangnan0@huawei.com, peterz@infradead.org, linux-kernel@vger.kernel.org, mingo@kernel.org, jolsa@kernel.org, yao.jin@linux.intel.com, kan.liang@intel.com, acme@redhat.com, hpa@zytor.com, ak@linux.intel.com In-Reply-To: <1516310792-208685-3-git-send-email-kan.liang@intel.com> References: <1516310792-208685-3-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf mmap: Recalculate size for overwrite mode Git-Commit-ID: ab463a252c4c790913c0ca0196e5dc7ea04b1f02 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ab463a252c4c790913c0ca0196e5dc7ea04b1f02 Gitweb: https://git.kernel.org/tip/ab463a252c4c790913c0ca0196e5dc7ea04b1f02 Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:17 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 6 Feb 2018 10:11:49 -0300 perf mmap: Recalculate size for overwrite mode In perf_mmap__push(), the 'size' need to be recalculated, otherwise the invalid data might be pushed to the record in overwrite mode. The issue is introduced by commit 7fb4b407a124 ("perf mmap: Don't discard prev in backward mode"). When the ring buffer is full in overwrite mode, backward_rb_find_range() will be called to recalculate the 'start' and 'end'. The 'size' needs to be recalculated accordingly. Unconditionally recalculate the 'size', not just for full ring buffer in overwrite mode. Because: - There is no harmful to recalculate the 'size' for other cases. - The code of calculating 'start' and 'end' will be factored out later. The new function does not need to return 'size'. Signed-off-by: Kan Liang Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Jin Yao Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Fixes: 7fb4b407a124 ("perf mmap: Don't discard prev in backward mode") Link: http://lkml.kernel.org/r/1516310792-208685-3-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/mmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 05076e6..97cf4fa 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -302,6 +302,8 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite, return -1; } + size = end - start; + if ((start & md->mask) + size != (end & md->mask)) { buf = &data[start & md->mask]; size = md->mask + 1 - (start & md->mask);