[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <OS3PR01MB9269843612B7E4980721A830F3099@OS3PR01MB9269.jpnprd01.prod.outlook.com>
Date: Fri, 18 Nov 2022 06:59:06 +0000
From: "Masahiko Yamada (Fujitsu)" <yamada.masahiko@...itsu.com>
To: "Itaru Kitayama (Fujitsu)" <itaru.kitayama@...itsu.com>
CC: "acme@...nel.org" <acme@...nel.org>,
"alexander.shishkin@...ux.intel.com"
<alexander.shishkin@...ux.intel.com>,
"jolsa@...nel.org" <jolsa@...nel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-perf-users@...r.kernel.org" <linux-perf-users@...r.kernel.org>,
"mark.rutland@....com" <mark.rutland@....com>,
"mingo@...hat.com" <mingo@...hat.com>,
"namhyung@...nel.org" <namhyung@...nel.org>,
"peterz@...radead.org" <peterz@...radead.org>
Subject: RE: [PATCH 1/1] perf: fix reset interface potential failure
Itaru san
> -----Original Message-----
> From: Itaru Kitayama <itaru.kitayama@...itsu.com>
> Sent: Friday, November 18, 2022 2:12 PM
> To: Yamada, Masahiko/山田 雅彦 <yamada.masahiko@...itsu.com>
> Cc: acme@...nel.org; alexander.shishkin@...ux.intel.com; jolsa@...nel.org;
> linux-kernel@...r.kernel.org; linux-perf-users@...r.kernel.org;
> mark.rutland@....com; mingo@...hat.com; namhyung@...nel.org;
> peterz@...radead.org
> Subject: [PATCH 1/1] perf: fix reset interface potential failure
>
> On Fri, Nov 18, 2022 at 11:00:16AM +0900, Masahiko wrote:
> > There is a potential bug where PERF_EVENT_IOC_RESET does not work
> when
> > accessing PMU registers directly from userspace in the perf_event
> > interface.
> > we have created a patch on the kernel
> > that fixes a potential perf_event reset failure.
> >
> > The motivation is to initialize pc->offset.
> > The perf_mmap__read_self function in tools/lib/perf/mmap.c is set by:.
> > cnt = READ_ONCE(pc->offset);
> > The pc->offset value is set in the following process in the
> > perf_event_update_userpage function:.
> > userpg->offset -= local64_read(&event->hw.prev_count);
> > hw->prev_count is set in the armpmu_event_set_period function
> > in drivers/perf/arm_pmu.c and in the x86_perf_event_set_period
> > function in arch/x86/events/core.c as follows:.
> > local64_set(&hwc->prev_count, (u64)-left);
> >
> > Therefore, this patch was created to initialize hwc->prev_count during
> > reset processing.
> >
> > Signed-off-by: Masahiko, Yamada <yamada.masahiko@...itsu.com>
> > ---
> > kernel/events/core.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/kernel/events/core.c b/kernel/events/core.c index
> > 4ec3717003d5..296549755a9c 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -5468,8 +5468,13 @@ static __poll_t perf_poll(struct file *file,
> > poll_table *wait)
> >
> > static void _perf_event_reset(struct perf_event *event) {
> > + struct hw_perf_event *hwc = &event->hw;
> > + s64 left;
> > +
> > (void)perf_event_read(event, false);
> > local64_set(&event->count, 0);
> > + left = local64_read(&hwc->period_left);
> > + local64_set(&hwc->prev_count, (u64)-left);
> > perf_event_update_userpage(event);
> > }
> >
> > --
> > 2.27.0
>
> Reviewed-by: Itaru Kitayama <itaru.kitayama@...itsu.com>
Thank you for your review.
Masahiko Yamada
Powered by blists - more mailing lists