2018-07-01 05:19:22

by Reinette Chatre

[permalink] [raw]
Subject: [PATCH 0/2] x86/intel_rdt: Display CPUs associated with pseudo-locked region

Dear Maintainers,

The cpus and cpus_list resctrl files are locked down when the resource
group enters pseudo-locksetup mode and remains locked down when the
resource group transitions to pseudo-locked mode. This was done to ensure a
resource group in pseudo-locksetup mode is and remain unused until it
transitions to pseudo-locked mode.

With this series read (but not write) access is restored to the cpus and
cpus_list files after a resource group enters pseudo-locked mode. The
information displayed is also adjusted appropriately. It is now possible
for users to view which cpus are associated with a pseudo-locked region
through the existing cpus and cpus_list resctrl files. Only the tasks file
remains locked down.

For example:
# mount -t resctrl resctrl /sys/fs/resctrl
# cd /sys/fs/resctrl
# echo 'L2:1=0xfc' > schemata
# mkdir p1
# ls -l p1/cpus* p1/tasks
-rw-r--r-- 1 root root 0 Jun 30 06:30 p1/cpus
-rw-r--r-- 1 root root 0 Jun 30 06:30 p1/cpus_list
-rw-r--r-- 1 root root 0 Jun 30 06:30 p1/tasks
# echo pseudo-locksetup > p1/mode
# ls -l p1/cpus* p1/tasks
---------- 1 root root 0 Jun 30 06:30 p1/cpus
---------- 1 root root 0 Jun 30 06:30 p1/cpus_list
---------- 1 root root 0 Jun 30 06:30 p1/tasks
# echo 'L2:1=0x3' > p1/schemata
# ls -l p1/cpus* p1/tasks
-r--r--r-- 1 root root 0 Jun 30 06:30 p1/cpus
-r--r--r-- 1 root root 0 Jun 30 06:30 p1/cpus_list
---------- 1 root root 0 Jun 30 06:30 p1/tasks
# grep . p1/*
p1/cpus:c
p1/cpus_list:2-3
p1/mode:pseudo-locked
p1/schemata:L2:1=3
p1/size:L2:1=262144
grep: p1/tasks: Permission denied

Reinette Chatre (2):
x86/intel_rdt: Support restoration of subset of permissions
x86/intel_rdt: cpu information accessible for pseudo-locked regions

Documentation/x86/intel_rdt_ui.txt | 3 +++
arch/x86/kernel/cpu/intel_rdt.h | 3 ++-
arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 17 ++++++++++-------
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 14 ++++++++++----
4 files changed, 25 insertions(+), 12 deletions(-)

--
2.17.0



2018-07-01 05:19:22

by Reinette Chatre

[permalink] [raw]
Subject: [PATCH 2/2] x86/intel_rdt: cpu information accessible for pseudo-locked regions

When a resource group enters pseudo-locksetup mode it reflects that the
platform supports cache pseudo-locking and the resource group is unused,
ready to be used for a pseudo-locked region. Until it is set up as a
pseudo-locked region the resource group is "locked down" such that no
new tasks or cpus can be assigned to it. This is accomplished in a user
visible way by making the cpus, cpus_list, and tasks resctrl files
inaccassible (user cannot read from or write to these files).

When the resource group changes to pseudo-locked mode it represents a
cache pseudo-locked region. While not appropriate to make any changes to
the cpus assigned to this region it is useful to make it easy for the
user to see which cpus are associated with the pseudo-locked region.

Modify the permissions of the cpus/cpus_list file when the resource
group changes to pseudo-locked mode to support reading (not writing).
The information presented to the user when reading the file are the cpus
associated with the pseudo-locked region.

Signed-off-by: Reinette Chatre <[email protected]>
---
Documentation/x86/intel_rdt_ui.txt | 3 +++
arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 3 +++
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 8 ++++++--
3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Documentation/x86/intel_rdt_ui.txt b/Documentation/x86/intel_rdt_ui.txt
index acac30b67c62..f662d3c530e5 100644
--- a/Documentation/x86/intel_rdt_ui.txt
+++ b/Documentation/x86/intel_rdt_ui.txt
@@ -178,6 +178,9 @@ All groups contain the following files:
CPUs to/from this group. As with the tasks file a hierarchy is
maintained where MON groups may only include CPUs owned by the
parent CTRL_MON group.
+ When the resouce group is in pseudo-locked mode this file will
+ only be readable, reflecting the CPUs associated with the
+ pseudo-locked region.


