From: Leo Yan <leo.yan@arm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>,
James Clark <james.clark@linaro.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Junhao He <hejunhao3@h-partners.com>,
coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Michiel van Tol <michiel.vantol@arm.com>
Subject: Re: [PATCH] coresight: tmc: Fix overflow when calculating is bigger than 2GiB
Date: Mon, 23 Feb 2026 10:23:43 +0000 [thread overview]
Message-ID: <20260223102343.GK136967@e132581.arm.com> (raw)
In-Reply-To: <666e2c55-a1aa-4960-a084-50921ec7f696@arm.com>
On Mon, Feb 23, 2026 at 09:50:41AM +0000, Suzuki K Poulose wrote:
[...]
> > --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
> > +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> > @@ -154,7 +154,7 @@ tmc_pages_get_offset(struct tmc_pages *tmc_pages, dma_addr_t addr)
> > for (i = 0; i < tmc_pages->nr_pages; i++) {
> > page_start = tmc_pages->daddrs[i];
> > if (addr >= page_start && addr < (page_start + PAGE_SIZE))
> > - return i * PAGE_SIZE + (addr - page_start);
> > + return (long)i * PAGE_SIZE + (addr - page_start);
> > }
> > return -EINVAL;
> > @@ -1381,7 +1381,7 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
> > node = (event->cpu == -1) ? NUMA_NO_NODE : cpu_to_node(event->cpu);
> > /* Use the minimum limit if the required size is smaller */
> > - size = nr_pages << PAGE_SHIFT;
> > + size = (ssize_t)nr_pages << PAGE_SHIFT;
> > size = max_t(ssize_t, size, TMC_ETR_PERF_MIN_BUF_SIZE);
> > /*
> >
>
> Thanks for the fix. Could we not fix the declaration of the variables
> instead ? (Also add a comment to make sure people don't revert it back )
I thought a bit the variable declaration when worked on the patch, but
it is tricky.
"nr_pages" is passed down from the perf core layer as an int type. In
CoreSight, the value is passed down through several functions using the
same type, and it does not seem necessary to change the type in every
function in the call path.
We could silently use wider type for the "nr_pages" argument or the
index variable "i". As you said, we need comments to remind future
changing. This might be more error-prone than using an explicit
cast at the point of calculation ?
Thanks,
Leo
next prev parent reply other threads:[~2026-02-23 10:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 13:19 Leo Yan
2026-02-23 9:50 ` Suzuki K Poulose
2026-02-23 10:23 ` Leo Yan [this message]
2026-05-07 19:12 ` Suzuki K Poulose
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260223102343.GK136967@e132581.arm.com \
--to=leo.yan@arm.com \
--cc=coresight@lists.linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hejunhao3@h-partners.com \
--cc=james.clark@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=michiel.vantol@arm.com \
--cc=mike.leach@linaro.org \
--cc=suzuki.poulose@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®