x86/resctrl: Fix default monitoring groups reporting

commit 064855a69003c24bd6b473b367d364e418c57625 upstream.

Creating a new sub monitoring group in the root /sys/fs/resctrl leads to
getting the "Unavailable" value for mbm_total_bytes and mbm_local_bytes
on the entire filesystem.

Steps to reproduce:

  1. mount -t resctrl resctrl /sys/fs/resctrl/

  2. cd /sys/fs/resctrl/

  3. cat mon_data/mon_L3_00/mbm_total_bytes
     23189832

  4. Create sub monitor group:
  mkdir mon_groups/test1

  5. cat mon_data/mon_L3_00/mbm_total_bytes
     Unavailable

When a new monitoring group is created, a new RMID is assigned to the
new group. But the RMID is not active yet. When the events are read on
the new RMID, it is expected to report the status as "Unavailable".

When the user reads the events on the default monitoring group with
multiple subgroups, the events on all subgroups are consolidated
together. Currently, if any of the RMID reads report as "Unavailable",
then everything will be reported as "Unavailable".

Fix the issue by discarding the "Unavailable" reads and reporting all
the successful RMID reads. This is not a problem on Intel systems as
Intel reports 0 on Inactive RMIDs.

Fixes: d89b737901 ("x86/intel_rdt/cqm: Add mon_data")
Reported-by: Paweł Szulik <pawel.szulik@intel.com>
Signed-off-by: Babu Moger <Babu.Moger@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
Cc: stable@vger.kernel.org
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213311
Link: https://lkml.kernel.org/r/162793309296.9224.15871659871696482080.stgit@bmoger-ubuntu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Babu Moger 2021-08-02 14:38:58 -05:00 committed by Greg Kroah-Hartman
parent 25216ed97d
commit f0736bed18

View File

@ -222,15 +222,14 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
return chunks >>= shift; return chunks >>= shift;
} }
static int __mon_event_count(u32 rmid, struct rmid_read *rr) static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
{ {
struct mbm_state *m; struct mbm_state *m;
u64 chunks, tval; u64 chunks, tval;
tval = __rmid_read(rmid, rr->evtid); tval = __rmid_read(rmid, rr->evtid);
if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) { if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
rr->val = tval; return tval;
return -EINVAL;
} }
switch (rr->evtid) { switch (rr->evtid) {
case QOS_L3_OCCUP_EVENT_ID: case QOS_L3_OCCUP_EVENT_ID:
@ -242,12 +241,6 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr)
case QOS_L3_MBM_LOCAL_EVENT_ID: case QOS_L3_MBM_LOCAL_EVENT_ID:
m = &rr->d->mbm_local[rmid]; m = &rr->d->mbm_local[rmid];
break; break;
default:
/*
* Code would never reach here because
* an invalid event id would fail the __rmid_read.
*/
return -EINVAL;
} }
if (rr->first) { if (rr->first) {
@ -297,23 +290,29 @@ void mon_event_count(void *info)
struct rdtgroup *rdtgrp, *entry; struct rdtgroup *rdtgrp, *entry;
struct rmid_read *rr = info; struct rmid_read *rr = info;
struct list_head *head; struct list_head *head;
u64 ret_val;
rdtgrp = rr->rgrp; rdtgrp = rr->rgrp;
if (__mon_event_count(rdtgrp->mon.rmid, rr)) ret_val = __mon_event_count(rdtgrp->mon.rmid, rr);
return;
/* /*
* For Ctrl groups read data from child monitor groups. * For Ctrl groups read data from child monitor groups and
* add them together. Count events which are read successfully.
* Discard the rmid_read's reporting errors.
*/ */
head = &rdtgrp->mon.crdtgrp_list; head = &rdtgrp->mon.crdtgrp_list;
if (rdtgrp->type == RDTCTRL_GROUP) { if (rdtgrp->type == RDTCTRL_GROUP) {
list_for_each_entry(entry, head, mon.crdtgrp_list) { list_for_each_entry(entry, head, mon.crdtgrp_list) {
if (__mon_event_count(entry->mon.rmid, rr)) if (__mon_event_count(entry->mon.rmid, rr) == 0)
return; ret_val = 0;
} }
} }
/* Report error if none of rmid_reads are successful */
if (ret_val)
rr->val = ret_val;
} }
/* /*