Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp262285ybl; Mon, 12 Aug 2019 15:58:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCyq1PzeAK48Dy4UqB5lZG7wDvjQkKDcNYZ3zsXTvupbenFTx0+wO/Q2kO7eHc2VduaBJB X-Received: by 2002:a63:704:: with SMTP id 4mr31987207pgh.242.1565650714979; Mon, 12 Aug 2019 15:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565650714; cv=none; d=google.com; s=arc-20160816; b=AkYgkbHtwaQceOv+bb3ygbXzejD4e8w6qp9M53pUCxMmqYSsAL9TzMg2guiadoS9eU 1YJHCBd7mwq2gQ3WgHeq4wo8fIBQ6TgW3m1ek+zwzp0ABow+FTbPVLJW1HiRMryU6NsE q/phhu3lVsslpXCkNiRjZL/o8UtWW8LDIaTZdy6ocXZ/e1IFHuoGMGPBxkU5963J+mbn AsYdgpauNvy+0hNOf9uL5zVvrqOGWaJroeOpW95fRw2YlWNAFLfSVSvTU+8tPMMWBlXO +HjfDx0g8zFMH0qv8NWMZQNY5agY/BM6FZ5yqvm2S26hZfM3kmnzBxNTl11tGfVtrSea oJFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=Jw1cj/+ww6TfMtRSJmzTU59qtmGQEsSIwrvBNo/N7vI=; b=CgaY5LH8k2gSWRCaj1eJlXecaN/7uVwfyGi/siuHew7TyaBrCBVk/xCM8Svk6BJObl espqRjSAKrMLKsBCNJHMNIt8YDcot9S78LxNnbNlnB5ZTCBvbORFGnsVrAqdaWRaqyE0 qxJPlb5qVvqfc/nc657Y0K4m4oZ+mwin949UkDoopfZIjtFDXeKy+shxnwDFpD/xBNxT KmAvVEzuUCUSyqXnCGRUfvqfj/XEtUa8vNW9vT/ZBK/YYG4tQdOO+LWF8aBpc/vhEZGx BHsY9E7TEGaF+6i3TxU8LVzhfZL5aCnvSH/HJqKCvmAZPmO7/vLBsBvZkN80ifO/mQM1 WCeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iChCTuWc; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a190si62845763pge.4.2019.08.12.15.58.19; Mon, 12 Aug 2019 15:58:34 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=iChCTuWc; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbfHLWL7 (ORCPT + 99 others); Mon, 12 Aug 2019 18:11:59 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:45225 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbfHLWL7 (ORCPT ); Mon, 12 Aug 2019 18:11:59 -0400 Received: by mail-qt1-f201.google.com with SMTP id l9so97731820qtu.12 for ; Mon, 12 Aug 2019 15:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=Jw1cj/+ww6TfMtRSJmzTU59qtmGQEsSIwrvBNo/N7vI=; b=iChCTuWckrWOil+NdSVQAXCes8B5y+65GYvCV0IakAqJktJmI/dqtiIt7UiI2ePUeJ uX7GWHA/fOMjJ9EroA9KTPBKBpIqHm34x/LpQfBTFSUtiQHqfLalCNCotPDpR94Y0nJo o1mh/M3dFf1EC0+hT6IcWPTi5U/HnvRqWstHp4Dmzei8hxvRLLPLpeIzU5wadrIp7tI3 wUjQgUPE5yzFkpb0NUVdDmaB5oOs/vdE3L1ZCWhniXfrVEiu4W+xhpdxOHBazvyNtiDy LnocJc9ECkP4GZmBtQ+yX8mBiYSTItXKBf9JTH/hOBQ3k7Jz7er1kzgVuECju5/jFzLc RVBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Jw1cj/+ww6TfMtRSJmzTU59qtmGQEsSIwrvBNo/N7vI=; b=WasKcxVR3liBEGivndwJ5Oaz73hJIDxlUeV3p23+UwKK6v9hVy/UkX/3rKjZts0/Z8 v97mfs2NN3yo3MloGOosGxCI533lGoS6RuSqKXRa77ST3pONd9oD7EwewMFCUs1m2IeR 75T3XjSsP3U/gkvi7TfkvF2+ybmrXOFxpNJJwXIgzs97bWXSEsi/BVV7/+Q7nIlZ7PXJ ywhIpihaGYHP85jkuMC6ne4DVsHx5i07duW3qFb52w1ALnDSE/WXO22o67S25AK6oM5v A2oIXBiCQSpev9j2eiTWHAZ865/ciXYgPSs6F9RFQeVpJmrz7/5Fi2LdhL46GdRLKh90 JPnw== X-Gm-Message-State: APjAAAWf3qAGBgZb8uKS49+xvzfTpLg3qo4rEedIOpAvEUfyVG2ja1oA e7Rw8qq0Ul+iTnPwK0ubtlEAFCeR+w== X-Received: by 2002:ae9:e007:: with SMTP id m7mr2877964qkk.87.1565647918275; Mon, 12 Aug 2019 15:11:58 -0700 (PDT) Date: Mon, 12 Aug 2019 15:11:54 -0700 Message-Id: <20190812221154.46875-1-yabinc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH v2] coresight: tmc-etr: Fix updating buffer in not-snapshot mode. From: Yabin Cui To: Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yabin Cui Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TMC etr always copies all available data to perf aux buffer, which may exceed the available space in perf aux buffer. It isn't suitable for not-snapshot mode, because: 1) It may overwrite previously written data. 2) It may make the perf_event_mmap_page->aux_head report having more or less data than the reality. So change to only copy the latest data fitting the available space in perf aux buffer. Signed-off-by: Yabin Cui --- v1 -> v2: copy the latest data instead of the earliest data. --- .../hwtracing/coresight/coresight-tmc-etr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 17006705287a..676dcb4cf0e2 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1410,9 +1410,10 @@ static void tmc_free_etr_buffer(void *config) * tmc_etr_sync_perf_buffer: Copy the actual trace data from the hardware * buffer to the perf ring buffer. */ -static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) +static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf, + unsigned long to_copy) { - long bytes, to_copy; + long bytes; long pg_idx, pg_offset, src_offset; unsigned long head = etr_perf->head; char **dst_pages, *src_buf; @@ -1422,8 +1423,7 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) pg_idx = head >> PAGE_SHIFT; pg_offset = head & (PAGE_SIZE - 1); dst_pages = (char **)etr_perf->pages; - src_offset = etr_buf->offset; - to_copy = etr_buf->len; + src_offset = etr_buf->offset + etr_buf->len - to_copy; while (to_copy > 0) { /* @@ -1434,6 +1434,8 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) * 3) what is available in the destination page. * in one iteration. */ + if (src_offset >= etr_buf->size) + src_offset -= etr_buf->size; bytes = tmc_etr_buf_get_data(etr_buf, src_offset, to_copy, &src_buf); if (WARN_ON_ONCE(bytes <= 0)) @@ -1454,8 +1456,6 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) /* Move source pointers */ src_offset += bytes; - if (src_offset >= etr_buf->size) - src_offset -= etr_buf->size; } } @@ -1501,7 +1501,11 @@ tmc_update_etr_buffer(struct coresight_device *csdev, spin_unlock_irqrestore(&drvdata->spinlock, flags); size = etr_buf->len; - tmc_etr_sync_perf_buffer(etr_perf); + if (!etr_perf->snapshot && size > handle->size) { + size = handle->size; + lost = true; + } + tmc_etr_sync_perf_buffer(etr_perf, size); /* * In snapshot mode we simply increment the head by the number of byte -- 2.23.0.rc1.153.gdeed80330f-goog