[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220517001234.3137157-1-eranian@google.com>
Date: Mon, 16 May 2022 17:12:34 -0700
From: Stephane Eranian <eranian@...gle.com>
To: linux-kernel@...r.kernel.org
Cc: fenghua.yu@...el.com, reinette.chatre@...el.com,
babu.moger@....com, x86@...nel.org
Subject: [PATCH v2] x86/resctrl: Fix zero cbm for AMD in cbm_validate
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@...gle.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
Powered by blists - more mailing lists