[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <90c483a2-a7e0-4c87-a3da-8643bec63879@nvidia.com>
Date: Wed, 12 Nov 2025 19:50:41 -0800
From: Fenghua Yu <fenghuay@...dia.com>
To: Ben Horgan <ben.horgan@....com>, james.morse@....com
Cc: amitsinght@...vell.com, baisheng.gao@...soc.com,
baolin.wang@...ux.alibaba.com, bobo.shaobowang@...wei.com,
carl@...amperecomputing.com, catalin.marinas@....com, dakr@...nel.org,
dave.martin@....com, david@...hat.com, dfustini@...libre.com,
gregkh@...uxfoundation.org, gshan@...hat.com, guohanjun@...wei.com,
jeremy.linton@....com, jonathan.cameron@...wei.com, kobak@...dia.com,
lcherian@...vell.com, lenb@...nel.org, linux-acpi@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
lpieralisi@...nel.org, peternewman@...gle.com, quic_jiles@...cinc.com,
rafael@...nel.org, robh@...nel.org, rohit.mathew@....com,
scott@...amperecomputing.com, sdonthineni@...dia.com, sudeep.holla@....com,
tan.shaopeng@...itsu.com, will@...nel.org, xhao@...ux.alibaba.com,
Shaopeng Tan <tan.shaopeng@...fujitsu.com>
Subject: Re: [PATCH 14/33] arm_mpam: Probe hardware to find the supported
partid/pmg values
Hi, Ben and James,
On 11/7/25 04:34, Ben Horgan wrote:
> From: James Morse <james.morse@....com>
[SNIP]
> +static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc,
> + u8 ris_idx)
> +{
> + int err;
> + struct mpam_msc_ris *ris;
> +
> + lockdep_assert_held(&mpam_list_lock);
> +
> + if (!test_bit(ris_idx, &msc->ris_idxs)) {
> + err = mpam_ris_create_locked(msc, ris_idx, MPAM_CLASS_UNKNOWN,
> + 0, 0);
> + if (err)
> + return ERR_PTR(err);
> + }
> +
> + list_for_each_entry(ris, &msc->ris, msc_list) {
> + if (ris->ris_idx == ris_idx)
> + return ris;
> + }
> +
> + return ERR_PTR(-ENOENT);
> +}
> +
> static int mpam_msc_hw_probe(struct mpam_msc *msc)
> {
> u64 idr;
> + u16 partid_max;
> + u8 ris_idx, pmg_max;
> + struct mpam_msc_ris *ris;
> struct device *dev = &msc->pdev->dev;
>
> lockdep_assert_held(&msc->probe_lock);
> @@ -464,6 +564,40 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)
> return -EIO;
> }
>
> + /* Grab an IDR value to find out how many RIS there are */
> + mutex_lock(&msc->part_sel_lock);
> + idr = mpam_msc_read_idr(msc);
> + mutex_unlock(&msc->part_sel_lock);
> +
> + msc->ris_max = FIELD_GET(MPAMF_IDR_RIS_MAX, idr);
> +
> + /* Use these values so partid/pmg always starts with a valid value */
> + msc->partid_max = FIELD_GET(MPAMF_IDR_PARTID_MAX, idr);
> + msc->pmg_max = FIELD_GET(MPAMF_IDR_PMG_MAX, idr);
> +
> + for (ris_idx = 0; ris_idx <= msc->ris_max; ris_idx++) {
> + mutex_lock(&msc->part_sel_lock);
> + __mpam_part_sel(ris_idx, 0, msc);
> + idr = mpam_msc_read_idr(msc);
> + mutex_unlock(&msc->part_sel_lock);
> +
> + partid_max = FIELD_GET(MPAMF_IDR_PARTID_MAX, idr);
> + pmg_max = FIELD_GET(MPAMF_IDR_PMG_MAX, idr);
> + msc->partid_max = min(msc->partid_max, partid_max);
> + msc->pmg_max = min(msc->pmg_max, pmg_max);
> +
> + mutex_lock(&mpam_list_lock);
> + ris = mpam_get_or_create_ris(msc, ris_idx);
> + mutex_unlock(&mpam_list_lock);
> + if (IS_ERR(ris))
> + return PTR_ERR(ris);
It's better to destroy ris's that were previously created before this
failed ris? Otherwise, there is a memory leak for those allocated ris's?
Thanks.
-Fenghua
Powered by blists - more mailing lists