"cpus_list":
diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index 5dfe4008c58f..751c78f9992f 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -1303,6 +1303,9 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp)

rdtgrp->mode = RDT_MODE_PSEUDO_LOCKED;
closid_free(rdtgrp->closid);
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus", 0444);
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus_list", 0444);
+
ret = 0;
goto out;

diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index c20b51afd62d..d6d7ea7349d0 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -265,8 +265,12 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
rdtgrp = rdtgroup_kn_lock_live(of->kn);

if (rdtgrp) {
- seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
- cpumask_pr_args(&rdtgrp->cpu_mask));
+ if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
+ seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
+ cpumask_pr_args(&rdtgrp->plr->d->cpu_mask));
+ else
+ seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
+ cpumask_pr_args(&rdtgrp->cpu_mask));
} else {
ret = -ENOENT;
}
--
2.17.0


2018-07-01 05:21:35

by Reinette Chatre

[permalink] [raw]
Subject: [PATCH 1/2] x86/intel_rdt: Support restoration of subset of permissions

As the mode of a resource group changes, the operations it can support
may also change. One way in which the supported operations are managed
is to modify the permissions of the files within the resource group's
resctrl directory.

At the moment only two possible permissions are supported: the default
permissions or no permissions in support for when the operation is
"locked down". It is possible where an operation on a resource group may
have more possibilities. For example, if by default changes can be made to
the resource group by writing to a resctrl file while the current
settings can be obtained by reading from the file, then it may be
possible that in another mode it is only possible to read the current
settings, and not change them.

Make it possible to modify some of the permissions of a resctrl file in
support of a more flexible way to manage the operations on a resource
group. In this preparation work the original behavior is maintained
where all permissions are restored.

Signed-off-by: Reinette Chatre <[email protected]>
---
arch/x86/kernel/cpu/intel_rdt.h | 3 ++-
arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 14 +++++++-------
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 6 ++++--
3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
index 2d9cbb9d7a58..4e588f36228f 100644
--- a/arch/x86/kernel/cpu/intel_rdt.h
+++ b/arch/x86/kernel/cpu/intel_rdt.h
@@ -512,7 +512,8 @@ void rdt_ctrl_update(void *arg);
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
void rdtgroup_kn_unlock(struct kernfs_node *kn);
int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name);
-int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name);
+int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
+ umode_t mask);
struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
struct list_head **pos);
ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index 8fd79c281ee6..5dfe4008c58f 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -590,11 +590,11 @@ static int rdtgroup_locksetup_user_restrict(struct rdtgroup *rdtgrp)
goto out;

err_cpus_list:
- rdtgroup_kn_mode_restore(rdtgrp, "cpus_list");
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus_list", 0777);
err_cpus:
- rdtgroup_kn_mode_restore(rdtgrp, "cpus");
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus", 0777);
err_tasks:
- rdtgroup_kn_mode_restore(rdtgrp, "tasks");
+ rdtgroup_kn_mode_restore(rdtgrp, "tasks", 0777);
out:
return ret;
}
@@ -615,20 +615,20 @@ static int rdtgroup_locksetup_user_restore(struct rdtgroup *rdtgrp)
{
int ret;

- ret = rdtgroup_kn_mode_restore(rdtgrp, "tasks");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "tasks", 0777);
if (ret)
return ret;

- ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus", 0777);
if (ret)
goto err_tasks;

- ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus_list");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus_list", 0777);
if (ret)
goto err_cpus;

