* [PATCH v5 1/2] x86/resctrl: Fix min_cbm_bits for AMD
2022-09-27 20:16 [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup Babu Moger
@ 2022-09-27 20:16 ` Babu Moger
2022-09-27 23:11 ` Yu, Fenghua
2022-09-27 20:16 ` [PATCH v5 2/2] x86/resctrl: Remove arch_has_empty_bitmaps Babu Moger
2022-10-18 16:26 ` [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup Reinette Chatre
2 siblings, 1 reply; 10+ messages in thread
From: Babu Moger @ 2022-09-27 20:16 UTC (permalink / raw)
To: corbet, reinette.chatre, tglx, mingo, bp
Cc: fenghua.yu, dave.hansen, x86, hpa, paulmck, akpm, quic_neeraju,
rdunlap, damien.lemoal, songmuchun, peterz, jpoimboe, pbonzini,
babu.moger, chang.seok.bae, pawan.kumar.gupta, jmattson,
daniel.sneddon, sandipan.das, tony.luck, james.morse, linux-doc,
linux-kernel, bagasdotme, eranian
AMD systems support zero CBM (capacity bit mask) for cache allocation.
That is reflected in rdt_init_res_defs_amd() by:
r->cache.arch_has_empty_bitmaps = true;
However given the unified code in cbm_validate(), checking for:
val == 0 && !arch_has_empty_bitmaps
is not enough because of another check in cbm_validate():
if ((zero_bit - first_bit) < r->cache.min_cbm_bits)
The default value of r->cache.min_cbm_bits = 1.
Leading to:
$ cd /sys/fs/resctrl
$ mkdir foo
$ cd foo
$ echo L3:0=0 > schemata
-bash: echo: write error: Invalid argument
$ cat /sys/fs/resctrl/info/last_cmd_status
Need at least 1 bits in the mask
Fix the issue by initializing the min_cbm_bits to 0 for AMD.
Also, remove the default setting of min_cbm_bits and initialize it
separately.
After the fix
$ cd /sys/fs/resctrl
$ mkdir foo
$ cd foo
$ echo L3:0=0 > schemata
$ cat /sys/fs/resctrl/info/last_cmd_status
ok
Link: https://lore.kernel.org/lkml/20220517001234.3137157-1-eranian@google.com/
Fixes: 316e7f901f5a ("x86/resctrl: Add struct rdt_cache::arch_has_{sparse, empty}_bitmaps")
Co-developed-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
arch/x86/kernel/cpu/resctrl/core.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index bb1c3f5f60c8..a5c51a14fbce 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -66,9 +66,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
.rid = RDT_RESOURCE_L3,
.name = "L3",
.cache_level = 3,
- .cache = {
- .min_cbm_bits = 1,
- },
.domains = domain_init(RDT_RESOURCE_L3),
.parse_ctrlval = parse_cbm,
.format_str = "%d=%0*x",
@@ -83,9 +80,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
.rid = RDT_RESOURCE_L2,
.name = "L2",
.cache_level = 2,
- .cache = {
- .min_cbm_bits = 1,
- },
.domains = domain_init(RDT_RESOURCE_L2),
.parse_ctrlval = parse_cbm,
.format_str = "%d=%0*x",
@@ -877,6 +871,7 @@ static __init void rdt_init_res_defs_intel(void)
r->cache.arch_has_sparse_bitmaps = false;
r->cache.arch_has_empty_bitmaps = false;
r->cache.arch_has_per_cpu_cfg = false;
+ r->cache.min_cbm_bits = 1;
} else if (r->rid == RDT_RESOURCE_MBA) {
hw_res->msr_base = MSR_IA32_MBA_THRTL_BASE;
hw_res->msr_update = mba_wrmsr_intel;
@@ -897,6 +892,7 @@ static __init void rdt_init_res_defs_amd(void)
r->cache.arch_has_sparse_bitmaps = true;
r->cache.arch_has_empty_bitmaps = true;
r->cache.arch_has_per_cpu_cfg = true;
+ r->cache.min_cbm_bits = 0;
} else if (r->rid == RDT_RESOURCE_MBA) {
hw_res->msr_base = MSR_IA32_MBA_BW_BASE;
hw_res->msr_update = mba_wrmsr_amd;
^ permalink raw reply related [flat|nested] 10+ messages in thread* RE: [PATCH v5 1/2] x86/resctrl: Fix min_cbm_bits for AMD
2022-09-27 20:16 ` [PATCH v5 1/2] x86/resctrl: Fix min_cbm_bits for AMD Babu Moger
@ 2022-09-27 23:11 ` Yu, Fenghua
0 siblings, 0 replies; 10+ messages in thread
From: Yu, Fenghua @ 2022-09-27 23:11 UTC (permalink / raw)
To: Babu Moger, corbet@lwn.net, Chatre, Reinette, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de
Cc: dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
paulmck@kernel.org, akpm@linux-foundation.org,
quic_neeraju@quicinc.com, rdunlap@infradead.org,
damien.lemoal@opensource.wdc.com, songmuchun@bytedance.com,
peterz@infradead.org, jpoimboe@kernel.org, pbonzini@redhat.com,
Bae, Chang Seok, pawan.kumar.gupta@linux.intel.com,
jmattson@google.com, daniel.sneddon@linux.intel.com,
sandipan.das@amd.com, Luck, Tony, james.morse@arm.com,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
bagasdotme@gmail.com, Eranian, Stephane
> AMD systems support zero CBM (capacity bit mask) for cache allocation.
> That is reflected in rdt_init_res_defs_amd() by:
>
> r->cache.arch_has_empty_bitmaps = true;
>
> However given the unified code in cbm_validate(), checking for:
> val == 0 && !arch_has_empty_bitmaps
>
> is not enough because of another check in cbm_validate():
>
> if ((zero_bit - first_bit) < r->cache.min_cbm_bits)
>
> The default value of r->cache.min_cbm_bits = 1.
>
> Leading to:
>
> $ cd /sys/fs/resctrl
> $ mkdir foo
> $ cd foo
> $ echo L3:0=0 > schemata
> -bash: echo: write error: Invalid argument
> $ cat /sys/fs/resctrl/info/last_cmd_status
> Need at least 1 bits in the mask
>
> Fix the issue by initializing the min_cbm_bits to 0 for AMD.
> Also, remove the default setting of min_cbm_bits and initialize it separately.
>
> After the fix
> $ cd /sys/fs/resctrl
> $ mkdir foo
> $ cd foo
> $ echo L3:0=0 > schemata
> $ cat /sys/fs/resctrl/info/last_cmd_status
> ok
>
> Link: https://lore.kernel.org/lkml/20220517001234.3137157-1-
> eranian@google.com/
> Fixes: 316e7f901f5a ("x86/resctrl: Add struct rdt_cache::arch_has_{sparse,
> empty}_bitmaps")
> Co-developed-by: Stephane Eranian <eranian@google.com>
> Signed-off-by: Stephane Eranian <eranian@google.com>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> Reviewed-by: Ingo Molnar <mingo@kernel.org>
> Reviewed-by: James Morse <james.morse@arm.com>
> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Fenghua Yu <fenghua.yu@intel.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 2/2] x86/resctrl: Remove arch_has_empty_bitmaps
2022-09-27 20:16 [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup Babu Moger
2022-09-27 20:16 ` [PATCH v5 1/2] x86/resctrl: Fix min_cbm_bits for AMD Babu Moger
@ 2022-09-27 20:16 ` Babu Moger
2022-09-27 23:20 ` Yu, Fenghua
2022-10-18 16:26 ` [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup Reinette Chatre
2 siblings, 1 reply; 10+ messages in thread
From: Babu Moger @ 2022-09-27 20:16 UTC (permalink / raw)
To: corbet, reinette.chatre, tglx, mingo, bp
Cc: fenghua.yu, dave.hansen, x86, hpa, paulmck, akpm, quic_neeraju,
rdunlap, damien.lemoal, songmuchun, peterz, jpoimboe, pbonzini,
babu.moger, chang.seok.bae, pawan.kumar.gupta, jmattson,
daniel.sneddon, sandipan.das, tony.luck, james.morse, linux-doc,
linux-kernel, bagasdotme, eranian
The field arch_has_empty_bitmaps is not required anymore. The field
min_cbm_bits is enough to validate the CBM (capacity bit mask) if the
architecture can support the zero CBM or not.
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
arch/x86/kernel/cpu/resctrl/core.c | 2 --
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 3 +--
include/linux/resctrl.h | 6 +++---
3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index a5c51a14fbce..c2657754672e 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -869,7 +869,6 @@ static __init void rdt_init_res_defs_intel(void)
if (r->rid == RDT_RESOURCE_L3 ||
r->rid == RDT_RESOURCE_L2) {
r->cache.arch_has_sparse_bitmaps = false;
- r->cache.arch_has_empty_bitmaps = false;
r->cache.arch_has_per_cpu_cfg = false;
r->cache.min_cbm_bits = 1;
} else if (r->rid == RDT_RESOURCE_MBA) {
@@ -890,7 +889,6 @@ static __init void rdt_init_res_defs_amd(void)
if (r->rid == RDT_RESOURCE_L3 ||
r->rid == RDT_RESOURCE_L2) {
r->cache.arch_has_sparse_bitmaps = true;
- r->cache.arch_has_empty_bitmaps = true;
r->cache.arch_has_per_cpu_cfg = true;
r->cache.min_cbm_bits = 0;
} else if (r->rid == RDT_RESOURCE_MBA) {
diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 87666275eed9..7f38c8bd8429 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -98,8 +98,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
return false;
}
- if ((!r->cache.arch_has_empty_bitmaps && val == 0) ||
- val > r->default_ctrl) {
+ if ((r->cache.min_cbm_bits > 0 && val == 0) || val > r->default_ctrl) {
rdt_last_cmd_puts("Mask out of range\n");
return false;
}
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 21deb5212bbd..46ed8589857c 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -72,11 +72,12 @@ struct rdt_domain {
/**
* struct resctrl_cache - Cache allocation related data
* @cbm_len: Length of the cache bit mask
- * @min_cbm_bits: Minimum number of consecutive bits to be set
+ * @min_cbm_bits: Minimum number of consecutive bits to be set.
+ * The value 0 means the architecture can support
+ * zero CBM.
* @shareable_bits: Bitmask of shareable resource with other
* executing entities
* @arch_has_sparse_bitmaps: True if a bitmap like f00f is valid.
- * @arch_has_empty_bitmaps: True if the '0' bitmap is valid.
* @arch_has_per_cpu_cfg: True if QOS_CFG register for this cache
* level has CPU scope.
*/
@@ -85,7 +86,6 @@ struct resctrl_cache {
unsigned int min_cbm_bits;
unsigned int shareable_bits;
bool arch_has_sparse_bitmaps;
- bool arch_has_empty_bitmaps;
bool arch_has_per_cpu_cfg;
};
^ permalink raw reply related [flat|nested] 10+ messages in thread* RE: [PATCH v5 2/2] x86/resctrl: Remove arch_has_empty_bitmaps
2022-09-27 20:16 ` [PATCH v5 2/2] x86/resctrl: Remove arch_has_empty_bitmaps Babu Moger
@ 2022-09-27 23:20 ` Yu, Fenghua
0 siblings, 0 replies; 10+ messages in thread
From: Yu, Fenghua @ 2022-09-27 23:20 UTC (permalink / raw)
To: Babu Moger, corbet@lwn.net, Chatre, Reinette, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de
Cc: dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
paulmck@kernel.org, akpm@linux-foundation.org,
quic_neeraju@quicinc.com, rdunlap@infradead.org,
damien.lemoal@opensource.wdc.com, songmuchun@bytedance.com,
peterz@infradead.org, jpoimboe@kernel.org, pbonzini@redhat.com,
Bae, Chang Seok, pawan.kumar.gupta@linux.intel.com,
jmattson@google.com, daniel.sneddon@linux.intel.com,
sandipan.das@amd.com, Luck, Tony, james.morse@arm.com,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
bagasdotme@gmail.com, Eranian, Stephane
> The field arch_has_empty_bitmaps is not required anymore. The field
> min_cbm_bits is enough to validate the CBM (capacity bit mask) if the
> architecture can support the zero CBM or not.
>
> Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Fenghua Yu <fenghua.yu@intel.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup
2022-09-27 20:16 [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup Babu Moger
2022-09-27 20:16 ` [PATCH v5 1/2] x86/resctrl: Fix min_cbm_bits for AMD Babu Moger
2022-09-27 20:16 ` [PATCH v5 2/2] x86/resctrl: Remove arch_has_empty_bitmaps Babu Moger
@ 2022-10-18 16:26 ` Reinette Chatre
2022-10-18 16:35 ` Borislav Petkov
2 siblings, 1 reply; 10+ messages in thread
From: Reinette Chatre @ 2022-10-18 16:26 UTC (permalink / raw)
To: tglx, mingo, bp, Dave Hansen, x86@kernel.org
Cc: fenghua.yu, hpa, paulmck, akpm, quic_neeraju, rdunlap,
damien.lemoal, songmuchun, peterz, jpoimboe, pbonzini,
chang.seok.bae, pawan.kumar.gupta, jmattson, daniel.sneddon,
sandipan.das, tony.luck, james.morse, linux-doc, linux-kernel,
bagasdotme, eranian, Jonathan Corbet, Babu Moger
Hi X86 Maintainers,
Could you please consider this fix and cleanup for inclusion?
Thank you very much
Reinette
On 9/27/2022 1:16 PM, Babu Moger wrote:
> This series adds a bug fix for AMD and a minor code cleanup.
>
> ---
> v5:
> This is bug. So, submitting these patches as a separate series from the old v4 series.
> This was a comment from James Morse.
>
> v4
> https://lore.kernel.org/lkml/166257348081.1043018.11227924488792315932.stgit@bmoger-ubuntu/
>
> Babu Moger (2):
> x86/resctrl: Fix min_cbm_bits for AMD
> x86/resctrl: Remove arch_has_empty_bitmaps
>
>
> arch/x86/kernel/cpu/resctrl/core.c | 10 ++--------
> arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 3 +--
> include/linux/resctrl.h | 6 +++---
> 3 files changed, 6 insertions(+), 13 deletions(-)
>
> --
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup
2022-10-18 16:26 ` [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup Reinette Chatre
@ 2022-10-18 16:35 ` Borislav Petkov
2022-10-18 16:43 ` Reinette Chatre
0 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2022-10-18 16:35 UTC (permalink / raw)
To: Reinette Chatre
Cc: tglx, mingo, Dave Hansen, x86@kernel.org, fenghua.yu, hpa,
paulmck, akpm, quic_neeraju, rdunlap, damien.lemoal, songmuchun,
peterz, jpoimboe, pbonzini, chang.seok.bae, pawan.kumar.gupta,
jmattson, daniel.sneddon, sandipan.das, tony.luck, james.morse,
linux-doc, linux-kernel, bagasdotme, eranian, Jonathan Corbet,
Babu Moger
On Tue, Oct 18, 2022 at 09:26:41AM -0700, Reinette Chatre wrote:
> Hi X86 Maintainers,
>
> Could you please consider this fix and cleanup for inclusion?
Sure.
From the looks of it, the first one needs to go to stable, right?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup
2022-10-18 16:35 ` Borislav Petkov
@ 2022-10-18 16:43 ` Reinette Chatre
2022-10-18 16:47 ` Borislav Petkov
0 siblings, 1 reply; 10+ messages in thread
From: Reinette Chatre @ 2022-10-18 16:43 UTC (permalink / raw)
To: Borislav Petkov
Cc: tglx, mingo, Dave Hansen, x86@kernel.org, fenghua.yu, hpa,
paulmck, akpm, quic_neeraju, rdunlap, damien.lemoal, songmuchun,
peterz, jpoimboe, pbonzini, chang.seok.bae, pawan.kumar.gupta,
jmattson, daniel.sneddon, sandipan.das, tony.luck, james.morse,
linux-doc, linux-kernel, bagasdotme, eranian, Jonathan Corbet,
Babu Moger
Hi Boris,
On 10/18/2022 9:35 AM, Borislav Petkov wrote:
> On Tue, Oct 18, 2022 at 09:26:41AM -0700, Reinette Chatre wrote:
>> Hi X86 Maintainers,
>>
>> Could you please consider this fix and cleanup for inclusion?
>
> Sure.
Thank you very much.
>
> From the looks of it, the first one needs to go to stable, right?
Correct. Apologies for missing the "Cc: stable@vger.kernel.org" in
that one.
Reinette
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup
2022-10-18 16:43 ` Reinette Chatre
@ 2022-10-18 16:47 ` Borislav Petkov
2022-10-18 16:51 ` Moger, Babu
0 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2022-10-18 16:47 UTC (permalink / raw)
To: Reinette Chatre
Cc: tglx, mingo, Dave Hansen, x86@kernel.org, fenghua.yu, hpa,
paulmck, akpm, quic_neeraju, rdunlap, damien.lemoal, songmuchun,
peterz, jpoimboe, pbonzini, chang.seok.bae, pawan.kumar.gupta,
jmattson, daniel.sneddon, sandipan.das, tony.luck, james.morse,
linux-doc, linux-kernel, bagasdotme, eranian, Jonathan Corbet,
Babu Moger
On Tue, Oct 18, 2022 at 09:43:15AM -0700, Reinette Chatre wrote:
> Correct. Apologies for missing the "Cc: stable@vger.kernel.org" in
> that one.
Nothing to apologize, all good.
Lemme take care of them.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v5 0/2] x86/resctrl: Fix min_cbm_bits for AMD and code cleanup
2022-10-18 16:47 ` Borislav Petkov
@ 2022-10-18 16:51 ` Moger, Babu
0 siblings, 0 replies; 10+ messages in thread
From: Moger, Babu @ 2022-10-18 16:51 UTC (permalink / raw)
To: Borislav Petkov, Reinette Chatre
Cc: tglx, mingo, Dave Hansen, x86@kernel.org, fenghua.yu, hpa,
paulmck, akpm, quic_neeraju, rdunlap, damien.lemoal, songmuchun,
peterz, jpoimboe, pbonzini, chang.seok.bae, pawan.kumar.gupta,
jmattson, daniel.sneddon, sandipan.das, tony.luck, james.morse,
linux-doc, linux-kernel, bagasdotme, eranian, Jonathan Corbet
On 10/18/22 11:47, Borislav Petkov wrote:
> On Tue, Oct 18, 2022 at 09:43:15AM -0700, Reinette Chatre wrote:
>> Correct. Apologies for missing the "Cc: stable@vger.kernel.org" in
>> that one.
> Nothing to apologize, all good.
>
> Lemme take care of them.
>
Thank you Reinette, Boris.
^ permalink raw reply [flat|nested] 10+ messages in thread