From 08d4517431f24b2aa6105d5b2a26cb7ec6fdd4f5 Mon Sep 17 00:00:00 2001 From: dongshen Date: Tue, 14 Sep 2021 16:38:08 -0700 Subject: [PATCH] hv: fix bugs in RDT's CDP code In current RDT code, if CDP is configured, L2/L3 resources' num_closids calculation is wrong: res_cap_info[res].num_closids = (uint16_t)((edx & 0xffffU) >> 1U) + 1U; Should be: res_cap_info[res].num_closids = (uint16_t)((edx & 0xffffU) >> 1U + 1) >> 1U; Aslo, in order to enable CDP system-wide, need to enable the CDP bit (bit 0) on all pcpus, not just on pcpu 0. Tracked-On: #5917 Signed-off-by: dongshen --- hypervisor/arch/x86/rdt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hypervisor/arch/x86/rdt.c b/hypervisor/arch/x86/rdt.c index 577ed9317..f6dc960f9 100644 --- a/hypervisor/arch/x86/rdt.c +++ b/hypervisor/arch/x86/rdt.c @@ -80,14 +80,9 @@ static void init_cat_capability(int res) #else res_cap_info[res].res.cache.is_cdp_enabled = false; #endif + res_cap_info[res].num_closids = (uint16_t)(edx & 0xffffU) + 1U; if (res_cap_info[res].res.cache.is_cdp_enabled) { - res_cap_info[res].num_closids = (uint16_t)((edx & 0xffffU) >> 1U) + 1U; - /* enable CDP before setting COS to simplify CAT mask remapping - * and prevent unintended behavior. - */ - msr_write(res_cap_info[res].res.cache.msr_qos_cfg, 0x1UL); - } else { - res_cap_info[res].num_closids = (uint16_t)(edx & 0xffffU) + 1U; + res_cap_info[res].num_closids >>= 1U; } } @@ -156,7 +151,13 @@ static void setup_res_clos_msr(uint16_t pcpu_id, uint16_t res, struct platform_c if (res != RDT_RESOURCE_MBA && res_cap_info[res].res.cache.is_cdp_enabled) { mask_array_size = mask_array_size << 1U; + + /* enable CDP before setting COS to simplify CAT mask remapping + * and prevent unintended behavior. + */ + msr_write(res_cap_info[res].res.cache.msr_qos_cfg, 0x1UL); } + for (i = 0U; i < mask_array_size; i++) { switch (res) { case RDT_RESOURCE_L3: