From 8340c9f96e00d3d4ac601ee9c312b223098a4760 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Fri, 8 May 2020 07:17:25 -0700 Subject: [PATCH] soc: qcom: mem-buf: Align allocation sizes to MHP subsection size The allocation code hot-adds the memory from another VM through the memory hotplug code to create the S1 CPU MMU mappings. The memory hotplug code can only add memory at a subsection granule, meaning that all memory requests must be subsection size aligned. Thus, enforce all allocation requests to be subsection size aligned. Change-Id: Ia4d3294e36265f0bd956fa42670f2ac8d6974908 Signed-off-by: Isaac J. Manjarres --- drivers/soc/qcom/mem-buf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/mem-buf.c b/drivers/soc/qcom/mem-buf.c index eaf4519e95d5..a68647bd240d 100644 --- a/drivers/soc/qcom/mem-buf.c +++ b/drivers/soc/qcom/mem-buf.c @@ -28,6 +28,7 @@ #include #define MEM_BUF_MAX_DEVS 1 +#define MEM_BUF_MHP_ALIGNMENT (1UL << SUBSECTION_SHIFT) #define MEM_BUF_TIMEOUT_MS 2000 #define to_rmt_msg(_work) container_of(_work, struct mem_buf_rmt_msg, work) @@ -977,6 +978,13 @@ static int mem_buf_map_mem_s1(struct mem_buf_desc *membuf) for (i = 0; i < membuf->sgl_desc->n_sgl_entries; i++) { base = membuf->sgl_desc->sgl_entries[i].ipa_base; size = membuf->sgl_desc->sgl_entries[i].size; + if (!IS_ALIGNED(base, MEM_BUF_MHP_ALIGNMENT) || + !IS_ALIGNED(size, MEM_BUF_MHP_ALIGNMENT)) { + ret = -EINVAL; + pr_err("%s: IPA base: 0x%lx or size: 0x%lx not aligned properly\n", + __func__, base, size); + goto err_add_mem; + } nid = memory_add_physaddr_to_nid(base); memblock_add_node(base, size, nid); ret = arch_add_memory(nid, base, size, &restrictions); @@ -1310,7 +1318,7 @@ void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data) if (!membuf) return ERR_PTR(-ENOMEM); - membuf->size = alloc_data->size; + membuf->size = ALIGN(alloc_data->size, MEM_BUF_MHP_ALIGNMENT); membuf->acl_desc = mem_buf_acl_to_hh_acl(alloc_data->nr_acl_entries, alloc_data->acl_list); if (IS_ERR(membuf->acl_desc)) {