2019-05-29 07:18:02 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-10-28 15:04:42 -07:00
|
|
|
/*
|
2021-03-18 15:28:01 +01:00
|
|
|
* User interface for Resource Allocation in Resource Director Technology(RDT)
|
2016-10-28 15:04:42 -07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Author: Fenghua Yu <fenghua.yu@intel.com>
|
|
|
|
*
|
|
|
|
* More information about RDT be found in the Intel (R) x86 Architecture
|
|
|
|
* Software Developer Manual.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2018-06-22 15:42:06 -07:00
|
|
|
#include <linux/cacheinfo.h>
|
2016-10-28 15:04:45 -07:00
|
|
|
#include <linux/cpu.h>
|
2018-06-22 15:42:25 -07:00
|
|
|
#include <linux/debugfs.h>
|
2016-10-28 15:04:42 -07:00
|
|
|
#include <linux/fs.h>
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
#include <linux/fs_parser.h>
|
2016-10-28 15:04:42 -07:00
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/kernfs.h>
|
2017-09-25 16:39:33 -07:00
|
|
|
#include <linux/seq_buf.h>
|
2016-10-28 15:04:43 -07:00
|
|
|
#include <linux/seq_file.h>
|
2017-02-08 18:51:30 +01:00
|
|
|
#include <linux/sched/signal.h>
|
2017-02-08 18:51:36 +01:00
|
|
|
#include <linux/sched/task.h>
|
2016-10-28 15:04:42 -07:00
|
|
|
#include <linux/slab.h>
|
2016-10-28 15:04:46 -07:00
|
|
|
#include <linux/task_work.h>
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
#include <linux/user_namespace.h>
|
2016-10-28 15:04:42 -07:00
|
|
|
|
|
|
|
#include <uapi/linux/magic.h>
|
|
|
|
|
2020-05-05 15:36:12 -07:00
|
|
|
#include <asm/resctrl.h>
|
2018-11-21 20:28:25 +00:00
|
|
|
#include "internal.h"
|
2016-10-28 15:04:42 -07:00
|
|
|
|
2017-07-25 14:14:41 -07:00
|
|
|
DEFINE_STATIC_KEY_FALSE(rdt_enable_key);
|
|
|
|
DEFINE_STATIC_KEY_FALSE(rdt_mon_enable_key);
|
2017-07-25 14:14:25 -07:00
|
|
|
DEFINE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
|
|
|
|
/* Mutex to protect rdtgroup access. */
|
|
|
|
DEFINE_MUTEX(rdtgroup_mutex);
|
|
|
|
|
2017-07-25 14:14:24 -07:00
|
|
|
static struct kernfs_root *rdt_root;
|
2016-10-28 15:04:42 -07:00
|
|
|
struct rdtgroup rdtgroup_default;
|
|
|
|
LIST_HEAD(rdt_all_groups);
|
|
|
|
|
2021-07-28 17:06:16 +00:00
|
|
|
/* list of entries for the schemata file */
|
|
|
|
LIST_HEAD(resctrl_schema_all);
|
|
|
|
|
2024-02-13 18:44:30 +00:00
|
|
|
/* The filesystem can only be mounted once. */
|
|
|
|
bool resctrl_mounted;
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
/* Kernel fs node for "info" directory under root */
|
|
|
|
static struct kernfs_node *kn_info;
|
|
|
|
|
2017-07-25 14:14:41 -07:00
|
|
|
/* Kernel fs node for "mon_groups" directory under root */
|
|
|
|
static struct kernfs_node *kn_mongrp;
|
|
|
|
|
|
|
|
/* Kernel fs node for "mon_data" directory under root */
|
|
|
|
static struct kernfs_node *kn_mondata;
|
|
|
|
|
2017-09-25 16:39:33 -07:00
|
|
|
static struct seq_buf last_cmd_status;
|
|
|
|
static char last_cmd_status_buf[512];
|
|
|
|
|
2023-10-16 19:23:04 -05:00
|
|
|
static int rdtgroup_setup_root(struct rdt_fs_context *ctx);
|
|
|
|
static void rdtgroup_destroy_root(void);
|
|
|
|
|
2018-06-22 15:42:25 -07:00
|
|
|
struct dentry *debugfs_resctrl;
|
|
|
|
|
2023-10-16 19:23:05 -05:00
|
|
|
static bool resctrl_debug;
|
|
|
|
|
2017-09-25 16:39:33 -07:00
|
|
|
void rdt_last_cmd_clear(void)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
seq_buf_clear(&last_cmd_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdt_last_cmd_puts(const char *s)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
seq_buf_puts(&last_cmd_status, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdt_last_cmd_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
seq_buf_vprintf(&last_cmd_status, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2023-01-17 13:14:50 -08:00
|
|
|
void rdt_staged_configs_clear(void)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r;
|
|
|
|
struct rdt_domain *dom;
|
|
|
|
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
for_each_alloc_capable_rdt_resource(r) {
|
|
|
|
list_for_each_entry(dom, &r->domains, list)
|
|
|
|
memset(dom->staged_config, 0, sizeof(dom->staged_config));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
/*
|
|
|
|
* Trivial allocator for CLOSIDs. Since h/w only supports a small number,
|
|
|
|
* we can keep a bitmap of free CLOSIDs in a single integer.
|
|
|
|
*
|
|
|
|
* Using a global CLOSID across all resources has some advantages and
|
|
|
|
* some drawbacks:
|
2024-02-13 18:44:25 +00:00
|
|
|
* + We can simply set current's closid to assign a task to a resource
|
2016-10-28 15:04:44 -07:00
|
|
|
* group.
|
|
|
|
* + Context switch code can avoid extra memory references deciding which
|
|
|
|
* CLOSID to load into the PQR_ASSOC MSR
|
|
|
|
* - We give up some options in configuring resource groups across multi-socket
|
|
|
|
* systems.
|
|
|
|
* - Our choices on how to configure each resource become progressively more
|
|
|
|
* limited as the number of resources grows.
|
|
|
|
*/
|
2024-02-13 18:44:23 +00:00
|
|
|
static unsigned long closid_free_map;
|
2018-09-15 14:58:21 -07:00
|
|
|
static int closid_free_map_len;
|
|
|
|
|
|
|
|
int closids_supported(void)
|
|
|
|
{
|
|
|
|
return closid_free_map_len;
|
|
|
|
}
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
static void closid_init(void)
|
|
|
|
{
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *s;
|
2021-07-28 17:06:21 +00:00
|
|
|
u32 rdt_min_closid = 32;
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
/* Compute rdt_min_closid across all resources */
|
2021-07-28 17:06:20 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list)
|
|
|
|
rdt_min_closid = min(rdt_min_closid, s->num_closid);
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
closid_free_map = BIT_MASK(rdt_min_closid) - 1;
|
|
|
|
|
2024-02-13 18:44:23 +00:00
|
|
|
/* RESCTRL_RESERVED_CLOSID is always reserved for the default group */
|
|
|
|
__clear_bit(RESCTRL_RESERVED_CLOSID, &closid_free_map);
|
2018-09-15 14:58:21 -07:00
|
|
|
closid_free_map_len = rdt_min_closid;
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:24 -07:00
|
|
|
static int closid_alloc(void)
|
2016-10-28 15:04:44 -07:00
|
|
|
{
|
2024-02-13 18:44:24 +00:00
|
|
|
int cleanest_closid;
|
|
|
|
u32 closid;
|
2016-10-28 15:04:44 -07:00
|
|
|
|
2024-02-13 18:44:23 +00:00
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
2024-02-13 18:44:24 +00:00
|
|
|
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
|
|
|
|
cleanest_closid = resctrl_find_cleanest_closid();
|
|
|
|
if (cleanest_closid < 0)
|
|
|
|
return cleanest_closid;
|
|
|
|
closid = cleanest_closid;
|
|
|
|
} else {
|
|
|
|
closid = ffs(closid_free_map);
|
|
|
|
if (closid == 0)
|
|
|
|
return -ENOSPC;
|
|
|
|
closid--;
|
|
|
|
}
|
2024-02-13 18:44:23 +00:00
|
|
|
__clear_bit(closid, &closid_free_map);
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
return closid;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:58 -07:00
|
|
|
void closid_free(int closid)
|
2016-10-28 15:04:44 -07:00
|
|
|
{
|
2024-02-13 18:44:23 +00:00
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
__set_bit(closid, &closid_free_map);
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:57 -07:00
|
|
|
/**
|
|
|
|
* closid_allocated - test if provided closid is in use
|
|
|
|
* @closid: closid to be tested
|
|
|
|
*
|
|
|
|
* Return: true if @closid is currently associated with a resource group,
|
|
|
|
* false if @closid is free
|
|
|
|
*/
|
2024-02-13 18:44:24 +00:00
|
|
|
bool closid_allocated(unsigned int closid)
|
2018-06-22 15:41:57 -07:00
|
|
|
{
|
2024-02-13 18:44:23 +00:00
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
return !test_bit(closid, &closid_free_map);
|
2018-06-22 15:41:57 -07:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:55 -07:00
|
|
|
/**
|
|
|
|
* rdtgroup_mode_by_closid - Return mode of resource group with closid
|
|
|
|
* @closid: closid if the resource group
|
|
|
|
*
|
|
|
|
* Each resource group is associated with a @closid. Here the mode
|
|
|
|
* of a resource group can be queried by searching for it using its closid.
|
|
|
|
*
|
|
|
|
* Return: mode as &enum rdtgrp_mode of resource group with closid @closid
|
|
|
|
*/
|
|
|
|
enum rdtgrp_mode rdtgroup_mode_by_closid(int closid)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
|
|
|
|
list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) {
|
|
|
|
if (rdtgrp->closid == closid)
|
|
|
|
return rdtgrp->mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RDT_NUM_MODES;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:56 -07:00
|
|
|
static const char * const rdt_mode_str[] = {
|
2018-06-22 15:42:08 -07:00
|
|
|
[RDT_MODE_SHAREABLE] = "shareable",
|
|
|
|
[RDT_MODE_EXCLUSIVE] = "exclusive",
|
|
|
|
[RDT_MODE_PSEUDO_LOCKSETUP] = "pseudo-locksetup",
|
|
|
|
[RDT_MODE_PSEUDO_LOCKED] = "pseudo-locked",
|
2018-06-22 15:41:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rdtgroup_mode_str - Return the string representation of mode
|
|
|
|
* @mode: the resource group mode as &enum rdtgroup_mode
|
|
|
|
*
|
|
|
|
* Return: string representation of valid mode, "unknown" otherwise
|
|
|
|
*/
|
|
|
|
static const char *rdtgroup_mode_str(enum rdtgrp_mode mode)
|
|
|
|
{
|
|
|
|
if (mode < RDT_MODE_SHAREABLE || mode >= RDT_NUM_MODES)
|
|
|
|
return "unknown";
|
|
|
|
|
|
|
|
return rdt_mode_str[mode];
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
/* set uid and gid of rdtgroup dirs and files to that of the creator */
|
|
|
|
static int rdtgroup_kn_set_ugid(struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
struct iattr iattr = { .ia_valid = ATTR_UID | ATTR_GID,
|
|
|
|
.ia_uid = current_fsuid(),
|
|
|
|
.ia_gid = current_fsgid(), };
|
|
|
|
|
|
|
|
if (uid_eq(iattr.ia_uid, GLOBAL_ROOT_UID) &&
|
|
|
|
gid_eq(iattr.ia_gid, GLOBAL_ROOT_GID))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return kernfs_setattr(kn, &iattr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft)
|
|
|
|
{
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
kn = __kernfs_create_file(parent_kn, rft->name, rft->mode,
|
2018-07-20 21:56:47 +00:00
|
|
|
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
|
2016-10-28 15:04:43 -07:00
|
|
|
0, rft->kf_ops, rft, NULL, NULL);
|
|
|
|
if (IS_ERR(kn))
|
|
|
|
return PTR_ERR(kn);
|
|
|
|
|
|
|
|
ret = rdtgroup_kn_set_ugid(kn);
|
|
|
|
if (ret) {
|
|
|
|
kernfs_remove(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdtgroup_seqfile_show(struct seq_file *m, void *arg)
|
|
|
|
{
|
|
|
|
struct kernfs_open_file *of = m->private;
|
|
|
|
struct rftype *rft = of->kn->priv;
|
|
|
|
|
|
|
|
if (rft->seq_show)
|
|
|
|
return rft->seq_show(of, m, arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t rdtgroup_file_write(struct kernfs_open_file *of, char *buf,
|
|
|
|
size_t nbytes, loff_t off)
|
|
|
|
{
|
|
|
|
struct rftype *rft = of->kn->priv;
|
|
|
|
|
|
|
|
if (rft->write)
|
|
|
|
return rft->write(of, buf, nbytes, off);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-11-11 00:02:28 +01:00
|
|
|
static const struct kernfs_ops rdtgroup_kf_single_ops = {
|
2016-10-28 15:04:43 -07:00
|
|
|
.atomic_write_len = PAGE_SIZE,
|
|
|
|
.write = rdtgroup_file_write,
|
|
|
|
.seq_show = rdtgroup_seqfile_show,
|
|
|
|
};
|
|
|
|
|
2020-11-11 00:02:28 +01:00
|
|
|
static const struct kernfs_ops kf_mondata_ops = {
|
2017-07-25 14:14:38 -07:00
|
|
|
.atomic_write_len = PAGE_SIZE,
|
|
|
|
.seq_show = rdtgroup_mondata_show,
|
|
|
|
};
|
|
|
|
|
2017-04-10 16:52:32 +02:00
|
|
|
static bool is_cpu_list(struct kernfs_open_file *of)
|
|
|
|
{
|
|
|
|
struct rftype *rft = of->kn->priv;
|
|
|
|
|
|
|
|
return rft->flags & RFTYPE_FLAGS_CPUS_LIST;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:45 -07:00
|
|
|
static int rdtgroup_cpus_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
2018-10-12 15:51:01 -07:00
|
|
|
struct cpumask *mask;
|
2016-10-28 15:04:45 -07:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
|
2017-04-10 16:52:32 +02:00
|
|
|
if (rdtgrp) {
|
2018-10-12 15:51:01 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
|
|
|
|
if (!rdtgrp->plr->d) {
|
|
|
|
rdt_last_cmd_clear();
|
|
|
|
rdt_last_cmd_puts("Cache domain offline\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
} else {
|
|
|
|
mask = &rdtgrp->plr->d->cpu_mask;
|
|
|
|
seq_printf(s, is_cpu_list(of) ?
|
|
|
|
"%*pbl\n" : "%*pb\n",
|
|
|
|
cpumask_pr_args(mask));
|
|
|
|
}
|
|
|
|
} else {
|
2018-06-30 22:17:33 -07:00
|
|
|
seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
|
|
|
|
cpumask_pr_args(&rdtgrp->cpu_mask));
|
2018-10-12 15:51:01 -07:00
|
|
|
}
|
2017-04-10 16:52:32 +02:00
|
|
|
} else {
|
2016-10-28 15:04:45 -07:00
|
|
|
ret = -ENOENT;
|
2017-04-10 16:52:32 +02:00
|
|
|
}
|
2016-10-28 15:04:45 -07:00
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-11 17:02:38 -08:00
|
|
|
/*
|
2018-11-21 20:28:27 +00:00
|
|
|
* This is safe against resctrl_sched_in() called from __switch_to()
|
2016-11-11 17:02:38 -08:00
|
|
|
* because __switch_to() is executed with interrupts disabled. A local call
|
2021-03-18 15:28:01 +01:00
|
|
|
* from update_closid_rmid() is protected against __switch_to() because
|
2016-11-11 17:02:38 -08:00
|
|
|
* preemption is disabled.
|
|
|
|
*/
|
2017-07-25 14:14:36 -07:00
|
|
|
static void update_cpu_closid_rmid(void *info)
|
2016-11-11 17:02:38 -08:00
|
|
|
{
|
2017-07-25 14:14:35 -07:00
|
|
|
struct rdtgroup *r = info;
|
|
|
|
|
2017-07-25 14:14:36 -07:00
|
|
|
if (r) {
|
2017-08-09 11:46:34 -07:00
|
|
|
this_cpu_write(pqr_state.default_closid, r->closid);
|
|
|
|
this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
|
2017-07-25 14:14:36 -07:00
|
|
|
}
|
2017-07-25 14:14:35 -07:00
|
|
|
|
2016-11-11 17:02:38 -08:00
|
|
|
/*
|
|
|
|
* We cannot unconditionally write the MSR because the current
|
|
|
|
* executing task might have its own closid selected. Just reuse
|
|
|
|
* the context switch code.
|
|
|
|
*/
|
x86/resctl: fix scheduler confusion with 'current'
The implementation of 'current' on x86 is very intentionally special: it
is a very common thing to look up, and it uses 'this_cpu_read_stable()'
to get the current thread pointer efficiently from per-cpu storage.
And the keyword in there is 'stable': the current thread pointer never
changes as far as a single thread is concerned. Even if when a thread
is preempted, or moved to another CPU, or even across an explicit call
'schedule()' that thread will still have the same value for 'current'.
It is, after all, the kernel base pointer to thread-local storage.
That's why it's stable to begin with, but it's also why it's important
enough that we have that special 'this_cpu_read_stable()' access for it.
So this is all done very intentionally to allow the compiler to treat
'current' as a value that never visibly changes, so that the compiler
can do CSE and combine multiple different 'current' accesses into one.
However, there is obviously one very special situation when the
currently running thread does actually change: inside the scheduler
itself.
So the scheduler code paths are special, and do not have a 'current'
thread at all. Instead there are _two_ threads: the previous and the
next thread - typically called 'prev' and 'next' (or prev_p/next_p)
internally.
So this is all actually quite straightforward and simple, and not all
that complicated.
Except for when you then have special code that is run in scheduler
context, that code then has to be aware that 'current' isn't really a
valid thing. Did you mean 'prev'? Did you mean 'next'?
In fact, even if then look at the code, and you use 'current' after the
new value has been assigned to the percpu variable, we have explicitly
told the compiler that 'current' is magical and always stable. So the
compiler is quite free to use an older (or newer) value of 'current',
and the actual assignment to the percpu storage is not relevant even if
it might look that way.
Which is exactly what happened in the resctl code, that blithely used
'current' in '__resctrl_sched_in()' when it really wanted the new
process state (as implied by the name: we're scheduling 'into' that new
resctl state). And clang would end up just using the old thread pointer
value at least in some configurations.
This could have happened with gcc too, and purely depends on random
compiler details. Clang just seems to have been more aggressive about
moving the read of the per-cpu current_task pointer around.
The fix is trivial: just make the resctl code adhere to the scheduler
rules of using the prev/next thread pointer explicitly, instead of using
'current' in a situation where it just wasn't valid.
That same code is then also used outside of the scheduler context (when
a thread resctl state is explicitly changed), and then we will just pass
in 'current' as that pointer, of course. There is no ambiguity in that
case.
The fix may be trivial, but noticing and figuring out what went wrong
was not. The credit for that goes to Stephane Eranian.
Reported-by: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/20230303231133.1486085-1-eranian@google.com/
Link: https://lore.kernel.org/lkml/alpine.LFD.2.01.0908011214330.3304@localhost.localdomain/
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Tested-by: Stephane Eranian <eranian@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-03-07 13:06:29 -08:00
|
|
|
resctrl_sched_in(current);
|
2016-11-11 17:02:38 -08:00
|
|
|
}
|
|
|
|
|
2016-11-18 15:18:04 -08:00
|
|
|
/*
|
|
|
|
* Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
|
|
|
|
*
|
2017-07-25 14:14:35 -07:00
|
|
|
* Per task closids/rmids must have been set up before calling this function.
|
2016-11-18 15:18:04 -08:00
|
|
|
*/
|
|
|
|
static void
|
2017-07-25 14:14:36 -07:00
|
|
|
update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
|
2016-11-11 17:02:38 -08:00
|
|
|
{
|
2023-01-13 09:20:27 -06:00
|
|
|
on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
|
2016-11-11 17:02:38 -08:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:36 -07:00
|
|
|
static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
|
|
|
|
cpumask_var_t tmpmask)
|
|
|
|
{
|
|
|
|
struct rdtgroup *prgrp = rdtgrp->mon.parent, *crgrp;
|
|
|
|
struct list_head *head;
|
|
|
|
|
|
|
|
/* Check whether cpus belong to parent ctrl group */
|
|
|
|
cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask)) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n");
|
2017-07-25 14:14:36 -07:00
|
|
|
return -EINVAL;
|
2017-09-25 16:39:36 -07:00
|
|
|
}
|
2017-07-25 14:14:36 -07:00
|
|
|
|
|
|
|
/* Check whether cpus are dropped from this group */
|
|
|
|
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask)) {
|
2017-07-25 14:14:36 -07:00
|
|
|
/* Give any dropped cpus to parent rdtgroup */
|
|
|
|
cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);
|
|
|
|
update_closid_rmid(tmpmask, prgrp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we added cpus, remove them from previous group that owned them
|
|
|
|
* and update per-cpu rmid
|
|
|
|
*/
|
|
|
|
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask)) {
|
2017-07-25 14:14:36 -07:00
|
|
|
head = &prgrp->mon.crdtgrp_list;
|
|
|
|
list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
|
|
|
|
if (crgrp == rdtgrp)
|
|
|
|
continue;
|
|
|
|
cpumask_andnot(&crgrp->cpu_mask, &crgrp->cpu_mask,
|
|
|
|
tmpmask);
|
|
|
|
}
|
|
|
|
update_closid_rmid(tmpmask, rdtgrp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done pushing/pulling - update this group with new mask */
|
|
|
|
cpumask_copy(&rdtgrp->cpu_mask, newmask);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpumask_rdtgrp_clear(struct rdtgroup *r, struct cpumask *m)
|
|
|
|
{
|
|
|
|
struct rdtgroup *crgrp;
|
|
|
|
|
|
|
|
cpumask_andnot(&r->cpu_mask, &r->cpu_mask, m);
|
|
|
|
/* update the child mon group masks as well*/
|
|
|
|
list_for_each_entry(crgrp, &r->mon.crdtgrp_list, mon.crdtgrp_list)
|
|
|
|
cpumask_and(&crgrp->cpu_mask, &r->cpu_mask, &crgrp->cpu_mask);
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:35 -07:00
|
|
|
static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
|
2017-07-25 14:14:36 -07:00
|
|
|
cpumask_var_t tmpmask, cpumask_var_t tmpmask1)
|
2017-07-25 14:14:35 -07:00
|
|
|
{
|
2017-07-25 14:14:36 -07:00
|
|
|
struct rdtgroup *r, *crgrp;
|
|
|
|
struct list_head *head;
|
2017-07-25 14:14:35 -07:00
|
|
|
|
|
|
|
/* Check whether cpus are dropped from this group */
|
|
|
|
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask)) {
|
2017-07-25 14:14:35 -07:00
|
|
|
/* Can't drop from default group */
|
2017-09-25 16:39:36 -07:00
|
|
|
if (rdtgrp == &rdtgroup_default) {
|
|
|
|
rdt_last_cmd_puts("Can't drop CPUs from default group\n");
|
2017-07-25 14:14:35 -07:00
|
|
|
return -EINVAL;
|
2017-09-25 16:39:36 -07:00
|
|
|
}
|
2017-07-25 14:14:35 -07:00
|
|
|
|
|
|
|
/* Give any dropped cpus to rdtgroup_default */
|
|
|
|
cpumask_or(&rdtgroup_default.cpu_mask,
|
|
|
|
&rdtgroup_default.cpu_mask, tmpmask);
|
2017-07-25 14:14:36 -07:00
|
|
|
update_closid_rmid(tmpmask, &rdtgroup_default);
|
2017-07-25 14:14:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-07-25 14:14:36 -07:00
|
|
|
* If we added cpus, remove them from previous group and
|
|
|
|
* the prev group's child groups that owned them
|
|
|
|
* and update per-cpu closid/rmid.
|
2017-07-25 14:14:35 -07:00
|
|
|
*/
|
|
|
|
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask)) {
|
2017-07-25 14:14:35 -07:00
|
|
|
list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
|
|
|
|
if (r == rdtgrp)
|
|
|
|
continue;
|
2017-07-25 14:14:36 -07:00
|
|
|
cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask1))
|
2017-07-25 14:14:36 -07:00
|
|
|
cpumask_rdtgrp_clear(r, tmpmask1);
|
2017-07-25 14:14:35 -07:00
|
|
|
}
|
2017-07-25 14:14:36 -07:00
|
|
|
update_closid_rmid(tmpmask, rdtgrp);
|
2017-07-25 14:14:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Done pushing/pulling - update this group with new mask */
|
|
|
|
cpumask_copy(&rdtgrp->cpu_mask, newmask);
|
|
|
|
|
2017-07-25 14:14:36 -07:00
|
|
|
/*
|
|
|
|
* Clear child mon group masks since there is a new parent mask
|
|
|
|
* now and update the rmid for the cpus the child lost.
|
|
|
|
*/
|
|
|
|
head = &rdtgrp->mon.crdtgrp_list;
|
|
|
|
list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
|
|
|
|
cpumask_and(tmpmask, &rdtgrp->cpu_mask, &crgrp->cpu_mask);
|
|
|
|
update_closid_rmid(tmpmask, rdtgrp);
|
|
|
|
cpumask_clear(&crgrp->cpu_mask);
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:45 -07:00
|
|
|
static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
|
|
|
{
|
2017-07-25 14:14:36 -07:00
|
|
|
cpumask_var_t tmpmask, newmask, tmpmask1;
|
2017-07-25 14:14:35 -07:00
|
|
|
struct rdtgroup *rdtgrp;
|
2016-11-11 17:02:38 -08:00
|
|
|
int ret;
|
2016-10-28 15:04:45 -07:00
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
if (!zalloc_cpumask_var(&newmask, GFP_KERNEL)) {
|
|
|
|
free_cpumask_var(tmpmask);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2017-07-25 14:14:36 -07:00
|
|
|
if (!zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) {
|
|
|
|
free_cpumask_var(tmpmask);
|
|
|
|
free_cpumask_var(newmask);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2016-11-15 15:12:13 +01:00
|
|
|
|
2016-10-28 15:04:45 -07:00
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:12 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
|
|
|
|
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
|
|
|
ret = -EINVAL;
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Pseudo-locking in progress\n");
|
2018-06-22 15:42:12 -07:00
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
2017-04-10 16:52:32 +02:00
|
|
|
if (is_cpu_list(of))
|
|
|
|
ret = cpulist_parse(buf, newmask);
|
|
|
|
else
|
|
|
|
ret = cpumask_parse(buf, newmask);
|
|
|
|
|
2017-09-25 16:39:36 -07:00
|
|
|
if (ret) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Bad CPU list/mask\n");
|
2016-10-28 15:04:45 -07:00
|
|
|
goto unlock;
|
2017-09-25 16:39:36 -07:00
|
|
|
}
|
2016-10-28 15:04:45 -07:00
|
|
|
|
|
|
|
/* check that user didn't specify any offline cpus */
|
|
|
|
cpumask_andnot(tmpmask, newmask, cpu_online_mask);
|
2022-02-10 14:49:00 -08:00
|
|
|
if (!cpumask_empty(tmpmask)) {
|
2016-10-28 15:04:45 -07:00
|
|
|
ret = -EINVAL;
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Can only assign online CPUs\n");
|
2016-11-15 15:12:13 +01:00
|
|
|
goto unlock;
|
2016-10-28 15:04:45 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:35 -07:00
|
|
|
if (rdtgrp->type == RDTCTRL_GROUP)
|
2017-07-25 14:14:36 -07:00
|
|
|
ret = cpus_ctrl_write(rdtgrp, newmask, tmpmask, tmpmask1);
|
|
|
|
else if (rdtgrp->type == RDTMON_GROUP)
|
|
|
|
ret = cpus_mon_write(rdtgrp, newmask, tmpmask);
|
2017-07-25 14:14:35 -07:00
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
2016-10-28 15:04:45 -07:00
|
|
|
|
|
|
|
unlock:
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
free_cpumask_var(tmpmask);
|
|
|
|
free_cpumask_var(newmask);
|
2017-07-25 14:14:36 -07:00
|
|
|
free_cpumask_var(tmpmask1);
|
2016-10-28 15:04:45 -07:00
|
|
|
|
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
2020-10-31 03:11:28 +08:00
|
|
|
/**
|
|
|
|
* rdtgroup_remove - the helper to remove resource group safely
|
|
|
|
* @rdtgrp: resource group to remove
|
|
|
|
*
|
|
|
|
* On resource group creation via a mkdir, an extra kernfs_node reference is
|
|
|
|
* taken to ensure that the rdtgroup structure remains accessible for the
|
|
|
|
* rdtgroup_kn_unlock() calls where it is removed.
|
|
|
|
*
|
|
|
|
* Drop the extra reference here, then free the rdtgroup structure.
|
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*/
|
|
|
|
static void rdtgroup_remove(struct rdtgroup *rdtgrp)
|
|
|
|
{
|
|
|
|
kernfs_put(rdtgrp->kn);
|
|
|
|
kfree(rdtgrp);
|
|
|
|
}
|
|
|
|
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
static void _update_task_closid_rmid(void *task)
|
2016-10-28 15:04:46 -07:00
|
|
|
{
|
|
|
|
/*
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
* If the task is still current on this CPU, update PQR_ASSOC MSR.
|
|
|
|
* Otherwise, the MSR is updated when the task is scheduled in.
|
2016-10-28 15:04:46 -07:00
|
|
|
*/
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
if (task == current)
|
x86/resctl: fix scheduler confusion with 'current'
The implementation of 'current' on x86 is very intentionally special: it
is a very common thing to look up, and it uses 'this_cpu_read_stable()'
to get the current thread pointer efficiently from per-cpu storage.
And the keyword in there is 'stable': the current thread pointer never
changes as far as a single thread is concerned. Even if when a thread
is preempted, or moved to another CPU, or even across an explicit call
'schedule()' that thread will still have the same value for 'current'.
It is, after all, the kernel base pointer to thread-local storage.
That's why it's stable to begin with, but it's also why it's important
enough that we have that special 'this_cpu_read_stable()' access for it.
So this is all done very intentionally to allow the compiler to treat
'current' as a value that never visibly changes, so that the compiler
can do CSE and combine multiple different 'current' accesses into one.
However, there is obviously one very special situation when the
currently running thread does actually change: inside the scheduler
itself.
So the scheduler code paths are special, and do not have a 'current'
thread at all. Instead there are _two_ threads: the previous and the
next thread - typically called 'prev' and 'next' (or prev_p/next_p)
internally.
So this is all actually quite straightforward and simple, and not all
that complicated.
Except for when you then have special code that is run in scheduler
context, that code then has to be aware that 'current' isn't really a
valid thing. Did you mean 'prev'? Did you mean 'next'?
In fact, even if then look at the code, and you use 'current' after the
new value has been assigned to the percpu variable, we have explicitly
told the compiler that 'current' is magical and always stable. So the
compiler is quite free to use an older (or newer) value of 'current',
and the actual assignment to the percpu storage is not relevant even if
it might look that way.
Which is exactly what happened in the resctl code, that blithely used
'current' in '__resctrl_sched_in()' when it really wanted the new
process state (as implied by the name: we're scheduling 'into' that new
resctl state). And clang would end up just using the old thread pointer
value at least in some configurations.
This could have happened with gcc too, and purely depends on random
compiler details. Clang just seems to have been more aggressive about
moving the read of the per-cpu current_task pointer around.
The fix is trivial: just make the resctl code adhere to the scheduler
rules of using the prev/next thread pointer explicitly, instead of using
'current' in a situation where it just wasn't valid.
That same code is then also used outside of the scheduler context (when
a thread resctl state is explicitly changed), and then we will just pass
in 'current' as that pointer, of course. There is no ambiguity in that
case.
The fix may be trivial, but noticing and figuring out what went wrong
was not. The credit for that goes to Stephane Eranian.
Reported-by: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/20230303231133.1486085-1-eranian@google.com/
Link: https://lore.kernel.org/lkml/alpine.LFD.2.01.0908011214330.3304@localhost.localdomain/
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Tested-by: Stephane Eranian <eranian@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-03-07 13:06:29 -08:00
|
|
|
resctrl_sched_in(task);
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
}
|
2016-10-28 15:04:48 -07:00
|
|
|
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
static void update_task_closid_rmid(struct task_struct *t)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_SMP) && task_curr(t))
|
|
|
|
smp_call_function_single(task_cpu(t), _update_task_closid_rmid, t, 1);
|
|
|
|
else
|
|
|
|
_update_task_closid_rmid(t);
|
2016-10-28 15:04:46 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:25 +00:00
|
|
|
static bool task_in_rdtgroup(struct task_struct *tsk, struct rdtgroup *rdtgrp)
|
|
|
|
{
|
|
|
|
u32 closid, rmid = rdtgrp->mon.rmid;
|
|
|
|
|
|
|
|
if (rdtgrp->type == RDTCTRL_GROUP)
|
|
|
|
closid = rdtgrp->closid;
|
|
|
|
else if (rdtgrp->type == RDTMON_GROUP)
|
|
|
|
closid = rdtgrp->mon.parent->closid;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return resctrl_arch_match_closid(tsk, closid) &&
|
|
|
|
resctrl_arch_match_rmid(tsk, closid, rmid);
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:46 -07:00
|
|
|
static int __rdtgroup_move_task(struct task_struct *tsk,
|
|
|
|
struct rdtgroup *rdtgrp)
|
|
|
|
{
|
2020-12-17 14:31:19 -08:00
|
|
|
/* If the task is already in rdtgrp, no need to move the task. */
|
2024-02-13 18:44:25 +00:00
|
|
|
if (task_in_rdtgroup(tsk, rdtgrp))
|
2020-12-17 14:31:19 -08:00
|
|
|
return 0;
|
|
|
|
|
2016-10-28 15:04:46 -07:00
|
|
|
/*
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
* Set the task's closid/rmid before the PQR_ASSOC MSR can be
|
|
|
|
* updated by them.
|
|
|
|
*
|
|
|
|
* For ctrl_mon groups, move both closid and rmid.
|
|
|
|
* For monitor groups, can move the tasks only from
|
|
|
|
* their parent CTRL group.
|
2016-10-28 15:04:46 -07:00
|
|
|
*/
|
2024-02-13 18:44:25 +00:00
|
|
|
if (rdtgrp->type == RDTMON_GROUP &&
|
|
|
|
!resctrl_arch_match_closid(tsk, rdtgrp->mon.parent->closid)) {
|
|
|
|
rdt_last_cmd_puts("Can't move task to different control group\n");
|
|
|
|
return -EINVAL;
|
2016-10-28 15:04:46 -07:00
|
|
|
}
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
|
2024-02-13 18:44:25 +00:00
|
|
|
if (rdtgrp->type == RDTMON_GROUP)
|
|
|
|
resctrl_arch_set_closid_rmid(tsk, rdtgrp->mon.parent->closid,
|
|
|
|
rdtgrp->mon.rmid);
|
|
|
|
else
|
|
|
|
resctrl_arch_set_closid_rmid(tsk, rdtgrp->closid,
|
|
|
|
rdtgrp->mon.rmid);
|
|
|
|
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
/*
|
|
|
|
* Ensure the task's closid and rmid are written before determining if
|
|
|
|
* the task is current that will decide if it will be interrupted.
|
x86/resctrl: Fix task CLOSID/RMID update race
When the user moves a running task to a new rdtgroup using the task's
file interface or by deleting its rdtgroup, the resulting change in
CLOSID/RMID must be immediately propagated to the PQR_ASSOC MSR on the
task(s) CPUs.
x86 allows reordering loads with prior stores, so if the task starts
running between a task_curr() check that the CPU hoisted before the
stores in the CLOSID/RMID update then it can start running with the old
CLOSID/RMID until it is switched again because __rdtgroup_move_task()
failed to determine that it needs to be interrupted to obtain the new
CLOSID/RMID.
Refer to the diagram below:
CPU 0 CPU 1
----- -----
__rdtgroup_move_task():
curr <- t1->cpu->rq->curr
__schedule():
rq->curr <- t1
resctrl_sched_in():
t1->{closid,rmid} -> {1,1}
t1->{closid,rmid} <- {2,2}
if (curr == t1) // false
IPI(t1->cpu)
A similar race impacts rdt_move_group_tasks(), which updates tasks in a
deleted rdtgroup.
In both cases, use smp_mb() to order the task_struct::{closid,rmid}
stores before the loads in task_curr(). In particular, in the
rdt_move_group_tasks() case, simply execute an smp_mb() on every
iteration with a matching task.
It is possible to use a single smp_mb() in rdt_move_group_tasks(), but
this would require two passes and a means of remembering which
task_structs were updated in the first loop. However, benchmarking
results below showed too little performance impact in the simple
approach to justify implementing the two-pass approach.
Times below were collected using `perf stat` to measure the time to
remove a group containing a 1600-task, parallel workload.
CPU: Intel(R) Xeon(R) Platinum P-8136 CPU @ 2.00GHz (112 threads)
# mkdir /sys/fs/resctrl/test
# echo $$ > /sys/fs/resctrl/test/tasks
# perf bench sched messaging -g 40 -l 100000
task-clock time ranges collected using:
# perf stat rmdir /sys/fs/resctrl/test
Baseline: 1.54 - 1.60 ms
smp_mb() every matching task: 1.57 - 1.67 ms
[ bp: Massage commit message. ]
Fixes: ae28d1aae48a ("x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR")
Fixes: 0efc89be9471 ("x86/intel_rdt: Update task closid immediately on CPU in rmdir and unmount")
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20221220161123.432120-1-peternewman@google.com
2022-12-20 17:11:23 +01:00
|
|
|
* This pairs with the full barrier between the rq->curr update and
|
|
|
|
* resctrl_sched_in() during context switch.
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
*/
|
x86/resctrl: Fix task CLOSID/RMID update race
When the user moves a running task to a new rdtgroup using the task's
file interface or by deleting its rdtgroup, the resulting change in
CLOSID/RMID must be immediately propagated to the PQR_ASSOC MSR on the
task(s) CPUs.
x86 allows reordering loads with prior stores, so if the task starts
running between a task_curr() check that the CPU hoisted before the
stores in the CLOSID/RMID update then it can start running with the old
CLOSID/RMID until it is switched again because __rdtgroup_move_task()
failed to determine that it needs to be interrupted to obtain the new
CLOSID/RMID.
Refer to the diagram below:
CPU 0 CPU 1
----- -----
__rdtgroup_move_task():
curr <- t1->cpu->rq->curr
__schedule():
rq->curr <- t1
resctrl_sched_in():
t1->{closid,rmid} -> {1,1}
t1->{closid,rmid} <- {2,2}
if (curr == t1) // false
IPI(t1->cpu)
A similar race impacts rdt_move_group_tasks(), which updates tasks in a
deleted rdtgroup.
In both cases, use smp_mb() to order the task_struct::{closid,rmid}
stores before the loads in task_curr(). In particular, in the
rdt_move_group_tasks() case, simply execute an smp_mb() on every
iteration with a matching task.
It is possible to use a single smp_mb() in rdt_move_group_tasks(), but
this would require two passes and a means of remembering which
task_structs were updated in the first loop. However, benchmarking
results below showed too little performance impact in the simple
approach to justify implementing the two-pass approach.
Times below were collected using `perf stat` to measure the time to
remove a group containing a 1600-task, parallel workload.
CPU: Intel(R) Xeon(R) Platinum P-8136 CPU @ 2.00GHz (112 threads)
# mkdir /sys/fs/resctrl/test
# echo $$ > /sys/fs/resctrl/test/tasks
# perf bench sched messaging -g 40 -l 100000
task-clock time ranges collected using:
# perf stat rmdir /sys/fs/resctrl/test
Baseline: 1.54 - 1.60 ms
smp_mb() every matching task: 1.57 - 1.67 ms
[ bp: Massage commit message. ]
Fixes: ae28d1aae48a ("x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR")
Fixes: 0efc89be9471 ("x86/intel_rdt: Update task closid immediately on CPU in rmdir and unmount")
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20221220161123.432120-1-peternewman@google.com
2022-12-20 17:11:23 +01:00
|
|
|
smp_mb();
|
x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.
Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.
This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.
This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.
As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.
To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.
[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com
[ bp: Massage commit message and drop the two update_task_closid_rmid()
variants. ]
Fixes: e02737d5b826 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2020-12-17 14:31:18 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* By now, the task's closid and rmid are set. If the task is current
|
|
|
|
* on a CPU, the PQR_ASSOC MSR needs to be updated to make the resource
|
|
|
|
* group go into effect. If the task is not current, the MSR will be
|
|
|
|
* updated when the task is scheduled in.
|
|
|
|
*/
|
|
|
|
update_task_closid_rmid(tsk);
|
|
|
|
|
|
|
|
return 0;
|
2016-10-28 15:04:46 -07:00
|
|
|
}
|
|
|
|
|
2020-07-08 16:39:25 +00:00
|
|
|
static bool is_closid_match(struct task_struct *t, struct rdtgroup *r)
|
|
|
|
{
|
2024-02-13 18:44:33 +00:00
|
|
|
return (resctrl_arch_alloc_capable() && (r->type == RDTCTRL_GROUP) &&
|
2024-02-13 18:44:25 +00:00
|
|
|
resctrl_arch_match_closid(t, r->closid));
|
2020-07-08 16:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_rmid_match(struct task_struct *t, struct rdtgroup *r)
|
|
|
|
{
|
2024-02-13 18:44:33 +00:00
|
|
|
return (resctrl_arch_mon_capable() && (r->type == RDTMON_GROUP) &&
|
2024-02-13 18:44:25 +00:00
|
|
|
resctrl_arch_match_rmid(t, r->mon.parent->closid,
|
|
|
|
r->mon.rmid));
|
2020-07-08 16:39:25 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:10 -07:00
|
|
|
/**
|
|
|
|
* rdtgroup_tasks_assigned - Test if tasks have been assigned to resource group
|
|
|
|
* @r: Resource group
|
|
|
|
*
|
|
|
|
* Return: 1 if tasks have been assigned to @r, 0 otherwise
|
|
|
|
*/
|
|
|
|
int rdtgroup_tasks_assigned(struct rdtgroup *r)
|
|
|
|
{
|
|
|
|
struct task_struct *p, *t;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
for_each_process_thread(p, t) {
|
2020-07-08 16:39:25 +00:00
|
|
|
if (is_closid_match(t, r) || is_rmid_match(t, r)) {
|
2018-06-22 15:42:10 -07:00
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:46 -07:00
|
|
|
static int rdtgroup_task_write_permission(struct task_struct *task,
|
|
|
|
struct kernfs_open_file *of)
|
|
|
|
{
|
|
|
|
const struct cred *tcred = get_task_cred(task);
|
|
|
|
const struct cred *cred = current_cred();
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Even if we're attaching all tasks in the thread group, we only
|
|
|
|
* need to check permissions on one of them.
|
|
|
|
*/
|
|
|
|
if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
|
|
|
|
!uid_eq(cred->euid, tcred->uid) &&
|
2017-09-25 16:39:35 -07:00
|
|
|
!uid_eq(cred->euid, tcred->suid)) {
|
|
|
|
rdt_last_cmd_printf("No permission to move task %d\n", task->pid);
|
2016-10-28 15:04:46 -07:00
|
|
|
ret = -EPERM;
|
2017-09-25 16:39:35 -07:00
|
|
|
}
|
2016-10-28 15:04:46 -07:00
|
|
|
|
|
|
|
put_cred(tcred);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdtgroup_move_task(pid_t pid, struct rdtgroup *rdtgrp,
|
|
|
|
struct kernfs_open_file *of)
|
|
|
|
{
|
|
|
|
struct task_struct *tsk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
if (pid) {
|
|
|
|
tsk = find_task_by_vpid(pid);
|
|
|
|
if (!tsk) {
|
|
|
|
rcu_read_unlock();
|
2017-09-25 16:39:35 -07:00
|
|
|
rdt_last_cmd_printf("No task %d\n", pid);
|
2016-10-28 15:04:46 -07:00
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tsk = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_task_struct(tsk);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
ret = rdtgroup_task_write_permission(tsk, of);
|
|
|
|
if (!ret)
|
|
|
|
ret = __rdtgroup_move_task(tsk, rdtgrp);
|
|
|
|
|
|
|
|
put_task_struct(tsk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
2023-10-16 19:23:00 -05:00
|
|
|
char *pid_str;
|
2016-10-28 15:04:46 -07:00
|
|
|
int ret = 0;
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
2018-06-22 15:42:12 -07:00
|
|
|
if (!rdtgrp) {
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2017-09-25 16:39:35 -07:00
|
|
|
rdt_last_cmd_clear();
|
2016-10-28 15:04:46 -07:00
|
|
|
|
2018-06-22 15:42:12 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
|
|
|
|
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
|
|
|
ret = -EINVAL;
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Pseudo-locking in progress\n");
|
2018-06-22 15:42:12 -07:00
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:23:00 -05:00
|
|
|
while (buf && buf[0] != '\0' && buf[0] != '\n') {
|
|
|
|
pid_str = strim(strsep(&buf, ","));
|
|
|
|
|
|
|
|
if (kstrtoint(pid_str, 0, &pid)) {
|
|
|
|
rdt_last_cmd_printf("Task list parsing error pid %s\n", pid_str);
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid < 0) {
|
|
|
|
rdt_last_cmd_printf("Invalid pid %d\n", pid);
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = rdtgroup_move_task(pid, rdtgrp, of);
|
|
|
|
if (ret) {
|
|
|
|
rdt_last_cmd_printf("Error while processing task %d\n", pid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-28 15:04:46 -07:00
|
|
|
|
2018-06-22 15:42:12 -07:00
|
|
|
unlock:
|
2016-10-28 15:04:46 -07:00
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
|
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
|
|
|
|
{
|
|
|
|
struct task_struct *p, *t;
|
2023-05-15 14:04:48 +08:00
|
|
|
pid_t pid;
|
2016-10-28 15:04:46 -07:00
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
for_each_process_thread(p, t) {
|
2023-05-15 14:04:48 +08:00
|
|
|
if (is_closid_match(t, r) || is_rmid_match(t, r)) {
|
|
|
|
pid = task_pid_vnr(t);
|
|
|
|
if (pid)
|
|
|
|
seq_printf(s, "%d\n", pid);
|
|
|
|
}
|
2016-10-28 15:04:46 -07:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdtgroup_tasks_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (rdtgrp)
|
|
|
|
show_rdt_tasks(rdtgrp, s);
|
|
|
|
else
|
|
|
|
ret = -ENOENT;
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:23:06 -05:00
|
|
|
static int rdtgroup_closid_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (rdtgrp)
|
|
|
|
seq_printf(s, "%u\n", rdtgrp->closid);
|
|
|
|
else
|
|
|
|
ret = -ENOENT;
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:23:08 -05:00
|
|
|
static int rdtgroup_rmid_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (rdtgrp)
|
|
|
|
seq_printf(s, "%u\n", rdtgrp->mon.rmid);
|
|
|
|
else
|
|
|
|
ret = -ENOENT;
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-15 17:28:51 +08:00
|
|
|
#ifdef CONFIG_PROC_CPU_RESCTRL
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A task can only be part of one resctrl control group and of one monitor
|
|
|
|
* group which is associated to that control group.
|
|
|
|
*
|
|
|
|
* 1) res:
|
|
|
|
* mon:
|
|
|
|
*
|
|
|
|
* resctrl is not available.
|
|
|
|
*
|
|
|
|
* 2) res:/
|
|
|
|
* mon:
|
|
|
|
*
|
|
|
|
* Task is part of the root resctrl control group, and it is not associated
|
|
|
|
* to any monitor group.
|
|
|
|
*
|
|
|
|
* 3) res:/
|
|
|
|
* mon:mon0
|
|
|
|
*
|
|
|
|
* Task is part of the root resctrl control group and monitor group mon0.
|
|
|
|
*
|
|
|
|
* 4) res:group0
|
|
|
|
* mon:
|
|
|
|
*
|
|
|
|
* Task is part of resctrl control group group0, and it is not associated
|
|
|
|
* to any monitor group.
|
|
|
|
*
|
|
|
|
* 5) res:group0
|
|
|
|
* mon:mon1
|
|
|
|
*
|
|
|
|
* Task is part of resctrl control group group0 and monitor group mon1.
|
|
|
|
*/
|
|
|
|
int proc_resctrl_show(struct seq_file *s, struct pid_namespace *ns,
|
|
|
|
struct pid *pid, struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtg;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
/* Return empty if resctrl has not been mounted. */
|
2024-02-13 18:44:30 +00:00
|
|
|
if (!resctrl_mounted) {
|
2020-01-15 17:28:51 +08:00
|
|
|
seq_puts(s, "res:\nmon:\n");
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) {
|
|
|
|
struct rdtgroup *crg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Task information is only relevant for shareable
|
|
|
|
* and exclusive groups.
|
|
|
|
*/
|
|
|
|
if (rdtg->mode != RDT_MODE_SHAREABLE &&
|
|
|
|
rdtg->mode != RDT_MODE_EXCLUSIVE)
|
|
|
|
continue;
|
|
|
|
|
2024-02-13 18:44:25 +00:00
|
|
|
if (!resctrl_arch_match_closid(tsk, rdtg->closid))
|
2020-01-15 17:28:51 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
seq_printf(s, "res:%s%s\n", (rdtg == &rdtgroup_default) ? "/" : "",
|
|
|
|
rdtg->kn->name);
|
|
|
|
seq_puts(s, "mon:");
|
|
|
|
list_for_each_entry(crg, &rdtg->mon.crdtgrp_list,
|
|
|
|
mon.crdtgrp_list) {
|
2024-02-13 18:44:25 +00:00
|
|
|
if (!resctrl_arch_match_rmid(tsk, crg->mon.parent->closid,
|
|
|
|
crg->mon.rmid))
|
2020-01-15 17:28:51 +08:00
|
|
|
continue;
|
|
|
|
seq_printf(s, "%s", crg->kn->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
seq_putc(s, '\n');
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The above search should succeed. Otherwise return
|
|
|
|
* with an error.
|
|
|
|
*/
|
|
|
|
ret = -ENOENT;
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-09-25 16:39:33 -07:00
|
|
|
static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
len = seq_buf_used(&last_cmd_status);
|
|
|
|
if (len)
|
|
|
|
seq_printf(seq, "%.*s", len, last_cmd_status_buf);
|
|
|
|
else
|
|
|
|
seq_puts(seq, "ok\n");
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
static int rdt_num_closids_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
2016-10-28 15:04:43 -07:00
|
|
|
|
2021-07-28 17:06:20 +00:00
|
|
|
seq_printf(seq, "%u\n", s->num_closid);
|
2016-10-28 15:04:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-07 17:33:51 -07:00
|
|
|
static int rdt_default_ctrl_show(struct kernfs_open_file *of,
|
2016-10-28 15:04:43 -07:00
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2016-10-28 15:04:43 -07:00
|
|
|
|
2017-04-07 17:33:51 -07:00
|
|
|
seq_printf(seq, "%x\n", r->default_ctrl);
|
2016-10-28 15:04:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-03 14:09:06 -07:00
|
|
|
static int rdt_min_cbm_bits_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2016-11-03 14:09:06 -07:00
|
|
|
|
2017-04-14 13:00:36 +02:00
|
|
|
seq_printf(seq, "%u\n", r->cache.min_cbm_bits);
|
2017-04-07 17:33:55 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 15:39:04 -07:00
|
|
|
static int rdt_shareable_bits_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2017-07-25 15:39:04 -07:00
|
|
|
|
|
|
|
seq_printf(seq, "%x\n", r->cache.shareable_bits);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-11 08:48:42 +02:00
|
|
|
/*
|
2018-06-22 15:42:05 -07:00
|
|
|
* rdt_bit_usage_show - Display current usage of resources
|
|
|
|
*
|
|
|
|
* A domain is a shared resource that can now be allocated differently. Here
|
|
|
|
* we display the current regions of the domain as an annotated bitmask.
|
|
|
|
* For each domain of this resource its allocation bitmask
|
|
|
|
* is annotated as below to indicate the current usage of the corresponding bit:
|
|
|
|
* 0 - currently unused
|
|
|
|
* X - currently available for sharing and used by software and hardware
|
|
|
|
* H - currently used by hardware only but available for software use
|
|
|
|
* S - currently used and shareable by software only
|
|
|
|
* E - currently used exclusively by one resource group
|
2018-06-22 15:42:23 -07:00
|
|
|
* P - currently pseudo-locked by one resource group
|
2018-06-22 15:42:05 -07:00
|
|
|
*/
|
|
|
|
static int rdt_bit_usage_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
2019-06-19 13:27:16 -07:00
|
|
|
/*
|
|
|
|
* Use unsigned long even though only 32 bits are used to ensure
|
|
|
|
* test_bit() is used safely.
|
|
|
|
*/
|
|
|
|
unsigned long sw_shareable = 0, hw_shareable = 0;
|
|
|
|
unsigned long exclusive = 0, pseudo_locked = 0;
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct rdt_resource *r = s->res;
|
2018-06-22 15:42:05 -07:00
|
|
|
struct rdt_domain *dom;
|
2018-06-22 15:42:23 -07:00
|
|
|
int i, hwb, swb, excl, psl;
|
2018-06-22 15:42:05 -07:00
|
|
|
enum rdtgrp_mode mode;
|
|
|
|
bool sep = false;
|
2021-07-28 17:06:29 +00:00
|
|
|
u32 ctrl_val;
|
2018-06-22 15:42:05 -07:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2018-06-22 15:42:05 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
hw_shareable = r->cache.shareable_bits;
|
|
|
|
list_for_each_entry(dom, &r->domains, list) {
|
|
|
|
if (sep)
|
|
|
|
seq_putc(seq, ';');
|
|
|
|
sw_shareable = 0;
|
|
|
|
exclusive = 0;
|
|
|
|
seq_printf(seq, "%d=", dom->id);
|
2021-07-28 17:06:29 +00:00
|
|
|
for (i = 0; i < closids_supported(); i++) {
|
2018-06-22 15:42:05 -07:00
|
|
|
if (!closid_allocated(i))
|
|
|
|
continue;
|
2021-08-11 16:38:31 +00:00
|
|
|
ctrl_val = resctrl_arch_get_config(r, dom, i,
|
|
|
|
s->conf_type);
|
2018-06-22 15:42:05 -07:00
|
|
|
mode = rdtgroup_mode_by_closid(i);
|
|
|
|
switch (mode) {
|
|
|
|
case RDT_MODE_SHAREABLE:
|
2021-07-28 17:06:29 +00:00
|
|
|
sw_shareable |= ctrl_val;
|
2018-06-22 15:42:05 -07:00
|
|
|
break;
|
|
|
|
case RDT_MODE_EXCLUSIVE:
|
2021-07-28 17:06:29 +00:00
|
|
|
exclusive |= ctrl_val;
|
2018-06-22 15:42:05 -07:00
|
|
|
break;
|
2018-06-22 15:42:23 -07:00
|
|
|
case RDT_MODE_PSEUDO_LOCKSETUP:
|
2018-06-22 15:42:08 -07:00
|
|
|
/*
|
2018-06-22 15:42:23 -07:00
|
|
|
* RDT_MODE_PSEUDO_LOCKSETUP is possible
|
|
|
|
* here but not included since the CBM
|
|
|
|
* associated with this CLOSID in this mode
|
|
|
|
* is not initialized and no task or cpu can be
|
|
|
|
* assigned this CLOSID.
|
2018-06-22 15:42:08 -07:00
|
|
|
*/
|
2018-06-22 15:42:23 -07:00
|
|
|
break;
|
2018-06-22 15:42:08 -07:00
|
|
|
case RDT_MODE_PSEUDO_LOCKED:
|
2018-06-22 15:42:05 -07:00
|
|
|
case RDT_NUM_MODES:
|
|
|
|
WARN(1,
|
|
|
|
"invalid mode for closid %d\n", i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = r->cache.cbm_len - 1; i >= 0; i--) {
|
2018-06-22 15:42:23 -07:00
|
|
|
pseudo_locked = dom->plr ? dom->plr->cbm : 0;
|
2019-06-19 13:27:16 -07:00
|
|
|
hwb = test_bit(i, &hw_shareable);
|
|
|
|
swb = test_bit(i, &sw_shareable);
|
|
|
|
excl = test_bit(i, &exclusive);
|
|
|
|
psl = test_bit(i, &pseudo_locked);
|
2018-06-22 15:42:05 -07:00
|
|
|
if (hwb && swb)
|
|
|
|
seq_putc(seq, 'X');
|
|
|
|
else if (hwb && !swb)
|
|
|
|
seq_putc(seq, 'H');
|
|
|
|
else if (!hwb && swb)
|
|
|
|
seq_putc(seq, 'S');
|
|
|
|
else if (excl)
|
|
|
|
seq_putc(seq, 'E');
|
2018-06-22 15:42:23 -07:00
|
|
|
else if (psl)
|
|
|
|
seq_putc(seq, 'P');
|
2018-06-22 15:42:05 -07:00
|
|
|
else /* Unused bits remain */
|
|
|
|
seq_putc(seq, '0');
|
|
|
|
}
|
|
|
|
sep = true;
|
|
|
|
}
|
|
|
|
seq_putc(seq, '\n');
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
2018-06-22 15:42:05 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-07 17:33:55 -07:00
|
|
|
static int rdt_min_bw_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2016-11-03 14:09:06 -07:00
|
|
|
|
2017-04-07 17:33:55 -07:00
|
|
|
seq_printf(seq, "%u\n", r->membw.min_bw);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:30 -07:00
|
|
|
static int rdt_num_rmids_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = of->kn->parent->priv;
|
|
|
|
|
|
|
|
seq_printf(seq, "%d\n", r->num_rmid);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdt_mon_features_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = of->kn->parent->priv;
|
|
|
|
struct mon_evt *mevt;
|
|
|
|
|
2023-01-13 09:20:34 -06:00
|
|
|
list_for_each_entry(mevt, &r->evt_list, list) {
|
2017-07-25 14:14:30 -07:00
|
|
|
seq_printf(seq, "%s\n", mevt->name);
|
2023-01-13 09:20:34 -06:00
|
|
|
if (mevt->configurable)
|
|
|
|
seq_printf(seq, "%s_config\n", mevt->name);
|
|
|
|
}
|
2017-07-25 14:14:30 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-07 17:33:55 -07:00
|
|
|
static int rdt_bw_gran_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2017-04-07 17:33:55 -07:00
|
|
|
|
|
|
|
seq_printf(seq, "%u\n", r->membw.bw_gran);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdt_delay_linear_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2017-04-07 17:33:55 -07:00
|
|
|
|
|
|
|
seq_printf(seq, "%u\n", r->membw.delay_linear);
|
2016-11-03 14:09:06 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:30 -07:00
|
|
|
static int max_threshold_occ_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
2022-09-02 15:48:27 +00:00
|
|
|
seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
|
2017-07-25 14:14:30 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-24 12:11:21 -07:00
|
|
|
static int rdt_thread_throttle_mode_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
2020-08-24 12:11:21 -07:00
|
|
|
|
|
|
|
if (r->membw.throttle_mode == THREAD_THROTTLE_PER_THREAD)
|
|
|
|
seq_puts(seq, "per-thread\n");
|
|
|
|
else
|
|
|
|
seq_puts(seq, "max\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:30 -07:00
|
|
|
static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
|
|
|
{
|
|
|
|
unsigned int bytes;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kstrtouint(buf, 0, &bytes);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-09-02 15:48:28 +00:00
|
|
|
if (bytes > resctrl_rmid_realloc_limit)
|
2017-07-25 14:14:30 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2022-09-02 15:48:27 +00:00
|
|
|
resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(bytes);
|
2017-07-25 14:14:30 -07:00
|
|
|
|
2017-08-08 10:28:59 +01:00
|
|
|
return nbytes;
|
2017-07-25 14:14:30 -07:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:56 -07:00
|
|
|
/*
|
|
|
|
* rdtgroup_mode_show - Display mode of this resource group
|
|
|
|
*/
|
|
|
|
static int rdtgroup_mode_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
seq_printf(s, "%s\n", rdtgroup_mode_str(rdtgrp->mode));
|
|
|
|
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:35 +00:00
|
|
|
static enum resctrl_conf_type resctrl_peer_type(enum resctrl_conf_type my_type)
|
2018-10-03 15:17:01 -07:00
|
|
|
{
|
2021-07-28 17:06:35 +00:00
|
|
|
switch (my_type) {
|
|
|
|
case CDP_CODE:
|
|
|
|
return CDP_DATA;
|
|
|
|
case CDP_DATA:
|
|
|
|
return CDP_CODE;
|
2018-10-03 15:17:01 -07:00
|
|
|
default:
|
2021-07-28 17:06:35 +00:00
|
|
|
case CDP_NONE:
|
|
|
|
return CDP_NONE;
|
2018-10-03 15:17:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 12:42:38 +02:00
|
|
|
static int rdt_has_sparse_bitmasks_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct resctrl_schema *s = of->kn->parent->priv;
|
|
|
|
struct rdt_resource *r = s->res;
|
|
|
|
|
|
|
|
seq_printf(seq, "%u\n", r->cache.arch_has_sparse_bitmasks);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:01 -07:00
|
|
|
/**
|
2018-10-03 15:17:02 -07:00
|
|
|
* __rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other
|
2018-06-22 15:42:01 -07:00
|
|
|
* @r: Resource to which domain instance @d belongs.
|
|
|
|
* @d: The domain instance for which @closid is being tested.
|
|
|
|
* @cbm: Capacity bitmask being tested.
|
|
|
|
* @closid: Intended closid for @cbm.
|
2023-10-11 08:48:42 +02:00
|
|
|
* @type: CDP type of @r.
|
2018-06-22 15:42:01 -07:00
|
|
|
* @exclusive: Only check if overlaps with exclusive resource groups
|
|
|
|
*
|
|
|
|
* Checks if provided @cbm intended to be used for @closid on domain
|
|
|
|
* @d overlaps with any other closids or other hardware usage associated
|
|
|
|
* with this domain. If @exclusive is true then only overlaps with
|
|
|
|
* resource groups in exclusive mode will be considered. If @exclusive
|
|
|
|
* is false then overlaps with any resource group or hardware entities
|
|
|
|
* will be considered.
|
|
|
|
*
|
2018-10-04 14:05:23 -07:00
|
|
|
* @cbm is unsigned long, even if only 32 bits are used, to make the
|
|
|
|
* bitmap functions work correctly.
|
|
|
|
*
|
2018-06-22 15:42:01 -07:00
|
|
|
* Return: false if CBM does not overlap, true if it does.
|
|
|
|
*/
|
2018-10-03 15:17:02 -07:00
|
|
|
static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
|
2021-07-28 17:06:30 +00:00
|
|
|
unsigned long cbm, int closid,
|
|
|
|
enum resctrl_conf_type type, bool exclusive)
|
2018-06-22 15:42:01 -07:00
|
|
|
{
|
|
|
|
enum rdtgrp_mode mode;
|
2018-10-04 14:05:23 -07:00
|
|
|
unsigned long ctrl_b;
|
2018-06-22 15:42:01 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Check for any overlap with regions used by hardware directly */
|
|
|
|
if (!exclusive) {
|
2018-10-04 14:05:23 -07:00
|
|
|
ctrl_b = r->cache.shareable_bits;
|
|
|
|
if (bitmap_intersects(&cbm, &ctrl_b, r->cache.cbm_len))
|
2018-06-22 15:42:01 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for overlap with other resource groups */
|
2021-07-28 17:06:29 +00:00
|
|
|
for (i = 0; i < closids_supported(); i++) {
|
2021-08-11 16:38:31 +00:00
|
|
|
ctrl_b = resctrl_arch_get_config(r, d, i, type);
|
2018-06-22 15:42:17 -07:00
|
|
|
mode = rdtgroup_mode_by_closid(i);
|
|
|
|
if (closid_allocated(i) && i != closid &&
|
|
|
|
mode != RDT_MODE_PSEUDO_LOCKSETUP) {
|
2018-10-04 14:05:23 -07:00
|
|
|
if (bitmap_intersects(&cbm, &ctrl_b, r->cache.cbm_len)) {
|
2018-06-22 15:42:01 -07:00
|
|
|
if (exclusive) {
|
|
|
|
if (mode == RDT_MODE_EXCLUSIVE)
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-03 15:17:02 -07:00
|
|
|
/**
|
|
|
|
* rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware
|
2021-07-28 17:06:22 +00:00
|
|
|
* @s: Schema for the resource to which domain instance @d belongs.
|
2018-10-03 15:17:02 -07:00
|
|
|
* @d: The domain instance for which @closid is being tested.
|
|
|
|
* @cbm: Capacity bitmask being tested.
|
|
|
|
* @closid: Intended closid for @cbm.
|
|
|
|
* @exclusive: Only check if overlaps with exclusive resource groups
|
|
|
|
*
|
|
|
|
* Resources that can be allocated using a CBM can use the CBM to control
|
|
|
|
* the overlap of these allocations. rdtgroup_cmb_overlaps() is the test
|
|
|
|
* for overlap. Overlap test is not limited to the specific resource for
|
|
|
|
* which the CBM is intended though - when dealing with CDP resources that
|
|
|
|
* share the underlying hardware the overlap check should be performed on
|
|
|
|
* the CDP resource sharing the hardware also.
|
|
|
|
*
|
|
|
|
* Refer to description of __rdtgroup_cbm_overlaps() for the details of the
|
|
|
|
* overlap test.
|
|
|
|
*
|
|
|
|
* Return: true if CBM overlap detected, false if there is no overlap
|
|
|
|
*/
|
2021-07-28 17:06:22 +00:00
|
|
|
bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_domain *d,
|
2018-10-03 15:17:02 -07:00
|
|
|
unsigned long cbm, int closid, bool exclusive)
|
|
|
|
{
|
2021-07-28 17:06:35 +00:00
|
|
|
enum resctrl_conf_type peer_type = resctrl_peer_type(s->conf_type);
|
2021-07-28 17:06:22 +00:00
|
|
|
struct rdt_resource *r = s->res;
|
2018-10-03 15:17:02 -07:00
|
|
|
|
2021-07-28 17:06:30 +00:00
|
|
|
if (__rdtgroup_cbm_overlaps(r, d, cbm, closid, s->conf_type,
|
|
|
|
exclusive))
|
2018-10-03 15:17:02 -07:00
|
|
|
return true;
|
|
|
|
|
2021-07-28 17:06:35 +00:00
|
|
|
if (!resctrl_arch_get_cdp_enabled(r->rid))
|
2018-10-03 15:17:02 -07:00
|
|
|
return false;
|
2021-07-28 17:06:35 +00:00
|
|
|
return __rdtgroup_cbm_overlaps(r, d, cbm, closid, peer_type, exclusive);
|
2018-10-03 15:17:02 -07:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:01 -07:00
|
|
|
/**
|
|
|
|
* rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive
|
2023-10-11 08:48:42 +02:00
|
|
|
* @rdtgrp: Resource group identified through its closid.
|
2018-06-22 15:42:01 -07:00
|
|
|
*
|
|
|
|
* An exclusive resource group implies that there should be no sharing of
|
|
|
|
* its allocated resources. At the time this group is considered to be
|
|
|
|
* exclusive this test can determine if its current schemata supports this
|
|
|
|
* setting by testing for overlap with all other resource groups.
|
|
|
|
*
|
|
|
|
* Return: true if resource group can be exclusive, false if there is overlap
|
|
|
|
* with allocations of other resource groups and thus this resource group
|
|
|
|
* cannot be exclusive.
|
|
|
|
*/
|
|
|
|
static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
|
|
|
|
{
|
|
|
|
int closid = rdtgrp->closid;
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *s;
|
2018-06-22 15:42:01 -07:00
|
|
|
struct rdt_resource *r;
|
2018-09-15 14:58:26 -07:00
|
|
|
bool has_cache = false;
|
2018-06-22 15:42:01 -07:00
|
|
|
struct rdt_domain *d;
|
2021-07-28 17:06:29 +00:00
|
|
|
u32 ctrl;
|
2018-06-22 15:42:01 -07:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
/* Walking r->domains, ensure it can't race with cpuhp */
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list) {
|
|
|
|
r = s->res;
|
2023-01-13 09:20:32 -06:00
|
|
|
if (r->rid == RDT_RESOURCE_MBA || r->rid == RDT_RESOURCE_SMBA)
|
2018-09-15 14:58:26 -07:00
|
|
|
continue;
|
|
|
|
has_cache = true;
|
2018-06-22 15:42:01 -07:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
2021-08-11 16:38:31 +00:00
|
|
|
ctrl = resctrl_arch_get_config(r, d, closid,
|
|
|
|
s->conf_type);
|
2021-07-28 17:06:29 +00:00
|
|
|
if (rdtgroup_cbm_overlaps(s, d, ctrl, closid, false)) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Schemata overlaps\n");
|
2018-06-22 15:42:01 -07:00
|
|
|
return false;
|
2018-09-15 14:58:26 -07:00
|
|
|
}
|
2018-06-22 15:42:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 14:58:26 -07:00
|
|
|
if (!has_cache) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Cannot be exclusive without CAT/CDP\n");
|
2018-09-15 14:58:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:01 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-11 08:48:42 +02:00
|
|
|
/*
|
2018-06-22 15:42:01 -07:00
|
|
|
* rdtgroup_mode_write - Modify the resource group's mode
|
|
|
|
*/
|
2018-06-22 15:41:56 -07:00
|
|
|
static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
enum rdtgrp_mode mode;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Valid input requires a trailing newline */
|
|
|
|
if (nbytes == 0 || buf[nbytes - 1] != '\n')
|
|
|
|
return -EINVAL;
|
|
|
|
buf[nbytes - 1] = '\0';
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdt_last_cmd_clear();
|
|
|
|
|
|
|
|
mode = rdtgrp->mode;
|
|
|
|
|
2018-06-22 15:42:01 -07:00
|
|
|
if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||
|
2018-06-22 15:42:17 -07:00
|
|
|
(!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
|
|
|
|
(!strcmp(buf, "pseudo-locksetup") &&
|
|
|
|
mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
|
|
|
|
(!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
|
2018-06-22 15:41:56 -07:00
|
|
|
goto out;
|
|
|
|
|
2018-06-22 15:42:17 -07:00
|
|
|
if (mode == RDT_MODE_PSEUDO_LOCKED) {
|
2018-11-27 11:19:36 -08:00
|
|
|
rdt_last_cmd_puts("Cannot change pseudo-locked group\n");
|
2018-06-22 15:42:17 -07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:56 -07:00
|
|
|
if (!strcmp(buf, "shareable")) {
|
2018-06-22 15:42:17 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
|
|
|
ret = rdtgroup_locksetup_exit(rdtgrp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
2018-06-22 15:41:56 -07:00
|
|
|
rdtgrp->mode = RDT_MODE_SHAREABLE;
|
2018-06-22 15:42:01 -07:00
|
|
|
} else if (!strcmp(buf, "exclusive")) {
|
|
|
|
if (!rdtgroup_mode_test_exclusive(rdtgrp)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-06-22 15:42:17 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
|
|
|
ret = rdtgroup_locksetup_exit(rdtgrp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
2018-06-22 15:42:01 -07:00
|
|
|
rdtgrp->mode = RDT_MODE_EXCLUSIVE;
|
2018-06-22 15:42:17 -07:00
|
|
|
} else if (!strcmp(buf, "pseudo-locksetup")) {
|
|
|
|
ret = rdtgroup_locksetup_enter(rdtgrp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
rdtgrp->mode = RDT_MODE_PSEUDO_LOCKSETUP;
|
2018-06-22 15:41:56 -07:00
|
|
|
} else {
|
2018-11-27 11:19:36 -08:00
|
|
|
rdt_last_cmd_puts("Unknown or unsupported mode\n");
|
2018-06-22 15:41:56 -07:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:06 -07:00
|
|
|
/**
|
|
|
|
* rdtgroup_cbm_to_size - Translate CBM to size in bytes
|
|
|
|
* @r: RDT resource to which @d belongs.
|
|
|
|
* @d: RDT domain instance.
|
|
|
|
* @cbm: bitmask for which the size should be computed.
|
|
|
|
*
|
|
|
|
* The bitmask provided associated with the RDT domain instance @d will be
|
|
|
|
* translated into how many bytes it represents. The size in bytes is
|
|
|
|
* computed by first dividing the total cache size by the CBM length to
|
|
|
|
* determine how many bytes each bit in the bitmask represents. The result
|
|
|
|
* is multiplied with the number of bits set in the bitmask.
|
2018-10-04 14:05:23 -07:00
|
|
|
*
|
|
|
|
* @cbm is unsigned long, even if only 32 bits are used to make the
|
|
|
|
* bitmap functions work correctly.
|
2018-06-22 15:42:06 -07:00
|
|
|
*/
|
|
|
|
unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
|
2018-10-04 14:05:23 -07:00
|
|
|
struct rdt_domain *d, unsigned long cbm)
|
2018-06-22 15:42:06 -07:00
|
|
|
{
|
|
|
|
struct cpu_cacheinfo *ci;
|
|
|
|
unsigned int size = 0;
|
|
|
|
int num_b, i;
|
|
|
|
|
2018-10-04 14:05:23 -07:00
|
|
|
num_b = bitmap_weight(&cbm, r->cache.cbm_len);
|
2018-06-22 15:42:06 -07:00
|
|
|
ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask));
|
|
|
|
for (i = 0; i < ci->num_leaves; i++) {
|
|
|
|
if (ci->info_list[i].level == r->cache_level) {
|
|
|
|
size = ci->info_list[i].size / r->cache.cbm_len * num_b;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2023-10-11 08:48:42 +02:00
|
|
|
/*
|
2018-06-22 15:42:06 -07:00
|
|
|
* rdtgroup_size_show - Display size in bytes of allocated regions
|
|
|
|
*
|
|
|
|
* The "size" file mirrors the layout of the "schemata" file, printing the
|
|
|
|
* size in bytes of each region instead of the capacity bitmask.
|
|
|
|
*/
|
|
|
|
static int rdtgroup_size_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *s, void *v)
|
|
|
|
{
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *schema;
|
2022-09-02 15:48:17 +00:00
|
|
|
enum resctrl_conf_type type;
|
2018-06-22 15:42:06 -07:00
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
struct rdt_resource *r;
|
|
|
|
struct rdt_domain *d;
|
|
|
|
unsigned int size;
|
2018-10-12 15:51:01 -07:00
|
|
|
int ret = 0;
|
2022-09-02 15:48:17 +00:00
|
|
|
u32 closid;
|
2018-09-15 14:58:20 -07:00
|
|
|
bool sep;
|
|
|
|
u32 ctrl;
|
2018-06-22 15:42:06 -07:00
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(of->kn);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:23 -07:00
|
|
|
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:", max_name_width,
|
2021-07-28 17:06:25 +00:00
|
|
|
rdtgrp->plr->s->name);
|
2021-07-28 17:06:23 +00:00
|
|
|
size = rdtgroup_cbm_to_size(rdtgrp->plr->s->res,
|
2018-10-12 15:51:01 -07:00
|
|
|
rdtgrp->plr->d,
|
|
|
|
rdtgrp->plr->cbm);
|
|
|
|
seq_printf(s, "%d=%u\n", rdtgrp->plr->d->id, size);
|
|
|
|
}
|
2018-06-22 15:42:23 -07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:17 +00:00
|
|
|
closid = rdtgrp->closid;
|
|
|
|
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(schema, &resctrl_schema_all, list) {
|
|
|
|
r = schema->res;
|
2022-09-02 15:48:17 +00:00
|
|
|
type = schema->conf_type;
|
2018-09-15 14:58:20 -07:00
|
|
|
sep = false;
|
2021-07-28 17:06:25 +00:00
|
|
|
seq_printf(s, "%*s:", max_name_width, schema->name);
|
2018-06-22 15:42:06 -07:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
|
|
|
if (sep)
|
|
|
|
seq_putc(s, ';');
|
2018-06-22 15:42:17 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
|
|
|
|
size = 0;
|
|
|
|
} else {
|
2022-09-02 15:48:17 +00:00
|
|
|
if (is_mba_sc(r))
|
|
|
|
ctrl = d->mbps_val[closid];
|
|
|
|
else
|
|
|
|
ctrl = resctrl_arch_get_config(r, d,
|
|
|
|
closid,
|
|
|
|
type);
|
2023-01-13 09:20:32 -06:00
|
|
|
if (r->rid == RDT_RESOURCE_MBA ||
|
|
|
|
r->rid == RDT_RESOURCE_SMBA)
|
2018-09-15 14:58:20 -07:00
|
|
|
size = ctrl;
|
|
|
|
else
|
|
|
|
size = rdtgroup_cbm_to_size(r, d, ctrl);
|
2018-06-22 15:42:17 -07:00
|
|
|
}
|
2018-06-22 15:42:06 -07:00
|
|
|
seq_printf(s, "%d=%u", d->id, size);
|
|
|
|
sep = true;
|
|
|
|
}
|
|
|
|
seq_putc(s, '\n');
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:23 -07:00
|
|
|
out:
|
2018-06-22 15:42:06 -07:00
|
|
|
rdtgroup_kn_unlock(of->kn);
|
|
|
|
|
2018-10-12 15:51:01 -07:00
|
|
|
return ret;
|
2018-06-22 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:35 -06:00
|
|
|
struct mon_config_info {
|
|
|
|
u32 evtid;
|
|
|
|
u32 mon_config;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INVALID_CONFIG_INDEX UINT_MAX
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mon_event_config_index_get - get the hardware index for the
|
|
|
|
* configurable event
|
|
|
|
* @evtid: event id.
|
|
|
|
*
|
|
|
|
* Return: 0 for evtid == QOS_L3_MBM_TOTAL_EVENT_ID
|
|
|
|
* 1 for evtid == QOS_L3_MBM_LOCAL_EVENT_ID
|
|
|
|
* INVALID_CONFIG_INDEX for invalid evtid
|
|
|
|
*/
|
|
|
|
static inline unsigned int mon_event_config_index_get(u32 evtid)
|
|
|
|
{
|
|
|
|
switch (evtid) {
|
|
|
|
case QOS_L3_MBM_TOTAL_EVENT_ID:
|
|
|
|
return 0;
|
|
|
|
case QOS_L3_MBM_LOCAL_EVENT_ID:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
/* Should never reach here */
|
|
|
|
return INVALID_CONFIG_INDEX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mon_event_config_read(void *info)
|
|
|
|
{
|
|
|
|
struct mon_config_info *mon_info = info;
|
|
|
|
unsigned int index;
|
2023-01-24 19:01:05 +01:00
|
|
|
u64 msrval;
|
2023-01-13 09:20:35 -06:00
|
|
|
|
|
|
|
index = mon_event_config_index_get(mon_info->evtid);
|
|
|
|
if (index == INVALID_CONFIG_INDEX) {
|
|
|
|
pr_warn_once("Invalid event id %d\n", mon_info->evtid);
|
|
|
|
return;
|
|
|
|
}
|
2023-01-24 19:01:05 +01:00
|
|
|
rdmsrl(MSR_IA32_EVT_CFG_BASE + index, msrval);
|
2023-01-13 09:20:35 -06:00
|
|
|
|
|
|
|
/* Report only the valid event configuration bits */
|
2023-01-24 19:01:05 +01:00
|
|
|
mon_info->mon_config = msrval & MAX_EVT_CONFIG_BITS;
|
2023-01-13 09:20:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mondata_config_read(struct rdt_domain *d, struct mon_config_info *mon_info)
|
|
|
|
{
|
|
|
|
smp_call_function_any(&d->cpu_mask, mon_event_config_read, mon_info, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid)
|
|
|
|
{
|
|
|
|
struct mon_config_info mon_info = {0};
|
|
|
|
struct rdt_domain *dom;
|
|
|
|
bool sep = false;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2023-01-13 09:20:35 -06:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(dom, &r->domains, list) {
|
|
|
|
if (sep)
|
|
|
|
seq_puts(s, ";");
|
|
|
|
|
|
|
|
memset(&mon_info, 0, sizeof(struct mon_config_info));
|
|
|
|
mon_info.evtid = evtid;
|
|
|
|
mondata_config_read(dom, &mon_info);
|
|
|
|
|
|
|
|
seq_printf(s, "%d=0x%02x", dom->id, mon_info.mon_config);
|
|
|
|
sep = true;
|
|
|
|
}
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
2023-01-13 09:20:35 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mbm_total_bytes_config_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = of->kn->parent->priv;
|
|
|
|
|
|
|
|
mbm_config_show(seq, r, QOS_L3_MBM_TOTAL_EVENT_ID);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:36 -06:00
|
|
|
static int mbm_local_bytes_config_show(struct kernfs_open_file *of,
|
|
|
|
struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = of->kn->parent->priv;
|
|
|
|
|
|
|
|
mbm_config_show(seq, r, QOS_L3_MBM_LOCAL_EVENT_ID);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:37 -06:00
|
|
|
static void mon_event_config_write(void *info)
|
|
|
|
{
|
|
|
|
struct mon_config_info *mon_info = info;
|
|
|
|
unsigned int index;
|
|
|
|
|
|
|
|
index = mon_event_config_index_get(mon_info->evtid);
|
|
|
|
if (index == INVALID_CONFIG_INDEX) {
|
|
|
|
pr_warn_once("Invalid event id %d\n", mon_info->evtid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);
|
|
|
|
}
|
|
|
|
|
2024-01-24 11:52:56 -06:00
|
|
|
static void mbm_config_write_domain(struct rdt_resource *r,
|
|
|
|
struct rdt_domain *d, u32 evtid, u32 val)
|
2023-01-13 09:20:37 -06:00
|
|
|
{
|
|
|
|
struct mon_config_info mon_info = {0};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the current config value first. If both are the same then
|
|
|
|
* no need to write it again.
|
|
|
|
*/
|
|
|
|
mon_info.evtid = evtid;
|
|
|
|
mondata_config_read(d, &mon_info);
|
|
|
|
if (mon_info.mon_config == val)
|
2024-01-24 11:52:56 -06:00
|
|
|
return;
|
2023-01-13 09:20:37 -06:00
|
|
|
|
|
|
|
mon_info.mon_config = val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update MSR_IA32_EVT_CFG_BASE MSR on one of the CPUs in the
|
|
|
|
* domain. The MSRs offset from MSR MSR_IA32_EVT_CFG_BASE
|
|
|
|
* are scoped at the domain level. Writing any of these MSRs
|
|
|
|
* on one CPU is observed by all the CPUs in the domain.
|
|
|
|
*/
|
|
|
|
smp_call_function_any(&d->cpu_mask, mon_event_config_write,
|
|
|
|
&mon_info, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When an Event Configuration is changed, the bandwidth counters
|
|
|
|
* for all RMIDs and Events will be cleared by the hardware. The
|
|
|
|
* hardware also sets MSR_IA32_QM_CTR.Unavailable (bit 62) for
|
|
|
|
* every RMID on the next read to any event for every RMID.
|
|
|
|
* Subsequent reads will have MSR_IA32_QM_CTR.Unavailable (bit 62)
|
|
|
|
* cleared while it is tracked by the hardware. Clear the
|
|
|
|
* mbm_local and mbm_total counts for all the RMIDs.
|
|
|
|
*/
|
|
|
|
resctrl_arch_reset_rmid_all(r, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
|
|
|
|
{
|
2024-01-15 16:52:28 -06:00
|
|
|
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
|
2023-01-13 09:20:37 -06:00
|
|
|
char *dom_str = NULL, *id_str;
|
|
|
|
unsigned long dom_id, val;
|
|
|
|
struct rdt_domain *d;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
/* Walking r->domains, ensure it can't race with cpuhp */
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
2023-01-13 09:20:37 -06:00
|
|
|
next:
|
|
|
|
if (!tok || tok[0] == '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Start processing the strings for each domain */
|
|
|
|
dom_str = strim(strsep(&tok, ";"));
|
|
|
|
id_str = strsep(&dom_str, "=");
|
|
|
|
|
|
|
|
if (!id_str || kstrtoul(id_str, 10, &dom_id)) {
|
|
|
|
rdt_last_cmd_puts("Missing '=' or non-numeric domain id\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dom_str || kstrtoul(dom_str, 16, &val)) {
|
|
|
|
rdt_last_cmd_puts("Non-numeric event configuration value\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:52:28 -06:00
|
|
|
/* Value from user cannot be more than the supported set of events */
|
|
|
|
if ((val & hw_res->mbm_cfg_mask) != val) {
|
|
|
|
rdt_last_cmd_printf("Invalid event configuration: max valid mask is 0x%02x\n",
|
|
|
|
hw_res->mbm_cfg_mask);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:37 -06:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
|
|
|
if (d->id == dom_id) {
|
2024-01-24 11:52:56 -06:00
|
|
|
mbm_config_write_domain(r, d, evtid, val);
|
2023-01-13 09:20:37 -06:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mbm_total_bytes_config_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes,
|
|
|
|
loff_t off)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = of->kn->parent->priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Valid input requires a trailing newline */
|
|
|
|
if (nbytes == 0 || buf[nbytes - 1] != '\n')
|
|
|
|
return -EINVAL;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2023-01-13 09:20:37 -06:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
rdt_last_cmd_clear();
|
|
|
|
|
|
|
|
buf[nbytes - 1] = '\0';
|
|
|
|
|
|
|
|
ret = mon_config_write(r, buf, QOS_L3_MBM_TOTAL_EVENT_ID);
|
|
|
|
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
2023-01-13 09:20:37 -06:00
|
|
|
|
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:38 -06:00
|
|
|
static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes,
|
|
|
|
loff_t off)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = of->kn->parent->priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Valid input requires a trailing newline */
|
|
|
|
if (nbytes == 0 || buf[nbytes - 1] != '\n')
|
|
|
|
return -EINVAL;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2023-01-13 09:20:38 -06:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
rdt_last_cmd_clear();
|
|
|
|
|
|
|
|
buf[nbytes - 1] = '\0';
|
|
|
|
|
|
|
|
ret = mon_config_write(r, buf, QOS_L3_MBM_LOCAL_EVENT_ID);
|
|
|
|
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
2023-01-13 09:20:38 -06:00
|
|
|
|
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
/* rdtgroup information files for one cache resource. */
|
2017-07-25 14:14:29 -07:00
|
|
|
static struct rftype res_common_files[] = {
|
2017-09-25 16:39:33 -07:00
|
|
|
{
|
|
|
|
.name = "last_cmd_status",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_last_cmd_status_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_TOP_INFO,
|
2017-09-25 16:39:33 -07:00
|
|
|
},
|
2016-10-28 15:04:43 -07:00
|
|
|
{
|
|
|
|
.name = "num_closids",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_num_closids_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO,
|
2016-10-28 15:04:43 -07:00
|
|
|
},
|
2017-07-25 14:14:30 -07:00
|
|
|
{
|
|
|
|
.name = "mon_features",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_mon_features_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_MON_INFO,
|
2017-07-25 14:14:30 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "num_rmids",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_num_rmids_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_MON_INFO,
|
2017-07-25 14:14:30 -07:00
|
|
|
},
|
2016-10-28 15:04:43 -07:00
|
|
|
{
|
|
|
|
.name = "cbm_mask",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
2017-04-07 17:33:51 -07:00
|
|
|
.seq_show = rdt_default_ctrl_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
|
2016-10-28 15:04:43 -07:00
|
|
|
},
|
2016-11-03 14:09:06 -07:00
|
|
|
{
|
|
|
|
.name = "min_cbm_bits",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_min_cbm_bits_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
|
2017-04-07 17:33:55 -07:00
|
|
|
},
|
2017-07-25 15:39:04 -07:00
|
|
|
{
|
|
|
|
.name = "shareable_bits",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_shareable_bits_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
|
2017-07-25 15:39:04 -07:00
|
|
|
},
|
2018-06-22 15:42:05 -07:00
|
|
|
{
|
|
|
|
.name = "bit_usage",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_bit_usage_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
|
2018-06-22 15:42:05 -07:00
|
|
|
},
|
2017-04-07 17:33:55 -07:00
|
|
|
{
|
|
|
|
.name = "min_bandwidth",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_min_bw_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB,
|
2017-04-07 17:33:55 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bandwidth_gran",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_bw_gran_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB,
|
2017-04-07 17:33:55 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "delay_linear",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_delay_linear_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB,
|
2017-07-25 14:14:29 -07:00
|
|
|
},
|
2020-08-24 12:11:21 -07:00
|
|
|
/*
|
|
|
|
* Platform specific which (if any) capabilities are provided by
|
|
|
|
* thread_throttle_mode. Defer "fflags" initialization to platform
|
|
|
|
* discovery.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
.name = "thread_throttle_mode",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_thread_throttle_mode_show,
|
|
|
|
},
|
2017-07-25 14:14:30 -07:00
|
|
|
{
|
|
|
|
.name = "max_threshold_occupancy",
|
|
|
|
.mode = 0644,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.write = max_threshold_occ_write,
|
|
|
|
.seq_show = max_threshold_occ_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_MON_INFO | RFTYPE_RES_CACHE,
|
2017-07-25 14:14:30 -07:00
|
|
|
},
|
2023-01-13 09:20:35 -06:00
|
|
|
{
|
|
|
|
.name = "mbm_total_bytes_config",
|
2023-01-13 09:20:37 -06:00
|
|
|
.mode = 0644,
|
2023-01-13 09:20:35 -06:00
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = mbm_total_bytes_config_show,
|
2023-01-13 09:20:37 -06:00
|
|
|
.write = mbm_total_bytes_config_write,
|
2023-01-13 09:20:35 -06:00
|
|
|
},
|
2023-01-13 09:20:36 -06:00
|
|
|
{
|
|
|
|
.name = "mbm_local_bytes_config",
|
2023-01-13 09:20:38 -06:00
|
|
|
.mode = 0644,
|
2023-01-13 09:20:36 -06:00
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = mbm_local_bytes_config_show,
|
2023-01-13 09:20:38 -06:00
|
|
|
.write = mbm_local_bytes_config_write,
|
2023-01-13 09:20:36 -06:00
|
|
|
},
|
2017-07-25 14:14:29 -07:00
|
|
|
{
|
|
|
|
.name = "cpus",
|
|
|
|
.mode = 0644,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.write = rdtgroup_cpus_write,
|
|
|
|
.seq_show = rdtgroup_cpus_show,
|
|
|
|
.fflags = RFTYPE_BASE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "cpus_list",
|
|
|
|
.mode = 0644,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.write = rdtgroup_cpus_write,
|
|
|
|
.seq_show = rdtgroup_cpus_show,
|
|
|
|
.flags = RFTYPE_FLAGS_CPUS_LIST,
|
|
|
|
.fflags = RFTYPE_BASE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "tasks",
|
|
|
|
.mode = 0644,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.write = rdtgroup_tasks_write,
|
|
|
|
.seq_show = rdtgroup_tasks_show,
|
|
|
|
.fflags = RFTYPE_BASE,
|
|
|
|
},
|
2023-10-16 19:23:08 -05:00
|
|
|
{
|
|
|
|
.name = "mon_hw_id",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdtgroup_rmid_show,
|
|
|
|
.fflags = RFTYPE_MON_BASE | RFTYPE_DEBUG,
|
|
|
|
},
|
2017-07-25 14:14:29 -07:00
|
|
|
{
|
|
|
|
.name = "schemata",
|
|
|
|
.mode = 0644,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.write = rdtgroup_schemata_write,
|
|
|
|
.seq_show = rdtgroup_schemata_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_BASE,
|
2017-04-07 17:33:55 -07:00
|
|
|
},
|
2018-06-22 15:41:56 -07:00
|
|
|
{
|
|
|
|
.name = "mode",
|
|
|
|
.mode = 0644,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.write = rdtgroup_mode_write,
|
|
|
|
.seq_show = rdtgroup_mode_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_BASE,
|
2018-06-22 15:41:56 -07:00
|
|
|
},
|
2018-06-22 15:42:06 -07:00
|
|
|
{
|
|
|
|
.name = "size",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdtgroup_size_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_BASE,
|
2018-06-22 15:42:06 -07:00
|
|
|
},
|
2023-10-10 12:42:38 +02:00
|
|
|
{
|
|
|
|
.name = "sparse_masks",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdt_has_sparse_bitmasks_show,
|
2023-10-16 19:23:02 -05:00
|
|
|
.fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
|
2023-10-10 12:42:38 +02:00
|
|
|
},
|
2023-10-16 19:23:06 -05:00
|
|
|
{
|
|
|
|
.name = "ctrl_hw_id",
|
|
|
|
.mode = 0444,
|
|
|
|
.kf_ops = &rdtgroup_kf_single_ops,
|
|
|
|
.seq_show = rdtgroup_closid_show,
|
|
|
|
.fflags = RFTYPE_CTRL_BASE | RFTYPE_DEBUG,
|
|
|
|
},
|
2018-06-22 15:42:06 -07:00
|
|
|
|
2017-04-07 17:33:55 -07:00
|
|
|
};
|
|
|
|
|
2017-07-25 14:14:29 -07:00
|
|
|
static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)
|
2017-04-07 17:33:55 -07:00
|
|
|
{
|
2017-07-25 14:14:29 -07:00
|
|
|
struct rftype *rfts, *rft;
|
|
|
|
int ret, len;
|
|
|
|
|
|
|
|
rfts = res_common_files;
|
|
|
|
len = ARRAY_SIZE(res_common_files);
|
|
|
|
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
2023-10-16 19:23:05 -05:00
|
|
|
if (resctrl_debug)
|
|
|
|
fflags |= RFTYPE_DEBUG;
|
|
|
|
|
2017-07-25 14:14:29 -07:00
|
|
|
for (rft = rfts; rft < rfts + len; rft++) {
|
2020-08-24 12:11:21 -07:00
|
|
|
if (rft->fflags && ((fflags & rft->fflags) == rft->fflags)) {
|
2017-07-25 14:14:29 -07:00
|
|
|
ret = rdtgroup_add_file(kn, rft);
|
|
|
|
if (ret)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
pr_warn("Failed to add %s, err=%d\n", rft->name, ret);
|
|
|
|
while (--rft >= rfts) {
|
|
|
|
if ((fflags & rft->fflags) == rft->fflags)
|
|
|
|
kernfs_remove_by_name(kn, rft->name);
|
|
|
|
}
|
|
|
|
return ret;
|
2017-04-07 17:33:55 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 12:11:21 -07:00
|
|
|
static struct rftype *rdtgroup_get_rftype_by_name(const char *name)
|
|
|
|
{
|
|
|
|
struct rftype *rfts, *rft;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
rfts = res_common_files;
|
|
|
|
len = ARRAY_SIZE(res_common_files);
|
|
|
|
|
|
|
|
for (rft = rfts; rft < rfts + len; rft++) {
|
|
|
|
if (!strcmp(rft->name, name))
|
|
|
|
return rft;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init thread_throttle_mode_init(void)
|
|
|
|
{
|
|
|
|
struct rftype *rft;
|
|
|
|
|
|
|
|
rft = rdtgroup_get_rftype_by_name("thread_throttle_mode");
|
|
|
|
if (!rft)
|
|
|
|
return;
|
|
|
|
|
2023-10-16 19:23:02 -05:00
|
|
|
rft->fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB;
|
2020-08-24 12:11:21 -07:00
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:35 -06:00
|
|
|
void __init mbm_config_rftype_init(const char *config)
|
|
|
|
{
|
|
|
|
struct rftype *rft;
|
|
|
|
|
|
|
|
rft = rdtgroup_get_rftype_by_name(config);
|
|
|
|
if (rft)
|
2023-10-16 19:23:02 -05:00
|
|
|
rft->fflags = RFTYPE_MON_INFO | RFTYPE_RES_CACHE;
|
2023-01-13 09:20:35 -06:00
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:11 -07:00
|
|
|
/**
|
|
|
|
* rdtgroup_kn_mode_restrict - Restrict user access to named resctrl file
|
|
|
|
* @r: The resource group with which the file is associated.
|
|
|
|
* @name: Name of the file
|
|
|
|
*
|
|
|
|
* The permissions of named resctrl file, directory, or link are modified
|
|
|
|
* to not allow read, write, or execute by any user.
|
|
|
|
*
|
|
|
|
* WARNING: This function is intended to communicate to the user that the
|
|
|
|
* resctrl file has been locked down - that it is not relevant to the
|
|
|
|
* particular state the system finds itself in. It should not be relied
|
|
|
|
* on to protect from user access because after the file's permissions
|
|
|
|
* are restricted the user can still change the permissions using chmod
|
|
|
|
* from the command line.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, <0 on failure.
|
|
|
|
*/
|
|
|
|
int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name)
|
|
|
|
{
|
|
|
|
struct iattr iattr = {.ia_valid = ATTR_MODE,};
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
kn = kernfs_find_and_get_ns(r->kn, name, NULL);
|
|
|
|
if (!kn)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
switch (kernfs_type(kn)) {
|
|
|
|
case KERNFS_DIR:
|
|
|
|
iattr.ia_mode = S_IFDIR;
|
|
|
|
break;
|
|
|
|
case KERNFS_FILE:
|
|
|
|
iattr.ia_mode = S_IFREG;
|
|
|
|
break;
|
|
|
|
case KERNFS_LINK:
|
|
|
|
iattr.ia_mode = S_IFLNK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kernfs_setattr(kn, &iattr);
|
|
|
|
kernfs_put(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rdtgroup_kn_mode_restore - Restore user access to named resctrl file
|
|
|
|
* @r: The resource group with which the file is associated.
|
|
|
|
* @name: Name of the file
|
2018-06-30 22:17:32 -07:00
|
|
|
* @mask: Mask of permissions that should be restored
|
2018-06-22 15:42:11 -07:00
|
|
|
*
|
|
|
|
* Restore the permissions of the named file. If @name is a directory the
|
|
|
|
* permissions of its parent will be used.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, <0 on failure.
|
|
|
|
*/
|
2018-06-30 22:17:32 -07:00
|
|
|
int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
|
|
|
|
umode_t mask)
|
2018-06-22 15:42:11 -07:00
|
|
|
{
|
|
|
|
struct iattr iattr = {.ia_valid = ATTR_MODE,};
|
|
|
|
struct kernfs_node *kn, *parent;
|
|
|
|
struct rftype *rfts, *rft;
|
|
|
|
int ret, len;
|
|
|
|
|
|
|
|
rfts = res_common_files;
|
|
|
|
len = ARRAY_SIZE(res_common_files);
|
|
|
|
|
|
|
|
for (rft = rfts; rft < rfts + len; rft++) {
|
|
|
|
if (!strcmp(rft->name, name))
|
2018-06-30 22:17:32 -07:00
|
|
|
iattr.ia_mode = rft->mode & mask;
|
2018-06-22 15:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
kn = kernfs_find_and_get_ns(r->kn, name, NULL);
|
|
|
|
if (!kn)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
switch (kernfs_type(kn)) {
|
|
|
|
case KERNFS_DIR:
|
|
|
|
parent = kernfs_get_parent(kn);
|
|
|
|
if (parent) {
|
|
|
|
iattr.ia_mode |= parent->mode;
|
|
|
|
kernfs_put(parent);
|
|
|
|
}
|
|
|
|
iattr.ia_mode |= S_IFDIR;
|
|
|
|
break;
|
|
|
|
case KERNFS_FILE:
|
|
|
|
iattr.ia_mode |= S_IFREG;
|
|
|
|
break;
|
|
|
|
case KERNFS_LINK:
|
|
|
|
iattr.ia_mode |= S_IFLNK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kernfs_setattr(kn, &iattr);
|
|
|
|
kernfs_put(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
|
2017-07-25 14:14:29 -07:00
|
|
|
unsigned long fflags)
|
2017-04-07 17:33:54 -07:00
|
|
|
{
|
2017-07-25 14:14:29 -07:00
|
|
|
struct kernfs_node *kn_subdir;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
kn_subdir = kernfs_create_dir(kn_info, name,
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
kn_info->mode, priv);
|
2017-07-25 14:14:29 -07:00
|
|
|
if (IS_ERR(kn_subdir))
|
|
|
|
return PTR_ERR(kn_subdir);
|
|
|
|
|
|
|
|
ret = rdtgroup_kn_set_ugid(kn_subdir);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = rdtgroup_add_files(kn_subdir, fflags);
|
|
|
|
if (!ret)
|
|
|
|
kernfs_activate(kn_subdir);
|
|
|
|
|
|
|
|
return ret;
|
2017-04-07 17:33:54 -07:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
|
|
|
|
{
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
struct resctrl_schema *s;
|
2016-10-28 15:04:43 -07:00
|
|
|
struct rdt_resource *r;
|
2017-07-25 14:14:29 -07:00
|
|
|
unsigned long fflags;
|
2017-07-25 14:14:30 -07:00
|
|
|
char name[32];
|
2017-07-25 14:14:29 -07:00
|
|
|
int ret;
|
2016-10-28 15:04:43 -07:00
|
|
|
|
|
|
|
/* create the directory */
|
|
|
|
kn_info = kernfs_create_dir(parent_kn, "info", parent_kn->mode, NULL);
|
|
|
|
if (IS_ERR(kn_info))
|
|
|
|
return PTR_ERR(kn_info);
|
|
|
|
|
2023-10-16 19:23:02 -05:00
|
|
|
ret = rdtgroup_add_files(kn_info, RFTYPE_TOP_INFO);
|
2017-09-25 16:39:33 -07:00
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
|
2022-09-02 15:48:09 +00:00
|
|
|
/* loop over enabled controls, these are all alloc_capable */
|
x86/resctrl: Pass the schema in info dir's private pointer
Many of resctrl's per-schema files return a value from struct
rdt_resource, which they take as their 'priv' pointer.
Moving properties that resctrl exposes to user-space into the core 'fs'
code, (e.g. the name of the schema), means some of the functions that
back the filesystem need the schema struct (to where the properties are
moved), but currently take struct rdt_resource. For example, once the
CDP resources are merged, struct rdt_resource no longer reflects all the
properties of the schema.
For the info dirs that represent a control, the information needed
will be accessed via struct resctrl_schema, as this is how the resource
is being used. For the monitors, its still struct rdt_resource as the
monitors aren't described as schema.
This difference means the type of the private pointers varies between
control and monitor info dirs.
Change the 'priv' pointer to point to struct resctrl_schema for
the per-schema files that represent a control. The type can be
determined from the fflags field. If the flags are RF_MON_INFO, its
a struct rdt_resource. If the flags are RF_CTRL_INFO, its a struct
resctrl_schema. No entry in res_common_files[] has both flags.
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-5-james.morse@arm.com
2021-07-28 17:06:17 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list) {
|
|
|
|
r = s->res;
|
2023-10-16 19:23:02 -05:00
|
|
|
fflags = r->fflags | RFTYPE_CTRL_INFO;
|
2021-07-28 17:06:25 +00:00
|
|
|
ret = rdtgroup_mkdir_info_resdir(s, s->name, fflags);
|
2016-10-28 15:04:43 -07:00
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
}
|
2017-07-25 14:14:30 -07:00
|
|
|
|
2022-09-02 15:48:10 +00:00
|
|
|
for_each_mon_capable_rdt_resource(r) {
|
2023-10-16 19:23:02 -05:00
|
|
|
fflags = r->fflags | RFTYPE_MON_INFO;
|
2017-07-25 14:14:30 -07:00
|
|
|
sprintf(name, "%s_MON", r->name);
|
|
|
|
ret = rdtgroup_mkdir_info_resdir(r, name, fflags);
|
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
ret = rdtgroup_kn_set_ugid(kn_info);
|
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
|
|
|
|
kernfs_activate(kn_info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_destroy:
|
|
|
|
kernfs_remove(kn_info);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:32 -07:00
|
|
|
static int
|
|
|
|
mongroup_create_dir(struct kernfs_node *parent_kn, struct rdtgroup *prgrp,
|
|
|
|
char *name, struct kernfs_node **dest_kn)
|
|
|
|
{
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* create the directory */
|
|
|
|
kn = kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp);
|
|
|
|
if (IS_ERR(kn))
|
|
|
|
return PTR_ERR(kn);
|
|
|
|
|
|
|
|
if (dest_kn)
|
|
|
|
*dest_kn = kn;
|
|
|
|
|
|
|
|
ret = rdtgroup_kn_set_ugid(kn);
|
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
|
|
|
|
kernfs_activate(kn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_destroy:
|
|
|
|
kernfs_remove(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-12-20 14:57:23 -08:00
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
static void l3_qos_cfg_update(void *arg)
|
|
|
|
{
|
|
|
|
bool *enable = arg;
|
|
|
|
|
2018-11-21 20:28:31 +00:00
|
|
|
wrmsrl(MSR_IA32_L3_QOS_CFG, *enable ? L3_QOS_CDP_ENABLE : 0ULL);
|
2016-10-28 15:04:42 -07:00
|
|
|
}
|
|
|
|
|
2017-12-20 14:57:23 -08:00
|
|
|
static void l2_qos_cfg_update(void *arg)
|
2016-10-28 15:04:42 -07:00
|
|
|
{
|
2017-12-20 14:57:23 -08:00
|
|
|
bool *enable = arg;
|
|
|
|
|
2018-11-21 20:28:31 +00:00
|
|
|
wrmsrl(MSR_IA32_L2_QOS_CFG, *enable ? L2_QOS_CDP_ENABLE : 0ULL);
|
2017-12-20 14:57:23 -08:00
|
|
|
}
|
|
|
|
|
2018-04-20 15:36:17 -07:00
|
|
|
static inline bool is_mba_linear(void)
|
|
|
|
{
|
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
|
|
|
return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.delay_linear;
|
2018-04-20 15:36:17 -07:00
|
|
|
}
|
|
|
|
|
2017-12-20 14:57:23 -08:00
|
|
|
static int set_cache_qos_cfg(int level, bool enable)
|
|
|
|
{
|
|
|
|
void (*update)(void *arg);
|
|
|
|
struct rdt_resource *r_l;
|
2016-10-28 15:04:42 -07:00
|
|
|
cpumask_var_t cpu_mask;
|
|
|
|
struct rdt_domain *d;
|
|
|
|
int cpu;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
/* Walking r->domains, ensure it can't race with cpuhp */
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
2017-12-20 14:57:23 -08:00
|
|
|
if (level == RDT_RESOURCE_L3)
|
|
|
|
update = l3_qos_cfg_update;
|
|
|
|
else if (level == RDT_RESOURCE_L2)
|
|
|
|
update = l2_qos_cfg_update;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-01-02 08:58:44 -08:00
|
|
|
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
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
|
|
|
r_l = &rdt_resources_all[level].r_resctrl;
|
2017-12-20 14:57:23 -08:00
|
|
|
list_for_each_entry(d, &r_l->domains, list) {
|
2020-11-30 09:57:20 -06:00
|
|
|
if (r_l->cache.arch_has_per_cpu_cfg)
|
|
|
|
/* Pick all the CPUs in the domain instance */
|
|
|
|
for_each_cpu(cpu, &d->cpu_mask)
|
|
|
|
cpumask_set_cpu(cpu, cpu_mask);
|
|
|
|
else
|
|
|
|
/* Pick one CPU from each domain instance to update MSR */
|
|
|
|
cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
|
2016-10-28 15:04:42 -07:00
|
|
|
}
|
2023-01-13 09:20:27 -06:00
|
|
|
|
|
|
|
/* Update QOS_CFG MSR on all the CPUs in cpu_mask */
|
|
|
|
on_each_cpu_mask(cpu_mask, update, &enable, 1);
|
2016-10-28 15:04:42 -07:00
|
|
|
|
|
|
|
free_cpumask_var(cpu_mask);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-21 16:21:05 +00:00
|
|
|
/* Restore the qos cfg state when a domain comes online */
|
|
|
|
void rdt_domain_reconfigure_cdp(struct rdt_resource *r)
|
|
|
|
{
|
2021-07-28 17:06:24 +00:00
|
|
|
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
|
|
|
|
|
|
|
|
if (!r->cdp_capable)
|
2020-02-21 16:21:05 +00:00
|
|
|
return;
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
if (r->rid == RDT_RESOURCE_L2)
|
2021-07-28 17:06:24 +00:00
|
|
|
l2_qos_cfg_update(&hw_res->cdp_enabled);
|
2020-02-21 16:21:05 +00:00
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
if (r->rid == RDT_RESOURCE_L3)
|
2021-07-28 17:06:24 +00:00
|
|
|
l3_qos_cfg_update(&hw_res->cdp_enabled);
|
2020-02-21 16:21:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:16 +00:00
|
|
|
static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domain *d)
|
|
|
|
{
|
|
|
|
u32 num_closid = resctrl_arch_get_num_closid(r);
|
|
|
|
int cpu = cpumask_any(&d->cpu_mask);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
d->mbps_val = kcalloc_node(num_closid, sizeof(*d->mbps_val),
|
|
|
|
GFP_KERNEL, cpu_to_node(cpu));
|
|
|
|
if (!d->mbps_val)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < num_closid; i++)
|
|
|
|
d->mbps_val[i] = MBA_MAX_MBPS;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mba_sc_domain_destroy(struct rdt_resource *r,
|
|
|
|
struct rdt_domain *d)
|
|
|
|
{
|
|
|
|
kfree(d->mbps_val);
|
|
|
|
d->mbps_val = NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-20 15:36:17 -07:00
|
|
|
/*
|
|
|
|
* MBA software controller is supported only if
|
|
|
|
* MBM is supported and MBA is in linear scale.
|
|
|
|
*/
|
2022-09-02 15:48:15 +00:00
|
|
|
static bool supports_mba_mbps(void)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
|
|
|
|
|
|
|
|
return (is_mbm_local_enabled() &&
|
|
|
|
r->alloc_capable && is_mba_linear());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable or disable the MBA software controller
|
|
|
|
* which helps user specify bandwidth in MBps.
|
|
|
|
*/
|
2018-04-20 15:36:17 -07:00
|
|
|
static int set_mba_sc(bool mba_sc)
|
|
|
|
{
|
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_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
|
2022-09-02 15:48:16 +00:00
|
|
|
u32 num_closid = resctrl_arch_get_num_closid(r);
|
|
|
|
struct rdt_domain *d;
|
|
|
|
int i;
|
2018-04-20 15:36:17 -07:00
|
|
|
|
2022-09-02 15:48:15 +00:00
|
|
|
if (!supports_mba_mbps() || mba_sc == is_mba_sc(r))
|
2018-04-20 15:36:17 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
r->membw.mba_sc = mba_sc;
|
|
|
|
|
2022-09-02 15:48:16 +00:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
|
|
|
for (i = 0; i < num_closid; i++)
|
|
|
|
d->mbps_val[i] = MBA_MAX_MBPS;
|
|
|
|
}
|
|
|
|
|
2018-04-20 15:36:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
static int cdp_enable(int level)
|
2016-10-28 15:04:42 -07:00
|
|
|
{
|
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_resource *r_l = &rdt_resources_all[level].r_resctrl;
|
2016-10-28 15:04:42 -07:00
|
|
|
int ret;
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
if (!r_l->alloc_capable)
|
2016-10-28 15:04:42 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2017-12-20 14:57:23 -08:00
|
|
|
ret = set_cache_qos_cfg(level, true);
|
2021-07-28 17:06:37 +00:00
|
|
|
if (!ret)
|
2021-07-28 17:06:24 +00:00
|
|
|
rdt_resources_all[level].cdp_enabled = true;
|
2021-07-28 17:06:37 +00:00
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
static void cdp_disable(int level)
|
2017-12-20 14:57:23 -08:00
|
|
|
{
|
2021-07-28 17:06:24 +00:00
|
|
|
struct rdt_hw_resource *r_hw = &rdt_resources_all[level];
|
2016-10-28 15:04:42 -07:00
|
|
|
|
2021-07-28 17:06:24 +00:00
|
|
|
if (r_hw->cdp_enabled) {
|
2017-12-20 14:57:23 -08:00
|
|
|
set_cache_qos_cfg(level, false);
|
2021-07-28 17:06:24 +00:00
|
|
|
r_hw->cdp_enabled = false;
|
2016-10-28 15:04:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:24 +00:00
|
|
|
int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable)
|
2017-12-20 14:57:23 -08:00
|
|
|
{
|
2021-07-28 17:06:24 +00:00
|
|
|
struct rdt_hw_resource *hw_res = &rdt_resources_all[l];
|
2017-12-20 14:57:23 -08:00
|
|
|
|
2021-07-28 17:06:24 +00:00
|
|
|
if (!hw_res->r_resctrl.cdp_capable)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (enable)
|
2021-07-28 17:06:37 +00:00
|
|
|
return cdp_enable(l);
|
2021-07-28 17:06:24 +00:00
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
cdp_disable(l);
|
2021-07-28 17:06:24 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-12-20 14:57:23 -08:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
/*
|
|
|
|
* We don't allow rdtgroup directories to be created anywhere
|
|
|
|
* except the root directory. Thus when looking for the rdtgroup
|
|
|
|
* structure for a kernfs node we are either looking at a directory,
|
|
|
|
* in which case the rdtgroup structure is pointed at by the "priv"
|
|
|
|
* field, otherwise we have a file, and need only look to the parent
|
|
|
|
* to find the rdtgroup.
|
|
|
|
*/
|
|
|
|
static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn)
|
|
|
|
{
|
2016-11-11 17:02:36 -08:00
|
|
|
if (kernfs_type(kn) == KERNFS_DIR) {
|
|
|
|
/*
|
|
|
|
* All the resource directories use "kn->priv"
|
|
|
|
* to point to the "struct rdtgroup" for the
|
|
|
|
* resource. "info" and its subdirectories don't
|
|
|
|
* have rdtgroup structures, so return NULL here.
|
|
|
|
*/
|
|
|
|
if (kn == kn_info || kn->parent == kn_info)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return kn->priv;
|
|
|
|
} else {
|
2016-10-28 15:04:44 -07:00
|
|
|
return kn->parent->priv;
|
2016-11-11 17:02:36 -08:00
|
|
|
}
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
|
|
|
|
2023-04-19 14:50:13 +02:00
|
|
|
static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
atomic_inc(&rdtgrp->waitcount);
|
|
|
|
kernfs_break_active_protection(kn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdtgroup_kn_put(struct rdtgroup *rdtgrp, struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&rdtgrp->waitcount) &&
|
|
|
|
(rdtgrp->flags & RDT_DELETED)) {
|
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
|
|
|
|
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
|
|
|
|
rdtgroup_pseudo_lock_remove(rdtgrp);
|
|
|
|
kernfs_unbreak_active_protection(kn);
|
|
|
|
rdtgroup_remove(rdtgrp);
|
|
|
|
} else {
|
|
|
|
kernfs_unbreak_active_protection(kn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
|
|
|
|
|
2016-11-11 17:02:36 -08:00
|
|
|
if (!rdtgrp)
|
|
|
|
return NULL;
|
|
|
|
|
2023-04-19 14:50:13 +02:00
|
|
|
rdtgroup_kn_get(rdtgrp, kn);
|
2016-10-28 15:04:44 -07:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2016-10-28 15:04:44 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
/* Was this group deleted while we waited? */
|
|
|
|
if (rdtgrp->flags & RDT_DELETED)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return rdtgrp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdtgroup_kn_unlock(struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
|
|
|
|
|
2016-11-11 17:02:36 -08:00
|
|
|
if (!rdtgrp)
|
|
|
|
return;
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
|
|
|
|
2023-04-19 14:50:13 +02:00
|
|
|
rdtgroup_kn_put(rdtgrp, kn);
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:41 -07:00
|
|
|
static int mkdir_mondata_all(struct kernfs_node *parent_kn,
|
|
|
|
struct rdtgroup *prgrp,
|
|
|
|
struct kernfs_node **mon_data_kn);
|
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
static void rdt_disable_ctx(void)
|
|
|
|
{
|
|
|
|
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
|
|
|
|
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
|
|
|
|
set_mba_sc(false);
|
2023-10-16 19:23:05 -05:00
|
|
|
|
|
|
|
resctrl_debug = false;
|
2023-10-16 19:23:03 -05:00
|
|
|
}
|
|
|
|
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
static int rdt_enable_ctx(struct rdt_fs_context *ctx)
|
2016-10-28 15:04:42 -07:00
|
|
|
{
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ctx->enable_cdpl2) {
|
2021-07-28 17:06:24 +00:00
|
|
|
ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, true);
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ret)
|
|
|
|
goto out_done;
|
|
|
|
}
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ctx->enable_cdpl3) {
|
2021-07-28 17:06:24 +00:00
|
|
|
ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, true);
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ret)
|
|
|
|
goto out_cdpl2;
|
|
|
|
}
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ctx->enable_mba_mbps) {
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
ret = set_mba_sc(true);
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ret)
|
|
|
|
goto out_cdpl3;
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:23:05 -05:00
|
|
|
if (ctx->enable_debug)
|
|
|
|
resctrl_debug = true;
|
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
return 0;
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
out_cdpl3:
|
|
|
|
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
|
|
|
|
out_cdpl2:
|
|
|
|
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
|
|
|
|
out_done:
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type)
|
2021-07-28 17:06:16 +00:00
|
|
|
{
|
|
|
|
struct resctrl_schema *s;
|
2021-07-28 17:06:37 +00:00
|
|
|
const char *suffix = "";
|
2021-07-28 17:06:25 +00:00
|
|
|
int ret, cl;
|
2021-07-28 17:06:16 +00:00
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
s = kzalloc(sizeof(*s), GFP_KERNEL);
|
|
|
|
if (!s)
|
|
|
|
return -ENOMEM;
|
2021-07-28 17:06:25 +00:00
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
s->res = r;
|
|
|
|
s->num_closid = resctrl_arch_get_num_closid(r);
|
|
|
|
if (resctrl_arch_get_cdp_enabled(r->rid))
|
|
|
|
s->num_closid /= 2;
|
2021-07-28 17:06:25 +00:00
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
s->conf_type = type;
|
|
|
|
switch (type) {
|
|
|
|
case CDP_CODE:
|
|
|
|
suffix = "CODE";
|
|
|
|
break;
|
|
|
|
case CDP_DATA:
|
|
|
|
suffix = "DATA";
|
|
|
|
break;
|
|
|
|
case CDP_NONE:
|
|
|
|
suffix = "";
|
|
|
|
break;
|
|
|
|
}
|
2021-07-28 17:06:25 +00:00
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
ret = snprintf(s->name, sizeof(s->name), "%s%s", r->name, suffix);
|
|
|
|
if (ret >= sizeof(s->name)) {
|
|
|
|
kfree(s);
|
|
|
|
return -EINVAL;
|
2021-07-28 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
cl = strlen(s->name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If CDP is supported by this resource, but not enabled,
|
|
|
|
* include the suffix. This ensures the tabular format of the
|
|
|
|
* schemata file does not change between mounts of the filesystem.
|
|
|
|
*/
|
|
|
|
if (r->cdp_capable && !resctrl_arch_get_cdp_enabled(r->rid))
|
|
|
|
cl += 4;
|
|
|
|
|
|
|
|
if (cl > max_name_width)
|
|
|
|
max_name_width = cl;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&s->list);
|
|
|
|
list_add(&s->list, &resctrl_schema_all);
|
|
|
|
|
2021-07-28 17:06:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:37 +00:00
|
|
|
static int schemata_list_create(void)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r;
|
|
|
|
int ret = 0;
|
|
|
|
|
2022-09-02 15:48:09 +00:00
|
|
|
for_each_alloc_capable_rdt_resource(r) {
|
2021-07-28 17:06:37 +00:00
|
|
|
if (resctrl_arch_get_cdp_enabled(r->rid)) {
|
|
|
|
ret = schemata_list_add(r, CDP_CODE);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = schemata_list_add(r, CDP_DATA);
|
|
|
|
} else {
|
|
|
|
ret = schemata_list_add(r, CDP_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:16 +00:00
|
|
|
static void schemata_list_destroy(void)
|
|
|
|
{
|
|
|
|
struct resctrl_schema *s, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(s, tmp, &resctrl_schema_all, list) {
|
|
|
|
list_del(&s->list);
|
|
|
|
kfree(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
static int rdt_get_tree(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
struct rdt_fs_context *ctx = rdt_fc2context(fc);
|
2023-10-16 19:23:07 -05:00
|
|
|
unsigned long flags = RFTYPE_CTRL_BASE;
|
2017-07-25 14:14:47 -07:00
|
|
|
struct rdt_domain *dom;
|
|
|
|
struct rdt_resource *r;
|
2016-10-28 15:04:42 -07:00
|
|
|
int ret;
|
|
|
|
|
2017-10-20 02:16:59 -07:00
|
|
|
cpus_read_lock();
|
2016-10-28 15:04:42 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
/*
|
|
|
|
* resctrl file system can only be mounted once.
|
|
|
|
*/
|
2024-02-13 18:44:30 +00:00
|
|
|
if (resctrl_mounted) {
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
ret = -EBUSY;
|
2016-10-28 15:04:42 -07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:23:04 -05:00
|
|
|
ret = rdtgroup_setup_root(ctx);
|
2023-10-16 19:23:03 -05:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2016-10-28 15:04:42 -07:00
|
|
|
|
2023-10-16 19:23:04 -05:00
|
|
|
ret = rdt_enable_ctx(ctx);
|
|
|
|
if (ret)
|
|
|
|
goto out_root;
|
|
|
|
|
2021-07-28 17:06:16 +00:00
|
|
|
ret = schemata_list_create();
|
|
|
|
if (ret) {
|
|
|
|
schemata_list_destroy();
|
2023-10-16 19:23:03 -05:00
|
|
|
goto out_ctx;
|
2021-07-28 17:06:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
closid_init();
|
|
|
|
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2023-10-16 19:23:07 -05:00
|
|
|
flags |= RFTYPE_MON;
|
|
|
|
|
|
|
|
ret = rdtgroup_add_files(rdtgroup_default.kn, flags);
|
2023-10-16 19:23:04 -05:00
|
|
|
if (ret)
|
|
|
|
goto out_schemata_free;
|
|
|
|
|
|
|
|
kernfs_activate(rdtgroup_default.kn);
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
ret = rdtgroup_create_info_dir(rdtgroup_default.kn);
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
if (ret < 0)
|
2021-07-28 17:06:16 +00:00
|
|
|
goto out_schemata_free;
|
2016-10-28 15:04:43 -07:00
|
|
|
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable()) {
|
2017-07-25 14:14:41 -07:00
|
|
|
ret = mongroup_create_dir(rdtgroup_default.kn,
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
&rdtgroup_default, "mon_groups",
|
2017-07-25 14:14:41 -07:00
|
|
|
&kn_mongrp);
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
if (ret < 0)
|
2017-07-25 14:14:41 -07:00
|
|
|
goto out_info;
|
|
|
|
|
|
|
|
ret = mkdir_mondata_all(rdtgroup_default.kn,
|
|
|
|
&rdtgroup_default, &kn_mondata);
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
if (ret < 0)
|
2017-07-25 14:14:41 -07:00
|
|
|
goto out_mongrp;
|
|
|
|
rdtgroup_default.mon.mon_data_kn = kn_mondata;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:52 -07:00
|
|
|
ret = rdt_pseudo_lock_init();
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
if (ret)
|
2018-06-22 15:41:52 -07:00
|
|
|
goto out_mondata;
|
|
|
|
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
ret = kernfs_get_tree(fc);
|
|
|
|
if (ret < 0)
|
2018-06-22 15:41:52 -07:00
|
|
|
goto out_psl;
|
2017-07-25 14:14:41 -07:00
|
|
|
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_alloc_capable())
|
2024-02-13 18:44:31 +00:00
|
|
|
resctrl_arch_enable_alloc();
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2024-02-13 18:44:31 +00:00
|
|
|
resctrl_arch_enable_mon();
|
2016-10-28 15:04:42 -07:00
|
|
|
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable())
|
2024-02-13 18:44:30 +00:00
|
|
|
resctrl_mounted = true;
|
2017-07-25 14:14:47 -07:00
|
|
|
|
|
|
|
if (is_mbm_enabled()) {
|
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
|
|
|
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
|
2017-07-25 14:14:47 -07:00
|
|
|
list_for_each_entry(dom, &r->domains, list)
|
2024-02-13 18:44:35 +00:00
|
|
|
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
|
|
|
|
RESCTRL_PICK_ANY_CPU);
|
2017-07-25 14:14:47 -07:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
goto out;
|
|
|
|
|
2018-06-22 15:41:52 -07:00
|
|
|
out_psl:
|
|
|
|
rdt_pseudo_lock_release();
|
2017-07-25 14:14:41 -07:00
|
|
|
out_mondata:
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2017-07-25 14:14:41 -07:00
|
|
|
kernfs_remove(kn_mondata);
|
|
|
|
out_mongrp:
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2017-07-25 14:14:41 -07:00
|
|
|
kernfs_remove(kn_mongrp);
|
|
|
|
out_info:
|
2017-06-26 11:55:49 -07:00
|
|
|
kernfs_remove(kn_info);
|
2021-07-28 17:06:16 +00:00
|
|
|
out_schemata_free:
|
|
|
|
schemata_list_destroy();
|
2023-10-16 19:23:03 -05:00
|
|
|
out_ctx:
|
|
|
|
rdt_disable_ctx();
|
2023-10-16 19:23:04 -05:00
|
|
|
out_root:
|
|
|
|
rdtgroup_destroy_root();
|
2016-10-28 15:04:42 -07:00
|
|
|
out:
|
2017-09-25 16:39:33 -07:00
|
|
|
rdt_last_cmd_clear();
|
2016-10-28 15:04:42 -07:00
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
2017-10-20 02:16:59 -07:00
|
|
|
cpus_read_unlock();
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum rdt_param {
|
|
|
|
Opt_cdp,
|
|
|
|
Opt_cdpl2,
|
2019-03-30 05:50:38 +08:00
|
|
|
Opt_mba_mbps,
|
2023-10-16 19:23:05 -05:00
|
|
|
Opt_debug,
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
nr__rdt_params
|
|
|
|
};
|
|
|
|
|
2019-09-07 07:23:15 -04:00
|
|
|
static const struct fs_parameter_spec rdt_fs_parameters[] = {
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
fsparam_flag("cdp", Opt_cdp),
|
|
|
|
fsparam_flag("cdpl2", Opt_cdpl2),
|
2019-03-30 05:50:38 +08:00
|
|
|
fsparam_flag("mba_MBps", Opt_mba_mbps),
|
2023-10-16 19:23:05 -05:00
|
|
|
fsparam_flag("debug", Opt_debug),
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
|
|
|
{
|
|
|
|
struct rdt_fs_context *ctx = rdt_fc2context(fc);
|
|
|
|
struct fs_parse_result result;
|
|
|
|
int opt;
|
|
|
|
|
2019-09-07 07:23:15 -04:00
|
|
|
opt = fs_parse(fc, rdt_fs_parameters, param, &result);
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
if (opt < 0)
|
|
|
|
return opt;
|
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
case Opt_cdp:
|
|
|
|
ctx->enable_cdpl3 = true;
|
|
|
|
return 0;
|
|
|
|
case Opt_cdpl2:
|
|
|
|
ctx->enable_cdpl2 = true;
|
|
|
|
return 0;
|
2019-03-30 05:50:38 +08:00
|
|
|
case Opt_mba_mbps:
|
2022-09-02 15:48:15 +00:00
|
|
|
if (!supports_mba_mbps())
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
ctx->enable_mba_mbps = true;
|
|
|
|
return 0;
|
2023-10-16 19:23:05 -05:00
|
|
|
case Opt_debug:
|
|
|
|
ctx->enable_debug = true;
|
|
|
|
return 0;
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdt_fs_context_free(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
struct rdt_fs_context *ctx = rdt_fc2context(fc);
|
2016-10-28 15:04:42 -07:00
|
|
|
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
kernfs_free_fs_context(fc);
|
|
|
|
kfree(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations rdt_fs_context_ops = {
|
|
|
|
.free = rdt_fs_context_free,
|
|
|
|
.parse_param = rdt_parse_param,
|
|
|
|
.get_tree = rdt_get_tree,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rdt_init_fs_context(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
struct rdt_fs_context *ctx;
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(struct rdt_fs_context), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ctx->kfc.magic = RDTGROUP_SUPER_MAGIC;
|
|
|
|
fc->fs_private = &ctx->kfc;
|
|
|
|
fc->ops = &rdt_fs_context_ops;
|
2019-05-12 12:42:58 -04:00
|
|
|
put_user_ns(fc->user_ns);
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
fc->user_ns = get_user_ns(&init_user_ns);
|
|
|
|
fc->global = true;
|
|
|
|
return 0;
|
2016-10-28 15:04:42 -07:00
|
|
|
}
|
|
|
|
|
2017-04-07 17:33:51 -07:00
|
|
|
static int reset_all_ctrls(struct rdt_resource *r)
|
2016-10-28 15:04:42 -07:00
|
|
|
{
|
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 = resctrl_to_arch_res(r);
|
2021-07-28 17:06:15 +00:00
|
|
|
struct rdt_hw_domain *hw_dom;
|
2016-10-28 15:04:42 -07:00
|
|
|
struct msr_param msr_param;
|
|
|
|
struct rdt_domain *d;
|
2023-01-13 09:20:27 -06:00
|
|
|
int i;
|
2016-10-28 15:04:42 -07:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
/* Walking r->domains, ensure it can't race with cpuhp */
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
msr_param.res = r;
|
|
|
|
msr_param.low = 0;
|
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
|
|
|
msr_param.high = hw_res->num_closid;
|
2016-10-28 15:04:42 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable resource control for this resource by setting all
|
|
|
|
* CBMs in all domains to the maximum mask value. Pick one CPU
|
|
|
|
* from each domain to update the MSRs below.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
2021-07-28 17:06:15 +00:00
|
|
|
hw_dom = resctrl_to_arch_dom(d);
|
2016-10-28 15:04:42 -07:00
|
|
|
|
2022-09-02 15:48:18 +00:00
|
|
|
for (i = 0; i < hw_res->num_closid; i++)
|
2021-07-28 17:06:15 +00:00
|
|
|
hw_dom->ctrl_val[i] = r->default_ctrl;
|
2024-03-08 13:38:45 -08:00
|
|
|
msr_param.dom = d;
|
|
|
|
smp_call_function_any(&d->cpu_mask, rdt_ctrl_update, &msr_param, 1);
|
2016-10-28 15:04:42 -07:00
|
|
|
}
|
2023-01-13 09:20:27 -06:00
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
return 0;
|
2017-07-25 14:14:40 -07:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
/*
|
2016-11-18 15:18:04 -08:00
|
|
|
* Move tasks from one to the other group. If @from is NULL, then all tasks
|
|
|
|
* in the systems are moved unconditionally (used for teardown).
|
|
|
|
*
|
|
|
|
* If @mask is not NULL the cpus on which moved tasks are running are set
|
|
|
|
* in that mask so the update smp function call is restricted to affected
|
|
|
|
* cpus.
|
2016-10-28 15:04:43 -07:00
|
|
|
*/
|
2016-11-18 15:18:04 -08:00
|
|
|
static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to,
|
|
|
|
struct cpumask *mask)
|
2016-10-28 15:04:43 -07:00
|
|
|
{
|
2016-10-28 15:04:46 -07:00
|
|
|
struct task_struct *p, *t;
|
|
|
|
|
|
|
|
read_lock(&tasklist_lock);
|
2016-11-18 15:18:04 -08:00
|
|
|
for_each_process_thread(p, t) {
|
2017-07-25 14:14:40 -07:00
|
|
|
if (!from || is_closid_match(t, from) ||
|
|
|
|
is_rmid_match(t, from)) {
|
2024-02-13 18:44:25 +00:00
|
|
|
resctrl_arch_set_closid_rmid(t, to->closid,
|
|
|
|
to->mon.rmid);
|
2017-07-25 14:14:40 -07:00
|
|
|
|
x86/resctrl: Fix task CLOSID/RMID update race
When the user moves a running task to a new rdtgroup using the task's
file interface or by deleting its rdtgroup, the resulting change in
CLOSID/RMID must be immediately propagated to the PQR_ASSOC MSR on the
task(s) CPUs.
x86 allows reordering loads with prior stores, so if the task starts
running between a task_curr() check that the CPU hoisted before the
stores in the CLOSID/RMID update then it can start running with the old
CLOSID/RMID until it is switched again because __rdtgroup_move_task()
failed to determine that it needs to be interrupted to obtain the new
CLOSID/RMID.
Refer to the diagram below:
CPU 0 CPU 1
----- -----
__rdtgroup_move_task():
curr <- t1->cpu->rq->curr
__schedule():
rq->curr <- t1
resctrl_sched_in():
t1->{closid,rmid} -> {1,1}
t1->{closid,rmid} <- {2,2}
if (curr == t1) // false
IPI(t1->cpu)
A similar race impacts rdt_move_group_tasks(), which updates tasks in a
deleted rdtgroup.
In both cases, use smp_mb() to order the task_struct::{closid,rmid}
stores before the loads in task_curr(). In particular, in the
rdt_move_group_tasks() case, simply execute an smp_mb() on every
iteration with a matching task.
It is possible to use a single smp_mb() in rdt_move_group_tasks(), but
this would require two passes and a means of remembering which
task_structs were updated in the first loop. However, benchmarking
results below showed too little performance impact in the simple
approach to justify implementing the two-pass approach.
Times below were collected using `perf stat` to measure the time to
remove a group containing a 1600-task, parallel workload.
CPU: Intel(R) Xeon(R) Platinum P-8136 CPU @ 2.00GHz (112 threads)
# mkdir /sys/fs/resctrl/test
# echo $$ > /sys/fs/resctrl/test/tasks
# perf bench sched messaging -g 40 -l 100000
task-clock time ranges collected using:
# perf stat rmdir /sys/fs/resctrl/test
Baseline: 1.54 - 1.60 ms
smp_mb() every matching task: 1.57 - 1.67 ms
[ bp: Massage commit message. ]
Fixes: ae28d1aae48a ("x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR")
Fixes: 0efc89be9471 ("x86/intel_rdt: Update task closid immediately on CPU in rmdir and unmount")
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20221220161123.432120-1-peternewman@google.com
2022-12-20 17:11:23 +01:00
|
|
|
/*
|
|
|
|
* Order the closid/rmid stores above before the loads
|
|
|
|
* in task_curr(). This pairs with the full barrier
|
|
|
|
* between the rq->curr update and resctrl_sched_in()
|
|
|
|
* during context switch.
|
|
|
|
*/
|
|
|
|
smp_mb();
|
|
|
|
|
2016-11-18 15:18:04 -08:00
|
|
|
/*
|
2020-12-17 14:31:20 -08:00
|
|
|
* If the task is on a CPU, set the CPU in the mask.
|
|
|
|
* The detection is inaccurate as tasks might move or
|
|
|
|
* schedule before the smp function call takes place.
|
|
|
|
* In such a case the function call is pointless, but
|
2016-11-18 15:18:04 -08:00
|
|
|
* there is no other side effect.
|
|
|
|
*/
|
2020-12-17 14:31:20 -08:00
|
|
|
if (IS_ENABLED(CONFIG_SMP) && mask && task_curr(t))
|
2016-11-18 15:18:04 -08:00
|
|
|
cpumask_set_cpu(task_cpu(t), mask);
|
|
|
|
}
|
|
|
|
}
|
2016-10-28 15:04:46 -07:00
|
|
|
read_unlock(&tasklist_lock);
|
2016-11-18 15:18:04 -08:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:40 -07:00
|
|
|
static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp)
|
|
|
|
{
|
|
|
|
struct rdtgroup *sentry, *stmp;
|
|
|
|
struct list_head *head;
|
|
|
|
|
|
|
|
head = &rdtgrp->mon.crdtgrp_list;
|
|
|
|
list_for_each_entry_safe(sentry, stmp, head, mon.crdtgrp_list) {
|
2024-02-13 18:44:19 +00:00
|
|
|
free_rmid(sentry->closid, sentry->mon.rmid);
|
2017-07-25 14:14:40 -07:00
|
|
|
list_del(&sentry->mon.crdtgrp_list);
|
x86/resctrl: Fix use-after-free when deleting resource groups
A resource group (rdtgrp) contains a reference count (rdtgrp->waitcount)
that indicates how many waiters expect this rdtgrp to exist. Waiters
could be waiting on rdtgroup_mutex or some work sitting on a task's
workqueue for when the task returns from kernel mode or exits.
The deletion of a rdtgrp is intended to have two phases:
(1) while holding rdtgroup_mutex the necessary cleanup is done and
rdtgrp->flags is set to RDT_DELETED,
(2) after releasing the rdtgroup_mutex, the rdtgrp structure is freed
only if there are no waiters and its flag is set to RDT_DELETED. Upon
gaining access to rdtgroup_mutex or rdtgrp, a waiter is required to check
for the RDT_DELETED flag.
When unmounting the resctrl file system or deleting ctrl_mon groups,
all of the subdirectories are removed and the data structure of rdtgrp
is forcibly freed without checking rdtgrp->waitcount. If at this point
there was a waiter on rdtgrp then a use-after-free issue occurs when the
waiter starts running and accesses the rdtgrp structure it was waiting
on.
See kfree() calls in [1], [2] and [3] in these two call paths in
following scenarios:
(1) rdt_kill_sb() -> rmdir_all_sub() -> free_all_child_rdtgrp()
(2) rdtgroup_rmdir() -> rdtgroup_rmdir_ctrl() -> free_all_child_rdtgrp()
There are several scenarios that result in use-after-free issue in
following:
Scenario 1:
-----------
In Thread 1, rdtgroup_tasks_write() adds a task_work callback
move_myself(). If move_myself() is scheduled to execute after Thread 2
rdt_kill_sb() is finished, referring to earlier rdtgrp memory
(rdtgrp->waitcount) which was already freed in Thread 2 results in
use-after-free issue.
Thread 1 (rdtgroup_tasks_write) Thread 2 (rdt_kill_sb)
------------------------------- ----------------------
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
mutex_lock
rdtgroup_move_task
__rdtgroup_move_task
/*
* Take an extra refcount, so rdtgrp cannot be freed
* before the call back move_myself has been invoked
*/
atomic_inc(&rdtgrp->waitcount)
/* Callback move_myself will be scheduled for later */
task_work_add(move_myself)
rdtgroup_kn_unlock
mutex_unlock
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
mutex_lock
rmdir_all_sub
/*
* sentry and rdtgrp are freed
* without checking refcount
*/
free_all_child_rdtgrp
kfree(sentry)*[1]
kfree(rdtgrp)*[2]
mutex_unlock
/*
* Callback is scheduled to execute
* after rdt_kill_sb is finished
*/
move_myself
/*
* Use-after-free: refer to earlier rdtgrp
* memory which was freed in [1] or [2].
*/
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
kfree(rdtgrp)
Scenario 2:
-----------
In Thread 1, rdtgroup_tasks_write() adds a task_work callback
move_myself(). If move_myself() is scheduled to execute after Thread 2
rdtgroup_rmdir() is finished, referring to earlier rdtgrp memory
(rdtgrp->waitcount) which was already freed in Thread 2 results in
use-after-free issue.
Thread 1 (rdtgroup_tasks_write) Thread 2 (rdtgroup_rmdir)
------------------------------- -------------------------
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
mutex_lock
rdtgroup_move_task
__rdtgroup_move_task
/*
* Take an extra refcount, so rdtgrp cannot be freed
* before the call back move_myself has been invoked
*/
atomic_inc(&rdtgrp->waitcount)
/* Callback move_myself will be scheduled for later */
task_work_add(move_myself)
rdtgroup_kn_unlock
mutex_unlock
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
/*
* sentry is freed without
* checking refcount
*/
kfree(sentry)*[3]
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
rdtgroup_kn_unlock
mutex_unlock
atomic_dec_and_test(
&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
kfree(rdtgrp)
/*
* Callback is scheduled to execute
* after rdt_kill_sb is finished
*/
move_myself
/*
* Use-after-free: refer to earlier rdtgrp
* memory which was freed in [3].
*/
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
kfree(rdtgrp)
If CONFIG_DEBUG_SLAB=y, Slab corruption on kmalloc-2k can be observed
like following. Note that "0x6b" is POISON_FREE after kfree(). The
corrupted bits "0x6a", "0x64" at offset 0x424 correspond to
waitcount member of struct rdtgroup which was freed:
Slab corruption (Not tainted): kmalloc-2k start=ffff9504c5b0d000, len=2048
420: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkjkkkkkkkkkkk
Single bit error detected. Probably bad RAM.
Run memtest86+ or a similar memory test tool.
Next obj: start=ffff9504c5b0d800, len=2048
000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
Slab corruption (Not tainted): kmalloc-2k start=ffff9504c58ab800, len=2048
420: 6b 6b 6b 6b 64 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkdkkkkkkkkkkk
Prev obj: start=ffff9504c58ab000, len=2048
000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
Fix this by taking reference count (waitcount) of rdtgrp into account in
the two call paths that currently do not do so. Instead of always
freeing the resource group it will only be freed if there are no waiters
on it. If there are waiters, the resource group will have its flags set
to RDT_DELETED.
It will be left to the waiter to free the resource group when it starts
running and finding that it was the last waiter and the resource group
has been removed (rdtgrp->flags & RDT_DELETED) since. (1) rdt_kill_sb()
-> rmdir_all_sub() -> free_all_child_rdtgrp() (2) rdtgroup_rmdir() ->
rdtgroup_rmdir_ctrl() -> free_all_child_rdtgrp()
Fixes: f3cbeacaa06e ("x86/intel_rdt/cqm: Add rmdir support")
Fixes: 60cf5e101fd4 ("x86/intel_rdt: Add mkdir to resctrl file system")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-2-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:03 +08:00
|
|
|
|
|
|
|
if (atomic_read(&sentry->waitcount) != 0)
|
|
|
|
sentry->flags = RDT_DELETED;
|
|
|
|
else
|
2020-10-31 03:11:28 +08:00
|
|
|
rdtgroup_remove(sentry);
|
2017-07-25 14:14:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 15:18:04 -08:00
|
|
|
/*
|
|
|
|
* Forcibly remove all of subdirectories under root.
|
|
|
|
*/
|
|
|
|
static void rmdir_all_sub(void)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp, *tmp;
|
|
|
|
|
|
|
|
/* Move all tasks to the default resource group */
|
|
|
|
rdt_move_group_tasks(NULL, &rdtgroup_default, NULL);
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
list_for_each_entry_safe(rdtgrp, tmp, &rdt_all_groups, rdtgroup_list) {
|
2017-07-25 14:14:41 -07:00
|
|
|
/* Free any child rmids */
|
|
|
|
free_all_child_rdtgrp(rdtgrp);
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
/* Remove each rdtgroup other than root */
|
|
|
|
if (rdtgrp == &rdtgroup_default)
|
|
|
|
continue;
|
2016-11-11 17:02:37 -08:00
|
|
|
|
2018-06-22 15:42:22 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
|
|
|
|
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
|
|
|
|
rdtgroup_pseudo_lock_remove(rdtgrp);
|
|
|
|
|
2016-11-11 17:02:37 -08:00
|
|
|
/*
|
|
|
|
* Give any CPUs back to the default group. We cannot copy
|
|
|
|
* cpu_online_mask because a CPU might have executed the
|
|
|
|
* offline callback already, but is still marked online.
|
|
|
|
*/
|
|
|
|
cpumask_or(&rdtgroup_default.cpu_mask,
|
|
|
|
&rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
free_rmid(rdtgrp->closid, rdtgrp->mon.rmid);
|
2017-07-25 14:14:41 -07:00
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
kernfs_remove(rdtgrp->kn);
|
|
|
|
list_del(&rdtgrp->rdtgroup_list);
|
x86/resctrl: Fix use-after-free when deleting resource groups
A resource group (rdtgrp) contains a reference count (rdtgrp->waitcount)
that indicates how many waiters expect this rdtgrp to exist. Waiters
could be waiting on rdtgroup_mutex or some work sitting on a task's
workqueue for when the task returns from kernel mode or exits.
The deletion of a rdtgrp is intended to have two phases:
(1) while holding rdtgroup_mutex the necessary cleanup is done and
rdtgrp->flags is set to RDT_DELETED,
(2) after releasing the rdtgroup_mutex, the rdtgrp structure is freed
only if there are no waiters and its flag is set to RDT_DELETED. Upon
gaining access to rdtgroup_mutex or rdtgrp, a waiter is required to check
for the RDT_DELETED flag.
When unmounting the resctrl file system or deleting ctrl_mon groups,
all of the subdirectories are removed and the data structure of rdtgrp
is forcibly freed without checking rdtgrp->waitcount. If at this point
there was a waiter on rdtgrp then a use-after-free issue occurs when the
waiter starts running and accesses the rdtgrp structure it was waiting
on.
See kfree() calls in [1], [2] and [3] in these two call paths in
following scenarios:
(1) rdt_kill_sb() -> rmdir_all_sub() -> free_all_child_rdtgrp()
(2) rdtgroup_rmdir() -> rdtgroup_rmdir_ctrl() -> free_all_child_rdtgrp()
There are several scenarios that result in use-after-free issue in
following:
Scenario 1:
-----------
In Thread 1, rdtgroup_tasks_write() adds a task_work callback
move_myself(). If move_myself() is scheduled to execute after Thread 2
rdt_kill_sb() is finished, referring to earlier rdtgrp memory
(rdtgrp->waitcount) which was already freed in Thread 2 results in
use-after-free issue.
Thread 1 (rdtgroup_tasks_write) Thread 2 (rdt_kill_sb)
------------------------------- ----------------------
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
mutex_lock
rdtgroup_move_task
__rdtgroup_move_task
/*
* Take an extra refcount, so rdtgrp cannot be freed
* before the call back move_myself has been invoked
*/
atomic_inc(&rdtgrp->waitcount)
/* Callback move_myself will be scheduled for later */
task_work_add(move_myself)
rdtgroup_kn_unlock
mutex_unlock
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
mutex_lock
rmdir_all_sub
/*
* sentry and rdtgrp are freed
* without checking refcount
*/
free_all_child_rdtgrp
kfree(sentry)*[1]
kfree(rdtgrp)*[2]
mutex_unlock
/*
* Callback is scheduled to execute
* after rdt_kill_sb is finished
*/
move_myself
/*
* Use-after-free: refer to earlier rdtgrp
* memory which was freed in [1] or [2].
*/
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
kfree(rdtgrp)
Scenario 2:
-----------
In Thread 1, rdtgroup_tasks_write() adds a task_work callback
move_myself(). If move_myself() is scheduled to execute after Thread 2
rdtgroup_rmdir() is finished, referring to earlier rdtgrp memory
(rdtgrp->waitcount) which was already freed in Thread 2 results in
use-after-free issue.
Thread 1 (rdtgroup_tasks_write) Thread 2 (rdtgroup_rmdir)
------------------------------- -------------------------
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
mutex_lock
rdtgroup_move_task
__rdtgroup_move_task
/*
* Take an extra refcount, so rdtgrp cannot be freed
* before the call back move_myself has been invoked
*/
atomic_inc(&rdtgrp->waitcount)
/* Callback move_myself will be scheduled for later */
task_work_add(move_myself)
rdtgroup_kn_unlock
mutex_unlock
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
/*
* sentry is freed without
* checking refcount
*/
kfree(sentry)*[3]
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
rdtgroup_kn_unlock
mutex_unlock
atomic_dec_and_test(
&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
kfree(rdtgrp)
/*
* Callback is scheduled to execute
* after rdt_kill_sb is finished
*/
move_myself
/*
* Use-after-free: refer to earlier rdtgrp
* memory which was freed in [3].
*/
atomic_dec_and_test(&rdtgrp->waitcount)
&& (flags & RDT_DELETED)
kfree(rdtgrp)
If CONFIG_DEBUG_SLAB=y, Slab corruption on kmalloc-2k can be observed
like following. Note that "0x6b" is POISON_FREE after kfree(). The
corrupted bits "0x6a", "0x64" at offset 0x424 correspond to
waitcount member of struct rdtgroup which was freed:
Slab corruption (Not tainted): kmalloc-2k start=ffff9504c5b0d000, len=2048
420: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkjkkkkkkkkkkk
Single bit error detected. Probably bad RAM.
Run memtest86+ or a similar memory test tool.
Next obj: start=ffff9504c5b0d800, len=2048
000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
Slab corruption (Not tainted): kmalloc-2k start=ffff9504c58ab800, len=2048
420: 6b 6b 6b 6b 64 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkdkkkkkkkkkkk
Prev obj: start=ffff9504c58ab000, len=2048
000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
Fix this by taking reference count (waitcount) of rdtgrp into account in
the two call paths that currently do not do so. Instead of always
freeing the resource group it will only be freed if there are no waiters
on it. If there are waiters, the resource group will have its flags set
to RDT_DELETED.
It will be left to the waiter to free the resource group when it starts
running and finding that it was the last waiter and the resource group
has been removed (rdtgrp->flags & RDT_DELETED) since. (1) rdt_kill_sb()
-> rmdir_all_sub() -> free_all_child_rdtgrp() (2) rdtgroup_rmdir() ->
rdtgroup_rmdir_ctrl() -> free_all_child_rdtgrp()
Fixes: f3cbeacaa06e ("x86/intel_rdt/cqm: Add rmdir support")
Fixes: 60cf5e101fd4 ("x86/intel_rdt: Add mkdir to resctrl file system")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-2-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:03 +08:00
|
|
|
|
|
|
|
if (atomic_read(&rdtgrp->waitcount) != 0)
|
|
|
|
rdtgrp->flags = RDT_DELETED;
|
|
|
|
else
|
2020-10-31 03:11:28 +08:00
|
|
|
rdtgroup_remove(rdtgrp);
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
2016-11-18 15:18:04 -08:00
|
|
|
/* Notify online CPUs to update per cpu storage and PQR_ASSOC MSR */
|
2017-07-25 14:14:36 -07:00
|
|
|
update_closid_rmid(cpu_online_mask, &rdtgroup_default);
|
2016-11-18 15:18:04 -08:00
|
|
|
|
2016-10-28 15:04:43 -07:00
|
|
|
kernfs_remove(kn_info);
|
2017-07-25 14:14:41 -07:00
|
|
|
kernfs_remove(kn_mongrp);
|
|
|
|
kernfs_remove(kn_mondata);
|
2016-10-28 15:04:43 -07:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
static void rdt_kill_sb(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r;
|
|
|
|
|
2017-10-20 02:16:58 -07:00
|
|
|
cpus_read_lock();
|
2016-10-28 15:04:42 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
2023-10-16 19:23:03 -05:00
|
|
|
rdt_disable_ctx();
|
2018-04-20 15:36:17 -07:00
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
/*Put everything back to default values. */
|
2022-09-02 15:48:09 +00:00
|
|
|
for_each_alloc_capable_rdt_resource(r)
|
2017-04-07 17:33:51 -07:00
|
|
|
reset_all_ctrls(r);
|
2016-10-28 15:04:43 -07:00
|
|
|
rmdir_all_sub();
|
2018-06-22 15:42:27 -07:00
|
|
|
rdt_pseudo_lock_release();
|
2018-06-22 15:41:55 -07:00
|
|
|
rdtgroup_default.mode = RDT_MODE_SHAREABLE;
|
2021-07-28 17:06:16 +00:00
|
|
|
schemata_list_destroy();
|
2023-10-16 19:23:04 -05:00
|
|
|
rdtgroup_destroy_root();
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_alloc_capable())
|
2024-02-13 18:44:32 +00:00
|
|
|
resctrl_arch_disable_alloc();
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2024-02-13 18:44:32 +00:00
|
|
|
resctrl_arch_disable_mon();
|
2024-02-13 18:44:30 +00:00
|
|
|
resctrl_mounted = false;
|
2016-10-28 15:04:42 -07:00
|
|
|
kernfs_kill_sb(sb);
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
2017-10-20 02:16:58 -07:00
|
|
|
cpus_read_unlock();
|
2016-10-28 15:04:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type rdt_fs_type = {
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
.name = "resctrl",
|
|
|
|
.init_fs_context = rdt_init_fs_context,
|
2019-09-07 07:23:15 -04:00
|
|
|
.parameters = rdt_fs_parameters,
|
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
Make kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the
kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra
namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the
kernfs_fs_context struct, but for the moment it does nothing except
get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
pass, but possibly this should be done anyway in case someone wants to
add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(),
which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather
than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm
told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.
[folded a leak fix from Andrey Vagin]
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Tejun Heo <tj@kernel.org>
cc: Li Zefan <lizefan@huawei.com>
cc: Johannes Weiner <hannes@cmpxchg.org>
cc: cgroups@vger.kernel.org
cc: fenghua.yu@intel.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2018-11-01 23:07:26 +00:00
|
|
|
.kill_sb = rdt_kill_sb,
|
2016-10-28 15:04:42 -07:00
|
|
|
};
|
|
|
|
|
2017-07-25 14:14:38 -07:00
|
|
|
static int mon_addfile(struct kernfs_node *parent_kn, const char *name,
|
|
|
|
void *priv)
|
|
|
|
{
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-07-20 21:56:47 +00:00
|
|
|
kn = __kernfs_create_file(parent_kn, name, 0444,
|
|
|
|
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, 0,
|
2017-07-25 14:14:38 -07:00
|
|
|
&kf_mondata_ops, priv, NULL, NULL);
|
|
|
|
if (IS_ERR(kn))
|
|
|
|
return PTR_ERR(kn);
|
|
|
|
|
|
|
|
ret = rdtgroup_kn_set_ugid(kn);
|
|
|
|
if (ret) {
|
|
|
|
kernfs_remove(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:44 -07:00
|
|
|
/*
|
|
|
|
* Remove all subdirectories of mon_data of ctrl_mon groups
|
|
|
|
* and monitor groups with given domain id.
|
|
|
|
*/
|
2022-09-02 15:48:13 +00:00
|
|
|
static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
|
|
|
|
unsigned int dom_id)
|
2017-07-25 14:14:44 -07:00
|
|
|
{
|
|
|
|
struct rdtgroup *prgrp, *crgrp;
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
|
|
|
|
sprintf(name, "mon_%s_%02d", r->name, dom_id);
|
|
|
|
kernfs_remove_by_name(prgrp->mon.mon_data_kn, name);
|
|
|
|
|
|
|
|
list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list)
|
|
|
|
kernfs_remove_by_name(crgrp->mon.mon_data_kn, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:38 -07:00
|
|
|
static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
|
|
|
|
struct rdt_domain *d,
|
|
|
|
struct rdt_resource *r, struct rdtgroup *prgrp)
|
|
|
|
{
|
|
|
|
union mon_data_bits priv;
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
struct mon_evt *mevt;
|
2017-07-25 14:14:46 -07:00
|
|
|
struct rmid_read rr;
|
2017-07-25 14:14:38 -07:00
|
|
|
char name[32];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
sprintf(name, "mon_%s_%02d", r->name, d->id);
|
|
|
|
/* create the directory */
|
|
|
|
kn = kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp);
|
|
|
|
if (IS_ERR(kn))
|
|
|
|
return PTR_ERR(kn);
|
|
|
|
|
|
|
|
ret = rdtgroup_kn_set_ugid(kn);
|
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
|
|
|
|
if (WARN_ON(list_empty(&r->evt_list))) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out_destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv.u.rid = r->rid;
|
|
|
|
priv.u.domid = d->id;
|
|
|
|
list_for_each_entry(mevt, &r->evt_list, list) {
|
|
|
|
priv.u.evtid = mevt->evtid;
|
|
|
|
ret = mon_addfile(kn, mevt->name, priv.priv);
|
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
2017-07-25 14:14:46 -07:00
|
|
|
|
|
|
|
if (is_mbm_event(mevt->evtid))
|
2020-05-05 15:36:16 -07:00
|
|
|
mon_event_read(&rr, r, d, prgrp, mevt->evtid, true);
|
2017-07-25 14:14:38 -07:00
|
|
|
}
|
|
|
|
kernfs_activate(kn);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_destroy:
|
|
|
|
kernfs_remove(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:44 -07:00
|
|
|
/*
|
|
|
|
* Add all subdirectories of mon_data for "ctrl_mon" groups
|
|
|
|
* and "monitor" groups with given domain id.
|
|
|
|
*/
|
2022-09-02 15:48:11 +00:00
|
|
|
static void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
|
|
|
|
struct rdt_domain *d)
|
2017-07-25 14:14:44 -07:00
|
|
|
{
|
|
|
|
struct kernfs_node *parent_kn;
|
|
|
|
struct rdtgroup *prgrp, *crgrp;
|
|
|
|
struct list_head *head;
|
|
|
|
|
|
|
|
list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
|
|
|
|
parent_kn = prgrp->mon.mon_data_kn;
|
|
|
|
mkdir_mondata_subdir(parent_kn, d, r, prgrp);
|
|
|
|
|
|
|
|
head = &prgrp->mon.crdtgrp_list;
|
|
|
|
list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
|
|
|
|
parent_kn = crgrp->mon.mon_data_kn;
|
|
|
|
mkdir_mondata_subdir(parent_kn, d, r, crgrp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:38 -07:00
|
|
|
static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,
|
|
|
|
struct rdt_resource *r,
|
|
|
|
struct rdtgroup *prgrp)
|
|
|
|
{
|
|
|
|
struct rdt_domain *dom;
|
|
|
|
int ret;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
/* Walking r->domains, ensure it can't race with cpuhp */
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
2017-07-25 14:14:38 -07:00
|
|
|
list_for_each_entry(dom, &r->domains, list) {
|
|
|
|
ret = mkdir_mondata_subdir(parent_kn, dom, r, prgrp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This creates a directory mon_data which contains the monitored data.
|
|
|
|
*
|
2021-03-21 22:28:53 +01:00
|
|
|
* mon_data has one directory for each domain which are named
|
2017-07-25 14:14:38 -07:00
|
|
|
* in the format mon_<domain_name>_<domain_id>. For ex: A mon_data
|
|
|
|
* with L3 domain looks as below:
|
|
|
|
* ./mon_data:
|
|
|
|
* mon_L3_00
|
|
|
|
* mon_L3_01
|
|
|
|
* mon_L3_02
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* Each domain directory has one file per event:
|
|
|
|
* ./mon_L3_00/:
|
|
|
|
* llc_occupancy
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int mkdir_mondata_all(struct kernfs_node *parent_kn,
|
|
|
|
struct rdtgroup *prgrp,
|
|
|
|
struct kernfs_node **dest_kn)
|
|
|
|
{
|
|
|
|
struct rdt_resource *r;
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the mon_data directory first.
|
|
|
|
*/
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
ret = mongroup_create_dir(parent_kn, prgrp, "mon_data", &kn);
|
2017-07-25 14:14:38 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (dest_kn)
|
|
|
|
*dest_kn = kn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the subdirectories for each domain. Note that all events
|
|
|
|
* in a domain like L3 are grouped into a resource whose domain is L3
|
|
|
|
*/
|
2022-09-02 15:48:10 +00:00
|
|
|
for_each_mon_capable_rdt_resource(r) {
|
2017-07-25 14:14:38 -07:00
|
|
|
ret = mkdir_mondata_subdir_alldom(kn, r, prgrp);
|
|
|
|
if (ret)
|
|
|
|
goto out_destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_destroy:
|
|
|
|
kernfs_remove(kn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:41:59 -07:00
|
|
|
/**
|
|
|
|
* cbm_ensure_valid - Enforce validity on provided CBM
|
|
|
|
* @_val: Candidate CBM
|
|
|
|
* @r: RDT resource to which the CBM belongs
|
|
|
|
*
|
|
|
|
* The provided CBM represents all cache portions available for use. This
|
|
|
|
* may be represented by a bitmap that does not consist of contiguous ones
|
|
|
|
* and thus be an invalid CBM.
|
|
|
|
* Here the provided CBM is forced to be a valid CBM by only considering
|
|
|
|
* the first set of contiguous bits as valid and clearing all bits.
|
|
|
|
* The intention here is to provide a valid default CBM with which a new
|
|
|
|
* resource group is initialized. The user can follow this with a
|
|
|
|
* modification to the CBM if the default does not satisfy the
|
|
|
|
* requirements.
|
|
|
|
*/
|
2019-06-24 13:34:27 -07:00
|
|
|
static u32 cbm_ensure_valid(u32 _val, struct rdt_resource *r)
|
2018-06-22 15:41:59 -07:00
|
|
|
{
|
|
|
|
unsigned int cbm_len = r->cache.cbm_len;
|
|
|
|
unsigned long first_bit, zero_bit;
|
2019-06-24 13:34:27 -07:00
|
|
|
unsigned long val = _val;
|
2018-06-22 15:41:59 -07:00
|
|
|
|
2019-06-24 13:34:27 -07:00
|
|
|
if (!val)
|
|
|
|
return 0;
|
2018-06-22 15:41:59 -07:00
|
|
|
|
2019-06-19 13:27:16 -07:00
|
|
|
first_bit = find_first_bit(&val, cbm_len);
|
|
|
|
zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);
|
2018-06-22 15:41:59 -07:00
|
|
|
|
|
|
|
/* Clear any remaining bits to ensure contiguous region */
|
2019-06-19 13:27:16 -07:00
|
|
|
bitmap_clear(&val, zero_bit, cbm_len - zero_bit);
|
2019-06-24 13:34:27 -07:00
|
|
|
return (u32)val;
|
2018-06-22 15:41:59 -07:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:08:48 +08:00
|
|
|
/*
|
|
|
|
* Initialize cache resources per RDT domain
|
|
|
|
*
|
|
|
|
* Set the RDT domain up to start off with all usable allocations. That is,
|
|
|
|
* all shareable and unused bits. All-zero CBM is invalid.
|
|
|
|
*/
|
2021-07-28 17:06:22 +00:00
|
|
|
static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,
|
2019-04-17 19:08:48 +08:00
|
|
|
u32 closid)
|
|
|
|
{
|
2021-07-28 17:06:35 +00:00
|
|
|
enum resctrl_conf_type peer_type = resctrl_peer_type(s->conf_type);
|
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;
|
2019-04-17 19:08:48 +08:00
|
|
|
u32 used_b = 0, unused_b = 0;
|
|
|
|
unsigned long tmp_cbm;
|
|
|
|
enum rdtgrp_mode mode;
|
2021-07-28 17:06:29 +00:00
|
|
|
u32 peer_ctl, ctrl_val;
|
2019-04-17 19:08:48 +08:00
|
|
|
int i;
|
|
|
|
|
2021-07-28 17:06:27 +00:00
|
|
|
cfg = &d->staged_config[t];
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->have_new_ctrl = false;
|
|
|
|
cfg->new_ctrl = r->cache.shareable_bits;
|
2019-04-17 19:08:48 +08:00
|
|
|
used_b = r->cache.shareable_bits;
|
2021-07-28 17:06:29 +00:00
|
|
|
for (i = 0; i < closids_supported(); i++) {
|
2019-04-17 19:08:48 +08:00
|
|
|
if (closid_allocated(i) && i != closid) {
|
|
|
|
mode = rdtgroup_mode_by_closid(i);
|
|
|
|
if (mode == RDT_MODE_PSEUDO_LOCKSETUP)
|
2019-06-03 18:25:31 +01:00
|
|
|
/*
|
|
|
|
* ctrl values for locksetup aren't relevant
|
|
|
|
* until the schemata is written, and the mode
|
|
|
|
* becomes RDT_MODE_PSEUDO_LOCKED.
|
|
|
|
*/
|
|
|
|
continue;
|
2019-04-17 19:08:48 +08:00
|
|
|
/*
|
|
|
|
* If CDP is active include peer domain's
|
|
|
|
* usage to ensure there is no overlap
|
|
|
|
* with an exclusive group.
|
|
|
|
*/
|
2021-07-28 17:06:35 +00:00
|
|
|
if (resctrl_arch_get_cdp_enabled(r->rid))
|
2021-08-11 16:38:31 +00:00
|
|
|
peer_ctl = resctrl_arch_get_config(r, d, i,
|
|
|
|
peer_type);
|
2019-04-17 19:08:48 +08:00
|
|
|
else
|
|
|
|
peer_ctl = 0;
|
2021-08-11 16:38:31 +00:00
|
|
|
ctrl_val = resctrl_arch_get_config(r, d, i,
|
|
|
|
s->conf_type);
|
2021-07-28 17:06:29 +00:00
|
|
|
used_b |= ctrl_val | peer_ctl;
|
2019-04-17 19:08:48 +08:00
|
|
|
if (mode == RDT_MODE_SHAREABLE)
|
2021-07-28 17:06:29 +00:00
|
|
|
cfg->new_ctrl |= ctrl_val | peer_ctl;
|
2019-04-17 19:08:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (d->plr && d->plr->cbm > 0)
|
|
|
|
used_b |= d->plr->cbm;
|
|
|
|
unused_b = used_b ^ (BIT_MASK(r->cache.cbm_len) - 1);
|
|
|
|
unused_b &= BIT_MASK(r->cache.cbm_len) - 1;
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->new_ctrl |= unused_b;
|
2019-04-17 19:08:48 +08:00
|
|
|
/*
|
|
|
|
* Force the initial CBM to be valid, user can
|
|
|
|
* modify the CBM based on system availability.
|
|
|
|
*/
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->new_ctrl = cbm_ensure_valid(cfg->new_ctrl, r);
|
2019-04-17 19:08:48 +08:00
|
|
|
/*
|
|
|
|
* Assign the u32 CBM to an unsigned long to ensure that
|
|
|
|
* bitmap_weight() does not access out-of-bound memory.
|
|
|
|
*/
|
2021-07-28 17:06:26 +00:00
|
|
|
tmp_cbm = cfg->new_ctrl;
|
2019-04-17 19:08:48 +08:00
|
|
|
if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) {
|
2021-07-28 17:06:25 +00:00
|
|
|
rdt_last_cmd_printf("No space on %s:%d\n", s->name, d->id);
|
2019-04-17 19:08:48 +08:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->have_new_ctrl = true;
|
2019-04-17 19:08:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:08:49 +08:00
|
|
|
/*
|
|
|
|
* Initialize cache resources with default values.
|
2018-06-22 15:41:59 -07:00
|
|
|
*
|
|
|
|
* A new RDT group is being created on an allocation capable (CAT)
|
|
|
|
* supporting system. Set this group up to start off with all usable
|
2019-04-17 19:08:48 +08:00
|
|
|
* allocations.
|
2018-06-22 15:41:59 -07:00
|
|
|
*
|
2019-04-17 19:08:48 +08:00
|
|
|
* If there are no more shareable bits available on any domain then
|
|
|
|
* the entire allocation will fail.
|
2018-06-22 15:41:59 -07:00
|
|
|
*/
|
2021-07-28 17:06:22 +00:00
|
|
|
static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)
|
2019-04-17 19:08:49 +08:00
|
|
|
{
|
|
|
|
struct rdt_domain *d;
|
|
|
|
int ret;
|
|
|
|
|
2021-07-28 17:06:22 +00:00
|
|
|
list_for_each_entry(d, &s->res->domains, list) {
|
|
|
|
ret = __init_one_rdt_domain(d, s, closid);
|
2019-04-17 19:08:49 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize MBA resource with default values. */
|
2022-09-02 15:48:17 +00:00
|
|
|
static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid)
|
2019-04-17 19:08:49 +08:00
|
|
|
{
|
2021-07-28 17:06:26 +00:00
|
|
|
struct resctrl_staged_config *cfg;
|
2019-04-17 19:08:49 +08:00
|
|
|
struct rdt_domain *d;
|
|
|
|
|
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
2022-09-02 15:48:17 +00:00
|
|
|
if (is_mba_sc(r)) {
|
|
|
|
d->mbps_val[closid] = MBA_MAX_MBPS;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:27 +00:00
|
|
|
cfg = &d->staged_config[CDP_NONE];
|
2022-09-02 15:48:17 +00:00
|
|
|
cfg->new_ctrl = r->default_ctrl;
|
2021-07-28 17:06:26 +00:00
|
|
|
cfg->have_new_ctrl = true;
|
2019-04-17 19:08:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the RDT group's allocations. */
|
2018-06-22 15:41:59 -07:00
|
|
|
static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
|
|
|
|
{
|
2021-07-28 17:06:19 +00:00
|
|
|
struct resctrl_schema *s;
|
2018-06-22 15:41:59 -07:00
|
|
|
struct rdt_resource *r;
|
2023-01-17 13:14:50 -08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rdt_staged_configs_clear();
|
2018-06-22 15:41:59 -07:00
|
|
|
|
2021-07-28 17:06:19 +00:00
|
|
|
list_for_each_entry(s, &resctrl_schema_all, list) {
|
|
|
|
r = s->res;
|
2023-01-13 09:20:32 -06:00
|
|
|
if (r->rid == RDT_RESOURCE_MBA ||
|
|
|
|
r->rid == RDT_RESOURCE_SMBA) {
|
2022-09-02 15:48:17 +00:00
|
|
|
rdtgroup_init_mba(r, rdtgrp->closid);
|
|
|
|
if (is_mba_sc(r))
|
|
|
|
continue;
|
2019-04-17 19:08:49 +08:00
|
|
|
} else {
|
2021-07-28 17:06:22 +00:00
|
|
|
ret = rdtgroup_init_cat(s, rdtgrp->closid);
|
2019-04-17 19:08:48 +08:00
|
|
|
if (ret < 0)
|
2023-01-17 13:14:50 -08:00
|
|
|
goto out;
|
2018-06-22 15:41:59 -07:00
|
|
|
}
|
|
|
|
|
2021-07-28 17:06:28 +00:00
|
|
|
ret = resctrl_arch_update_domains(r, rdtgrp->closid);
|
2018-06-22 15:41:59 -07:00
|
|
|
if (ret < 0) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Failed to initialize allocations\n");
|
2023-01-17 13:14:50 -08:00
|
|
|
goto out;
|
2018-06-22 15:41:59 -07:00
|
|
|
}
|
2019-04-17 19:08:49 +08:00
|
|
|
|
2018-06-22 15:41:59 -07:00
|
|
|
}
|
|
|
|
|
2019-04-10 03:53:49 +08:00
|
|
|
rdtgrp->mode = RDT_MODE_SHAREABLE;
|
|
|
|
|
2023-01-17 13:14:50 -08:00
|
|
|
out:
|
|
|
|
rdt_staged_configs_clear();
|
|
|
|
return ret;
|
2018-06-22 15:41:59 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:17 +00:00
|
|
|
static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2024-02-13 18:44:33 +00:00
|
|
|
if (!resctrl_arch_mon_capable())
|
2024-02-13 18:44:17 +00:00
|
|
|
return 0;
|
|
|
|
|
2024-02-13 18:44:21 +00:00
|
|
|
ret = alloc_rmid(rdtgrp->closid);
|
2024-02-13 18:44:17 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
rdt_last_cmd_puts("Out of RMIDs\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
rdtgrp->mon.rmid = ret;
|
|
|
|
|
|
|
|
ret = mkdir_mondata_all(rdtgrp->kn, rdtgrp, &rdtgrp->mon.mon_data_kn);
|
|
|
|
if (ret) {
|
|
|
|
rdt_last_cmd_puts("kernfs subdir error\n");
|
2024-02-13 18:44:19 +00:00
|
|
|
free_rmid(rdtgrp->closid, rdtgrp->mon.rmid);
|
2024-02-13 18:44:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:18 +00:00
|
|
|
static void mkdir_rdt_prepare_rmid_free(struct rdtgroup *rgrp)
|
|
|
|
{
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2024-02-13 18:44:19 +00:00
|
|
|
free_rmid(rgrp->closid, rgrp->mon.rmid);
|
2024-02-13 18:44:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
|
|
|
|
const char *name, umode_t mode,
|
2017-07-25 14:14:32 -07:00
|
|
|
enum rdt_group_type rtype, struct rdtgroup **r)
|
2016-10-28 15:04:44 -07:00
|
|
|
{
|
2017-07-25 14:14:31 -07:00
|
|
|
struct rdtgroup *prdtgrp, *rdtgrp;
|
2023-10-16 19:23:07 -05:00
|
|
|
unsigned long files = 0;
|
2016-10-28 15:04:44 -07:00
|
|
|
struct kernfs_node *kn;
|
2017-07-25 14:14:31 -07:00
|
|
|
int ret;
|
2016-10-28 15:04:44 -07:00
|
|
|
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
prdtgrp = rdtgroup_kn_lock_live(parent_kn);
|
2017-07-25 14:14:31 -07:00
|
|
|
if (!prdtgrp) {
|
2016-10-28 15:04:44 -07:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
2018-06-22 15:42:12 -07:00
|
|
|
if (rtype == RDTMON_GROUP &&
|
|
|
|
(prdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
|
|
|
|
prdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)) {
|
|
|
|
ret = -EINVAL;
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Pseudo-locking in progress\n");
|
2018-06-22 15:42:12 -07:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:44 -07:00
|
|
|
/* allocate the rdtgroup. */
|
|
|
|
rdtgrp = kzalloc(sizeof(*rdtgrp), GFP_KERNEL);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
ret = -ENOSPC;
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Kernel out of memory\n");
|
2017-07-25 14:14:31 -07:00
|
|
|
goto out_unlock;
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
2017-07-25 14:14:31 -07:00
|
|
|
*r = rdtgrp;
|
2017-07-25 14:14:32 -07:00
|
|
|
rdtgrp->mon.parent = prdtgrp;
|
|
|
|
rdtgrp->type = rtype;
|
|
|
|
INIT_LIST_HEAD(&rdtgrp->mon.crdtgrp_list);
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
/* kernfs creates the directory for rdtgrp */
|
2017-07-25 14:14:31 -07:00
|
|
|
kn = kernfs_create_dir(parent_kn, name, mode, rdtgrp);
|
2016-10-28 15:04:44 -07:00
|
|
|
if (IS_ERR(kn)) {
|
|
|
|
ret = PTR_ERR(kn);
|
2017-09-25 16:39:37 -07:00
|
|
|
rdt_last_cmd_puts("kernfs create error\n");
|
2017-07-25 14:14:31 -07:00
|
|
|
goto out_free_rgrp;
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
|
|
|
rdtgrp->kn = kn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kernfs_remove() will drop the reference count on "kn" which
|
|
|
|
* will free it. But we still need it to stick around for the
|
2020-10-31 03:10:53 +08:00
|
|
|
* rdtgroup_kn_unlock(kn) call. Take one extra reference here,
|
2020-10-31 03:11:28 +08:00
|
|
|
* which will be dropped by kernfs_put() in rdtgroup_remove().
|
2016-10-28 15:04:44 -07:00
|
|
|
*/
|
|
|
|
kernfs_get(kn);
|
|
|
|
|
|
|
|
ret = rdtgroup_kn_set_ugid(kn);
|
2017-09-25 16:39:37 -07:00
|
|
|
if (ret) {
|
|
|
|
rdt_last_cmd_puts("kernfs perm error\n");
|
2016-10-28 15:04:44 -07:00
|
|
|
goto out_destroy;
|
2017-09-25 16:39:37 -07:00
|
|
|
}
|
2016-10-28 15:04:44 -07:00
|
|
|
|
2023-10-16 19:23:07 -05:00
|
|
|
if (rtype == RDTCTRL_GROUP) {
|
2023-10-03 18:54:22 -05:00
|
|
|
files = RFTYPE_BASE | RFTYPE_CTRL;
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable())
|
2023-10-16 19:23:07 -05:00
|
|
|
files |= RFTYPE_MON;
|
|
|
|
} else {
|
2023-10-03 18:54:22 -05:00
|
|
|
files = RFTYPE_BASE | RFTYPE_MON;
|
2023-10-16 19:23:07 -05:00
|
|
|
}
|
2023-10-03 18:54:22 -05:00
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
ret = rdtgroup_add_files(kn, files);
|
2017-09-25 16:39:37 -07:00
|
|
|
if (ret) {
|
|
|
|
rdt_last_cmd_puts("kernfs fill error\n");
|
2016-10-28 15:04:45 -07:00
|
|
|
goto out_destroy;
|
2017-09-25 16:39:37 -07:00
|
|
|
}
|
2016-10-28 15:04:45 -07:00
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
/*
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
* The caller unlocks the parent_kn upon success.
|
2017-07-25 14:14:31 -07:00
|
|
|
*/
|
|
|
|
return 0;
|
2016-10-28 15:04:44 -07:00
|
|
|
|
|
|
|
out_destroy:
|
2020-10-31 03:11:28 +08:00
|
|
|
kernfs_put(rdtgrp->kn);
|
2016-10-28 15:04:44 -07:00
|
|
|
kernfs_remove(rdtgrp->kn);
|
2017-07-25 14:14:31 -07:00
|
|
|
out_free_rgrp:
|
2016-10-28 15:04:44 -07:00
|
|
|
kfree(rdtgrp);
|
|
|
|
out_unlock:
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
rdtgroup_kn_unlock(parent_kn);
|
2017-07-25 14:14:31 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mkdir_rdt_prepare_clean(struct rdtgroup *rgrp)
|
|
|
|
{
|
|
|
|
kernfs_remove(rgrp->kn);
|
2020-10-31 03:11:28 +08:00
|
|
|
rdtgroup_remove(rgrp);
|
2017-07-25 14:14:31 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:32 -07:00
|
|
|
/*
|
|
|
|
* Create a monitor group under "mon_groups" directory of a control
|
|
|
|
* and monitor group(ctrl_mon). This is a resource group
|
|
|
|
* to monitor a subset of tasks and cpus in its parent ctrl_mon group.
|
|
|
|
*/
|
|
|
|
static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn,
|
2020-01-09 00:28:06 +08:00
|
|
|
const char *name, umode_t mode)
|
2017-07-25 14:14:32 -07:00
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp, *prgrp;
|
|
|
|
int ret;
|
|
|
|
|
2020-01-09 00:28:06 +08:00
|
|
|
ret = mkdir_rdt_prepare(parent_kn, name, mode, RDTMON_GROUP, &rdtgrp);
|
2017-07-25 14:14:32 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
prgrp = rdtgrp->mon.parent;
|
|
|
|
rdtgrp->closid = prgrp->closid;
|
|
|
|
|
2024-02-13 18:44:18 +00:00
|
|
|
ret = mkdir_rdt_prepare_rmid_alloc(rdtgrp);
|
|
|
|
if (ret) {
|
|
|
|
mkdir_rdt_prepare_clean(rdtgrp);
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
kernfs_activate(rdtgrp->kn);
|
|
|
|
|
2017-07-25 14:14:32 -07:00
|
|
|
/*
|
|
|
|
* Add the rdtgrp to the list of rdtgrps the parent
|
|
|
|
* ctrl_mon group has to track.
|
|
|
|
*/
|
|
|
|
list_add_tail(&rdtgrp->mon.crdtgrp_list, &prgrp->mon.crdtgrp_list);
|
|
|
|
|
2024-02-13 18:44:18 +00:00
|
|
|
out_unlock:
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
rdtgroup_kn_unlock(parent_kn);
|
2017-07-25 14:14:32 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
/*
|
|
|
|
* These are rdtgroups created under the root directory. Can be used
|
2017-07-25 14:14:32 -07:00
|
|
|
* to allocate and monitor resources.
|
2017-07-25 14:14:31 -07:00
|
|
|
*/
|
2017-07-25 14:14:32 -07:00
|
|
|
static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
|
|
|
|
const char *name, umode_t mode)
|
2017-07-25 14:14:31 -07:00
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
struct kernfs_node *kn;
|
|
|
|
u32 closid;
|
|
|
|
int ret;
|
|
|
|
|
2020-01-09 00:28:06 +08:00
|
|
|
ret = mkdir_rdt_prepare(parent_kn, name, mode, RDTCTRL_GROUP, &rdtgrp);
|
2017-07-25 14:14:31 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
kn = rdtgrp->kn;
|
|
|
|
ret = closid_alloc();
|
2017-09-25 16:39:37 -07:00
|
|
|
if (ret < 0) {
|
2018-11-21 20:28:43 +00:00
|
|
|
rdt_last_cmd_puts("Out of CLOSIDs\n");
|
2017-07-25 14:14:31 -07:00
|
|
|
goto out_common_fail;
|
2017-09-25 16:39:37 -07:00
|
|
|
}
|
2017-07-25 14:14:31 -07:00
|
|
|
closid = ret;
|
2018-02-22 19:26:03 -08:00
|
|
|
ret = 0;
|
2017-07-25 14:14:31 -07:00
|
|
|
|
|
|
|
rdtgrp->closid = closid;
|
2024-02-13 18:44:18 +00:00
|
|
|
|
|
|
|
ret = mkdir_rdt_prepare_rmid_alloc(rdtgrp);
|
|
|
|
if (ret)
|
|
|
|
goto out_closid_free;
|
|
|
|
|
|
|
|
kernfs_activate(rdtgrp->kn);
|
|
|
|
|
2018-06-22 15:41:59 -07:00
|
|
|
ret = rdtgroup_init_alloc(rdtgrp);
|
|
|
|
if (ret < 0)
|
2024-02-13 18:44:18 +00:00
|
|
|
goto out_rmid_free;
|
2018-06-22 15:41:59 -07:00
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups);
|
|
|
|
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable()) {
|
2017-07-25 14:14:32 -07:00
|
|
|
/*
|
|
|
|
* Create an empty mon_groups directory to hold the subset
|
|
|
|
* of tasks and cpus to monitor.
|
|
|
|
*/
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
ret = mongroup_create_dir(kn, rdtgrp, "mon_groups", NULL);
|
2017-09-25 16:39:37 -07:00
|
|
|
if (ret) {
|
|
|
|
rdt_last_cmd_puts("kernfs subdir error\n");
|
2018-06-22 15:41:59 -07:00
|
|
|
goto out_del_list;
|
2017-09-25 16:39:37 -07:00
|
|
|
}
|
2017-07-25 14:14:32 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
goto out_unlock;
|
|
|
|
|
2018-06-22 15:41:59 -07:00
|
|
|
out_del_list:
|
|
|
|
list_del(&rdtgrp->rdtgroup_list);
|
2024-02-13 18:44:18 +00:00
|
|
|
out_rmid_free:
|
|
|
|
mkdir_rdt_prepare_rmid_free(rdtgrp);
|
|
|
|
out_closid_free:
|
2017-07-25 14:14:32 -07:00
|
|
|
closid_free(closid);
|
2017-07-25 14:14:31 -07:00
|
|
|
out_common_fail:
|
|
|
|
mkdir_rdt_prepare_clean(rdtgrp);
|
|
|
|
out_unlock:
|
x86/resctrl: Fix a deadlock due to inaccurate reference
There is a race condition which results in a deadlock when rmdir and
mkdir execute concurrently:
$ ls /sys/fs/resctrl/c1/mon_groups/m1/
cpus cpus_list mon_data tasks
Thread 1: rmdir /sys/fs/resctrl/c1
Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
3 locks held by mkdir/48649:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
#2: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
4 locks held by rmdir/48652:
#0: (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
#1: (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
#2: (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
#3: (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
kernfs_remove() removes all kernfs nodes under directory "c1"
recursively, then waits for sub kernfs node "mon_groups" to drop active
reference.
Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
directory. The wrapper kernfs_iop_mkdir() takes an active reference to
the "mon_groups" directory but the code drops the active reference to
the parent directory "c1" instead.
As a result, Thread 1 is blocked on waiting for active reference to drop
and never release rdtgroup_mutex, while Thread 2 is also blocked on
trying to get rdtgroup_mutex.
Thread 1 (rdtgroup_rmdir) Thread 2 (rdtgroup_mkdir)
(rmdir /sys/fs/resctrl/c1) (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
------------------------- -------------------------
kernfs_iop_mkdir
/*
* kn: "m1", parent_kn: "mon_groups",
* prgrp_kn: parent_kn->parent: "c1",
*
* "mon_groups", parent_kn->active++: 1
*/
kernfs_get_active(parent_kn)
kernfs_iop_rmdir
/* "c1", kn->active++ */
kernfs_get_active(kn)
rdtgroup_kn_lock_live
atomic_inc(&rdtgrp->waitcount)
/* "c1", kn->active-- */
kernfs_break_active_protection(kn)
mutex_lock
rdtgroup_rmdir_ctrl
free_all_child_rdtgrp
sentry->flags = RDT_DELETED
rdtgroup_ctrl_remove
rdtgrp->flags = RDT_DELETED
kernfs_get(kn)
kernfs_remove(rdtgrp->kn)
__kernfs_remove
/* "mon_groups", sub_kn */
atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
kernfs_drain(sub_kn)
/*
* sub_kn->active == KN_DEACTIVATED_BIAS + 1,
* waiting on sub_kn->active to drop, but it
* never drops in Thread 2 which is blocked
* on getting rdtgroup_mutex.
*/
Thread 1 hangs here ---->
wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
...
rdtgroup_mkdir
rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
mkdir_rdt_prepare(parent_kn, prgrp_kn)
rdtgroup_kn_lock_live(prgrp_kn)
atomic_inc(&rdtgrp->waitcount)
/*
* "c1", prgrp_kn->active--
*
* The active reference on "c1" is
* dropped, but not matching the
* actual active reference taken
* on "mon_groups", thus causing
* Thread 1 to wait forever while
* holding rdtgroup_mutex.
*/
kernfs_break_active_protection(
prgrp_kn)
/*
* Trying to get rdtgroup_mutex
* which is held by Thread 1.
*/
Thread 2 hangs here ----> mutex_lock
...
The problem is that the creation of a subdirectory in the "mon_groups"
directory incorrectly releases the active protection of its parent
directory instead of itself before it starts waiting for rdtgroup_mutex.
This is triggered by the rdtgroup_mkdir() flow calling
rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
parent control group ("c1") as argument. It should be called with kernfs
node "mon_groups" instead. What is currently missing is that the
kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
instead. And then it operates on the same rdtgroup structure but handles
the active reference of kernfs node "mon_groups" to prevent deadlock.
The same changes are also made to the "mon_data" directories.
This results in some unused function parameters that will be cleaned up
in follow-up patch as the focus here is on the fix only in support of
backporting efforts.
Fixes: c7d9aac61311 ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
2020-01-09 00:28:05 +08:00
|
|
|
rdtgroup_kn_unlock(parent_kn);
|
2016-10-28 15:04:44 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:32 -07:00
|
|
|
/*
|
|
|
|
* We allow creating mon groups only with in a directory called "mon_groups"
|
|
|
|
* which is present in every ctrl_mon group. Check if this is a valid
|
|
|
|
* "mon_groups" directory.
|
|
|
|
*
|
|
|
|
* 1. The directory should be named "mon_groups".
|
|
|
|
* 2. The mon group itself should "not" be named "mon_groups".
|
|
|
|
* This makes sure "mon_groups" directory always has a ctrl_mon group
|
|
|
|
* as parent.
|
|
|
|
*/
|
|
|
|
static bool is_mon_groups(struct kernfs_node *kn, const char *name)
|
|
|
|
{
|
|
|
|
return (!strcmp(kn->name, "mon_groups") &&
|
|
|
|
strcmp(name, "mon_groups"));
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:31 -07:00
|
|
|
static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
|
|
|
|
umode_t mode)
|
|
|
|
{
|
|
|
|
/* Do not accept '\n' to avoid unparsable situation. */
|
|
|
|
if (strchr(name, '\n'))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the parent directory is the root directory and RDT
|
2017-07-25 14:14:32 -07:00
|
|
|
* allocation is supported, add a control and monitoring
|
|
|
|
* subdirectory
|
2017-07-25 14:14:31 -07:00
|
|
|
*/
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_alloc_capable() && parent_kn == rdtgroup_default.kn)
|
2020-01-09 00:28:06 +08:00
|
|
|
return rdtgroup_mkdir_ctrl_mon(parent_kn, name, mode);
|
2017-07-25 14:14:32 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If RDT monitoring is supported and the parent directory is a valid
|
|
|
|
* "mon_groups" directory, add a monitoring subdirectory.
|
|
|
|
*/
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_arch_mon_capable() && is_mon_groups(parent_kn, name))
|
2020-01-09 00:28:06 +08:00
|
|
|
return rdtgroup_mkdir_mon(parent_kn, name, mode);
|
2017-07-25 14:14:31 -07:00
|
|
|
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-12-01 02:06:58 +08:00
|
|
|
static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
|
2017-07-25 14:14:40 -07:00
|
|
|
{
|
|
|
|
struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
/* Give any tasks back to the parent group */
|
|
|
|
rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
|
|
|
|
|
|
|
|
/* Update per cpu rmid of the moved CPUs first */
|
|
|
|
for_each_cpu(cpu, &rdtgrp->cpu_mask)
|
2017-08-09 11:46:34 -07:00
|
|
|
per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
|
2017-07-25 14:14:40 -07:00
|
|
|
/*
|
|
|
|
* Update the MSR on moved CPUs and CPUs which have moved
|
|
|
|
* task running on them.
|
|
|
|
*/
|
|
|
|
cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
|
|
|
|
update_closid_rmid(tmpmask, NULL);
|
|
|
|
|
|
|
|
rdtgrp->flags = RDT_DELETED;
|
2024-02-13 18:44:19 +00:00
|
|
|
free_rmid(rdtgrp->closid, rdtgrp->mon.rmid);
|
2017-07-25 14:14:40 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the rdtgrp from the parent ctrl_mon group's list
|
|
|
|
*/
|
|
|
|
WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
|
|
|
|
list_del(&rdtgrp->mon.crdtgrp_list);
|
|
|
|
|
|
|
|
kernfs_remove(rdtgrp->kn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-01 02:06:58 +08:00
|
|
|
static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)
|
2018-06-22 15:42:18 -07:00
|
|
|
{
|
|
|
|
rdtgrp->flags = RDT_DELETED;
|
|
|
|
list_del(&rdtgrp->rdtgroup_list);
|
|
|
|
|
|
|
|
kernfs_remove(rdtgrp->kn);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-01 02:06:58 +08:00
|
|
|
static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
|
2016-10-28 15:04:44 -07:00
|
|
|
{
|
2017-07-25 14:14:39 -07:00
|
|
|
int cpu;
|
2016-10-28 15:04:44 -07:00
|
|
|
|
2016-10-28 15:04:46 -07:00
|
|
|
/* Give any tasks back to the default group */
|
2016-11-18 15:18:04 -08:00
|
|
|
rdt_move_group_tasks(rdtgrp, &rdtgroup_default, tmpmask);
|
2016-10-28 15:04:46 -07:00
|
|
|
|
2016-10-28 15:04:45 -07:00
|
|
|
/* Give any CPUs back to the default group */
|
|
|
|
cpumask_or(&rdtgroup_default.cpu_mask,
|
|
|
|
&rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
|
2016-11-18 15:18:04 -08:00
|
|
|
|
2017-07-25 14:14:40 -07:00
|
|
|
/* Update per cpu closid and rmid of the moved CPUs first */
|
|
|
|
for_each_cpu(cpu, &rdtgrp->cpu_mask) {
|
2017-08-09 11:46:34 -07:00
|
|
|
per_cpu(pqr_state.default_closid, cpu) = rdtgroup_default.closid;
|
|
|
|
per_cpu(pqr_state.default_rmid, cpu) = rdtgroup_default.mon.rmid;
|
2017-07-25 14:14:40 -07:00
|
|
|
}
|
|
|
|
|
2016-11-18 15:18:04 -08:00
|
|
|
/*
|
|
|
|
* Update the MSR on moved CPUs and CPUs which have moved
|
|
|
|
* task running on them.
|
|
|
|
*/
|
|
|
|
cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
|
2017-07-25 14:14:36 -07:00
|
|
|
update_closid_rmid(tmpmask, NULL);
|
2016-10-28 15:04:45 -07:00
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
free_rmid(rdtgrp->closid, rdtgrp->mon.rmid);
|
2016-10-28 15:04:44 -07:00
|
|
|
closid_free(rdtgrp->closid);
|
2017-07-25 14:14:40 -07:00
|
|
|
|
2020-12-01 02:06:58 +08:00
|
|
|
rdtgroup_ctrl_remove(rdtgrp);
|
2020-01-09 00:28:04 +08:00
|
|
|
|
2017-07-25 14:14:40 -07:00
|
|
|
/*
|
|
|
|
* Free all the child monitor group rmids.
|
|
|
|
*/
|
|
|
|
free_all_child_rdtgrp(rdtgrp);
|
|
|
|
|
2017-07-25 14:14:39 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdtgroup_rmdir(struct kernfs_node *kn)
|
|
|
|
{
|
|
|
|
struct kernfs_node *parent_kn = kn->parent;
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
cpumask_var_t tmpmask;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rdtgrp = rdtgroup_kn_lock_live(kn);
|
|
|
|
if (!rdtgrp) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the rdtgroup is a ctrl_mon group and parent directory
|
2017-07-25 14:14:40 -07:00
|
|
|
* is the root directory, remove the ctrl_mon group.
|
|
|
|
*
|
|
|
|
* If the rdtgroup is a mon group and parent directory
|
|
|
|
* is a valid "mon_groups" directory, remove the mon group.
|
2017-07-25 14:14:39 -07:00
|
|
|
*/
|
2020-03-17 09:26:45 -07:00
|
|
|
if (rdtgrp->type == RDTCTRL_GROUP && parent_kn == rdtgroup_default.kn &&
|
|
|
|
rdtgrp != &rdtgroup_default) {
|
2018-06-22 15:42:22 -07:00
|
|
|
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
|
|
|
|
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
|
2020-12-01 02:06:58 +08:00
|
|
|
ret = rdtgroup_ctrl_remove(rdtgrp);
|
2018-06-22 15:42:22 -07:00
|
|
|
} else {
|
2020-12-01 02:06:58 +08:00
|
|
|
ret = rdtgroup_rmdir_ctrl(rdtgrp, tmpmask);
|
2018-06-22 15:42:22 -07:00
|
|
|
}
|
|
|
|
} else if (rdtgrp->type == RDTMON_GROUP &&
|
|
|
|
is_mon_groups(parent_kn, kn->name)) {
|
2020-12-01 02:06:58 +08:00
|
|
|
ret = rdtgroup_rmdir_mon(rdtgrp, tmpmask);
|
2018-06-22 15:42:22 -07:00
|
|
|
} else {
|
2017-07-25 14:14:39 -07:00
|
|
|
ret = -EPERM;
|
2018-06-22 15:42:22 -07:00
|
|
|
}
|
2017-07-25 14:14:39 -07:00
|
|
|
|
2016-11-18 15:18:04 -08:00
|
|
|
out:
|
2016-10-28 15:04:44 -07:00
|
|
|
rdtgroup_kn_unlock(kn);
|
2016-11-18 15:18:04 -08:00
|
|
|
free_cpumask_var(tmpmask);
|
|
|
|
return ret;
|
2016-10-28 15:04:44 -07:00
|
|
|
}
|
|
|
|
|
2023-04-19 14:50:14 +02:00
|
|
|
/**
|
|
|
|
* mongrp_reparent() - replace parent CTRL_MON group of a MON group
|
|
|
|
* @rdtgrp: the MON group whose parent should be replaced
|
|
|
|
* @new_prdtgrp: replacement parent CTRL_MON group for @rdtgrp
|
|
|
|
* @cpus: cpumask provided by the caller for use during this call
|
|
|
|
*
|
|
|
|
* Replaces the parent CTRL_MON group for a MON group, resulting in all member
|
|
|
|
* tasks' CLOSID immediately changing to that of the new parent group.
|
|
|
|
* Monitoring data for the group is unaffected by this operation.
|
|
|
|
*/
|
|
|
|
static void mongrp_reparent(struct rdtgroup *rdtgrp,
|
|
|
|
struct rdtgroup *new_prdtgrp,
|
|
|
|
cpumask_var_t cpus)
|
|
|
|
{
|
|
|
|
struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
|
|
|
|
|
|
|
|
WARN_ON(rdtgrp->type != RDTMON_GROUP);
|
|
|
|
WARN_ON(new_prdtgrp->type != RDTCTRL_GROUP);
|
|
|
|
|
|
|
|
/* Nothing to do when simply renaming a MON group. */
|
|
|
|
if (prdtgrp == new_prdtgrp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
|
|
|
|
list_move_tail(&rdtgrp->mon.crdtgrp_list,
|
|
|
|
&new_prdtgrp->mon.crdtgrp_list);
|
|
|
|
|
|
|
|
rdtgrp->mon.parent = new_prdtgrp;
|
|
|
|
rdtgrp->closid = new_prdtgrp->closid;
|
|
|
|
|
|
|
|
/* Propagate updated closid to all tasks in this group. */
|
|
|
|
rdt_move_group_tasks(rdtgrp, rdtgrp, cpus);
|
|
|
|
|
|
|
|
update_closid_rmid(cpus, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdtgroup_rename(struct kernfs_node *kn,
|
|
|
|
struct kernfs_node *new_parent, const char *new_name)
|
|
|
|
{
|
|
|
|
struct rdtgroup *new_prdtgrp;
|
|
|
|
struct rdtgroup *rdtgrp;
|
|
|
|
cpumask_var_t tmpmask;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
rdtgrp = kernfs_to_rdtgroup(kn);
|
|
|
|
new_prdtgrp = kernfs_to_rdtgroup(new_parent);
|
|
|
|
if (!rdtgrp || !new_prdtgrp)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
/* Release both kernfs active_refs before obtaining rdtgroup mutex. */
|
|
|
|
rdtgroup_kn_get(rdtgrp, kn);
|
|
|
|
rdtgroup_kn_get(new_prdtgrp, new_parent);
|
|
|
|
|
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
rdt_last_cmd_clear();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't allow kernfs_to_rdtgroup() to return a parent rdtgroup if
|
|
|
|
* either kernfs_node is a file.
|
|
|
|
*/
|
|
|
|
if (kernfs_type(kn) != KERNFS_DIR ||
|
|
|
|
kernfs_type(new_parent) != KERNFS_DIR) {
|
|
|
|
rdt_last_cmd_puts("Source and destination must be directories");
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdtgrp->type != RDTMON_GROUP || !kn->parent ||
|
|
|
|
!is_mon_groups(kn->parent, kn->name)) {
|
|
|
|
rdt_last_cmd_puts("Source must be a MON group\n");
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_mon_groups(new_parent, new_name)) {
|
|
|
|
rdt_last_cmd_puts("Destination must be a mon_groups subdirectory\n");
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the MON group is monitoring CPUs, the CPUs must be assigned to the
|
|
|
|
* current parent CTRL_MON group and therefore cannot be assigned to
|
|
|
|
* the new parent, making the move illegal.
|
|
|
|
*/
|
|
|
|
if (!cpumask_empty(&rdtgrp->cpu_mask) &&
|
|
|
|
rdtgrp->mon.parent != new_prdtgrp) {
|
|
|
|
rdt_last_cmd_puts("Cannot move a MON group that monitors CPUs\n");
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the cpumask for use in mongrp_reparent() to avoid the
|
|
|
|
* possibility of failing to allocate it after kernfs_rename() has
|
|
|
|
* succeeded.
|
|
|
|
*/
|
|
|
|
if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform all input validation and allocations needed to ensure
|
|
|
|
* mongrp_reparent() will succeed before calling kernfs_rename(),
|
|
|
|
* otherwise it would be necessary to revert this call if
|
|
|
|
* mongrp_reparent() failed.
|
|
|
|
*/
|
|
|
|
ret = kernfs_rename(kn, new_parent, new_name);
|
|
|
|
if (!ret)
|
|
|
|
mongrp_reparent(rdtgrp, new_prdtgrp, tmpmask);
|
|
|
|
|
|
|
|
free_cpumask_var(tmpmask);
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
rdtgroup_kn_put(rdtgrp, kn);
|
|
|
|
rdtgroup_kn_put(new_prdtgrp, new_parent);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-12-02 14:21:06 -08:00
|
|
|
static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
|
|
|
|
{
|
2021-07-28 17:06:24 +00:00
|
|
|
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
|
2016-12-02 14:21:06 -08:00
|
|
|
seq_puts(seq, ",cdp");
|
x86/intel_rdt: Show missing resctrl mount options
In resctrl filesystem, mount options exist to enable L3/L2 CDP and MBA
Software Controller features if the platform supports them:
mount -t resctrl resctrl [-o cdp[,cdpl2][,mba_MBps]] /sys/fs/resctrl
But currently only "cdp" option is displayed in /proc/mounts. "cdpl2" and
"mba_MBps" options are not shown even when they are active.
Before:
# mount -t resctrl resctrl -o cdp,mba_MBps /sys/fs/resctrl
# grep resctrl /proc/mounts
/sys/fs/resctrl /sys/fs/resctrl resctrl rw,relatime,cdp 0 0
After:
# mount -t resctrl resctrl -o cdp,mba_MBps /sys/fs/resctrl
# grep resctrl /proc/mounts
/sys/fs/resctrl /sys/fs/resctrl resctrl rw,relatime,cdp,mba_MBps 0 0
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "H Peter Anvin" <hpa@zytor.com>
Cc: "Tony Luck" <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/1536796118-60135-1-git-send-email-fenghua.yu@intel.com
2018-09-12 16:48:38 -07:00
|
|
|
|
2021-07-28 17:06:24 +00:00
|
|
|
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
|
x86/intel_rdt: Show missing resctrl mount options
In resctrl filesystem, mount options exist to enable L3/L2 CDP and MBA
Software Controller features if the platform supports them:
mount -t resctrl resctrl [-o cdp[,cdpl2][,mba_MBps]] /sys/fs/resctrl
But currently only "cdp" option is displayed in /proc/mounts. "cdpl2" and
"mba_MBps" options are not shown even when they are active.
Before:
# mount -t resctrl resctrl -o cdp,mba_MBps /sys/fs/resctrl
# grep resctrl /proc/mounts
/sys/fs/resctrl /sys/fs/resctrl resctrl rw,relatime,cdp 0 0
After:
# mount -t resctrl resctrl -o cdp,mba_MBps /sys/fs/resctrl
# grep resctrl /proc/mounts
/sys/fs/resctrl /sys/fs/resctrl resctrl rw,relatime,cdp,mba_MBps 0 0
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "H Peter Anvin" <hpa@zytor.com>
Cc: "Tony Luck" <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/1536796118-60135-1-git-send-email-fenghua.yu@intel.com
2018-09-12 16:48:38 -07:00
|
|
|
seq_puts(seq, ",cdpl2");
|
|
|
|
|
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
|
|
|
if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
|
x86/intel_rdt: Show missing resctrl mount options
In resctrl filesystem, mount options exist to enable L3/L2 CDP and MBA
Software Controller features if the platform supports them:
mount -t resctrl resctrl [-o cdp[,cdpl2][,mba_MBps]] /sys/fs/resctrl
But currently only "cdp" option is displayed in /proc/mounts. "cdpl2" and
"mba_MBps" options are not shown even when they are active.
Before:
# mount -t resctrl resctrl -o cdp,mba_MBps /sys/fs/resctrl
# grep resctrl /proc/mounts
/sys/fs/resctrl /sys/fs/resctrl resctrl rw,relatime,cdp 0 0
After:
# mount -t resctrl resctrl -o cdp,mba_MBps /sys/fs/resctrl
# grep resctrl /proc/mounts
/sys/fs/resctrl /sys/fs/resctrl resctrl rw,relatime,cdp,mba_MBps 0 0
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "H Peter Anvin" <hpa@zytor.com>
Cc: "Tony Luck" <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/1536796118-60135-1-git-send-email-fenghua.yu@intel.com
2018-09-12 16:48:38 -07:00
|
|
|
seq_puts(seq, ",mba_MBps");
|
|
|
|
|
2023-10-16 19:23:05 -05:00
|
|
|
if (resctrl_debug)
|
|
|
|
seq_puts(seq, ",debug");
|
|
|
|
|
2016-12-02 14:21:06 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = {
|
2016-12-02 14:21:06 -08:00
|
|
|
.mkdir = rdtgroup_mkdir,
|
|
|
|
.rmdir = rdtgroup_rmdir,
|
2023-04-19 14:50:14 +02:00
|
|
|
.rename = rdtgroup_rename,
|
2016-12-02 14:21:06 -08:00
|
|
|
.show_options = rdtgroup_show_options,
|
2016-10-28 15:04:42 -07:00
|
|
|
};
|
|
|
|
|
2023-10-16 19:23:04 -05:00
|
|
|
static int rdtgroup_setup_root(struct rdt_fs_context *ctx)
|
2016-10-28 15:04:42 -07:00
|
|
|
{
|
|
|
|
rdt_root = kernfs_create_root(&rdtgroup_kf_syscall_ops,
|
2018-06-22 15:42:09 -07:00
|
|
|
KERNFS_ROOT_CREATE_DEACTIVATED |
|
|
|
|
KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
|
2016-10-28 15:04:42 -07:00
|
|
|
&rdtgroup_default);
|
|
|
|
if (IS_ERR(rdt_root))
|
|
|
|
return PTR_ERR(rdt_root);
|
|
|
|
|
2023-10-16 19:23:04 -05:00
|
|
|
ctx->kfc.root = rdt_root;
|
|
|
|
rdtgroup_default.kn = kernfs_root_to_node(rdt_root);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdtgroup_destroy_root(void)
|
|
|
|
{
|
|
|
|
kernfs_destroy_root(rdt_root);
|
|
|
|
rdtgroup_default.kn = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init rdtgroup_setup_default(void)
|
|
|
|
{
|
2016-10-28 15:04:42 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
rdtgroup_default.closid = RESCTRL_RESERVED_CLOSID;
|
|
|
|
rdtgroup_default.mon.rmid = RESCTRL_RESERVED_RMID;
|
2017-07-25 14:14:32 -07:00
|
|
|
rdtgroup_default.type = RDTCTRL_GROUP;
|
|
|
|
INIT_LIST_HEAD(&rdtgroup_default.mon.crdtgrp_list);
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups);
|
|
|
|
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:13 +00:00
|
|
|
static void domain_destroy_mon_state(struct rdt_domain *d)
|
|
|
|
{
|
|
|
|
bitmap_free(d->rmid_busy_llc);
|
|
|
|
kfree(d->mbm_total);
|
|
|
|
kfree(d->mbm_local);
|
|
|
|
}
|
|
|
|
|
|
|
|
void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)
|
|
|
|
{
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
2022-09-02 15:48:13 +00:00
|
|
|
|
2022-09-02 15:48:16 +00:00
|
|
|
if (supports_mba_mbps() && r->rid == RDT_RESOURCE_MBA)
|
|
|
|
mba_sc_domain_destroy(r, d);
|
|
|
|
|
2022-09-02 15:48:13 +00:00
|
|
|
if (!r->mon_capable)
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
goto out_unlock;
|
2022-09-02 15:48:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If resctrl is mounted, remove all the
|
|
|
|
* per domain monitor data directories.
|
|
|
|
*/
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_mounted && resctrl_arch_mon_capable())
|
2022-09-02 15:48:13 +00:00
|
|
|
rmdir_mondata_subdir_allrdtgrp(r, d->id);
|
|
|
|
|
|
|
|
if (is_mbm_enabled())
|
|
|
|
cancel_delayed_work(&d->mbm_over);
|
2024-02-13 18:44:20 +00:00
|
|
|
if (is_llc_occupancy_enabled() && has_busy_rmid(d)) {
|
2022-09-02 15:48:13 +00:00
|
|
|
/*
|
|
|
|
* When a package is going down, forcefully
|
|
|
|
* decrement rmid->ebusy. There is no way to know
|
|
|
|
* that the L3 was flushed and hence may lead to
|
|
|
|
* incorrect counts in rare scenarios, but leaving
|
|
|
|
* the RMID as busy creates RMID leaks if the
|
|
|
|
* package never comes back.
|
|
|
|
*/
|
|
|
|
__check_limbo(d, true);
|
|
|
|
cancel_delayed_work(&d->cqm_limbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
domain_destroy_mon_state(d);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
2022-09-02 15:48:13 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:11 +00:00
|
|
|
static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
|
|
|
|
{
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
|
2022-09-02 15:48:11 +00:00
|
|
|
size_t tsize;
|
|
|
|
|
|
|
|
if (is_llc_occupancy_enabled()) {
|
2024-02-13 18:44:20 +00:00
|
|
|
d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
|
2022-09-02 15:48:11 +00:00
|
|
|
if (!d->rmid_busy_llc)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
if (is_mbm_total_enabled()) {
|
|
|
|
tsize = sizeof(*d->mbm_total);
|
2024-02-13 18:44:20 +00:00
|
|
|
d->mbm_total = kcalloc(idx_limit, tsize, GFP_KERNEL);
|
2022-09-02 15:48:11 +00:00
|
|
|
if (!d->mbm_total) {
|
|
|
|
bitmap_free(d->rmid_busy_llc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_mbm_local_enabled()) {
|
|
|
|
tsize = sizeof(*d->mbm_local);
|
2024-02-13 18:44:20 +00:00
|
|
|
d->mbm_local = kcalloc(idx_limit, tsize, GFP_KERNEL);
|
2022-09-02 15:48:11 +00:00
|
|
|
if (!d->mbm_local) {
|
|
|
|
bitmap_free(d->rmid_busy_llc);
|
|
|
|
kfree(d->mbm_total);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
|
|
|
|
{
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
int err = 0;
|
2022-09-02 15:48:11 +00:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
2022-09-02 15:48:11 +00:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
if (supports_mba_mbps() && r->rid == RDT_RESOURCE_MBA) {
|
2022-09-02 15:48:16 +00:00
|
|
|
/* RDT_RESOURCE_MBA is never mon_capable */
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
err = mba_sc_domain_allocate(r, d);
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
2022-09-02 15:48:16 +00:00
|
|
|
|
2022-09-02 15:48:11 +00:00
|
|
|
if (!r->mon_capable)
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
goto out_unlock;
|
2022-09-02 15:48:11 +00:00
|
|
|
|
|
|
|
err = domain_setup_mon_state(r, d);
|
|
|
|
if (err)
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
goto out_unlock;
|
2022-09-02 15:48:11 +00:00
|
|
|
|
|
|
|
if (is_mbm_enabled()) {
|
|
|
|
INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
|
2024-02-13 18:44:35 +00:00
|
|
|
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL,
|
|
|
|
RESCTRL_PICK_ANY_CPU);
|
2022-09-02 15:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_llc_occupancy_enabled())
|
|
|
|
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
|
|
|
|
|
2024-02-13 18:44:30 +00:00
|
|
|
/*
|
|
|
|
* If the filesystem is not mounted then only the default resource group
|
|
|
|
* exists. Creation of its directories is deferred until mount time
|
|
|
|
* by rdt_get_tree() calling mkdir_mondata_all().
|
|
|
|
* If resctrl is mounted, add per domain monitor data directories.
|
|
|
|
*/
|
2024-02-13 18:44:33 +00:00
|
|
|
if (resctrl_mounted && resctrl_arch_mon_capable())
|
2022-09-02 15:48:11 +00:00
|
|
|
mkdir_mondata_subdir_allrdtgrp(r, d);
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
return err;
|
2022-09-02 15:48:11 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:34 +00:00
|
|
|
void resctrl_online_cpu(unsigned int cpu)
|
|
|
|
{
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
2024-02-13 18:44:34 +00:00
|
|
|
/* The CPU is set in default rdtgroup after online. */
|
|
|
|
cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
2024-02-13 18:44:34 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:36 +00:00
|
|
|
static void clear_childcpus(struct rdtgroup *r, unsigned int cpu)
|
|
|
|
{
|
|
|
|
struct rdtgroup *cr;
|
|
|
|
|
|
|
|
list_for_each_entry(cr, &r->mon.crdtgrp_list, mon.crdtgrp_list) {
|
|
|
|
if (cpumask_test_and_clear_cpu(cpu, &cr->cpu_mask))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void resctrl_offline_cpu(unsigned int cpu)
|
|
|
|
{
|
2024-02-13 18:44:37 +00:00
|
|
|
struct rdt_resource *l3 = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
|
2024-02-13 18:44:36 +00:00
|
|
|
struct rdtgroup *rdtgrp;
|
2024-02-13 18:44:37 +00:00
|
|
|
struct rdt_domain *d;
|
2024-02-13 18:44:36 +00:00
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
2024-02-13 18:44:36 +00:00
|
|
|
list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) {
|
|
|
|
if (cpumask_test_and_clear_cpu(cpu, &rdtgrp->cpu_mask)) {
|
|
|
|
clear_childcpus(rdtgrp, cpu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-02-13 18:44:37 +00:00
|
|
|
|
|
|
|
if (!l3->mon_capable)
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
goto out_unlock;
|
2024-02-13 18:44:37 +00:00
|
|
|
|
|
|
|
d = get_domain_from_cpu(cpu, l3);
|
|
|
|
if (d) {
|
|
|
|
if (is_mbm_enabled() && cpu == d->mbm_work_cpu) {
|
|
|
|
cancel_delayed_work(&d->mbm_over);
|
|
|
|
mbm_setup_overflow_handler(d, 0, cpu);
|
|
|
|
}
|
|
|
|
if (is_llc_occupancy_enabled() && cpu == d->cqm_work_cpu &&
|
|
|
|
has_busy_rmid(d)) {
|
|
|
|
cancel_delayed_work(&d->cqm_limbo);
|
|
|
|
cqm_setup_limbo_handler(d, 0, cpu);
|
|
|
|
}
|
|
|
|
}
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
2024-02-13 18:44:36 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
/*
|
|
|
|
* rdtgroup_init - rdtgroup initialization
|
|
|
|
*
|
|
|
|
* Setup resctrl file system including set up root, create mount point,
|
|
|
|
* register rdtgroup filesystem, and initialize files under root directory.
|
|
|
|
*
|
|
|
|
* Return: 0 on success or -errno
|
|
|
|
*/
|
|
|
|
int __init rdtgroup_init(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-09-25 16:39:33 -07:00
|
|
|
seq_buf_init(&last_cmd_status, last_cmd_status_buf,
|
|
|
|
sizeof(last_cmd_status_buf));
|
|
|
|
|
2023-10-16 19:23:04 -05:00
|
|
|
rdtgroup_setup_default();
|
2016-10-28 15:04:42 -07:00
|
|
|
|
|
|
|
ret = sysfs_create_mount_point(fs_kobj, "resctrl");
|
|
|
|
if (ret)
|
2023-10-16 19:23:04 -05:00
|
|
|
return ret;
|
2016-10-28 15:04:42 -07:00
|
|
|
|
|
|
|
ret = register_filesystem(&rdt_fs_type);
|
|
|
|
if (ret)
|
|
|
|
goto cleanup_mountpoint;
|
|
|
|
|
2018-06-22 15:42:25 -07:00
|
|
|
/*
|
|
|
|
* Adding the resctrl debugfs directory here may not be ideal since
|
|
|
|
* it would let the resctrl debugfs directory appear on the debugfs
|
|
|
|
* filesystem before the resctrl filesystem is mounted.
|
|
|
|
* It may also be ok since that would enable debugging of RDT before
|
|
|
|
* resctrl is mounted.
|
|
|
|
* The reason why the debugfs directory is created here and not in
|
2020-07-08 16:39:22 +00:00
|
|
|
* rdt_get_tree() is because rdt_get_tree() takes rdtgroup_mutex and
|
2018-06-22 15:42:25 -07:00
|
|
|
* during the debugfs directory creation also &sb->s_type->i_mutex_key
|
|
|
|
* (the lockdep class of inode->i_rwsem). Other filesystem
|
|
|
|
* interactions (eg. SyS_getdents) have the lock ordering:
|
2020-06-08 21:33:54 -07:00
|
|
|
* &sb->s_type->i_mutex_key --> &mm->mmap_lock
|
|
|
|
* During mmap(), called with &mm->mmap_lock, the rdtgroup_mutex
|
2018-06-22 15:42:25 -07:00
|
|
|
* is taken, thus creating dependency:
|
2020-06-08 21:33:54 -07:00
|
|
|
* &mm->mmap_lock --> rdtgroup_mutex for the latter that can cause
|
2018-06-22 15:42:25 -07:00
|
|
|
* issues considering the other two lock dependencies.
|
|
|
|
* By creating the debugfs directory here we avoid a dependency
|
|
|
|
* that may cause deadlock (even though file operations cannot
|
|
|
|
* occur until the filesystem is mounted, but I do not know how to
|
|
|
|
* tell lockdep that).
|
|
|
|
*/
|
|
|
|
debugfs_resctrl = debugfs_create_dir("resctrl", NULL);
|
|
|
|
|
2016-10-28 15:04:42 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup_mountpoint:
|
|
|
|
sysfs_remove_mount_point(fs_kobj, "resctrl");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2018-06-22 15:42:24 -07:00
|
|
|
|
|
|
|
void __exit rdtgroup_exit(void)
|
|
|
|
{
|
2018-06-22 15:42:25 -07:00
|
|
|
debugfs_remove_recursive(debugfs_resctrl);
|
2018-06-22 15:42:24 -07:00
|
|
|
unregister_filesystem(&rdt_fs_type);
|
|
|
|
sysfs_remove_mount_point(fs_kobj, "resctrl");
|
|
|
|
}
|