Skip to content

Commit 49f7b4e

Browse files
rchatreKAGA-KOKO
authored andcommitted
x86/intel_rdt: Enable setting of exclusive mode
The new "mode" file now accepts "exclusive" that means that the allocations of this resource group cannot be shared. Enable users to modify a resource group's mode to "exclusive". To succeed it is required that there is no overlap between resource group's current schemata and that of all the other active resource groups as well as cache regions potentially used by other hardware entities. Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: fenghua.yu@intel.com Cc: tony.luck@intel.com Cc: vikas.shivappa@linux.intel.com Cc: gavin.hindman@intel.com Cc: jithu.joseph@intel.com Cc: dave.hansen@intel.com Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/83642cbba3c8c21db7fa6bb36fe7d385d3b275f2.1529706536.git.reinette.chatre@intel.com
1 parent 414dd2b commit 49f7b4e

File tree

1 file changed

+96
-1
lines changed

1 file changed

+96
-1
lines changed

arch/x86/kernel/cpu/intel_rdt_rdtgroup.c

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,93 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,
812812
return 0;
813813
}
814814

815+
/**
816+
* rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other
817+
* @r: Resource to which domain instance @d belongs.
818+
* @d: The domain instance for which @closid is being tested.
819+
* @cbm: Capacity bitmask being tested.
820+
* @closid: Intended closid for @cbm.
821+
* @exclusive: Only check if overlaps with exclusive resource groups
822+
*
823+
* Checks if provided @cbm intended to be used for @closid on domain
824+
* @d overlaps with any other closids or other hardware usage associated
825+
* with this domain. If @exclusive is true then only overlaps with
826+
* resource groups in exclusive mode will be considered. If @exclusive
827+
* is false then overlaps with any resource group or hardware entities
828+
* will be considered.
829+
*
830+
* Return: false if CBM does not overlap, true if it does.
831+
*/
832+
static bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
833+
u32 _cbm, int closid, bool exclusive)
834+
{
835+
unsigned long *cbm = (unsigned long *)&_cbm;
836+
unsigned long *ctrl_b;
837+
enum rdtgrp_mode mode;
838+
u32 *ctrl;
839+
int i;
840+
841+
/* Check for any overlap with regions used by hardware directly */
842+
if (!exclusive) {
843+
if (bitmap_intersects(cbm,
844+
(unsigned long *)&r->cache.shareable_bits,
845+
r->cache.cbm_len))
846+
return true;
847+
}
848+
849+
/* Check for overlap with other resource groups */
850+
ctrl = d->ctrl_val;
851+
for (i = 0; i < r->num_closid; i++, ctrl++) {
852+
ctrl_b = (unsigned long *)ctrl;
853+
if (closid_allocated(i) && i != closid) {
854+
if (bitmap_intersects(cbm, ctrl_b, r->cache.cbm_len)) {
855+
mode = rdtgroup_mode_by_closid(i);
856+
if (exclusive) {
857+
if (mode == RDT_MODE_EXCLUSIVE)
858+
return true;
859+
continue;
860+
}
861+
return true;
862+
}
863+
}
864+
}
865+
866+
return false;
867+
}
868+
869+
/**
870+
* rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive
871+
*
872+
* An exclusive resource group implies that there should be no sharing of
873+
* its allocated resources. At the time this group is considered to be
874+
* exclusive this test can determine if its current schemata supports this
875+
* setting by testing for overlap with all other resource groups.
876+
*
877+
* Return: true if resource group can be exclusive, false if there is overlap
878+
* with allocations of other resource groups and thus this resource group
879+
* cannot be exclusive.
880+
*/
881+
static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
882+
{
883+
int closid = rdtgrp->closid;
884+
struct rdt_resource *r;
885+
struct rdt_domain *d;
886+
887+
for_each_alloc_enabled_rdt_resource(r) {
888+
list_for_each_entry(d, &r->domains, list) {
889+
if (rdtgroup_cbm_overlaps(r, d, d->ctrl_val[closid],
890+
rdtgrp->closid, false))
891+
return false;
892+
}
893+
}
894+
895+
return true;
896+
}
897+
898+
/**
899+
* rdtgroup_mode_write - Modify the resource group's mode
900+
*
901+
*/
815902
static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
816903
char *buf, size_t nbytes, loff_t off)
817904
{
@@ -834,11 +921,19 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
834921

835922
mode = rdtgrp->mode;
836923

837-
if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE))
924+
if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||
925+
(!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE))
838926
goto out;
839927

840928
if (!strcmp(buf, "shareable")) {
841929
rdtgrp->mode = RDT_MODE_SHAREABLE;
930+
} else if (!strcmp(buf, "exclusive")) {
931+
if (!rdtgroup_mode_test_exclusive(rdtgrp)) {
932+
rdt_last_cmd_printf("schemata overlaps\n");
933+
ret = -EINVAL;
934+
goto out;
935+
}
936+
rdtgrp->mode = RDT_MODE_EXCLUSIVE;
842937
} else {
843938
rdt_last_cmd_printf("unknown/unsupported mode\n");
844939
ret = -EINVAL;

0 commit comments

Comments
 (0)