All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Hanjun Guo <guohanjun@huawei.com>,
	Sudeep Holla <sudeep.holla@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, James Morse <james.morse@arm.com>,
	Ben Horgan <ben.horgan@arm.com>,
	Reinette Chatre <reinette.chatre@intel.com>,
	Fenghua Yu <fenghuay@nvidia.com>,
	Srivathsa L Rao <srivathsa.rao@oss.qualcomm.com>,
	Ganapatrao Kulkarni <ganapatrao.kulkarni@oss.qualcomm.com>,
	Trilok Soni <tsoni@quicinc.com>,
	Srinivas Ramana <sramana@qti.qualcomm.com>,
	Niyas Sait <niyas.sait@arm.com>, Lee Trager <lee@trager.us>,
	linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 01/10] arm_mpam: let low level MSC accessors return an error
Date: Tue, 28 Jul 2026 17:35:07 +0200	[thread overview]
Message-ID: <fb4a7883-2ef5-4ca9-b375-e1a8d3ad111d@arm.com> (raw)
In-Reply-To: <20260727231231.62baa831@jic23-huawei>

Hi Jonathan,

On 7/28/26 00:12, Jonathan Cameron wrote:
> On Thu, 23 Jul 2026 17:54:45 +0200
> Andre Przywara <andre.przywara@arm.com> wrote:
> 
>> The upcoming MPAM-Fb support does not use MMIO primitives to access an
>> MSC, but employs a shared-memory/doorbell based firmware protocol.
>> Its complexity means that is must be able to handle errors, whereas we
> 
> that it must
> 
>> always assume an MMIO based MSC access succeeds today.
>>
>> Change the __mpam_read_reg() low level accessor function to return the
>> requested data through a pointer, and return an error code instead.
>> Also change the __mpam_write_reg() accessor function to return an error
>> code. At the moment this is always 0, but this will change with alternative
>> MSC access methods.
> 
> Be consistent on paragraph formatting.  So blank line here.  Check whole
> series for such tiny consistency problems.
> 
>> Change all direct users of those MSC wrappers to comply with the new
>> prototypes, though the errors are not propagated all the way up yet.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> 
> Some comments inline.  A few are 'whilst you are here let us make this
> more readable'.  I was in two minds about the temporary lack of handling
> of uninitialised (looking) variables but in the interests of expediency
> I suppose we can rely on the functions never actually failing at this
> point in the series.

I probably should have made this explicit in at least the cover letter, 
but that was the intention: for most of the patches, the lower level 
functions only ever return 0, so no error path will be triggered at this 
point. This allows to code to grow more slowly, and remaining issues are 
then fixed in later patches (7/10-9/10), before only the last patch 
actually activates MPAM-Fb, and introduces the possibility of an error 
return. So there is no real functional change, it's all refactoring.
Interestingly Sashiko missed that, many complaints are about things that 
cannot happen before patch 10/10.

I will add a comment to that effect to the commit message and the cover 
letter.

> I will note that if you did adding the returns from outer calls to inner
> you wouldn't get this problem.  However you might get other problems!

Thanks for the suggestion, I might try it the next time I encounter a 
similar problem! I briefly looked at applying it here, but already 
struggled to identify those outer functions. So I think this "lower 
level first" is still more comprehensible.

>> ---
>>   drivers/resctrl/mpam_devices.c | 204 +++++++++++++++++++++------------
>>   1 file changed, 130 insertions(+), 74 deletions(-)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
>> index b69f99488111..912c21ce7f9f 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
> 
> 
> 
>> -static u64 mpam_msc_read_idr(struct mpam_msc *msc)
>> +static int mpam_msc_read_idr(struct mpam_msc *msc, u64 *res)
>>   {
>> -	u64 idr_high = 0, idr_low;
>> +	u32 idr_high = 0, idr_low;
>> +	int ret;
>>   
>>   	lockdep_assert_held(&msc->part_sel_lock);
>>   
>> -	idr_low = mpam_read_partsel_reg(msc, IDR);
>> -	if (FIELD_GET(MPAMF_IDR_EXT, idr_low))
>> -		idr_high = mpam_read_partsel_reg(msc, IDR + 4);
>> +	ret = mpam_read_partsel_reg(msc, IDR, &idr_low);
>> +	if (ret)
>> +		return ret;
>> +
>> +	if (FIELD_GET(MPAMF_IDR_EXT, idr_low)) {
>> +		ret = mpam_read_partsel_reg(msc, IDR + 4, &idr_high);
>> +		if (ret)
>> +			return ret;
>> +	}
> As a whilst you are here type of comment. I'd find this more obvious if it were
> 
> 	} else {
> 		idr_high = 0;
> 	}
> 
> rather than assign a default at top of what is now a rather more complex function.

