Skip to content

Commit a6e766d

Browse files
ekanshibugregkh
authored andcommitted
misc: fastrpc: Pass proper scm arguments for secure map request
If a map request is made with securemap attribute, the memory ownership needs to be reassigned to new VMID to allow access from protection domain. Currently only DSP VMID is passed to the reassign call which is incorrect as only a combination of HLOS and DSP VMID is allowed for memory ownership reassignment and passing only DSP VMID will cause assign call failure. Also pass proper restoring permissions to HLOS as the source permission will now carry both HLOS and DSP VMID permission. Change is also made to get valid physical address from scatter/gather for this allocation request. Fixes: e90d911 ("misc: fastrpc: Add support to secure memory map") Cc: stable <[email protected]> Tested-by: Ekansh Gupta <[email protected]> Signed-off-by: Ekansh Gupta <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bca7a46 commit a6e766d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

drivers/misc/fastrpc.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,14 @@ static void fastrpc_free_map(struct kref *ref)
316316
if (map->table) {
317317
if (map->attr & FASTRPC_ATTR_SECUREMAP) {
318318
struct qcom_scm_vmperm perm;
319+
int vmid = map->fl->cctx->vmperms[0].vmid;
320+
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS) | BIT(vmid);
319321
int err = 0;
320322

321323
perm.vmid = QCOM_SCM_VMID_HLOS;
322324
perm.perm = QCOM_SCM_PERM_RWX;
323325
err = qcom_scm_assign_mem(map->phys, map->size,
324-
&map->fl->cctx->perms, &perm, 1);
326+
&src_perms, &perm, 1);
325327
if (err) {
326328
dev_err(map->fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d",
327329
map->phys, map->size, err);
@@ -787,8 +789,12 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
787789
goto map_err;
788790
}
789791

790-
map->phys = sg_dma_address(map->table->sgl);
791-
map->phys += ((u64)fl->sctx->sid << 32);
792+
if (attr & FASTRPC_ATTR_SECUREMAP) {
793+
map->phys = sg_phys(map->table->sgl);
794+
} else {
795+
map->phys = sg_dma_address(map->table->sgl);
796+
map->phys += ((u64)fl->sctx->sid << 32);
797+
}
792798
map->size = len;
793799
map->va = sg_virt(map->table->sgl);
794800
map->len = len;
@@ -798,9 +804,15 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
798804
* If subsystem VMIDs are defined in DTSI, then do
799805
* hyp_assign from HLOS to those VM(s)
800806
*/
807+
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS);
808+
struct qcom_scm_vmperm dst_perms[2] = {0};
809+
810+
dst_perms[0].vmid = QCOM_SCM_VMID_HLOS;
811+
dst_perms[0].perm = QCOM_SCM_PERM_RW;
812+
dst_perms[1].vmid = fl->cctx->vmperms[0].vmid;
813+
dst_perms[1].perm = QCOM_SCM_PERM_RWX;
801814
map->attr = attr;
802-
err = qcom_scm_assign_mem(map->phys, (u64)map->size, &fl->cctx->perms,
803-
fl->cctx->vmperms, fl->cctx->vmcount);
815+
err = qcom_scm_assign_mem(map->phys, (u64)map->size, &src_perms, dst_perms, 2);
804816
if (err) {
805817
dev_err(sess->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d",
806818
map->phys, map->size, err);

0 commit comments

Comments
 (0)