Received: by 10.223.185.116 with SMTP id b49csp1018948wrg; Fri, 16 Feb 2018 10:55:41 -0800 (PST) X-Google-Smtp-Source: AH8x225qxZ/zKHQbpAOkMDKEytJIpV9/PWetDtWfEKnm2r4nClB6959fwOhTI570l9xVM+0GD6GX X-Received: by 2002:a17:902:2901:: with SMTP id g1-v6mr6658162plb.69.1518807341674; Fri, 16 Feb 2018 10:55:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518807341; cv=none; d=google.com; s=arc-20160816; b=WWc85VsXotzrIo5x67dgqkz4IMjXXG9IXJ1PfKlMcGlPMD94UM5yruxZGUzPesLkmc m/y/l+JKL+Uz70fUMqkgZIVxrz/Qrz1tWTLEbcKEwKBKoi4cOJ+EfrlIIRke1lTqg+IA o5JftCQsMov1ojB+bwoEZtDqAA4GUhHoOCcEjXXAoY+nOea6haekp6FY3K2Y+BnqpJjq kOh3TGiuudgmVfM/2uS7fVApFAmREt1dMgVF+zlEUVC7gS/SBB/ZwqXdX/nCgcQgBY8O PweDjh6JUIkxLjC4sDyuYk9ggu2KnNx+f2GanmhgD3M3cum8iiTyU5nMELoIybXrReNB mTQw== 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=nCIR6J/eZCppsBJKEf8NYlwMFM/PMkQy25qRrG+idLk=; b=i9nTXt70WCWBiY+bxgHOmhcBP06O4mxR4NzPb9UJw1wk5cfuZYcLKo0eVBjD883pOQ JAZ6fmsSPgX0Igzyqln01ObJUnGualwYuE/G3hHhbfLSaDvgS0cF5xUSdsoU0iy/w0Oq pjZU/+Ze8FiYEpYoTOsdMrUS1GFiI4mKzrbZU5qoQAmsEwB/kjEQpUxKtSwRm+U0N7vQ cEKILmLbJu6S2BKmzeTKfEnCP/Cukj5kxiu85cQ686gNE5ICK+S+MRXrp6nguJXR4J10 QL2L6wlKZIKjEKKQ3NVWJ5D4H6irVIBKrsYnahJsFo/G3v+mA7WXgXeY9CUPy79r7RIs p03Q== 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 g1-v6si434301plm.441.2018.02.16.10.55.27; Fri, 16 Feb 2018 10:55:41 -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 S932617AbeBPJt7 (ORCPT + 99 others); Fri, 16 Feb 2018 04:49:59 -0500 Received: from terminus.zytor.com ([198.137.202.136]:48125 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932579AbeBPJtz (ORCPT ); Fri, 16 Feb 2018 04:49:55 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1G9YtrW021309; Fri, 16 Feb 2018 01:34:55 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1G9Ys1J021305; Fri, 16 Feb 2018 01:34:54 -0800 Date: Fri, 16 Feb 2018 01:34:54 -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, peterz@infradead.org, acme@redhat.com, wangnan0@huawei.com, kan.liang@intel.com, hpa@zytor.com, namhyung@kernel.org, yao.jin@linux.intel.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, ak@linux.intel.com Reply-To: mingo@kernel.org, ak@linux.intel.com, linux-kernel@vger.kernel.org, yao.jin@linux.intel.com, jolsa@kernel.org, wangnan0@huawei.com, namhyung@kernel.org, hpa@zytor.com, kan.liang@intel.com, peterz@infradead.org, acme@redhat.com, tglx@linutronix.de 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: dc6c35c679e96987dc83a003f30bc2cc33c84c00 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: dc6c35c679e96987dc83a003f30bc2cc33c84c00 Gitweb: https://git.kernel.org/tip/dc6c35c679e96987dc83a003f30bc2cc33c84c00 Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:17 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 15 Feb 2018 09:51:57 -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);