I see what you mean, makes sense.

>>   
>> -	return (idr_high << 32) | idr_low;
>> +	*res = ((u64)idr_high << 32) | idr_low;
>> +
>> +	return 0;
>>   }
> 
> 
>>   
>> -static u64 mpam_msc_read_esr(struct mpam_msc *msc)
>> +static int mpam_msc_read_esr(struct mpam_msc *msc, u64 *res)
>>   {
>> -	u64 esr_high = 0, esr_low;
>> +	u32 esr_high = 0, esr_low;
>> +	int ret;
>>   
>> -	esr_low = __mpam_read_reg(msc, MPAMF_ESR);
>> -	if (msc->has_extd_esr)
>> -		esr_high = __mpam_read_reg(msc, MPAMF_ESR + 4);
>> +	ret = __mpam_read_reg(msc, MPAMF_ESR, &esr_low);
>> +	if (ret)
>> +		return ret;
>>   
>> -	return (esr_high << 32) | esr_low;
>> +	if (msc->has_extd_esr) {
>> +		ret = __mpam_read_reg(msc, MPAMF_ESR + 4, &esr_high);
>> +		if (ret)
>> +			return ret;
>> +	}
> 
> Same as the other example above.  } else { esr_high = 0; }
> would be slightly clearer now this whole function has gotten more complex.
> 
>> +
>> +	*res = ((u64)esr_high << 32) | esr_low;
>> +
>> +	return 0;
>>   }
>>   
> 
>>   int mpam_register_requestor(u16 partid_max, u8 pmg_max)
>> @@ -774,13 +810,13 @@ static bool mpam_ris_hw_probe_csu_nrdy(struct mpam_msc_ris *ris)
>>   	mpam_write_monsel_reg(msc, CFG_CSU_CTL, ctl_val);
>>   
>>   	_mpam_write_monsel_reg(msc, MSMON_CSU, MSMON___NRDY);
>> -	now = _mpam_read_monsel_reg(msc, MSMON_CSU);
>> +	_mpam_read_monsel_reg(msc, MSMON_CSU, &now);
> 
> If an error were to occur and "now" not get assigned, would this being
> accessing undefined data? 

But there will be no error at this point, as __mpam_read_reg() 
unconditionally still returns 0. And this missing error code check will 
be fixed in a later patch, before proper error returns get enabled.

If checking return values doesn't make sense
> in here it should still not result in something static analysis might
> get annoyed by.  This gets cleaned up in next patch so maybe that
> is just about ok.  Alternative would be to just initialize any such
> variables in this patch and drop those initializations in next.
> Doing it just above the code that is going to change anyway would be cleanest.
> 
> 	now = 0;
> 	_mpam_read_monsel_reg(msc, MSMON_CSU, &now);
> 
> for example.
> 
> Hmm. I suppose this is a bit of a special case because we know the
> calls don't return errors at this point in the set.
> 
> So whilst I don't like it I'll not insist that you fix all the
> instances of this.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>

Thanks!

Cheers,
Andre

