Loading drivers/staging/android/ion/ion.c +62 −7 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ #include <soc/qcom/secure_buffer.h> #include "ion.h" #include "ion_secure_util.h" static struct ion_device *internal_dev; Loading Loading @@ -298,9 +299,14 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, struct ion_dma_buf_attachment *a = attachment->priv; struct sg_table *table; int ret, count, map_attrs; struct ion_buffer *buffer = attachment->dmabuf->priv; table = a->table; map_attrs = attachment->dma_map_attrs; if (!(buffer->flags & ION_FLAG_CACHED) || !hlos_accessible_buffer(buffer)) map_attrs |= DMA_ATTR_SKIP_CPU_SYNC; if (map_attrs & DMA_ATTR_DELAYED_UNMAP) { count = msm_dma_map_sg_attrs(attachment->dev, table->sgl, Loading @@ -316,6 +322,7 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, ret = -ENOMEM; goto err; } return table; err: Loading @@ -327,14 +334,22 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_table *table, enum dma_data_direction direction) { if (attachment->dma_map_attrs & DMA_ATTR_DELAYED_UNMAP) int map_attrs; struct ion_buffer *buffer = attachment->dmabuf->priv; map_attrs = attachment->dma_map_attrs; if (!(buffer->flags & ION_FLAG_CACHED) || !hlos_accessible_buffer(buffer)) map_attrs |= DMA_ATTR_SKIP_CPU_SYNC; if (map_attrs & DMA_ATTR_DELAYED_UNMAP) msm_dma_unmap_sg_attrs(attachment->dev, table->sgl, table->nents, direction, attachment->dmabuf, attachment->dma_map_attrs); map_attrs); else dma_unmap_sg_attrs(attachment->dev, table->sgl, table->nents, direction, attachment->dma_map_attrs); direction, map_attrs); } void ion_pages_sync_for_device(struct device *dev, struct page *page, Loading Loading @@ -504,6 +519,12 @@ static int __ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, struct ion_buffer *buffer = dmabuf->priv; void *vaddr; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } /* * TODO: Move this elsewhere because we don't always need a vaddr Loading @@ -514,6 +535,9 @@ static int __ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { if (sync_only_mapped) Loading @@ -526,7 +550,8 @@ static int __ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, Loading @@ -535,6 +560,12 @@ static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, { struct ion_buffer *buffer = dmabuf->priv; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } if (buffer->heap->ops->map_kernel) { mutex_lock(&buffer->lock); Loading @@ -542,6 +573,9 @@ static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { if (sync_only_mapped) Loading @@ -554,7 +588,8 @@ static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, Loading Loading @@ -589,6 +624,12 @@ static int ion_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, struct ion_buffer *buffer = dmabuf->priv; void *vaddr; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } /* * TODO: Move this elsewhere because we don't always need a vaddr Loading @@ -599,6 +640,9 @@ static int ion_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { ion_sgl_sync_range(a->dev, a->table->sgl, a->table->nents, Loading @@ -606,7 +650,8 @@ static int ion_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, Loading @@ -616,6 +661,12 @@ static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, { struct ion_buffer *buffer = dmabuf->priv; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } if (buffer->heap->ops->map_kernel) { mutex_lock(&buffer->lock); Loading @@ -623,6 +674,9 @@ static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { ion_sgl_sync_range(a->dev, a->table->sgl, a->table->nents, Loading @@ -630,7 +684,8 @@ static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int ion_dma_buf_get_flags(struct dma_buf *dmabuf, Loading drivers/staging/android/ion/ion_secure_util.c +15 −1 Original line number Diff line number Diff line /* * * Copyright (c) 2017, The Linux Foundation. All rights reserved. * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -202,3 +202,17 @@ int ion_hyp_assign_sg_from_flags(struct sg_table *sgt, unsigned long flags, out: return ret; } bool hlos_accessible_buffer(struct ion_buffer *buffer) { if ((buffer->flags & ION_FLAG_SECURE) && !(buffer->flags & ION_FLAG_CP_HLOS) && !(buffer->flags & ION_FLAG_CP_SPSS_HLOS_SHARED)) return false; else if ((get_secure_vmid(buffer->flags) > 0) && !(buffer->flags & ION_FLAG_CP_HLOS) && !(buffer->flags & ION_FLAG_CP_SPSS_HLOS_SHARED)) return false; return true; } drivers/staging/android/ion/ion_secure_util.h +5 −1 Original line number Diff line number Diff line /* Copyright (c) 2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading @@ -10,6 +10,8 @@ * GNU General Public License for more details. */ #include "ion.h" #ifndef _ION_SECURE_UTIL_H #define _ION_SECURE_UTIL_H Loading @@ -24,4 +26,6 @@ int ion_hyp_unassign_sg_from_flags(struct sg_table *sgt, unsigned long flags, int ion_hyp_assign_sg_from_flags(struct sg_table *sgt, unsigned long flags, bool set_page_private); bool hlos_accessible_buffer(struct ion_buffer *buffer); #endif /* _ION_SECURE_UTIL_H */ Loading
drivers/staging/android/ion/ion.c +62 −7 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ #include <soc/qcom/secure_buffer.h> #include "ion.h" #include "ion_secure_util.h" static struct ion_device *internal_dev; Loading Loading @@ -298,9 +299,14 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, struct ion_dma_buf_attachment *a = attachment->priv; struct sg_table *table; int ret, count, map_attrs; struct ion_buffer *buffer = attachment->dmabuf->priv; table = a->table; map_attrs = attachment->dma_map_attrs; if (!(buffer->flags & ION_FLAG_CACHED) || !hlos_accessible_buffer(buffer)) map_attrs |= DMA_ATTR_SKIP_CPU_SYNC; if (map_attrs & DMA_ATTR_DELAYED_UNMAP) { count = msm_dma_map_sg_attrs(attachment->dev, table->sgl, Loading @@ -316,6 +322,7 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, ret = -ENOMEM; goto err; } return table; err: Loading @@ -327,14 +334,22 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_table *table, enum dma_data_direction direction) { if (attachment->dma_map_attrs & DMA_ATTR_DELAYED_UNMAP) int map_attrs; struct ion_buffer *buffer = attachment->dmabuf->priv; map_attrs = attachment->dma_map_attrs; if (!(buffer->flags & ION_FLAG_CACHED) || !hlos_accessible_buffer(buffer)) map_attrs |= DMA_ATTR_SKIP_CPU_SYNC; if (map_attrs & DMA_ATTR_DELAYED_UNMAP) msm_dma_unmap_sg_attrs(attachment->dev, table->sgl, table->nents, direction, attachment->dmabuf, attachment->dma_map_attrs); map_attrs); else dma_unmap_sg_attrs(attachment->dev, table->sgl, table->nents, direction, attachment->dma_map_attrs); direction, map_attrs); } void ion_pages_sync_for_device(struct device *dev, struct page *page, Loading Loading @@ -504,6 +519,12 @@ static int __ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, struct ion_buffer *buffer = dmabuf->priv; void *vaddr; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } /* * TODO: Move this elsewhere because we don't always need a vaddr Loading @@ -514,6 +535,9 @@ static int __ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { if (sync_only_mapped) Loading @@ -526,7 +550,8 @@ static int __ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, Loading @@ -535,6 +560,12 @@ static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, { struct ion_buffer *buffer = dmabuf->priv; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } if (buffer->heap->ops->map_kernel) { mutex_lock(&buffer->lock); Loading @@ -542,6 +573,9 @@ static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { if (sync_only_mapped) Loading @@ -554,7 +588,8 @@ static int __ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, Loading Loading @@ -589,6 +624,12 @@ static int ion_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, struct ion_buffer *buffer = dmabuf->priv; void *vaddr; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } /* * TODO: Move this elsewhere because we don't always need a vaddr Loading @@ -599,6 +640,9 @@ static int ion_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { ion_sgl_sync_range(a->dev, a->table->sgl, a->table->nents, Loading @@ -606,7 +650,8 @@ static int ion_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, Loading @@ -616,6 +661,12 @@ static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, { struct ion_buffer *buffer = dmabuf->priv; struct ion_dma_buf_attachment *a; int ret = 0; if (!hlos_accessible_buffer(buffer)) { ret = -EPERM; goto out; } if (buffer->heap->ops->map_kernel) { mutex_lock(&buffer->lock); Loading @@ -623,6 +674,9 @@ static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, mutex_unlock(&buffer->lock); } if (!(buffer->flags & ION_FLAG_CACHED)) goto out; mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { ion_sgl_sync_range(a->dev, a->table->sgl, a->table->nents, Loading @@ -630,7 +684,8 @@ static int ion_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, } mutex_unlock(&buffer->lock); return 0; out: return ret; } static int ion_dma_buf_get_flags(struct dma_buf *dmabuf, Loading
drivers/staging/android/ion/ion_secure_util.c +15 −1 Original line number Diff line number Diff line /* * * Copyright (c) 2017, The Linux Foundation. All rights reserved. * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -202,3 +202,17 @@ int ion_hyp_assign_sg_from_flags(struct sg_table *sgt, unsigned long flags, out: return ret; } bool hlos_accessible_buffer(struct ion_buffer *buffer) { if ((buffer->flags & ION_FLAG_SECURE) && !(buffer->flags & ION_FLAG_CP_HLOS) && !(buffer->flags & ION_FLAG_CP_SPSS_HLOS_SHARED)) return false; else if ((get_secure_vmid(buffer->flags) > 0) && !(buffer->flags & ION_FLAG_CP_HLOS) && !(buffer->flags & ION_FLAG_CP_SPSS_HLOS_SHARED)) return false; return true; }
drivers/staging/android/ion/ion_secure_util.h +5 −1 Original line number Diff line number Diff line /* Copyright (c) 2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading @@ -10,6 +10,8 @@ * GNU General Public License for more details. */ #include "ion.h" #ifndef _ION_SECURE_UTIL_H #define _ION_SECURE_UTIL_H Loading @@ -24,4 +26,6 @@ int ion_hyp_unassign_sg_from_flags(struct sg_table *sgt, unsigned long flags, int ion_hyp_assign_sg_from_flags(struct sg_table *sgt, unsigned long flags, bool set_page_private); bool hlos_accessible_buffer(struct ion_buffer *buffer); #endif /* _ION_SECURE_UTIL_H */