Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Athira Rajeev" <atrajeev@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH V5 1/6] powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro data
Date: Fri, 07 Aug 2026 14:58:29 +0000	[thread overview]
Message-ID: <20260807145830.4707D1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260807143734.1224-2-atrajeev@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing state reset in htm_event_del() causes spurious STOP and DECONFIGURE hcalls on subsequent htm_event_add() failures.
--

--- Patch [1]: [PATCH V5 1/6] powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro data ---
commit 482e76cb25a86207519e7500e8ca689e3b600e86
Author: Athira Rajeev <atrajeev@linux.ibm.com>

powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro data

This commit adds a new PMU driver for the Hardware Trace Macro (HTM) on
POWER systems. It maps the PMU lifecycle to HTM hypervisor calls and 
implements state tracking to handle hcall retries and error conditions.

> diff --git a/arch/powerpc/perf/htm-perf.c b/arch/powerpc/perf/htm-perf.c
> new file mode 100644
> index 0000000000000..cbe4f62813ee0
> --- /dev/null
> +++ b/arch/powerpc/perf/htm-perf.c
[ ... ]
> +static void htm_event_del(struct perf_event *event, int flags)
> +{
> +	int rc, ret, retries = 0;
> +	struct htm_target_id *target = event->pmu_private;
> +	struct htm_config cfg = target->cfg;
[ ... ]
> +	htm_event_stop(event, 0);
> +
> +	/*
> +	 * Only issue H_HTM_OP_DECONFIGURE if this driver successfully issued
> +	 * the paired H_HTM_OP_CONFIGURE.  If htm_event_add() failed before or
> +	 * during CONFIGURE (configured == 0), there is nothing to tear down.
> +	 * Issuing DECONFIGURE without a prior CONFIGURE would silently destroy
> +	 * a concurrent trace session that owns the same hardware target and
> +	 * produce spurious pr_err() noise for an expected H_STATE / H_NOT_AVAILABLE
> +	 * response.
> +	 */
> +	if (!target->configured)
> +		return;
> +
> +	/*
> +	 * Deconfigure the hardware resource.  Only H_BUSY is retried.
> +	 * If H_LONG_BUSY_* or any other error is returned, the resource
> +	 * cannot be reclaimed in this atomic context; log the failure so it
> +	 * is visible in the kernel log.
> +	 */
> +	do {
> +		rc = htm_hcall_wrapper(htmflags, cfg.nodeindex, cfg.nodalchipindex,
> +				       cfg.coreindexonchip, cfg.htmtype,
> +				       H_HTM_OP_DECONFIGURE, 0, 0, 0);
> +		ret = htm_return_check(rc);
> +	} while (ret == -EBUSY && ++retries < MAX_RETRIES);
> +	if (ret <= 0) {
> +		pr_err("DECONFIGURE failed in htm event del (ret=%d) node:%u chip:%u core:%u type:%u;\n",
> +				ret, cfg.nodeindex, cfg.nodalchipindex, cfg.coreindexonchip, cfg.htmtype);
> +	}
> +	/* pmu_private freed by event->destroy = reset_htm_active */
> +}

[Severity: High]
Does this code need to reset target->configured to 0 after issuing the
H_HTM_OP_DECONFIGURE hcall?

If Process A disables an event via ioctl(PERF_EVENT_IOC_DISABLE),
htm_event_del() correctly deconfigures the hardware but leaves
target->configured as 1.

If Process B then opens and enables the same HTM target, it takes ownership.
If Process A subsequently re-enables its event, the H_HTM_OP_CONFIGURE in
htm_event_add() will fail. When Process A's htm_event_del() runs on the
error path, it will see the stale configured == 1 state and spuriously issue
H_HTM_OP_DECONFIGURE. 

Can this silently destroy Process B's active trace?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260807143734.1224-1-atrajeev@linux.ibm.com?part=1

  reply	other threads:[~2026-08-07 14:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 14:37 [PATCH V5 0/6] powerpc/perf: Add HTM PMU driver and perf AUX support Athira Rajeev
2026-08-07 14:37 ` [PATCH V5 1/6] powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro data Athira Rajeev
2026-08-07 14:58   ` sashiko-bot [this message]
2026-08-07 14:37 ` [PATCH V5 2/6] powerpc/perf: Reject duplicate HTM target reservations Athira Rajeev
2026-08-07 14:37 ` [PATCH V5 3/6] powerpc/perf: Add AUX buffer management to capture HTM trace data Athira Rajeev
2026-08-07 14:57   ` sashiko-bot
2026-08-07 14:37 ` [PATCH V5 4/6] powerpc/perf: Capture the HTM memory configuration as part of perf data Athira Rajeev
2026-08-07 14:51   ` sashiko-bot
2026-08-07 14:37 ` [PATCH V5 5/6] docs: ABI: sysfs-bus-event_source-devices-htm: Document sysfs event format entries for htm pmu Athira Rajeev
2026-08-07 14:37 ` [PATCH V5 6/6] powerpc/perf/htm: Add documentation for Hardware Trace Macro PMU Athira Rajeev
2026-08-07 14:45   ` sashiko-bot

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=20260807145830.4707D1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atrajeev@linux.ibm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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