> 
> 
> 
> 
> 
>>   	can_set = now & MSMON___NRDY;
>>   
>>   	_mpam_write_monsel_reg(msc, MSMON_CSU, 0);
>>   	/* Configuration change to try and coax hardware into setting nrdy */
>>   	mpam_write_monsel_reg(msc, CFG_CSU_FLT, 0x1);
>> -	now = _mpam_read_monsel_reg(msc, MSMON_CSU);
>> +	_mpam_read_monsel_reg(msc, MSMON_CSU, &now);
>>   	can_clear = !(now & MSMON___NRDY);



  reply	other threads:[~2026-07-28 15:35 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 15:54 [PATCH v4 00/10] arm_mpam: Add MPAM-Fb firmware support Andre Przywara
2026-07-23 15:54 ` [PATCH v4 01/10] arm_mpam: let low level MSC accessors return an error Andre Przywara
2026-07-27 22:12   ` Jonathan Cameron
2026-07-28 15:35     ` Andre Przywara [this message]
2026-07-23 15:54 ` [PATCH v4 02/10] arm_mpam: propagate MSC access errors for hw_probe functions Andre Przywara
2026-07-27 22:21   ` Jonathan Cameron
2026-07-23 15:54 ` [PATCH v4 03/10] arm_mpam: propagate MSC access errors for MBWU counters Andre Przywara
2026-07-27 22:37   ` Jonathan Cameron
2026-07-23 15:54 ` [PATCH v4 04/10] arm_mpam: propagate MSC access errors for msmon helpers Andre Przywara
2026-07-27 22:41   ` Jonathan Cameron
2026-07-23 15:54 ` [PATCH v4 05/10] arm_mpam: propagate MSC access errors for __ris_msmon_read() Andre Przywara
2026-07-24 10:02   ` Sudeep Holla
2026-07-24 11:17     ` Andre Przywara
2026-07-24 12:19       ` Sudeep Holla
2026-07-27 22:44   ` Jonathan Cameron
2026-07-23 15:54 ` [PATCH v4 06/10] arm_mpam: propagate MSC access errors for state saving function Andre Przywara
2026-07-24 10:07   ` Sudeep Holla
2026-07-24 11:19     ` Andre Przywara
2026-07-24 12:27       ` Sudeep Holla
2026-07-24 16:43         ` Ben Horgan
2026-07-27 22:51           ` Jonathan Cameron
2026-07-28  8:43             ` Ben Horgan
2026-07-27 22:46   ` Jonathan Cameron
2026-07-23 15:54 ` [PATCH v4 07/10] arm_mpam: prepare mon_sel locking for MPAM-Fb Andre Przywara
2026-07-24 16:56   ` Ben Horgan
2026-07-23 15:54 ` [PATCH v4 08/10] arm_mpam: add MPAM-Fb MSC firmware access support Andre Przywara
2026-07-24  9:55   ` Sudeep Holla
2026-07-24 11:17     ` Andre Przywara
2026-07-24 12:22       ` Sudeep Holla
2026-07-24 17:08   ` Ben Horgan
2026-07-24 18:03     ` Sudeep Holla
2026-07-28 12:27       ` Andre Przywara
2026-07-28 16:04     ` Andre Przywara
2026-07-27 23:22   ` Jonathan Cameron
2026-07-28  6:27   ` Srivathsa L Rao
2026-07-28 16:19     ` Andre Przywara
     [not found]   ` <20260728100421.4047928-1-ritwick.sharma@arm.com>
2026-07-28 10:24     ` Andre Przywara
2026-07-23 15:54 ` [PATCH v4 09/10] arm_mpam: prevent MPAM-Fb accesses inside IRQ handler Andre Przywara
2026-07-24 16:52   ` Ben Horgan
2026-07-23 15:54 ` [PATCH v4 10/10] arm_mpam: detect and enable MPAM-Fb PCC support Andre Przywara
2026-07-24 10:18   ` Sudeep Holla
2026-07-27 12:48     ` Lorenzo Pieralisi
2026-07-27 13:20       ` Sudeep Holla
2026-07-27 13:33         ` Lorenzo Pieralisi
2026-07-27 13:39           ` Sudeep Holla
2026-07-27 13:39         ` Andre Przywara
2026-07-27 16:27   ` Srivathsa L Rao
2026-07-27 23:36     ` Jonathan Cameron

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=fb4a7883-2ef5-4ca9-b375-e1a8d3ad111d@arm.com \
    --to=andre.przywara@arm.com \
    --cc=ben.horgan@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=fenghuay@nvidia.com \
    --cc=ganapatrao.kulkarni@oss.qualcomm.com \
    --cc=guohanjun@huawei.com \
    --cc=james.morse@arm.com \
    --cc=jic23@kernel.org \
    --cc=lee@trager.us \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=niyas.sait@arm.com \
    --cc=rafael@kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=sramana@qti.qualcomm.com \
    --cc=srivathsa.rao@oss.qualcomm.com \
    --cc=sudeep.holla@kernel.org \
    --cc=tsoni@quicinc.com \
    --cc=will@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.