if (rdt_mon_capable) {
- ret = rdtgroup_kn_mode_restore(rdtgrp, "mon_groups");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "mon_groups", 0777);
if (ret)
goto err_cpus_list;
}
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index 7b4a09d81a30..c20b51afd62d 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -1405,13 +1405,15 @@ int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name)
* 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
+ * @mask: Mask of permissions that should be restored
*
* 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.
*/
-int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name)
+int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
+ umode_t mask)
{
struct iattr iattr = {.ia_valid = ATTR_MODE,};
struct kernfs_node *kn, *parent;
@@ -1423,7 +1425,7 @@ int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name)

for (rft = rfts; rft < rfts + len; rft++) {
if (!strcmp(rft->name, name))
- iattr.ia_mode = rft->mode;
+ iattr.ia_mode = rft->mode & mask;
}

kn = kernfs_find_and_get_ns(r->kn, name, NULL);
--
2.17.0


Subject: [tip:x86/cache] x86/intel_rdt: Support restoration of subset of permissions

Commit-ID: 392487def48e4b596526a4a8c2c2ec4cfe73bf13
Gitweb: https://git.kernel.org/tip/392487def48e4b596526a4a8c2c2ec4cfe73bf13
Author: Reinette Chatre <[email protected]>
AuthorDate: Sat, 30 Jun 2018 22:17:32 -0700
Committer: Thomas Gleixner <[email protected]>
CommitDate: Tue, 3 Jul 2018 08:38:40 +0200

x86/intel_rdt: Support restoration of subset of permissions

As the mode of a resource group changes, the operations it can support may
also change. One way in which the supported operations are managed is to
modify the permissions of the files within the resource group's resctrl
directory.

At the moment only two possible permissions are supported: the default
permissions or no permissions in support for when the operation is "locked
down". It is possible where an operation on a resource group may have more
possibilities. For example, if by default changes can be made to the
resource group by writing to a resctrl file while the current settings can
be obtained by reading from the file, then it may be possible that in
another mode it is only possible to read the current settings, and not
change them.

Make it possible to modify some of the permissions of a resctrl file in
support of a more flexible way to manage the operations on a resource
group. In this preparation work the original behavior is maintained where
all permissions are restored.

Signed-off-by: Reinette Chatre <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://lkml.kernel.org/r/8773aadfade7bcb2c48a45fa294a04d2c03bb0a1.1530421961.git.reinette.chatre@intel.com

---
arch/x86/kernel/cpu/intel_rdt.h | 3 ++-
arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 14 +++++++-------
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 6 ++++--
3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
index 2d9cbb9d7a58..4e588f36228f 100644
--- a/arch/x86/kernel/cpu/intel_rdt.h
+++ b/arch/x86/kernel/cpu/intel_rdt.h
@@ -512,7 +512,8 @@ void rdt_ctrl_update(void *arg);
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
void rdtgroup_kn_unlock(struct kernfs_node *kn);
int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name);
-int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name);
+int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
+ umode_t mask);
struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
struct list_head **pos);
ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index 8fd79c281ee6..5dfe4008c58f 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -590,11 +590,11 @@ static int rdtgroup_locksetup_user_restrict(struct rdtgroup *rdtgrp)
goto out;

err_cpus_list:
- rdtgroup_kn_mode_restore(rdtgrp, "cpus_list");
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus_list", 0777);
err_cpus:
- rdtgroup_kn_mode_restore(rdtgrp, "cpus");
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus", 0777);
err_tasks:
- rdtgroup_kn_mode_restore(rdtgrp, "tasks");
+ rdtgroup_kn_mode_restore(rdtgrp, "tasks", 0777);
out:
return ret;
}
@@ -615,20 +615,20 @@ static int rdtgroup_locksetup_user_restore(struct rdtgroup *rdtgrp)
{
int ret;

- ret = rdtgroup_kn_mode_restore(rdtgrp, "tasks");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "tasks", 0777);
if (ret)
return ret;

- ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus", 0777);
if (ret)
goto err_tasks;

- ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus_list");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "cpus_list", 0777);
if (ret)
goto err_cpus;

