From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Stuart Summers <stuart.summers@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 2/2] drm/i915: Only disable PMU on stop if not already closed
Date: Thu, 4 Aug 2022 09:46:33 +0100 [thread overview]
Message-ID: <e5e6bd39-de83-63bf-4798-8a58a5328720@linux.intel.com> (raw)
In-Reply-To: <20220803230325.137593-2-stuart.summers@intel.com>
On 04/08/2022 00:03, Stuart Summers wrote:
> There can be a race in the PMU process teardown vs the
> time when the driver is unbound in which the user attempts
> to stop the PMU process, but the actual data structure
> in the kernel is no longer available. Avoid this use-after-free
> by skipping the PMU disable in i915_pmu_event_stop() when
> the PMU has already been closed/unregistered by the driver.
>
> Fixes: b00bccb3f0bb ("drm/i915/pmu: Handle PCI unbind")
> Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Signed-off-by: Stuart Summers <stuart.summers@intel.com>
> ---
> drivers/gpu/drm/i915/i915_pmu.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
> index 958b37123bf12..0d02f338118e4 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.c
> +++ b/drivers/gpu/drm/i915/i915_pmu.c
> @@ -760,9 +760,17 @@ static void i915_pmu_event_start(struct perf_event *event, int flags)
>
> static void i915_pmu_event_stop(struct perf_event *event, int flags)
> {
> + struct drm_i915_private *i915 =
> + container_of(event->pmu, typeof(*i915), pmu.base);
> + struct i915_pmu *pmu = &i915->pmu;
> +
> + if (pmu->closed)
> + goto out;
> +
> if (flags & PERF_EF_UPDATE)
> i915_pmu_event_read(event);
> i915_pmu_disable(event);
> +out:
> event->hw.state = PERF_HES_STOPPED;
> }
>
LGTM, although I am not sure who feels comfortable to r-b since we all
kind of suggested the same fix. :)
FWIW:
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Regards,
Tvrtko
next prev parent reply other threads:[~2022-08-04 8:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 23:03 [Intel-gfx] [PATCH 1/2] drm/i915: Fix NPD in PMU during driver teardown Stuart Summers
2022-08-03 23:03 ` [Intel-gfx] [PATCH 2/2] drm/i915: Only disable PMU on stop if not already closed Stuart Summers
2022-08-04 8:46 ` Tvrtko Ursulin [this message]
2022-08-04 18:56 ` Summers, Stuart
2022-08-04 23:26 ` Umesh Nerlige Ramappa
2022-08-03 23:50 ` [Intel-gfx] ✓ Fi.CI.BAT: success for series starting with [1/2] drm/i915: Fix NPD in PMU during driver teardown Patchwork
2022-08-04 6:29 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2022-08-04 8:42 ` [Intel-gfx] [PATCH 1/2] " Tvrtko Ursulin
2022-08-04 18:56 ` Summers, Stuart
2022-08-05 9:26 ` Tvrtko Ursulin
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=e5e6bd39-de83-63bf-4798-8a58a5328720@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=stuart.summers@intel.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