mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/resctrl: Do not round up mba_MBps values in schemata file
@ 2024-09-27 22:30 Tony Luck
  2024-09-27 22:46 ` Reinette Chatre
  0 siblings, 1 reply; 3+ messages in thread
From: Tony Luck @ 2024-09-27 22:30 UTC (permalink / raw)
  To: Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman, Peter Newman,
	James Morse, Babu Moger, Drew Fustini, Dave Martin,
	Borislav Petkov
  Cc: x86, linux-kernel, patches, Tony Luck

When the mba_MBps mount option is used Linux initializes the
MBA control values in the schemata file to MBA_MAX_MBPS (which
is defined as U32_MAX). So the schemata file contains this line:

 MB:0=4294967295;1=4294967295

If a user edits the schemata file with vi(1) (or other editor) and
simply writes that line back, it gets changed to:

  MB:0=   4;1=   4

which sets maximum bandwidth to a very low value.

This happens because bw_validate() unconditionally rounds user supplied
values up to next multiple of r->membw.bw_gran. That results in a value
that will not fit into d->mbps_val[closid].

Rounding up only makes sense when mba_MBps is not enabled and control
values are expressed as percentage values.

Skip the roundup() when mba_MBps is enabled.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 50fa1fe9a073..ac636366c0cb 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -55,7 +55,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
 		return false;
 	}
 
-	*data = roundup(bw, (unsigned long)r->membw.bw_gran);
+	*data = is_mba_sc(r) ? bw : roundup(bw, (unsigned long)r->membw.bw_gran);
 	return true;
 }
 
-- 
2.46.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/resctrl: Do not round up mba_MBps values in schemata file
  2024-09-27 22:30 [PATCH] x86/resctrl: Do not round up mba_MBps values in schemata file Tony Luck
@ 2024-09-27 22:46 ` Reinette Chatre
  2024-09-27 23:03   ` Luck, Tony
  0 siblings, 1 reply; 3+ messages in thread
From: Reinette Chatre @ 2024-09-27 22:46 UTC (permalink / raw)
  To: Tony Luck, Fenghua Yu, Maciej Wieczor-Retman, Peter Newman,
	James Morse, Babu Moger, Drew Fustini, Dave Martin,
	Borislav Petkov, Martin Kletzander
  Cc: x86, linux-kernel, patches

+Martin

Hi Tony,

On 9/27/24 3:30 PM, Tony Luck wrote:
> When the mba_MBps mount option is used Linux initializes the
> MBA control values in the schemata file to MBA_MAX_MBPS (which
> is defined as U32_MAX). So the schemata file contains this line:
> 
>  MB:0=4294967295;1=4294967295
> 
> If a user edits the schemata file with vi(1) (or other editor) and
> simply writes that line back, it gets changed to:
> 
>   MB:0=   4;1=   4
> 
> which sets maximum bandwidth to a very low value.
> 
> This happens because bw_validate() unconditionally rounds user supplied
> values up to next multiple of r->membw.bw_gran. That results in a value
> that will not fit into d->mbps_val[closid].
> 
> Rounding up only makes sense when mba_MBps is not enabled and control
> values are expressed as percentage values.
> 
> Skip the roundup() when mba_MBps is enabled.
> 
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---

A fix for this issue is already being discussed. Please see latest fix
at [1] that additionally addresses the issue if a user attempts to 
write a value larger than 4294967295. Could you please check if that
fix works for you?

Thank you.

Reinette

[1] https://lore.kernel.org/all/a7c80676-0761-4618-ac07-0b53434b1a9b@intel.com/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] x86/resctrl: Do not round up mba_MBps values in schemata file
  2024-09-27 22:46 ` Reinette Chatre
@ 2024-09-27 23:03   ` Luck, Tony
  0 siblings, 0 replies; 3+ messages in thread
From: Luck, Tony @ 2024-09-27 23:03 UTC (permalink / raw)
  To: Chatre, Reinette, Yu, Fenghua, Wieczor-Retman, Maciej,
	Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
	Borislav Petkov, Martin Kletzander
  Cc: x86, linux-kernel, patches

> A fix for this issue is already being discussed. Please see latest fix
> at [1] that additionally addresses the issue if a user attempts to 
> write a value larger than 4294967295. Could you please check if that
> fix works for you?

That one looks more complete. My patch only covered the case for overflow
during roundup. That one uses kstrtou32() instead of kstrtoul() so will also
catch the case where a user enters a value bigger that U32_MAX.

-Tony

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-27 23:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-27 22:30 [PATCH] x86/resctrl: Do not round up mba_MBps values in schemata file Tony Luck
2024-09-27 22:46 ` Reinette Chatre
2024-09-27 23:03   ` Luck, Tony

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®