Received: by 10.223.176.46 with SMTP id f43csp32729wra; Thu, 18 Jan 2018 13:29:31 -0800 (PST) X-Google-Smtp-Source: ACJfBoswpm6PTwWKRY/y1CI858snnYrxLJecbC9Lmgy3WGszea4XZPJCwq403ZxxfgCKH5L0mfbd X-Received: by 10.99.116.22 with SMTP id p22mr33543561pgc.182.1516310971808; Thu, 18 Jan 2018 13:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516310971; cv=none; d=google.com; s=arc-20160816; b=SD/3FF8gI4BOSdLOM3EiTT+/Khly4Pkdr4VdNVE/qRIAFu4mABo+t4YcaNWDn3XGQH eSVes3EDxsR/nbWI9/Ka8ttfJy4YnJiY83MklaZYepW4fFkdZXZ2wCh+XS5uhh1L1qy8 SdFUGgLuxqQ33mt6+lC/+FKi+bSDgAeocKapM5g5oYr9g3hvslChMddHG5cct1oFiug8 OPy4RwB6LGu41OxKFncr6X1I/ZxaJyB2msnOyrYijFpfnap8C50JigB/qliZ94ILfWwC th+ph4UVnPJTzOzynm96kBajy/1iACtmH/mFWxD3CCQvGTZ70wT+/FeOyGlCADZXjwkm OUYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=gf5Sf71HxTGXCF/v8xECOXheJc3T87Zf+UQZtb0ukcY=; b=SUeTPaBYZIjEhFMncHtf1YTWV0iLxr22ObAkdWUTzFoJpndZBQIs6IH2Yr5AocwpX2 eTmOQZxTUOBFuxW204z9cpSZ03thWFMry9Ehkr+OHM+wNdvL2qnkq8PwCTIpJeSn66c7 gMXsPBMVTC/xBHYckn+L8IIFNjXGAG8KjkIRSy7q7jsUUP4fp9gsW3078xPTR5RsOxfT wAtJsB0a0mC4IKQy5GKFIDEp4NzWqoBBs2YzrmSI7id2Ae5OKszT37P05JetOYRMrae/ ECMwwnP9TVJr3wadcNbLMD+aKIeeSsKjZJj1NAHGOTAwvXWSnCzNUnAsvZoAgCjzYxuD 3juw== 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 64si6723991pgd.45.2018.01.18.13.29.18; Thu, 18 Jan 2018 13:29:31 -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 S932338AbeARV1n (ORCPT + 99 others); Thu, 18 Jan 2018 16:27:43 -0500 Received: from mga04.intel.com ([192.55.52.120]:47419 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752689AbeARV1d (ORCPT ); Thu, 18 Jan 2018 16:27:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2018 13:27:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11477204" Received: from otc-knm-01.jf.intel.com ([10.54.39.34]) by fmsmga008.fm.intel.com with ESMTP; 18 Jan 2018 13:27:30 -0800 From: kan.liang@intel.com To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: wangnan0@huawei.com, jolsa@kernel.org, namhyung@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, Kan Liang Subject: [PATCH V5 02/17] perf mmap: fix: recalculate size for overwrite mode. Date: Thu, 18 Jan 2018 13:26:17 -0800 Message-Id: <1516310792-208685-3-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516310792-208685-1-git-send-email-kan.liang@intel.com> References: <1516310792-208685-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang 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 ringbuffer 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 ringbuffer 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 --- 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); -- 2.5.5