diff --git a/drivers/soc/qcom/secure_buffer.c b/drivers/soc/qcom/secure_buffer.c index 023b8abb750b..a3a970961a67 100644 --- a/drivers/soc/qcom/secure_buffer.c +++ b/drivers/soc/qcom/secure_buffer.c @@ -146,6 +146,32 @@ static int batched_hyp_assign(struct sg_table *table, u32 *source_vmids, return ret; } +static inline void set_each_page_of_sg(struct sg_table *table, u64 flag) +{ + struct scatterlist *sg; + int npages; + int i = 0; + + for_each_sg(table->sgl, sg, table->nents, i) { + npages = sg->length / PAGE_SIZE; + if (sg->length % PAGE_SIZE) + npages++; + while (npages--) + set_page_private(nth_page(sg_page(sg), npages), flag); + } +} + +#define SECURE_PAGE_MAGIC 0xEEEEEEEE +int page_accessible(unsigned long pfn) +{ + struct page *page = pfn_to_page(pfn); + + if (page->private == SECURE_PAGE_MAGIC) + return 0; + else + return 1; +} + /* * When -EADDRNOTAVAIL is returned the memory may no longer be in * a usable state and should no longer be accessed by the HLOS. @@ -207,6 +233,19 @@ int hyp_assign_table(struct sg_table *table, ret = batched_hyp_assign(table, source_vm_copy, source_vm_copy_size, dest_vm_copy, dest_vm_copy_size); + if (!ret) { + while (dest_nelems--) { + if (dest_vmids[dest_nelems] == VMID_HLOS) + break; + } + + if (dest_nelems == -1) + set_each_page_of_sg(table, SECURE_PAGE_MAGIC); + else + set_each_page_of_sg(table, 0); + } + + dma_unmap_single(qcom_secure_buffer_dev, dest_dma_addr, dest_vm_copy_size, DMA_TO_DEVICE); out_free_dest: diff --git a/include/soc/qcom/secure_buffer.h b/include/soc/qcom/secure_buffer.h index 3c8b3c7146ee..2d28674a3cb9 100644 --- a/include/soc/qcom/secure_buffer.h +++ b/include/soc/qcom/secure_buffer.h @@ -54,6 +54,7 @@ int hyp_assign_phys(phys_addr_t addr, u64 size, int *dest_vmids, int *dest_perms, int dest_nelems); const char *msm_secure_vmid_to_string(int secure_vmid); u32 msm_secure_get_vmid_perms(u32 vmid); +int page_accessible(unsigned long pfn); #else static inline int hyp_assign_table(struct sg_table *table, u32 *source_vm_list, int source_nelems, @@ -79,5 +80,10 @@ static inline u32 msm_secure_get_vmid_perms(u32 vmid) { return 0; } + +static inline int page_accessible(unsigned long pfn) +{ + return 1; +} #endif #endif