if (rdt_mon_capable) {
- ret = rdtgroup_kn_mode_restore(rdtgrp, "mon_groups");
+ ret = rdtgroup_kn_mode_restore(rdtgrp, "mon_groups", 0777);
if (ret)
goto err_cpus_list;
}
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index 7b4a09d81a30..c20b51afd62d 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -1405,13 +1405,15 @@ int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name)
* 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
+ * @mask: Mask of permissions that should be restored
*
* 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.
*/
-int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name)
+int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
+ umode_t mask)
{
struct iattr iattr = {.ia_valid = ATTR_MODE,};
struct kernfs_node *kn, *parent;
@@ -1423,7 +1425,7 @@ int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name)

for (rft = rfts; rft < rfts + len; rft++) {
if (!strcmp(rft->name, name))
- iattr.ia_mode = rft->mode;
+ iattr.ia_mode = rft->mode & mask;
}

kn = kernfs_find_and_get_ns(r->kn, name, NULL);

Subject: [tip:x86/cache] x86/intel_rdt: Make CPU information accessible for pseudo-locked regions

Commit-ID: 33dc3e410a0d99f394905143b26d34f1fd64c962
Gitweb: https://git.kernel.org/tip/33dc3e410a0d99f394905143b26d34f1fd64c962
Author: Reinette Chatre <[email protected]>
AuthorDate: Sat, 30 Jun 2018 22:17:33 -0700
Committer: Thomas Gleixner <[email protected]>
CommitDate: Tue, 3 Jul 2018 08:38:40 +0200

x86/intel_rdt: Make CPU information accessible for pseudo-locked regions

When a resource group enters pseudo-locksetup mode it reflects that the
platform supports cache pseudo-locking and the resource group is unused,
ready to be used for a pseudo-locked region. Until it is set up as a
pseudo-locked region the resource group is "locked down" such that no new
tasks or cpus can be assigned to it. This is accomplished in a user visible
way by making the cpus, cpus_list, and tasks resctrl files inaccassible
(user cannot read from or write to these files).

When the resource group changes to pseudo-locked mode it represents a cache
pseudo-locked region. While not appropriate to make any changes to the cpus
assigned to this region it is useful to make it easy for the user to see
which cpus are associated with the pseudo-locked region.

Modify the permissions of the cpus/cpus_list file when the resource group
changes to pseudo-locked mode to support reading (not writing). The
information presented to the user when reading the file are the cpus
associated with the pseudo-locked region.

Signed-off-by: Reinette Chatre <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://lkml.kernel.org/r/12756b7963b6abc1bffe8fb560b87b75da827bd1.1530421961.git.reinette.chatre@intel.com

---
Documentation/x86/intel_rdt_ui.txt | 3 +++
arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 3 +++
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 8 ++++++--
3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Documentation/x86/intel_rdt_ui.txt b/Documentation/x86/intel_rdt_ui.txt
index acac30b67c62..f662d3c530e5 100644
--- a/Documentation/x86/intel_rdt_ui.txt
+++ b/Documentation/x86/intel_rdt_ui.txt
@@ -178,6 +178,9 @@ All groups contain the following files:
CPUs to/from this group. As with the tasks file a hierarchy is
maintained where MON groups may only include CPUs owned by the
parent CTRL_MON group.
+ When the resouce group is in pseudo-locked mode this file will
+ only be readable, reflecting the CPUs associated with the
+ pseudo-locked region.


"cpus_list":
diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index 5dfe4008c58f..751c78f9992f 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -1303,6 +1303,9 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp)

rdtgrp->mode = RDT_MODE_PSEUDO_LOCKED;
closid_free(rdtgrp->closid);
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus", 0444);
+ rdtgroup_kn_mode_restore(rdtgrp, "cpus_list", 0444);
+
ret = 0;
goto out;

diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index c20b51afd62d..d6d7ea7349d0 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -265,8 +265,12 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
rdtgrp = rdtgroup_kn_lock_live(of->kn);

if (rdtgrp) {
- seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
- cpumask_pr_args(&rdtgrp->cpu_mask));
+ if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
+ seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
+ cpumask_pr_args(&rdtgrp->plr->d->cpu_mask));
+ else
+ seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
+ cpumask_pr_args(&rdtgrp->cpu_mask));
} else {
ret = -ENOENT;
}