2019-05-29 07:18:02 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-10-28 15:04:47 -07:00
|
|
|
/*
|
|
|
|
* Resource Director Technology(RDT)
|
|
|
|
* - Cache Allocation code.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Fenghua Yu <fenghua.yu@intel.com>
|
|
|
|
* Tony Luck <tony.luck@intel.com>
|
|
|
|
*
|
|
|
|
* More information about RDT be found in the Intel (R) x86 Architecture
|
|
|
|
* Software Developer Manual June 2016, volume 3, section 17.17.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2018-12-10 13:21:54 -08:00
|
|
|
#include <linux/cpu.h>
|
2016-10-28 15:04:47 -07:00
|
|
|
#include <linux/kernfs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/slab.h>
|
2018-11-21 20:28:25 +00:00
|
|
|
#include "internal.h"
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2017-04-07 17:33:57 -07:00
|
|
|
/*
|
|
|
|
* Check whether MBA bandwidth percentage value is correct. The value is
|
|
|
|
* checked against the minimum and max bandwidth values specified by the
|
|
|
|
* hardware. The allocated bandwidth percentage is rounded to the next
|
|
|
|
* control step available on the hardware.
|
|
|
|
*/
|
|
|
|
static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
|
|
|
|
{
|
|
|
|
unsigned long bw;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only linear delay values is supported for current Intel SKUs.
|
|
|
|
*/
|
2020-07-08 16:39:26 +00:00
|
|
|
if (!r->membw.delay_linear && r->membw.arch_needs_linear) {
|
2017-09-25 16:39:34 -07:00
|
|
|
rdt_last_cmd_puts("No support for non-linear MB domains\n");
|
2017-04-07 17:33:57 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-07 17:33:57 -07:00
|
|
|
|
|
|
|
ret = kstrtoul(buf, 10, &bw);
|
2017-09-25 16:39:34 -07:00
|
|
|
if (ret) {
|
|
|
|
rdt_last_cmd_printf("Non-decimal digit in MB value %s\n", buf);
|
2017-04-07 17:33:57 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-07 17:33:57 -07:00
|
|
|
|
2018-04-20 15:36:19 -07:00
|
|
|
if ((bw < r->membw.min_bw || bw > r->default_ctrl) &&
|
|
|
|
!is_mba_sc(r)) {
|
2017-09-25 16:39:34 -07:00
|
|
|
rdt_last_cmd_printf("MB value %ld out of range [%d,%d]\n", bw,
|
|
|
|
r->membw.min_bw, r->default_ctrl);
|
2017-04-07 17:33:57 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-07 17:33:57 -07:00
|
|
|
|
|
|
|
*data = roundup(bw, (unsigned long)r->membw.bw_gran);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:22 +00:00
|
|
|
int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
|
2020-07-08 16:39:27 +00:00
|
|
|
struct rdt_domain *d)
|
2017-04-07 17:33:57 -07:00
|
|
|
{
|
2021-07-28 17:06:27 +00:00
|
|
|
struct resctrl_staged_config *cfg;
|
2021-07-28 17:06:22 +00:00
|
|
|
struct rdt_resource *r = s->res;
|
2018-09-15 14:58:19 -07:00
|
|
|
unsigned long bw_val;
|
2017-04-07 17:33:57 -07:00
|
|
|
|
2021-07-28 17:06:27 +00:00
|
|
|
cfg = &d->staged_config[s->conf_type];
|
2021-07-28 17:06:26 +00:00
|
|
|
if (cfg->have_new_ctrl) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_printf("Duplicate domain %d\n", d->id);
|
2017-04-07 17:33:57 -07:00
|
|
|
return -EINVAL;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-07 17:33:57 -07:00
|
|
|
|
2018-09-15 14:58:19 -07:00
|
|
|
if (!bw_validate(data->buf, &bw_val, r))
|
2017-04-07 17:33:57 -07:00
|
|
|
return -EINVAL;
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->new_ctrl = bw_val;
|
|
|
|
cfg->have_new_ctrl = true;
|
2017-04-07 17:33:57 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:47 -07:00
|
|
|
/*
|
2020-07-08 16:39:28 +00:00
|
|
|
* Check whether a cache bit mask is valid.
|
|
|
|
* For Intel the SDM says:
|
2016-10-28 15:04:47 -07:00
|
|
|
* Please note that all (and only) contiguous '1' combinations
|
|
|
|
* are allowed (e.g. FFFFH, 0FF0H, 003CH, etc.).
|
|
|
|
* Additionally Haswell requires at least two bits set.
|
2020-07-08 16:39:28 +00:00
|
|
|
* AMD allows non-contiguous bitmasks.
|
2016-10-28 15:04:47 -07:00
|
|
|
*/
|
2020-07-08 16:39:28 +00:00
|
|
|
static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
|
2016-10-28 15:04:47 -07:00
|
|
|
{
|
2017-04-07 17:33:56 -07:00
|
|
|
unsigned long first_bit, zero_bit, val;
|
2017-04-14 13:00:36 +02:00
|
|
|
unsigned int cbm_len = r->cache.cbm_len;
|
2017-04-07 17:33:56 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kstrtoul(buf, 16, &val);
|
2017-09-25 16:39:34 -07:00
|
|
|
if (ret) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_printf("Non-hex character in the mask %s\n", buf);
|
2017-04-07 17:33:56 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2020-07-08 16:39:28 +00:00
|
|
|
if ((!r->cache.arch_has_empty_bitmaps && val == 0) ||
|
|
|
|
val > r->default_ctrl) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Mask out of range\n");
|
2016-10-28 15:04:47 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2017-04-07 17:33:56 -07:00
|
|
|
first_bit = find_first_bit(&val, cbm_len);
|
|
|
|
zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2020-07-08 16:39:28 +00:00
|
|
|
/* Are non-contiguous bitmaps allowed? */
|
|
|
|
if (!r->cache.arch_has_sparse_bitmaps &&
|
|
|
|
(find_next_bit(&val, cbm_len, zero_bit) < cbm_len)) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_printf("The mask %lx has non-consecutive 1-bits\n", val);
|
2016-10-28 15:04:47 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2017-09-25 16:39:34 -07:00
|
|
|
if ((zero_bit - first_bit) < r->cache.min_cbm_bits) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_printf("Need at least %d bits in the mask\n",
|
2017-09-25 16:39:34 -07:00
|
|
|
r->cache.min_cbm_bits);
|
2016-10-28 15:04:47 -07:00
|
|
|
return false;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-07 17:33:56 -07:00
|
|
|
|
|
|
|
*data = val;
|
2016-10-28 15:04:47 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read one cache bit mask (hex). Check that it is valid for the current
|
|
|
|
* resource type.
|
|
|
|
*/
|
2021-07-28 17:06:22 +00:00
|
|
|
int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
|
2018-09-15 14:58:19 -07:00
|
|
|
struct rdt_domain *d)
|
2016-10-28 15:04:47 -07:00
|
|
|
{
|
2018-06-22 15:42:04 -07:00
|
|
|
struct rdtgroup *rdtgrp = data->rdtgrp;
|
2021-07-28 17:06:27 +00:00
|
|
|
struct resctrl_staged_config *cfg;
|
2021-07-28 17:06:22 +00:00
|
|
|
struct rdt_resource *r = s->res;
|
2018-06-22 15:42:02 -07:00
|
|
|
u32 cbm_val;
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2021-07-28 17:06:27 +00:00
|
|
|
cfg = &d->staged_config[s->conf_type];
|
2021-07-28 17:06:26 +00:00
|
|
|
if (cfg->have_new_ctrl) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_printf("Duplicate domain %d\n", d->id);
|
2017-04-03 14:44:16 -07:00
|
|
|
return -EINVAL;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-03 14:44:16 -07:00
|
|
|
|
2018-06-22 15:42:22 -07:00
|
|
|
/*
|
|
|
|
* Cannot set up more than one pseudo-locked region in a cache
|
|
|
|
* hierarchy.
|
|
|
|
*/
|
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
|
|
|
|
rdtgroup_pseudo_locked_in_hierarchy(d)) {
|
2018-11-27 11:19:36 -08:00
|
|
|
rdt_last_cmd_puts("Pseudo-locked region in hierarchy\n");
|
2018-06-22 15:42:22 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-07-08 16:39:28 +00:00
|
|
|
if (!cbm_validate(data->buf, &cbm_val, r))
|
2018-06-22 15:42:04 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-06-22 15:42:22 -07:00
|
|
|
if ((rdtgrp->mode == RDT_MODE_EXCLUSIVE ||
|
|
|
|
rdtgrp->mode == RDT_MODE_SHAREABLE) &&
|
|
|
|
rdtgroup_cbm_overlaps_pseudo_locked(d, cbm_val)) {
|
2018-11-27 11:19:36 -08:00
|
|
|
rdt_last_cmd_puts("CBM overlaps with pseudo-locked region\n");
|
2018-06-22 15:42:22 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:04 -07:00
|
|
|
/*
|
|
|
|
* The CBM may not overlap with the CBM of another closid if
|
|
|
|
* either is exclusive.
|
|
|
|
*/
|
2021-07-28 17:06:22 +00:00
|
|
|
if (rdtgroup_cbm_overlaps(s, d, cbm_val, rdtgrp->closid, true)) {
|
2018-11-27 11:19:36 -08:00
|
|
|
rdt_last_cmd_puts("Overlaps with exclusive group\n");
|
2016-10-28 15:04:47 -07:00
|
|
|
return -EINVAL;
|
2018-06-22 15:42:04 -07:00
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:22 +00:00
|
|
|
if (rdtgroup_cbm_overlaps(s, d, cbm_val, rdtgrp->closid, false)) {
|
2018-06-22 15:42:17 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_EXCLUSIVE ||
|
|
|
|
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
2018-11-27 11:19:36 -08:00
|
|
|
rdt_last_cmd_puts("Overlaps with other group\n");
|
2018-06-22 15:42:04 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 15:42:02 -07:00
|
|
|
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->new_ctrl = cbm_val;
|
|
|
|
cfg->have_new_ctrl = true;
|
2016-10-28 15:04:47 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each domain in this resource we expect to find a series of:
|
|
|
|
* id=mask
|
2017-04-03 14:44:16 -07:00
|
|
|
* separated by ";". The "id" is in decimal, and must match one of
|
|
|
|
* the "id"s for this resource.
|
2016-10-28 15:04:47 -07:00
|
|
|
*/
|
2021-07-28 17:06:22 +00:00
|
|
|
static int parse_line(char *line, struct resctrl_schema *s,
|
2018-06-22 15:42:04 -07:00
|
|
|
struct rdtgroup *rdtgrp)
|
2016-10-28 15:04:47 -07:00
|
|
|
{
|
2021-07-28 17:06:27 +00:00
|
|
|
enum resctrl_conf_type t = s->conf_type;
|
2021-07-28 17:06:26 +00:00
|
|
|
struct resctrl_staged_config *cfg;
|
2021-07-28 17:06:22 +00:00
|
|
|
struct rdt_resource *r = s->res;
|
2018-09-15 14:58:19 -07:00
|
|
|
struct rdt_parse_data data;
|
2016-10-28 15:04:47 -07:00
|
|
|
char *dom = NULL, *id;
|
|
|
|
struct rdt_domain *d;
|
|
|
|
unsigned long dom_id;
|
|
|
|
|
2018-09-15 14:58:24 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
|
|
|
|
r->rid == RDT_RESOURCE_MBA) {
|
|
|
|
rdt_last_cmd_puts("Cannot pseudo-lock MBA resource\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-04-03 14:44:16 -07:00
|
|
|
next:
|
|
|
|
if (!line || line[0] == '\0')
|
|
|
|
return 0;
|
|
|
|
dom = strsep(&line, ";");
|
|
|
|
id = strsep(&dom, "=");
|
2017-09-25 16:39:34 -07:00
|
|
|
if (!dom || kstrtoul(id, 10, &dom_id)) {
|
|
|
|
rdt_last_cmd_puts("Missing '=' or non-numeric domain\n");
|
2017-04-03 14:44:16 -07:00
|
|
|
return -EINVAL;
|
2017-09-25 16:39:34 -07:00
|
|
|
}
|
2017-04-19 16:50:03 -07:00
|
|
|
dom = strim(dom);
|
2016-10-28 15:04:47 -07:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
2017-04-03 14:44:16 -07:00
|
|
|
if (d->id == dom_id) {
|
2018-06-22 15:42:04 -07:00
|
|
|
data.buf = dom;
|
|
|
|
data.rdtgrp = rdtgrp;
|
2021-07-28 17:06:22 +00:00
|
|
|
if (r->parse_ctrlval(&data, s, d))
|
2017-04-03 14:44:16 -07:00
|
|
|
return -EINVAL;
|
2018-06-22 15:42:22 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
2021-07-28 17:06:27 +00:00
|
|
|
cfg = &d->staged_config[t];
|
2018-06-22 15:42:22 -07:00
|
|
|
/*
|
|
|
|
* In pseudo-locking setup mode and just
|
|
|
|
* parsed a valid CBM that should be
|
|
|
|
* pseudo-locked. Only one locked region per
|
|
|
|
* resource group and domain so just do
|
|
|
|
* the required initialization for single
|
|
|
|
* region and return.
|
|
|
|
*/
|
2021-07-28 17:06:23 +00:00
|
|
|
rdtgrp->plr->s = s;
|
2018-06-22 15:42:22 -07:00
|
|
|
rdtgrp->plr->d = d;
|
2021-07-28 17:06:26 +00:00
|
|
|
rdtgrp->plr->cbm = cfg->new_ctrl;
|
2018-06-22 15:42:22 -07:00
|
|
|
d->plr = rdtgrp->plr;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-04-03 14:44:16 -07:00
|
|
|
goto next;
|
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
}
|
2017-04-03 14:44:16 -07:00
|
|
|
return -EINVAL;
|
2016-10-28 15:04:47 -07:00
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:26 +00:00
|
|
|
static void apply_config(struct rdt_hw_domain *hw_dom,
|
|
|
|
struct resctrl_staged_config *cfg, int closid,
|
|
|
|
cpumask_var_t cpu_mask, bool mba_sc)
|
|
|
|
{
|
|
|
|
struct rdt_domain *dom = &hw_dom->d_resctrl;
|
|
|
|
u32 *dc = !mba_sc ? hw_dom->ctrl_val : hw_dom->mbps_val;
|
|
|
|
|
|
|
|
if (cfg->new_ctrl != dc[closid]) {
|
|
|
|
cpumask_set_cpu(cpumask_any(&dom->cpu_mask), cpu_mask);
|
|
|
|
dc[closid] = cfg->new_ctrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:28 +00:00
|
|
|
int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
|
2016-10-28 15:04:47 -07:00
|
|
|
{
|
2021-07-28 17:06:26 +00:00
|
|
|
struct resctrl_staged_config *cfg;
|
2021-07-28 17:06:15 +00:00
|
|
|
struct rdt_hw_domain *hw_dom;
|
2016-10-28 15:04:47 -07:00
|
|
|
struct msr_param msr_param;
|
2021-07-28 17:06:27 +00:00
|
|
|
enum resctrl_conf_type t;
|
2016-10-28 15:04:47 -07:00
|
|
|
cpumask_var_t cpu_mask;
|
|
|
|
struct rdt_domain *d;
|
2018-04-20 15:36:19 -07:00
|
|
|
bool mba_sc;
|
2017-04-03 14:44:16 -07:00
|
|
|
int cpu;
|
2016-10-28 15:04:47 -07:00
|
|
|
|
|
|
|
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
msr_param.low = closid;
|
|
|
|
msr_param.high = msr_param.low + 1;
|
|
|
|
msr_param.res = r;
|
|
|
|
|
2018-04-20 15:36:19 -07:00
|
|
|
mba_sc = is_mba_sc(r);
|
2016-10-28 15:04:47 -07:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
2021-07-28 17:06:15 +00:00
|
|
|
hw_dom = resctrl_to_arch_dom(d);
|
2021-07-28 17:06:27 +00:00
|
|
|
for (t = 0; t < CDP_NUM_TYPES; t++) {
|
|
|
|
cfg = &hw_dom->d_resctrl.staged_config[t];
|
|
|
|
if (!cfg->have_new_ctrl)
|
|
|
|
continue;
|
|
|
|
|
2021-07-28 17:06:26 +00:00
|
|
|
apply_config(hw_dom, cfg, closid, cpu_mask, mba_sc);
|
2021-07-28 17:06:27 +00:00
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
}
|
2018-04-20 15:36:19 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid writing the control msr with control values when
|
|
|
|
* MBA software controller is enabled
|
|
|
|
*/
|
|
|
|
if (cpumask_empty(cpu_mask) || mba_sc)
|
2017-04-03 14:44:16 -07:00
|
|
|
goto done;
|
2016-10-28 15:04:47 -07:00
|
|
|
cpu = get_cpu();
|
2019-04-17 19:08:49 +08:00
|
|
|
/* Update resource control msr on this CPU if it's in cpu_mask. */
|
2016-10-28 15:04:47 -07:00
|
|
|
if (cpumask_test_cpu(cpu, cpu_mask))
|
2017-04-07 17:33:51 -07:00
|
|
|
rdt_ctrl_update(&msr_param);
|
2019-04-17 19:08:49 +08:00
|
|
|
/* Update resource control msr on other CPUs. */
|
2017-04-07 17:33:51 -07:00
|
|
|
smp_call_function_many(cpu_mask, rdt_ctrl_update, &msr_param, 1);
|
2016-10-28 15:04:47 -07:00
|
|
|
put_cpu();
|
|
|
|
|
2017-04-03 14:44:16 -07:00
|
|
|
done:
|
2016-10-28 15:04:47 -07:00
|
|
|
free_cpumask_var(cpu_mask);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:04 -07:00
|
|
|
static int rdtgroup_parse_resource(char *resname, char *tok,
|
|
|
|
struct rdtgroup *rdtgrp)
|
2017-04-19 16:50:04 -07:00
|
|
|
{
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *s;
|
2017-04-19 16:50:04 -07:00
|
|
|
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list) {
|
2021-07-28 17:06:25 +00:00
|
|
|
if (!strcmp(resname, s->name) && rdtgrp->closid < s->num_closid)
|
2021-07-28 17:06:22 +00:00
|
|
|
return parse_line(tok, s, rdtgrp);
|
2017-04-19 16:50:04 -07:00
|
|
|
}
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_printf("Unknown or unsupported resource name '%s'\n", resname);
|
2017-04-19 16:50:04 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:47 -07:00
|
|
|
ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
|
|
|
{
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *s;
|
2016-10-28 15:04:47 -07:00
|
|
|
struct rdtgroup *rdtgrp;
|
2017-04-03 14:44:16 -07:00
|
|
|
struct rdt_domain *dom;
|
2016-10-28 15:04:47 -07:00
|
|
|
struct rdt_resource *r;
|
|
|
|
char *tok, *resname;
|
2018-06-22 15:42:04 -07:00
|
|
|
int ret = 0;
|
2016-10-28 15:04:47 -07:00
|
|
|
|
|
|
|
/* Valid input requires a trailing newline */
|
2017-09-25 16:39:35 -07:00
|
|
|
if (nbytes == 0 || buf[nbytes - 1] != '\n')
|
2016-10-28 15:04:47 -07:00
|
|
|
return -EINVAL;
|
|
|
|
buf[nbytes - 1] = '\0';
|
|
|
|
|
2018-12-10 13:21:54 -08:00
|
|
|
cpus_read_lock();
|
2016-10-28 15:04:47 -07:00
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
2018-12-10 13:21:54 -08:00
|
|
|
cpus_read_unlock();
|
2016-10-28 15:04:47 -07:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
2017-09-25 16:39:34 -07:00
|
|
|
rdt_last_cmd_clear();
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2018-06-22 15:42:12 -07:00
|
|
|
/*
|
|
|
|
* No changes to pseudo-locked region allowed. It has to be removed
|
|
|
|
* and re-created instead.
|
|
|
|
*/
|
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
|
|
|
|
ret = -EINVAL;
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Resource group is pseudo-locked\n");
|
2018-06-22 15:42:12 -07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list) {
|
|
|
|
list_for_each_entry(dom, &s->res->domains, list)
|
2021-07-28 17:06:27 +00:00
|
|
|
memset(dom->staged_config, 0, sizeof(dom->staged_config));
|
2017-04-19 16:50:04 -07:00
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
|
|
|
|
while ((tok = strsep(&buf, "\n")) != NULL) {
|
2017-04-19 16:50:03 -07:00
|
|
|
resname = strim(strsep(&tok, ":"));
|
2016-10-28 15:04:47 -07:00
|
|
|
if (!tok) {
|
2017-09-25 16:39:34 -07:00
|
|
|
rdt_last_cmd_puts("Missing ':'\n");
|
2016-10-28 15:04:47 -07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-11-10 11:16:24 -08:00
|
|
|
if (tok[0] == '\0') {
|
|
|
|
rdt_last_cmd_printf("Missing '%s' value\n", resname);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-06-22 15:42:04 -07:00
|
|
|
ret = rdtgroup_parse_resource(resname, tok, rdtgrp);
|
2017-04-19 16:50:04 -07:00
|
|
|
if (ret)
|
2016-10-28 15:04:47 -07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list) {
|
|
|
|
r = s->res;
|
2021-07-28 17:06:28 +00:00
|
|
|
ret = resctrl_arch_update_domains(r, rdtgrp->closid);
|
2016-10-28 15:04:47 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:22 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
|
|
|
/*
|
|
|
|
* If pseudo-locking fails we keep the resource group in
|
|
|
|
* mode RDT_MODE_PSEUDO_LOCKSETUP with its class of service
|
|
|
|
* active and updated for just the domain the pseudo-locked
|
|
|
|
* region was requested for.
|
|
|
|
*/
|
|
|
|
ret = rdtgroup_pseudo_lock_create(rdtgrp);
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:47 -07:00
|
|
|
out:
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
2018-12-10 13:21:54 -08:00
|
|
|
cpus_read_unlock();
|
2016-10-28 15:04:47 -07:00
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:22 +00:00
|
|
|
static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int closid)
|
2016-10-28 15:04:47 -07:00
|
|
|
{
|
2021-07-28 17:06:22 +00:00
|
|
|
struct rdt_resource *r = schema->res;
|
2021-07-28 17:06:15 +00:00
|
|
|
struct rdt_hw_domain *hw_dom;
|
2016-10-28 15:04:47 -07:00
|
|
|
struct rdt_domain *dom;
|
|
|
|
bool sep = false;
|
2018-04-20 15:36:19 -07:00
|
|
|
u32 ctrl_val;
|
2016-10-28 15:04:47 -07:00
|
|
|
|
2021-07-28 17:06:25 +00:00
|
|
|
seq_printf(s, "%*s:", max_name_width, schema->name);
|
2016-10-28 15:04:47 -07:00
|
|
|
list_for_each_entry(dom, &r->domains, list) {
|
2021-07-28 17:06:15 +00:00
|
|
|
hw_dom = resctrl_to_arch_dom(dom);
|
2016-10-28 15:04:47 -07:00
|
|
|
if (sep)
|
|
|
|
seq_puts(s, ";");
|
2018-04-20 15:36:19 -07:00
|
|
|
|
2021-07-28 17:06:15 +00:00
|
|
|
ctrl_val = (!is_mba_sc(r) ? hw_dom->ctrl_val[closid] :
|
|
|
|
hw_dom->mbps_val[closid]);
|
2017-04-07 17:33:56 -07:00
|
|
|
seq_printf(s, r->format_str, dom->id, max_data_width,
|
2018-04-20 15:36:19 -07:00
|
|
|
ctrl_val);
|
2016-10-28 15:04:47 -07:00
|
|
|
sep = true;
|
|
|
|
}
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdtgroup_schemata_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *schema;
|
2016-10-28 15:04:47 -07:00
|
|
|
struct rdtgroup *rdtgrp;
|
2017-07-25 14:14:38 -07:00
|
|
|
int ret = 0;
|
|
|
|
u32 closid;
|
2016-10-28 15:04:47 -07:00
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (rdtgrp) {
|
2018-06-22 15:42:17 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(schema, &resctrl_schema_all, list) {
|
2021-07-28 17:06:25 +00:00
|
|
|
seq_printf(s, "%s:uninitialized\n", schema->name);
|
2021-07-28 17:06:19 +00:00
|
|
|
}
|
2018-06-22 15:42:23 -07:00
|
|
|
} else if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
|
2018-10-12 15:51:01 -07:00
|
|
|
if (!rdtgrp->plr->d) {
|
|
|
|
rdt_last_cmd_clear();
|
|
|
|
rdt_last_cmd_puts("Cache domain offline\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
} else {
|
|
|
|
seq_printf(s, "%s:%d=%x\n",
|
2021-07-28 17:06:23 +00:00
|
|
|
rdtgrp->plr->s->res->name,
|
2018-10-12 15:51:01 -07:00
|
|
|
rdtgrp->plr->d->id,
|
|
|
|
rdtgrp->plr->cbm);
|
|
|
|
}
|
2018-06-22 15:42:17 -07:00
|
|
|
} else {
|
|
|
|
closid = rdtgrp->closid;
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(schema, &resctrl_schema_all, list) {
|
2021-07-28 17:06:20 +00:00
|
|
|
if (closid < schema->num_closid)
|
2021-07-28 17:06:22 +00:00
|
|
|
show_doms(s, schema, closid);
|
2018-06-22 15:42:17 -07:00
|
|
|
}
|
2016-10-28 15:04:47 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-07-25 14:14:38 -07:00
|
|
|
|
2020-05-05 15:36:16 -07:00
|
|
|
void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
|
|
|
|
struct rdt_domain *d, struct rdtgroup *rdtgrp,
|
|
|
|
int evtid, int first)
|
2017-07-25 14:14:38 -07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* setup the parameters to send to the IPI to read the data.
|
|
|
|
*/
|
|
|
|
rr->rgrp = rdtgrp;
|
|
|
|
rr->evtid = evtid;
|
2020-05-05 15:36:16 -07:00
|
|
|
rr->r = r;
|
2017-07-25 14:14:45 -07:00
|
|
|
rr->d = d;
|
2017-07-25 14:14:38 -07:00
|
|
|
rr->val = 0;
|
2017-07-25 14:14:46 -07:00
|
|
|
rr->first = first;
|
2017-07-25 14:14:38 -07:00
|
|
|
|
|
|
|
smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdtgroup_mondata_show(struct seq_file *m, void *arg)
|
|
|
|
{
|
|
|
|
struct kernfs_open_file *of = m->private;
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
struct rdt_hw_resource *hw_res;
|
2017-07-25 14:14:38 -07:00
|
|
|
u32 resid, evtid, domid;
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
struct rdt_resource *r;
|
|
|
|
union mon_data_bits md;
|
|
|
|
struct rdt_domain *d;
|
|
|
|
struct rmid_read rr;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
2019-10-29 13:25:02 +08:00
|
|
|
if (!rdtgrp) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-07-25 14:14:38 -07:00
|
|
|
|
|
|
|
md.priv = of->kn->priv;
|
|
|
|
resid = md.u.rid;
|
|
|
|
domid = md.u.domid;
|
|
|
|
evtid = md.u.evtid;
|
|
|
|
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
hw_res = &rdt_resources_all[resid];
|
|
|
|
r = &hw_res->r_resctrl;
|
2017-07-25 14:14:38 -07:00
|
|
|
d = rdt_find_domain(r, domid, NULL);
|
2018-12-10 14:31:13 -08:00
|
|
|
if (IS_ERR_OR_NULL(d)) {
|
2017-07-25 14:14:38 -07:00
|
|
|
ret = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-05-05 15:36:16 -07:00
|
|
|
mon_event_read(&rr, r, d, rdtgrp, evtid, false);
|
2017-07-25 14:14:38 -07:00
|
|
|
|
|
|
|
if (rr.val & RMID_VAL_ERROR)
|
|
|
|
seq_puts(m, "Error\n");
|
|
|
|
else if (rr.val & RMID_VAL_UNAVAIL)
|
|
|
|
seq_puts(m, "Unavailable\n");
|
|
|
|
else
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
seq_printf(m, "%llu\n", rr.val * hw_res->mon_scale);
|
2017-07-25 14:14:38 -07:00
|
|
|
|
|
|
|
out:
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return ret;
|
|
|
|
}
|