diff options
author | Gabor Kertesz <gabor.kertesz@arm.com> | 2023-01-19 13:01:31 +0100 |
---|---|---|
committer | Juan Yescas <jyescas@google.com> | 2024-01-31 12:48:01 -0800 |
commit | 55b5ae0f4535b5de37b860dc5209738615d3e245 (patch) | |
tree | 9d9cd80b4de73149e92ca03f3aa529e81fff27bb | |
parent | a0740c0766ccf7d7da78ea936ac77a0a93afe128 (diff) | |
download | gs-55b5ae0f4535b5de37b860dc5209738615d3e245.tar.gz |
ANDROID: trusty: Make Trusty driver page size agnostic
The FW interface expects number of 4K pages when memory is shared.
However the driver and the FW share memory in contigous memory areas,
so converting the number of kernel size pages to Trusty FW size pages
makes the Trusty kernel driver page size agnostic.
The patch was cherry picked from aosp/2399652.
Bug: 294914413
Bug: 265047549
Bug: 267220208
Bug: 308663811
Change-Id: Ie0b88c9cb30a0a16ea67f8046c7d0def2886c93f
Signed-off-by: Gabor Kertesz <gabor.kertesz@arm.com>
[ Kalesh Singh - Round up vds buffer allocation size to page boundary ]
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
(cherry picked from commit 73d5f1d8e2c977e099ccc11bc83efb9abfe21ee3)
-rw-r--r-- | drivers/trusty/trusty-ipc.c | 2 | ||||
-rw-r--r-- | drivers/trusty/trusty.c | 16 | ||||
-rw-r--r-- | include/linux/trusty/arm_ffa.h | 7 |
3 files changed, 20 insertions, 5 deletions
diff --git a/drivers/trusty/trusty-ipc.c b/drivers/trusty/trusty-ipc.c index 83df24e40660..a7d7fd13eb78 100644 --- a/drivers/trusty/trusty-ipc.c +++ b/drivers/trusty/trusty-ipc.c @@ -210,7 +210,7 @@ static struct tipc_msg_buf *vds_alloc_msg_buf(struct tipc_virtio_dev *vds, { int ret; struct tipc_msg_buf *mb; - size_t sz = vds->msg_buf_max_sz; + size_t sz = ALIGN(vds->msg_buf_max_sz, PAGE_SIZE); pgprot_t pgprot = share_write ? PAGE_KERNEL : PAGE_KERNEL_RO; /* allocate tracking structure */ diff --git a/drivers/trusty/trusty.c b/drivers/trusty/trusty.c index 88c89a3fe7de..b7f43f54037b 100644 --- a/drivers/trusty/trusty.c +++ b/drivers/trusty/trusty.c @@ -349,7 +349,7 @@ int trusty_transfer_memory(struct device *dev, u64 *id, emad->comp_mrd_offset = comp_mrd_offset; emad->reserved_8_15 = 0; } - comp_mrd->total_page_count = len / PAGE_SIZE; + comp_mrd->total_page_count = len / FFA_PAGE_SIZE; comp_mrd->address_range_count = nents; comp_mrd->reserved_8_15 = 0; @@ -364,7 +364,7 @@ int trusty_transfer_memory(struct device *dev, u64 *id, for (i = 0; i < lcount; i++) { cons_mrd[i].address = sg_dma_address(sg); - cons_mrd[i].page_count = sg_dma_len(sg) / PAGE_SIZE; + cons_mrd[i].page_count = sg_dma_len(sg) / FFA_PAGE_SIZE; cons_mrd[i].reserved_12_15 = 0; sg = sg_next(sg); } @@ -617,6 +617,14 @@ static int trusty_init_msg_buf(struct trusty_state *s, struct device *dev) s->ffa_local_id = smc_ret.r2; s->ffa_remote_id = 0x8000; + /* + * The pKVM hypervisor uses the same page size as the host, including for + * stage-2 mappings. So the rx/tx buffers need to be page-sized multiple, + * and page-aligned. + * + * TODO: This can be made more generic by discovering the required size + * through SMC_FC_FFA_FEATURES later. + */ s->ffa_tx = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!s->ffa_tx) { ret = -ENOMEM; @@ -639,8 +647,8 @@ static int trusty_init_msg_buf(struct trusty_state *s, struct device *dev) goto err_unaligned_rx_buf; } - smc_ret = trusty_smc8(SMC_FCZ_FFA_RXTX_MAP, tx_paddr, rx_paddr, 1, 0, - 0, 0, 0); + smc_ret = trusty_smc8(SMC_FCZ_FFA_RXTX_MAP, tx_paddr, rx_paddr, + PAGE_SIZE / FFA_PAGE_SIZE, 0, 0, 0, 0); if (smc_ret.r0 != SMC_FC_FFA_SUCCESS) { dev_err(s->dev, "%s: SMC_FCZ_FFA_RXTX_MAP failed 0x%lx 0x%lx 0x%lx\n", __func__, smc_ret.r0, smc_ret.r1, smc_ret.r2); diff --git a/include/linux/trusty/arm_ffa.h b/include/linux/trusty/arm_ffa.h index ab7b2afb794c..95d31b32bac6 100644 --- a/include/linux/trusty/arm_ffa.h +++ b/include/linux/trusty/arm_ffa.h @@ -36,6 +36,13 @@ SMC_FASTCALL64_NR(SMC_ENTITY_SHARED_MEMORY, nr) /** + * FF-A specification mentions explicitly about '4K pages'. This should + * not be confused with the kernel PAGE_SIZE, which is the translation + * granule kernel is configured and may be one among 4K, 16K and 64K. + */ +#define FFA_PAGE_SIZE SZ_4K + +/** * typedef ffa_endpoint_id16_t - Endpoint ID * * Current implementation only supports VMIDs. FFA spec also support stream |