x86/intel_rdt: Fix exclusive mode with CDP resources
v2 cover x86/intel_rdt: Fix exclusive mode with CDP resources
Changes in V2:
- Have the new rdt_cdp_peer_get() return EINVAL instead of ENOENT when only one of the CDP peers have a rdt_domain associated with it.
- Rename _rdtgroup_cbm_overlaps() to __rdtgroup_cbm_overlaps() to stand out more.
- Fix kernel-doc to match function parameter name.
- Rename rdtgroup_cbm_overlaps()'s _cbm function parameter to cbm.
- Simplify the code in rdtgroup_cbm_overlaps() to make the flow more obvious.
Nothing (apart from diffstat) changed below since original submission.
Dear Maintainers,
CDP resources do not currently behave as expected when there are resource groups with mode 'exclusive'.
In the example below it was possible to create two resource groups, p1 and p2, that are both in exclusive mode but their usage of the underlying L2 cache actually overlaps.
root@glk:/sys/fs/resctrl# ls cpus cpus_list info mode p1 p2 schemata size tasks root@glk:/sys/fs/resctrl# cat schemata L2DATA:0=fff0 L2CODE:0=fff0 root@glk:/sys/fs/resctrl# cat mode shareable
root@glk:/sys/fs/resctrl# cat p1/schemata L2DATA:0=0003 L2CODE:0=000c root@glk:/sys/fs/resctrl# cat p1/mode exclusive
root@glk:/sys/fs/resctrl# cat p2/schemata L2DATA:0=000c L2CODE:0=0003 root@glk:/sys/fs/resctrl# cat p2/mode exclusive
root@glk:/sys/fs/resctrl# cat info/L2CODE/bit_usage 0=SSSSSSSSSSSSEEEE root@glk:/sys/fs/resctrl# cat info/L2DATA/bit_usage 0=SSSSSSSSSSSSEEEE root@glk:/sys/fs/resctrl#
In the above example, the CBM of L2DATA in p1 overlaps with the CBM of L2CODE in p2 while they are both in exclusive mode. While it may reflect no overlap among the L2DATA resources specifically it does actually imply overlap of use of the underlying hardware that is not the intention of 'exclusive' mode. This happens because the current implementation treats L2CODE and L2DATA as totally independent, when it is actually referring to the same underlying hardware.
This series fixes the potential for overlap of hardware resource use when resource groups are in 'exclusive' mode by ensuring that if there is a CDP peer on the same hardware then any overlap test would consider it also.
Allocations of data and code resources within the same exclusive resource group are allowed to overlap.
Your feedback will be greatly appreciated.
Reinette
Reinette Chatre (3):
x86/intel_rdt: Introduce utility to obtain CDP peer x86/intel_rdt: CBM overlap should also check for overlap with CDP peer x86/intel_rdt: Fix initial allocation to consider CDP
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 133 ++++++++++++++++++++++- 1 file changed, 127 insertions(+), 6 deletions(-)
Signature · 1 line
2.17.0
PATCH v2 1/3 x86/intel_rdt: Introduce utility to obtain CDP peer
Introduce a utility that, when provided with a RDT resource and an instance of this RDT resource (a RDT domain), would return pointers to the RDT resource and RDT domain that share the same hardware. This is specific to the CDP resources that share the same hardware.
For example, if a pointer to the RDT_RESOURCE_L2DATA resource (struct rdt_resource) and a pointer to an instance of this resource (struct rdt_domain) is provided, then it will return a pointer to the RDT_RESOURCE_L2CODE resource as well as the specific instance that shares the same hardware as the provided rdt_domain.
This utility is created in support of the "exclusive" resource group mode where overlap of resource allocation between resource groups need to be avoided. The overlap test need to consider not just the matching resources, but also the resources that share the same hardware.
Temporarily mark it as unused in support of patch testing to avoid compile warnings until it is used.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +72 -0
@@ -960,6 +960,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,return 0 ; } +/** +* rdt_cdp_peer_get - Retrieve CDP peer if it exists +* @r: RDT resource to which RDT domain @d belongs +* @d: Cache instance for which a CDP peer is requested +* @r_cdp: RDT resource that shares hardware with @r (RDT resource peer) +* Used to return the result. +* @d_cdp: RDT domain that shares hardware with @d (RDT domain peer) +* Used to return the result. +* +* RDT resources are managed independently and by extension the RDT domains +* (RDT resource instances) are managed independently also. The Code and +* Data Prioritization (CDP) RDT resources, while managed independently, +* could refer to the same underlying hardware. For example, +* RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache. +* +* When provided with an RDT resource @r and an instance of that RDT +* resource @d rdt_cdp_peer_get() will return if there is a peer RDT +* resource and the exact instance that shares the same hardware. +* +* Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists. +* If a CDP peer was found, @r_cdp will point to the peer RDT resource +* and @d_cdp will point to the peer RDT domain. +*/ +static int __attribute__((unused))rdt_cdp_peer_get (struct rdt_resource *r, +struct rdt_domain *d, +struct rdt_resource **r_cdp, +struct rdt_domain **d_cdp) +{ +struct rdt_resource *_r_cdp =NULL ; +struct rdt_domain *_d_cdp =NULL ; +int ret =0 ; + +switch (r->rid) { +case RDT_RESOURCE_L3DATA : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE ]; +break ; +case RDT_RESOURCE_L3CODE : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA ]; +break ; +case RDT_RESOURCE_L2DATA : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE ]; +break ; +case RDT_RESOURCE_L2CODE : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA ]; +break ; +default : + ret = -ENOENT ; + goto out; + } + +/* +* When a new CPU comes online and CDP is enabled then the new +* RDT domains (if any) associated with both CDP RDT resources +* are added in the same CPU online routine while the +* rdtgroup_mutex is held. It should thus not happen for one +* RDT domain to exist and be associated with its RDT CDP +* resource but there is no RDT domain associated with the +* peer RDT CDP resource. Hence the WARN. +*/ + _d_cdp =rdt_find_domain (_r_cdp, d->id,NULL ); +if (WARN_ON (!_d_cdp)) { + _r_cdp =NULL ; + ret = -EINVAL ; + } + +out: + *r_cdp = _r_cdp; + *d_cdp = _d_cdp; + +return ret; +} +/** * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs.
Signature · 1 line
2.17.0
tip-bot for Reinette Chatre
merge bot[tip:x86/cache] x86/intel_rdt: Introduce utility to obtain CDP peer
x86/intel_rdt: Introduce utility to obtain CDP peer
Commit-ID: fa9032bca042b50f0ba7d80e53025cecbd5ad0f3 Gitweb: https://git.kernel.org/tip/fa9032bca042b50f0ba7d80e53025cecbd5ad0f3 Author: Reinette Chatre <[email protected]> AuthorDate: Wed, 3 Oct 2018 15:17:01 -0700 Committer: Thomas Gleixner <[email protected]> CommitDate: Sat, 6 Oct 2018 20:46:26 +0200
x86/intel_rdt: Introduce utility to obtain CDP peer
Introduce a utility that, when provided with a RDT resource and an instance of this RDT resource (a RDT domain), would return pointers to the RDT resource and RDT domain that share the same hardware. This is specific to the CDP resources that share the same hardware.
For example, if a pointer to the RDT_RESOURCE_L2DATA resource (struct rdt_resource) and a pointer to an instance of this resource (struct rdt_domain) is provided, then it will return a pointer to the RDT_RESOURCE_L2CODE resource as well as the specific instance that shares the same hardware as the provided rdt_domain.
This utility is created in support of the "exclusive" resource group mode where overlap of resource allocation between resource groups need to be avoided. The overlap test need to consider not just the matching resources, but also the resources that share the same hardware.
Temporarily mark it as unused in support of patch testing to avoid compile warnings until it is used.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +72 -0
@@ -960,6 +960,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,return 0 ; } +/** +* rdt_cdp_peer_get - Retrieve CDP peer if it exists +* @r: RDT resource to which RDT domain @d belongs +* @d: Cache instance for which a CDP peer is requested +* @r_cdp: RDT resource that shares hardware with @r (RDT resource peer) +* Used to return the result. +* @d_cdp: RDT domain that shares hardware with @d (RDT domain peer) +* Used to return the result. +* +* RDT resources are managed independently and by extension the RDT domains +* (RDT resource instances) are managed independently also. The Code and +* Data Prioritization (CDP) RDT resources, while managed independently, +* could refer to the same underlying hardware. For example, +* RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache. +* +* When provided with an RDT resource @r and an instance of that RDT +* resource @d rdt_cdp_peer_get() will return if there is a peer RDT +* resource and the exact instance that shares the same hardware. +* +* Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists. +* If a CDP peer was found, @r_cdp will point to the peer RDT resource +* and @d_cdp will point to the peer RDT domain. +*/ +static int __attribute__((unused))rdt_cdp_peer_get (struct rdt_resource *r, +struct rdt_domain *d, +struct rdt_resource **r_cdp, +struct rdt_domain **d_cdp) +{ +struct rdt_resource *_r_cdp =NULL ; +struct rdt_domain *_d_cdp =NULL ; +int ret =0 ; + +switch (r->rid) { +case RDT_RESOURCE_L3DATA : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE ]; +break ; +case RDT_RESOURCE_L3CODE : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA ]; +break ; +case RDT_RESOURCE_L2DATA : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE ]; +break ; +case RDT_RESOURCE_L2CODE : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA ]; +break ; +default : + ret = -ENOENT ; + goto out; + } + +/* +* When a new CPU comes online and CDP is enabled then the new +* RDT domains (if any) associated with both CDP RDT resources +* are added in the same CPU online routine while the +* rdtgroup_mutex is held. It should thus not happen for one +* RDT domain to exist and be associated with its RDT CDP +* resource but there is no RDT domain associated with the +* peer RDT CDP resource. Hence the WARN. +*/ + _d_cdp =rdt_find_domain (_r_cdp, d->id,NULL ); +if (WARN_ON (!_d_cdp)) { + _r_cdp =NULL ; + ret = -EINVAL ; + } + +out: + *r_cdp = _r_cdp; + *d_cdp = _d_cdp; + +return ret; +} +/** * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs.
tip-bot for Reinette Chatre
merge bot[tip:x86/cache] x86/intel_rdt: Introduce utility to obtain CDP peer
In reply to Reinette Chatrex86/intel_rdt: Introduce utility to obtain CDP peer
Commit-ID: 521348b011d64cf3febb10b64ba5b472681bef94 Gitweb: https://git.kernel.org/tip/521348b011d64cf3febb10b64ba5b472681bef94 Author: Reinette Chatre <[email protected]> AuthorDate: Wed, 3 Oct 2018 15:17:01 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 9 Oct 2018 08:50:40 +0200
x86/intel_rdt: Introduce utility to obtain CDP peer
Introduce a utility that, when provided with a RDT resource and an instance of this RDT resource (a RDT domain), would return pointers to the RDT resource and RDT domain that share the same hardware. This is specific to the CDP resources that share the same hardware.
For example, if a pointer to the RDT_RESOURCE_L2DATA resource (struct rdt_resource) and a pointer to an instance of this resource (struct rdt_domain) is provided, then it will return a pointer to the RDT_RESOURCE_L2CODE resource as well as the specific instance that shares the same hardware as the provided rdt_domain.
This utility is created in support of the "exclusive" resource group mode where overlap of resource allocation between resource groups need to be avoided. The overlap test need to consider not just the matching resources, but also the resources that share the same hardware.
Temporarily mark it as unused in support of patch testing to avoid compile warnings until it is used.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +72 -0
@@ -960,6 +960,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,return 0 ; } +/** +* rdt_cdp_peer_get - Retrieve CDP peer if it exists +* @r: RDT resource to which RDT domain @d belongs +* @d: Cache instance for which a CDP peer is requested +* @r_cdp: RDT resource that shares hardware with @r (RDT resource peer) +* Used to return the result. +* @d_cdp: RDT domain that shares hardware with @d (RDT domain peer) +* Used to return the result. +* +* RDT resources are managed independently and by extension the RDT domains +* (RDT resource instances) are managed independently also. The Code and +* Data Prioritization (CDP) RDT resources, while managed independently, +* could refer to the same underlying hardware. For example, +* RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache. +* +* When provided with an RDT resource @r and an instance of that RDT +* resource @d rdt_cdp_peer_get() will return if there is a peer RDT +* resource and the exact instance that shares the same hardware. +* +* Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists. +* If a CDP peer was found, @r_cdp will point to the peer RDT resource +* and @d_cdp will point to the peer RDT domain. +*/ +static int __attribute__((unused))rdt_cdp_peer_get (struct rdt_resource *r, +struct rdt_domain *d, +struct rdt_resource **r_cdp, +struct rdt_domain **d_cdp) +{ +struct rdt_resource *_r_cdp =NULL ; +struct rdt_domain *_d_cdp =NULL ; +int ret =0 ; + +switch (r->rid) { +case RDT_RESOURCE_L3DATA : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE ]; +break ; +case RDT_RESOURCE_L3CODE : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA ]; +break ; +case RDT_RESOURCE_L2DATA : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE ]; +break ; +case RDT_RESOURCE_L2CODE : + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA ]; +break ; +default : + ret = -ENOENT ; + goto out; + } + +/* +* When a new CPU comes online and CDP is enabled then the new +* RDT domains (if any) associated with both CDP RDT resources +* are added in the same CPU online routine while the +* rdtgroup_mutex is held. It should thus not happen for one +* RDT domain to exist and be associated with its RDT CDP +* resource but there is no RDT domain associated with the +* peer RDT CDP resource. Hence the WARN. +*/ + _d_cdp =rdt_find_domain (_r_cdp, d->id,NULL ); +if (WARN_ON (!_d_cdp)) { + _r_cdp =NULL ; + ret = -EINVAL ; + } + +out: + *r_cdp = _r_cdp; + *d_cdp = _d_cdp; + +return ret; +} +/** * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs.
PATCH v2 2/3 x86/intel_rdt: CBM overlap should also check for overlap with CDP peer
In reply to Reinette ChatreThe CBM overlap test is used to manage the allocations of RDT resources where overlap is possible between resource groups. When a resource group is in exclusive mode then there should be no overlap between resource groups.
The current overlap test only considers overlap between the same resources, for example, that usage of a RDT_RESOURCE_L2DATA resource in one resource group does not overlap with usage of a RDT_RESOURCE_L2DATA resource in another resource group. The problem with this is that it allows overlap between a RDT_RESOURCE_L2DATA resource in one resource group with a RDT_RESOURCE_L2CODE resource in another resource group - even if both resource groups are in exclusive mode. This is a problem because even though these appear to be different resources they end up sharing the same underlying hardware and thus does not fulfill the user's request for exclusive use of hardware resources.
Fix this by including the CDP peer (if there is one) in every CBM overlap test. This does not impact the overlap between resources within the same exclusive resource group that is allowed.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 51 ++++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +43 -8
@@ -983,10 +983,9 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,* If a CDP peer was found, @r_cdp will point to the peer RDT resource * and @d_cdp will point to the peer RDT domain. */ -static int __attribute__((unused))rdt_cdp_peer_get (struct rdt_resource *r, -struct rdt_domain *d, -struct rdt_resource **r_cdp, -struct rdt_domain **d_cdp) +static int rdt_cdp_peer_get (struct rdt_resource *r,struct rdt_domain *d, +struct rdt_resource **r_cdp, +struct rdt_domain **d_cdp) {struct rdt_resource *_r_cdp =NULL ;struct rdt_domain *_d_cdp =NULL ;
@@ -1033,10 +1032,10 @@ static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r, }/** -* rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other +* __rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs. * @d: The domain instance for which @closid is being tested. -* @cbm: Capacity bitmask being tested. +* @_cbm: Capacity bitmask being tested. * @closid: Intended closid for @cbm. * @exclusive: Only check if overlaps with exclusive resource groups *
@@ -1049,8 +1048,9 @@ static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r,* * Return: false if CBM does not overlap, true if it does. */ -bool rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, -u32 _cbm,int closid,bool exclusive) +static bool __rdtgroup_cbm_overlaps (struct rdt_resource *r, +struct rdt_domain *d,u32 _cbm, +int closid,bool exclusive) {unsigned long *cbm = (unsigned long *)&_cbm;unsigned long *ctrl_b;
@@ -1087,6 +1087,41 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,return false; } +/** +* rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware +* @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. +* @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 +*/ +bool rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, +u32 cbm,int closid,bool exclusive) +{ +struct rdt_resource *r_cdp; +struct rdt_domain *d_cdp; + +if (__rdtgroup_cbm_overlaps (r, d, cbm, closid, exclusive)) +return true; + +if (rdt_cdp_peer_get (r, d, &r_cdp, &d_cdp) <0 ) +return false; + +return __rdtgroup_cbm_overlaps (r_cdp, d_cdp, cbm, closid, exclusive); +} +/** * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive *
Signature · 1 line
2.17.0
tip-bot for Reinette Chatre
merge bot[tip:x86/cache] x86/intel_rdt: CBM overlap should also check for overlap with CDP peer
x86/intel_rdt: CBM overlap should also check for overlap with CDP peer
Commit-ID: edbdd2c8bd30da45629e6466714c86eec915364a Gitweb: https://git.kernel.org/tip/edbdd2c8bd30da45629e6466714c86eec915364a Author: Reinette Chatre <[email protected]> AuthorDate: Wed, 3 Oct 2018 15:17:02 -0700 Committer: Thomas Gleixner <[email protected]> CommitDate: Sat, 6 Oct 2018 20:46:27 +0200
x86/intel_rdt: CBM overlap should also check for overlap with CDP peer
The CBM overlap test is used to manage the allocations of RDT resources where overlap is possible between resource groups. When a resource group is in exclusive mode then there should be no overlap between resource groups.
The current overlap test only considers overlap between the same resources, for example, that usage of a RDT_RESOURCE_L2DATA resource in one resource group does not overlap with usage of a RDT_RESOURCE_L2DATA resource in another resource group. The problem with this is that it allows overlap between a RDT_RESOURCE_L2DATA resource in one resource group with a RDT_RESOURCE_L2CODE resource in another resource group - even if both resource groups are in exclusive mode. This is a problem because even though these appear to be different resources they end up sharing the same underlying hardware and thus does not fulfill the user's request for exclusive use of hardware resources.
Fix this by including the CDP peer (if there is one) in every CBM overlap test. This does not impact the overlap between resources within the same exclusive resource group that is allowed.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 48 +++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +41 -7
@@ -983,10 +983,9 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,* If a CDP peer was found, @r_cdp will point to the peer RDT resource * and @d_cdp will point to the peer RDT domain. */ -static int __attribute__((unused))rdt_cdp_peer_get (struct rdt_resource *r, -struct rdt_domain *d, -struct rdt_resource **r_cdp, -struct rdt_domain **d_cdp) +static int rdt_cdp_peer_get (struct rdt_resource *r,struct rdt_domain *d, +struct rdt_resource **r_cdp, +struct rdt_domain **d_cdp) {struct rdt_resource *_r_cdp =NULL ;struct rdt_domain *_d_cdp =NULL ;
@@ -1033,7 +1032,7 @@ out: }/** -* rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other +* __rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs. * @d: The domain instance for which @closid is being tested. * @cbm: Capacity bitmask being tested.
@@ -1052,8 +1051,8 @@ out:* * Return: false if CBM does not overlap, true if it does. */ -bool rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, -unsigned long cbm,int closid,bool exclusive) +static bool __rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, +unsigned long cbm,int closid,bool exclusive) {enum rdtgrp_mode mode;unsigned long ctrl_b;
@@ -1088,6 +1087,41 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,return false; } +/** +* rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware +* @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. +* @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 +*/ +bool rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, +unsigned long cbm,int closid,bool exclusive) +{ +struct rdt_resource *r_cdp; +struct rdt_domain *d_cdp; + +if (__rdtgroup_cbm_overlaps (r, d, cbm, closid, exclusive)) +return true; + +if (rdt_cdp_peer_get (r, d, &r_cdp, &d_cdp) <0 ) +return false; + +return __rdtgroup_cbm_overlaps (r_cdp, d_cdp, cbm, closid, exclusive); +} +/** * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive *
tip-bot for Reinette Chatre
merge bot[tip:x86/cache] x86/intel_rdt: CBM overlap should also check for overlap with CDP peer
In reply to Reinette Chatrex86/intel_rdt: CBM overlap should also check for overlap with CDP peer
Commit-ID: e5f3530c391105fdd6174852e3ea6136d073b45a Gitweb: https://git.kernel.org/tip/e5f3530c391105fdd6174852e3ea6136d073b45a Author: Reinette Chatre <[email protected]> AuthorDate: Wed, 3 Oct 2018 15:17:02 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 9 Oct 2018 08:50:43 +0200
x86/intel_rdt: CBM overlap should also check for overlap with CDP peer
The CBM overlap test is used to manage the allocations of RDT resources where overlap is possible between resource groups. When a resource group is in exclusive mode then there should be no overlap between resource groups.
The current overlap test only considers overlap between the same resources, for example, that usage of a RDT_RESOURCE_L2DATA resource in one resource group does not overlap with usage of a RDT_RESOURCE_L2DATA resource in another resource group. The problem with this is that it allows overlap between a RDT_RESOURCE_L2DATA resource in one resource group with a RDT_RESOURCE_L2CODE resource in another resource group - even if both resource groups are in exclusive mode. This is a problem because even though these appear to be different resources they end up sharing the same underlying hardware and thus does not fulfill the user's request for exclusive use of hardware resources.
Fix this by including the CDP peer (if there is one) in every CBM overlap test. This does not impact the overlap between resources within the same exclusive resource group that is allowed.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 48 +++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +41 -7
@@ -983,10 +983,9 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,* If a CDP peer was found, @r_cdp will point to the peer RDT resource * and @d_cdp will point to the peer RDT domain. */ -static int __attribute__((unused))rdt_cdp_peer_get (struct rdt_resource *r, -struct rdt_domain *d, -struct rdt_resource **r_cdp, -struct rdt_domain **d_cdp) +static int rdt_cdp_peer_get (struct rdt_resource *r,struct rdt_domain *d, +struct rdt_resource **r_cdp, +struct rdt_domain **d_cdp) {struct rdt_resource *_r_cdp =NULL ;struct rdt_domain *_d_cdp =NULL ;
@@ -1033,7 +1032,7 @@ out: }/** -* rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other +* __rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs. * @d: The domain instance for which @closid is being tested. * @cbm: Capacity bitmask being tested.
@@ -1052,8 +1051,8 @@ out:* * Return: false if CBM does not overlap, true if it does. */ -bool rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, -unsigned long cbm,int closid,bool exclusive) +static bool __rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, +unsigned long cbm,int closid,bool exclusive) {enum rdtgrp_mode mode;unsigned long ctrl_b;
@@ -1088,6 +1087,41 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,return false; } +/** +* rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware +* @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. +* @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 +*/ +bool rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, +unsigned long cbm,int closid,bool exclusive) +{ +struct rdt_resource *r_cdp; +struct rdt_domain *d_cdp; + +if (__rdtgroup_cbm_overlaps (r, d, cbm, closid, exclusive)) +return true; + +if (rdt_cdp_peer_get (r, d, &r_cdp, &d_cdp) <0 ) +return false; + +return __rdtgroup_cbm_overlaps (r_cdp, d_cdp, cbm, closid, exclusive); +} +/** * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive *
PATCH v2 3/3 x86/intel_rdt: Fix initial allocation to consider CDP
In reply to Reinette ChatreWhen a new resource group is created it is initialized with a default allocation that considers which portions of cache are currently available for sharing across all resource groups or which portions of cache are currently unused.
If a CDP allocation forms part of a resource group that is in exclusive mode then it should be ensured that no new allocation overlaps with any resource that shares the underlying hardware. The current initial allocation does not take this sharing of hardware into account and a new allocation in a resource that shares the same
hardware would affect the exclusive resource group.
Fix this by considering the allocation of a peer RDT domain - a RDT domain sharing the same hardware - as part of the test to determine which portion of cache is in use and available for use.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +16 -2
@@ -2457,11 +2457,14 @@ static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)*/ static int rdtgroup_init_alloc (struct rdtgroup *rdtgrp) { +struct rdt_resource *r_cdp =NULL ; +struct rdt_domain *d_cdp =NULL ;u32 used_b =0 , unused_b =0 ;u32 closid = rdtgrp->closid;struct rdt_resource *r;enum rdtgrp_mode mode;struct rdt_domain *d; +u32 peer_ctl;int i, ret;u32 *ctrl;
@@ -2473,6 +2476,7 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)if (r->rid ==RDT_RESOURCE_MBA )continue ;list_for_each_entry (d, &r->domains, list) { +rdt_cdp_peer_get (r, d, &r_cdp, &d_cdp); d->have_new_ctrl = false; d->new_ctrl = r->cache.shareable_bits; used_b = r->cache.shareable_bits;
@@ -2482,9 +2486,19 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) mode =rdtgroup_mode_by_closid (i);if (mode ==RDT_MODE_PSEUDO_LOCKSETUP )break ; - used_b |= *ctrl; +/* +* If CDP is active include peer +* domain's usage to ensure there +* is no overlap with an exclusive +* group. +*/ +if (d_cdp) + peer_ctl = d_cdp->ctrl_val[i]; +else + peer_ctl =0 ; + used_b |= *ctrl | peer_ctl;if (mode ==RDT_MODE_SHAREABLE ) - d->new_ctrl |= *ctrl; + d->new_ctrl |= *ctrl | peer_ctl; } }if (d->plr && d->plr->cbm >0 )
Signature · 1 line
2.17.0
tip-bot for Reinette Chatre
merge bot[tip:x86/cache] x86/intel_rdt: Fix initial allocation to consider CDP
x86/intel_rdt: Fix initial allocation to consider CDP
Commit-ID: 42688c0c327ec0d647db6e0fc18fd644e7c50e3d Gitweb: https://git.kernel.org/tip/42688c0c327ec0d647db6e0fc18fd644e7c50e3d Author: Reinette Chatre <[email protected]> AuthorDate: Wed, 3 Oct 2018 15:17:03 -0700 Committer: Thomas Gleixner <[email protected]> CommitDate: Sat, 6 Oct 2018 20:46:27 +0200
x86/intel_rdt: Fix initial allocation to consider CDP
When a new resource group is created it is initialized with a default allocation that considers which portions of cache are currently available for sharing across all resource groups or which portions of cache are currently unused.
If a CDP allocation forms part of a resource group that is in exclusive mode then it should be ensured that no new allocation overlaps with any resource that shares the underlying hardware. The current initial allocation does not take this sharing of hardware into account and a new allocation in a resource that shares the same
hardware would affect the exclusive resource group.
Fix this by considering the allocation of a peer RDT domain - a RDT domain sharing the same hardware - as part of the test to determine which portion of cache is in use and available for use.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +16 -3
@@ -2460,14 +2460,16 @@ static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)*/ static int rdtgroup_init_alloc (struct rdtgroup *rdtgrp) { +struct rdt_resource *r_cdp =NULL ; +struct rdt_domain *d_cdp =NULL ;u32 used_b =0 , unused_b =0 ;u32 closid = rdtgrp->closid;struct rdt_resource *r;unsigned long tmp_cbm;enum rdtgrp_mode mode;struct rdt_domain *d; +u32 peer_ctl, *ctrl;int i, ret; -u32 *ctrl;for_each_alloc_enabled_rdt_resource (r) {/*
@@ -2477,6 +2479,7 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)if (r->rid ==RDT_RESOURCE_MBA )continue ;list_for_each_entry (d, &r->domains, list) { +rdt_cdp_peer_get (r, d, &r_cdp, &d_cdp); d->have_new_ctrl = false; d->new_ctrl = r->cache.shareable_bits; used_b = r->cache.shareable_bits;
@@ -2486,9 +2489,19 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) mode =rdtgroup_mode_by_closid (i);if (mode ==RDT_MODE_PSEUDO_LOCKSETUP )break ; - used_b |= *ctrl; +/* +* If CDP is active include peer +* domain's usage to ensure there +* is no overlap with an exclusive +* group. +*/ +if (d_cdp) + peer_ctl = d_cdp->ctrl_val[i]; +else + peer_ctl =0 ; + used_b |= *ctrl | peer_ctl;if (mode ==RDT_MODE_SHAREABLE ) - d->new_ctrl |= *ctrl; + d->new_ctrl |= *ctrl | peer_ctl; } }if (d->plr && d->plr->cbm >0 )
tip-bot for Reinette Chatre
merge bot[tip:x86/cache] x86/intel_rdt: Fix initial allocation to consider CDP
In reply to Reinette Chatrex86/intel_rdt: Fix initial allocation to consider CDP
Commit-ID: 2a7adf6ce643fdeec051dc88e5250b08c83bbb67 Gitweb: https://git.kernel.org/tip/2a7adf6ce643fdeec051dc88e5250b08c83bbb67 Author: Reinette Chatre <[email protected]> AuthorDate: Wed, 3 Oct 2018 15:17:03 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 9 Oct 2018 08:50:47 +0200
x86/intel_rdt: Fix initial allocation to consider CDP
When a new resource group is created it is initialized with a default allocation that considers which portions of cache are currently available for sharing across all resource groups or which portions of cache are currently unused.
If a CDP allocation forms part of a resource group that is in exclusive mode then it should be ensured that no new allocation overlaps with any resource that shares the underlying hardware. The current initial allocation does not take this sharing of hardware into account and a new allocation in a resource that shares the same
hardware would affect the exclusive resource group.
Fix this by considering the allocation of a peer RDT domain - a RDT domain sharing the same hardware - as part of the test to determine which portion of cache is in use and available for use.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +16 -3
@@ -2460,14 +2460,16 @@ static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)*/ static int rdtgroup_init_alloc (struct rdtgroup *rdtgrp) { +struct rdt_resource *r_cdp =NULL ; +struct rdt_domain *d_cdp =NULL ;u32 used_b =0 , unused_b =0 ;u32 closid = rdtgrp->closid;struct rdt_resource *r;unsigned long tmp_cbm;enum rdtgrp_mode mode;struct rdt_domain *d; +u32 peer_ctl, *ctrl;int i, ret; -u32 *ctrl;for_each_alloc_enabled_rdt_resource (r) {/*
@@ -2477,6 +2479,7 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)if (r->rid ==RDT_RESOURCE_MBA )continue ;list_for_each_entry (d, &r->domains, list) { +rdt_cdp_peer_get (r, d, &r_cdp, &d_cdp); d->have_new_ctrl = false; d->new_ctrl = r->cache.shareable_bits; used_b = r->cache.shareable_bits;
@@ -2486,9 +2489,19 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) mode =rdtgroup_mode_by_closid (i);if (mode ==RDT_MODE_PSEUDO_LOCKSETUP )break ; - used_b |= *ctrl; +/* +* If CDP is active include peer +* domain's usage to ensure there +* is no overlap with an exclusive +* group. +*/ +if (d_cdp) + peer_ctl = d_cdp->ctrl_val[i]; +else + peer_ctl =0 ; + used_b |= *ctrl | peer_ctl;if (mode ==RDT_MODE_SHAREABLE ) - d->new_ctrl |= *ctrl; + d->new_ctrl |= *ctrl | peer_ctl; } }if (d->plr && d->plr->cbm >0 )