This commit ensures that creating and destroying a cell returns the
ROOT_COS CBM to the prior state.
Previously, the following sequence would change the CBM of the root
cell for a 10-way (bit) CBM:
jailhouse enable: creates a root cell with COS0 and CBM 3FF
jailhouse cell create: creates cell1 with COS1 and CBM 1FF
The root CBM is shrinked to 200
jailhouse cell create: creates cell2 with COS2 and CBM 1F0
The root CBM is unmodified.
jailhouse cell destroy: destroyes cell2 with CBM 1F0.
The root CBM is extended to 3F0.
The last extension is considered undesirable, because the bits freed
from cell2 are still in use by cell1. Due to this, cell creation and
destruction are not inverse operations, but instead leave the system in
a different state.
This patch checks whether the bits are in use by another cell, and
whether this cell allows the bits to be ROOTSHARED. If these bits are in
use, but not shared, they are not returned to the root.
Additionally, the root_cell bits are removed from the freed_mask to
prevent merge_freed_mask_to_root() from considering these.
Fixes: 3f04eb1753bb ("x86: Introduce Cache Allocation Technology support
for Intel CPUs")
Signed-off-by: Bram Hooimeijer <[email protected]>
---
hypervisor/arch/x86/cat.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/hypervisor/arch/x86/cat.c b/hypervisor/arch/x86/cat.c
index 42fd83d9..d3425f7b 100644
--- a/hypervisor/arch/x86/cat.c
+++ b/hypervisor/arch/x86/cat.c
@@ -204,6 +204,9 @@ static int cat_cell_init(struct cell *cell)
static void cat_cell_exit(struct cell *cell)
{
+ struct cell *oth_cell;
+ const struct jailhouse_cache *cache;
+
/*
* Only release the mask of cells with an own partition.
* cos is also CAT_ROOT_COS if CAT is unsupported.
@@ -212,10 +215,22 @@ static void cat_cell_exit(struct cell *cell)
return;
/*
- * Queue bits of released mask for returning to root that were in the
- * original root mask as well.
+ * Queue bits of released mask for returning to root, if
+ * - the bits were in the original root mask as well, and,
+ * - the bits are not in the current root mask, and,
+ * - every other cell using these bits indicate these to be ROOTSHARED.
*/
- freed_mask |= cell->arch.cat_mask & orig_root_mask;
+ /* Remove bits from cell->arch.cat_mask used by others: */
+ for_each_non_root_cell(oth_cell) {
+ if (oth_cell != cell &&
+ oth_cell->config->num_cache_regions > 0) {
+ cache = jailhouse_cell_cache_regions(oth_cell->config);
+ if (!(cache->flags & JAILHOUSE_CACHE_ROOTSHARED))
+ cell->arch.cat_mask &= ~oth_cell->arch.cat_mask;
+ }
+ }
+ freed_mask |= cell->arch.cat_mask & orig_root_mask
+ & ~root_cell.arch.cat_mask;
if (merge_freed_mask_to_root()) {
printk("CAT: Extended COS %d bitmask to %08llx for root cell",
--
2.28.0
--
You received this message because you are subscribed to the Google Groups
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jailhouse-dev/PA4PR02MB667022FEAA58A2425E69A019B6B59%40PA4PR02MB6670.eurprd02.prod.outlook.com.