Message ID | 20221118020016.1571100-2-yamada.masahiko@fujitsu.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp734938wrr; Thu, 17 Nov 2022 18:14:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4pPhguBpPGULuPH1wLIVLOUINRkSL8Li5FUw27pJTYjVMu2TRZV4K3noi0wrdb4HoSrknI X-Received: by 2002:a05:6402:f:b0:468:56c3:7c8 with SMTP id d15-20020a056402000f00b0046856c307c8mr4505735edu.109.1668737695814; Thu, 17 Nov 2022 18:14:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668737695; cv=none; d=google.com; s=arc-20160816; b=y6y4km+8AsAsV/UC/qFvm3JPcGj/ItD38ul5coxfvH99DCNyyjEIgiUYbzNb/2XTYt Kvbd9haEY8bReZ4bMqaasiEA1c5Jyg3A4lFKc1Ew0FRPobhVOTIXpQ8ZNno1aRE8r1Y9 6L8qn5JEkflADPQFKYJkDe3VMJwSUm8/onw8QAcQzYNqOeyhOsYJcczpAXFlRBvNxPHE Jf4eQThq26YgzN1fls0Pk7nu9CiL71cDQMVXB5YyRsD2KnDnwoJsePJR1C9aPkcdKNPV 4+JJAHexFdn28RkBokvpIXM1FuHpRkQMOH4m31eIUML3AYNGbw75jlyiaZFL165wKq98 jAWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0BVHaq9VqhxnOKuyOK/mDFqB2UTHQddzHXA/Gkk7Y5w=; b=PmLYqLeJ+adh79ilaixPCBrBE/sr6WevFlWmYzGEhzs3f0rJSXQOBrPMYB3qo8FuVt Qmz4U1kmehHhB4Xvx9I/WAI8F73rj6v3ouhyZxY67biKkCBqxagx2LEkXE2BkcAP149m d5I/6okQvT2GkLuwyUTFwrAK4fcWzux0BKF41vdVpBlPdniVVegdvbKjUxq7xPsYYyQR j+BLUlWnMJ3Uj3noNlvoAcch4zVvr6Ei9WfwIr6rY61H3hL32ryeywqjwnoCmaCwKooo 4w/07ZL1ZBv3sn6rR2WswlvYcDtb3jRUmlB/h3NyWPmNQaxqOzfpPNdPcWMQleBPkpZv JW+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs17-20020a170906dc9100b00791994dfb9esi2066830ejc.491.2022.11.17.18.14.32; Thu, 17 Nov 2022 18:14:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240840AbiKRCHx (ORCPT <rfc822;a1648639935@gmail.com> + 99 others); Thu, 17 Nov 2022 21:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240499AbiKRCHu (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 17 Nov 2022 21:07:50 -0500 X-Greylist: delayed 65 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 17 Nov 2022 18:07:36 PST Received: from esa9.hc1455-7.c3s2.iphmx.com (esa9.hc1455-7.c3s2.iphmx.com [139.138.36.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B0FD898F8; Thu, 17 Nov 2022 18:07:35 -0800 (PST) X-IronPort-AV: E=McAfee;i="6500,9779,10534"; a="84612510" X-IronPort-AV: E=Sophos;i="5.96,172,1665414000"; d="scan'208";a="84612510" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa9.hc1455-7.c3s2.iphmx.com with ESMTP; 18 Nov 2022 11:06:28 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 4750ADE51A; Fri, 18 Nov 2022 11:06:27 +0900 (JST) Received: from oym-om2.fujitsu.com (oym-om2.o.css.fujitsu.com [10.85.58.162]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 8D742CFF9D; Fri, 18 Nov 2022 11:06:26 +0900 (JST) Received: from cn-r05-10.example.com (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by oym-om2.fujitsu.com (Postfix) with ESMTP id 6789D40421239; Fri, 18 Nov 2022 11:06:26 +0900 (JST) From: "Masahiko, Yamada" <yamada.masahiko@fujitsu.com> To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] perf: fix reset interface potential failure Date: Fri, 18 Nov 2022 11:00:16 +0900 Message-Id: <20221118020016.1571100-2-yamada.masahiko@fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221118020016.1571100-1-yamada.masahiko@fujitsu.com> References: <20221118020016.1571100-1-yamada.masahiko@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749798176607571169?= X-GMAIL-MSGID: =?utf-8?q?1749798298309877224?= |
Series |
perf: fix reset interface potential failure
|
|
Commit Message
Masahiko Yamada (Fujitsu)
Nov. 18, 2022, 2 a.m. UTC
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@fujitsu.com>
---
kernel/events/core.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
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@fujitsu.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@fujitsu.com>
Itaru san > -----Original Message----- > From: Itaru Kitayama <itaru.kitayama@fujitsu.com> > Sent: Friday, November 18, 2022 2:12 PM > To: Yamada, Masahiko/山田 雅彦 <yamada.masahiko@fujitsu.com> > Cc: acme@kernel.org; alexander.shishkin@linux.intel.com; jolsa@kernel.org; > linux-kernel@vger.kernel.org; linux-perf-users@vger.kernel.org; > mark.rutland@arm.com; mingo@redhat.com; namhyung@kernel.org; > peterz@infradead.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@fujitsu.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@fujitsu.com> Thank you for your review. Masahiko Yamada
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); }