From 436d1f81a75b4b2fc91d077f4d588fe7141ce05f Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Thu, 19 Sep 2019 09:59:41 -0700 Subject: [PATCH 1/2] ion: Fail system secure heap creation if system heap is unavailable The system secure heap relies on the existence of the system heap. Thus, if the system heap is not available, do not create, the system secure heap. Change-Id: I7a99e0fda45ae02ed6e5c8a797d29e917e84f182 Signed-off-by: Isaac J. Manjarres --- .../staging/android/ion/heaps/ion_system_secure_heap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/ion/heaps/ion_system_secure_heap.c b/drivers/staging/android/ion/heaps/ion_system_secure_heap.c index 8e561a48047c..1ecc903b8ce0 100644 --- a/drivers/staging/android/ion/heaps/ion_system_secure_heap.c +++ b/drivers/staging/android/ion/heaps/ion_system_secure_heap.c @@ -323,6 +323,12 @@ static struct ion_heap_ops system_secure_heap_ops = { struct ion_heap *ion_system_secure_heap_create(struct ion_platform_heap *unused) { struct ion_system_secure_heap *heap; + struct ion_heap *sys_heap = get_ion_heap(ION_SYSTEM_HEAP_ID); + + if (!sys_heap) { + pr_err("Sys heap missing; ensure it's specified in the DT, before the sys secure heap\n"); + return ERR_PTR(-EINVAL); + } heap = kzalloc(sizeof(*heap), GFP_KERNEL); if (!heap) @@ -330,7 +336,7 @@ struct ion_heap *ion_system_secure_heap_create(struct ion_platform_heap *unused) heap->heap.ion_heap.ops = &system_secure_heap_ops; heap->heap.ion_heap.type = (enum ion_heap_type)ION_HEAP_TYPE_SYSTEM_SECURE; - heap->sys_heap = get_ion_heap(ION_SYSTEM_HEAP_ID); + heap->sys_heap = sys_heap; heap->destroy_heap = false; heap->work_lock = __SPIN_LOCK_UNLOCKED(heap->work_lock); From 5d45437535e7a22de6e0835047cb44149a21ed4e Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Wed, 4 Sep 2019 14:35:29 -0700 Subject: [PATCH 2/2] ion: msm: Relocate MSM ION header directly to include/uapi/linux Instead of using a symlink to point to the MSM ION header, place it directly in the include/uapi/linux path. Change-Id: Id2a91adb4bdfc2c03e8eb535882734603ccd0f94 Signed-off-by: Isaac J. Manjarres --- .../staging/android/ion/heaps/msm_ion_priv.h | 2 +- drivers/staging/android/uapi/msm_ion.h | 122 ----------------- include/uapi/linux/msm_ion.h | 123 +++++++++++++++++- 3 files changed, 123 insertions(+), 124 deletions(-) delete mode 100644 drivers/staging/android/uapi/msm_ion.h mode change 120000 => 100644 include/uapi/linux/msm_ion.h diff --git a/drivers/staging/android/ion/heaps/msm_ion_priv.h b/drivers/staging/android/ion/heaps/msm_ion_priv.h index 84408ee682d0..fb2c2a6a5ad4 100644 --- a/drivers/staging/android/ion/heaps/msm_ion_priv.h +++ b/drivers/staging/android/ion/heaps/msm_ion_priv.h @@ -22,8 +22,8 @@ #include #include #include +#include #include "../ion_private.h" -#include "../../uapi/msm_ion.h" #define ION_ADSP_HEAP_NAME "adsp" #define ION_SYSTEM_HEAP_NAME "system" diff --git a/drivers/staging/android/uapi/msm_ion.h b/drivers/staging/android/uapi/msm_ion.h deleted file mode 100644 index 87d8d8cb36eb..000000000000 --- a/drivers/staging/android/uapi/msm_ion.h +++ /dev/null @@ -1,122 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -/* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. - */ -#ifndef _UAPI_LINUX_MSM_ION_H -#define _UAPI_LINUX_MSM_ION_H - -#include - -#define ION_BIT(nr) (1U << (nr)) - -/** - * TARGET_ION_ABI_VERSION can be used by user space clients to ensure that at - * compile time only their code which uses the appropriate ION APIs for - * this kernel is included. - */ -#define TARGET_ION_ABI_VERSION 2 - -enum msm_ion_heap_types { - ION_HEAP_TYPE_MSM_START = 6, - ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START, - ION_HEAP_TYPE_SYSTEM_SECURE, - ION_HEAP_TYPE_HYP_CMA, - ION_HEAP_TYPE_SECURE_CARVEOUT, -}; - -/** - * These are the only ids that should be used for Ion heap ids. - * The ids listed are the order in which allocation will be attempted - * if specified. Don't swap the order of heap ids unless you know what - * you are doing! - * Id's are spaced by purpose to allow new Id's to be inserted in-between (for - * possible fallbacks) - */ - -enum ion_heap_ids { - INVALID_HEAP_ID = -1, - ION_CP_MM_HEAP_ID = 8, - ION_SECURE_HEAP_ID = 9, - ION_SECURE_DISPLAY_HEAP_ID = 10, - ION_SPSS_HEAP_ID = 13, /* Secure Processor ION heap */ - ION_ADSP_HEAP_ID = 22, - ION_SYSTEM_HEAP_ID = 25, - ION_QSECOM_HEAP_ID = 27, - ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */ -}; - -/** - * Newly added heap ids have to be #define(d) since all API changes must - * include a new #define. - */ -#define ION_SECURE_CARVEOUT_HEAP_ID 14 -#define ION_QSECOM_TA_HEAP_ID 19 -#define ION_AUDIO_HEAP_ID 28 -#define ION_CAMERA_HEAP_ID 20 -#define ION_USER_CONTIG_HEAP_ID 26 -/** - * Flags to be used when allocating from the secure heap for - * content protection - */ -#define ION_FLAG_CP_TOUCH ION_BIT(17) -#define ION_FLAG_CP_BITSTREAM ION_BIT(18) -#define ION_FLAG_CP_PIXEL ION_BIT(19) -#define ION_FLAG_CP_NON_PIXEL ION_BIT(20) -#define ION_FLAG_CP_CAMERA ION_BIT(21) -#define ION_FLAG_CP_HLOS ION_BIT(22) -#define ION_FLAG_CP_SPSS_SP ION_BIT(23) -#define ION_FLAG_CP_SPSS_SP_SHARED ION_BIT(24) -#define ION_FLAG_CP_SEC_DISPLAY ION_BIT(25) -#define ION_FLAG_CP_APP ION_BIT(26) -#define ION_FLAG_CP_CAMERA_PREVIEW ION_BIT(27) -/* ION_FLAG_ALLOW_NON_CONTIG uses ION_BIT(28) */ -#define ION_FLAG_CP_CDSP ION_BIT(29) -#define ION_FLAG_CP_SPSS_HLOS_SHARED ION_BIT(30) - -#define ION_FLAGS_CP_MASK 0x6FFE0000 - -/** - * Flag to allow non continguous allocation of memory from secure - * heap - */ -#define ION_FLAG_ALLOW_NON_CONTIG ION_BIT(28) - -/** - * Flag to use when allocating to indicate that a heap is secure. - * Do NOT use BIT macro since it is defined in #ifdef __KERNEL__ - */ -#define ION_FLAG_SECURE ION_BIT(ION_HEAP_ID_RESERVED) - -/* - * Used in conjunction with heap which pool memory to force an allocation - * to come from the page allocator directly instead of from the pool allocation - */ -#define ION_FLAG_POOL_FORCE_ALLOC ION_BIT(16) - -/** - * Macro should be used with ion_heap_ids defined above. - */ -#define ION_HEAP(bit) ION_BIT(bit) - -#define ION_IOC_MSM_MAGIC 'M' - -struct ion_prefetch_regions { - __u64 sizes; - __u32 vmid; - __u32 nr_sizes; -}; - -struct ion_prefetch_data { - __u64 len; - __u64 regions; - __u32 heap_id; - __u32 nr_regions; -}; - -#define ION_IOC_PREFETCH _IOWR(ION_IOC_MSM_MAGIC, 3, \ - struct ion_prefetch_data) - -#define ION_IOC_DRAIN _IOWR(ION_IOC_MSM_MAGIC, 4, \ - struct ion_prefetch_data) - -#endif /* _UAPI_LINUX_MSM_ION_H */ diff --git a/include/uapi/linux/msm_ion.h b/include/uapi/linux/msm_ion.h deleted file mode 120000 index 94349d27efa6..000000000000 --- a/include/uapi/linux/msm_ion.h +++ /dev/null @@ -1 +0,0 @@ -../../../drivers/staging/android/uapi/msm_ion.h \ No newline at end of file diff --git a/include/uapi/linux/msm_ion.h b/include/uapi/linux/msm_ion.h new file mode 100644 index 000000000000..87d8d8cb36eb --- /dev/null +++ b/include/uapi/linux/msm_ion.h @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + */ +#ifndef _UAPI_LINUX_MSM_ION_H +#define _UAPI_LINUX_MSM_ION_H + +#include + +#define ION_BIT(nr) (1U << (nr)) + +/** + * TARGET_ION_ABI_VERSION can be used by user space clients to ensure that at + * compile time only their code which uses the appropriate ION APIs for + * this kernel is included. + */ +#define TARGET_ION_ABI_VERSION 2 + +enum msm_ion_heap_types { + ION_HEAP_TYPE_MSM_START = 6, + ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START, + ION_HEAP_TYPE_SYSTEM_SECURE, + ION_HEAP_TYPE_HYP_CMA, + ION_HEAP_TYPE_SECURE_CARVEOUT, +}; + +/** + * These are the only ids that should be used for Ion heap ids. + * The ids listed are the order in which allocation will be attempted + * if specified. Don't swap the order of heap ids unless you know what + * you are doing! + * Id's are spaced by purpose to allow new Id's to be inserted in-between (for + * possible fallbacks) + */ + +enum ion_heap_ids { + INVALID_HEAP_ID = -1, + ION_CP_MM_HEAP_ID = 8, + ION_SECURE_HEAP_ID = 9, + ION_SECURE_DISPLAY_HEAP_ID = 10, + ION_SPSS_HEAP_ID = 13, /* Secure Processor ION heap */ + ION_ADSP_HEAP_ID = 22, + ION_SYSTEM_HEAP_ID = 25, + ION_QSECOM_HEAP_ID = 27, + ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */ +}; + +/** + * Newly added heap ids have to be #define(d) since all API changes must + * include a new #define. + */ +#define ION_SECURE_CARVEOUT_HEAP_ID 14 +#define ION_QSECOM_TA_HEAP_ID 19 +#define ION_AUDIO_HEAP_ID 28 +#define ION_CAMERA_HEAP_ID 20 +#define ION_USER_CONTIG_HEAP_ID 26 +/** + * Flags to be used when allocating from the secure heap for + * content protection + */ +#define ION_FLAG_CP_TOUCH ION_BIT(17) +#define ION_FLAG_CP_BITSTREAM ION_BIT(18) +#define ION_FLAG_CP_PIXEL ION_BIT(19) +#define ION_FLAG_CP_NON_PIXEL ION_BIT(20) +#define ION_FLAG_CP_CAMERA ION_BIT(21) +#define ION_FLAG_CP_HLOS ION_BIT(22) +#define ION_FLAG_CP_SPSS_SP ION_BIT(23) +#define ION_FLAG_CP_SPSS_SP_SHARED ION_BIT(24) +#define ION_FLAG_CP_SEC_DISPLAY ION_BIT(25) +#define ION_FLAG_CP_APP ION_BIT(26) +#define ION_FLAG_CP_CAMERA_PREVIEW ION_BIT(27) +/* ION_FLAG_ALLOW_NON_CONTIG uses ION_BIT(28) */ +#define ION_FLAG_CP_CDSP ION_BIT(29) +#define ION_FLAG_CP_SPSS_HLOS_SHARED ION_BIT(30) + +#define ION_FLAGS_CP_MASK 0x6FFE0000 + +/** + * Flag to allow non continguous allocation of memory from secure + * heap + */ +#define ION_FLAG_ALLOW_NON_CONTIG ION_BIT(28) + +/** + * Flag to use when allocating to indicate that a heap is secure. + * Do NOT use BIT macro since it is defined in #ifdef __KERNEL__ + */ +#define ION_FLAG_SECURE ION_BIT(ION_HEAP_ID_RESERVED) + +/* + * Used in conjunction with heap which pool memory to force an allocation + * to come from the page allocator directly instead of from the pool allocation + */ +#define ION_FLAG_POOL_FORCE_ALLOC ION_BIT(16) + +/** + * Macro should be used with ion_heap_ids defined above. + */ +#define ION_HEAP(bit) ION_BIT(bit) + +#define ION_IOC_MSM_MAGIC 'M' + +struct ion_prefetch_regions { + __u64 sizes; + __u32 vmid; + __u32 nr_sizes; +}; + +struct ion_prefetch_data { + __u64 len; + __u64 regions; + __u32 heap_id; + __u32 nr_regions; +}; + +#define ION_IOC_PREFETCH _IOWR(ION_IOC_MSM_MAGIC, 3, \ + struct ion_prefetch_data) + +#define ION_IOC_DRAIN _IOWR(ION_IOC_MSM_MAGIC, 4, \ + struct ion_prefetch_data) + +#endif /* _UAPI_LINUX_MSM_ION_H */