Re: [PATCH] x86/resctrl: Refactor to make adding extra MBM events easy

From: Luck, Tony
Date: Mon Mar 17 2025 - 14:23:57 EST


Here's my other bug:

> @@ -4162,31 +4156,29 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domain
> {
> u32 idx_limit = resctrl_arch_system_num_rmid_idx();
> size_t tsize;
> + int evt;
>
> if (resctrl_arch_is_llc_occupancy_enabled()) {
> d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
> if (!d->rmid_busy_llc)
> return -ENOMEM;
> }
> - if (resctrl_arch_is_mbm_total_enabled()) {
> - tsize = sizeof(*d->mbm_total);
> - d->mbm_total = kcalloc(idx_limit, tsize, GFP_KERNEL);
> - if (!d->mbm_total) {
> - bitmap_free(d->rmid_busy_llc);
> - return -ENOMEM;
> - }
> - }
> - if (resctrl_arch_is_mbm_local_enabled()) {
> - tsize = sizeof(*d->mbm_local);
> - d->mbm_local = kcalloc(idx_limit, tsize, GFP_KERNEL);
> - if (!d->mbm_local) {
> - bitmap_free(d->rmid_busy_llc);
> - kfree(d->mbm_total);
> - return -ENOMEM;
> - }
> +
> + for_each_set_bit(evt, &rdt_mon_features, sizeof(rdt_mon_features)) {
> + if (!resctrl_arch_is_mbm_event(evt))
> + continue;
> + d->mbm_states[evt] = kcalloc(idx_limit, tsize, GFP_KERNEL);

tsize used uninitialized ... so "random" allocation amount.

> + if (!d->mbm_states[evt])
> + goto cleanup;
> }
>
> return 0;
> +cleanup:
> + bitmap_free(d->rmid_busy_llc);
> + for (evt = 0; evt < QOS_L3_NUM_EVENTS; evt++)
> + kfree(d->mbm_states[evt]);
> +
> + return -ENOMEM;
> }

-Tony