[PATCH v2] x86/resctrl: Fix zero cbm for AMD in cbm_validate

Stephane Eranian
2022-05-17T00:12:44Z

AMD supports cbm with no bits set as 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 you also have in cbm_validate():
if ((zero_bit - first_bit) < r->cache.min_cbm_bits)

Default value for if 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

Patch initializes fixes the logic in cbm_validate() to take into account
arch_has_empty_bitmaps when true and cbm value is 0.

Fixes: 316e7f901f5a ("x86/resctrl: Add struct rdt_cache::arch_has_{sparse, empty}_bitmaps")

Signed-off-by: Stephane Eranian <eranian@google.com>
---
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 87666275eed9..f376ed8bff8f 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -107,6 +107,10 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
first_bit = find_first_bit(&val, cbm_len);
zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);

+ /* no need to check bits if arch supports no bits set */
+ if (r->cache.arch_has_empty_bitmaps && val == 0)
+ goto done;
+
/* Are non-contiguous bitmaps allowed? */
if (!r->cache.arch_has_sparse_bitmaps &&
(find_next_bit(&val, cbm_len, zero_bit) < cbm_len)) {
@@ -119,7 +123,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
r->cache.min_cbm_bits);
return false;
}
-
+done:
*data = val;
return true;
}
--
2.36.0.550.gb090851708-goog