From: Jan Kiszka <[email protected]>

As we map each cell on an exclusively used context bank, make sure we do
not overrun the hardware limits.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/arch/arm64/smmu.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/hypervisor/arch/arm64/smmu.c b/hypervisor/arch/arm64/smmu.c
index e316a553..da904d1d 100644
--- a/hypervisor/arch/arm64/smmu.c
+++ b/hypervisor/arch/arm64/smmu.c
@@ -466,6 +466,7 @@ static int arm_smmu_find_sme(u16 id, struct arm_smmu_device 
*smmu)
 
 static int arm_smmu_cell_init(struct cell *cell)
 {
+       unsigned int vmid = cell->config->id;
        struct arm_smmu_device *smmu;
        struct arm_smmu_cfg *cfg;
        struct arm_smmu_smr *smr;
@@ -477,7 +478,10 @@ static int arm_smmu_cell_init(struct cell *cell)
                return 0;
 
        for_each_smmu(smmu, dev) {
-               cfg = &smmu->cfgs[cell->config->id];
+               if (vmid >= smmu->num_context_banks)
+                       return trace_error(-ERANGE);
+
+               cfg = &smmu->cfgs[vmid];
 
                cfg->cbar = CBAR_TYPE_S2_TRANS;
 
@@ -485,7 +489,7 @@ static int arm_smmu_cell_init(struct cell *cell)
                 * We use the cell ID here, one cell use one context, and its
                 * index is also the VMID.
                 */
-               cfg->id = cell->config->id;
+               cfg->id = vmid;
 
                ret = arm_smmu_init_context_bank(smmu, cfg, cell);
                if (ret)
@@ -504,8 +508,7 @@ static int arm_smmu_cell_init(struct cell *cell)
                        printk("Assigning StreamID 0x%x to cell \"%s\"\n",
                               sid, cell->config->name);
 
-                       arm_smmu_write_s2cr(smmu, idx, S2CR_TYPE_TRANS,
-                                           cfg->id);
+                       arm_smmu_write_s2cr(smmu, idx, S2CR_TYPE_TRANS, vmid);
 
                        smr[idx].id = sid;
                        smr[idx].mask = smmu->arm_sid_mask;
@@ -514,8 +517,7 @@ static int arm_smmu_cell_init(struct cell *cell)
                        arm_smmu_write_smr(smmu, idx);
                }
 
-               mmio_write32(ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_TLBIVMID,
-                            cfg->id);
+               mmio_write32(ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_TLBIVMID, vmid);
                ret = arm_smmu_tlb_sync_global(smmu);
                if (ret < 0)
                        return ret;
-- 
2.26.2

-- 
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/bf62abf1407d8f2d8bcbde24a3bb50bbd5dcb88d.1601838005.git.jan.kiszka%40siemens.com.

Reply via email to