From 878cf94a7a17bf57b9cd24d256e967c9df8f3d5f Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Thu, 23 Jan 2020 21:55:49 -0800 Subject: [PATCH 1/2] ion: msm: Add support for querying the security state of heaps ION clients may want to know about the security state of a heap prior to allocating from it, so expose an interface for querying the security state of a heap. Change-Id: Ibf832792ffbc81b5b96b8ddbc507db5418a47928 Signed-off-by: Isaac J. Manjarres --- drivers/staging/android/ion/heaps/msm_ion.c | 15 ++++++++++++++- include/linux/msm_ion.h | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/ion/heaps/msm_ion.c b/drivers/staging/android/ion/heaps/msm_ion.c index ab84b2f2a5c6..a8e5ba75c804 100644 --- a/drivers/staging/android/ion/heaps/msm_ion.c +++ b/drivers/staging/android/ion/heaps/msm_ion.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. */ #include @@ -229,6 +229,19 @@ struct device *msm_ion_heap_device_by_id(int heap_id) } EXPORT_SYMBOL(msm_ion_heap_device_by_id); +bool msm_ion_heap_is_secure(int heap_id) +{ + struct ion_heap *heap = ion_heap_by_id(heap_id); + + if (IS_ERR(heap) || !(heap->type == ION_HEAP_TYPE_SECURE_CARVEOUT || + heap->type == ION_HEAP_TYPE_SYSTEM_SECURE || + heap->type == ION_HEAP_TYPE_HYP_CMA)) + return false; + + return true; +} +EXPORT_SYMBOL(msm_ion_heap_is_secure); + int msm_ion_heap_prefetch(int heap_id, struct ion_prefetch_region *regions, int nr_regions) { diff --git a/include/linux/msm_ion.h b/include/linux/msm_ion.h index 8be7ded32e5d..76f9b24f608e 100644 --- a/include/linux/msm_ion.h +++ b/include/linux/msm_ion.h @@ -37,6 +37,8 @@ int msm_ion_heap_drain(int heap_id, struct ion_prefetch_region *regions, int get_ion_flags(u32 vmid); +bool msm_ion_heap_is_secure(int heap_id); + #else static inline struct device *msm_ion_heap_device_by_id(int heap_id) @@ -74,5 +76,10 @@ static inline int get_ion_flags(u32 vmid) return -EINVAL; } +static inline bool msm_ion_heap_is_secure(int heap_id) +{ + return false; +} + #endif /* CONFIG_ION_MSM_HEAPS */ #endif /* _MSM_ION_H */ From 0585fb44529544bc47740fb196330de30bba8ef0 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Thu, 6 Feb 2020 13:42:59 -0800 Subject: [PATCH 2/2] ion: msm: Add support for addition/removal of memory to ION heaps There is currently no interface for adding/removing memory to an ION heap, so add one. Change-Id: I68061feca3c29cd8f2370665f40f8005fb8765ff Signed-off-by: Isaac J. Manjarres --- drivers/staging/android/ion/heaps/msm_ion.c | 34 +++++++++++++++++++ .../staging/android/ion/heaps/msm_ion_priv.h | 9 ++++- include/linux/msm_ion.h | 15 ++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/ion/heaps/msm_ion.c b/drivers/staging/android/ion/heaps/msm_ion.c index a8e5ba75c804..0be995f17f53 100644 --- a/drivers/staging/android/ion/heaps/msm_ion.c +++ b/drivers/staging/android/ion/heaps/msm_ion.c @@ -280,6 +280,40 @@ int msm_ion_heap_drain(int heap_id, struct ion_prefetch_region *regions, } EXPORT_SYMBOL(msm_ion_heap_drain); +int msm_ion_heap_add_memory(int heap_id, struct sg_table *sgt) +{ + struct ion_heap *heap = ion_heap_by_id(heap_id); + struct msm_ion_heap *msm_heap; + + if (IS_ERR(heap)) + return PTR_ERR(heap); + + msm_heap = to_msm_ion_heap(heap); + + if (msm_heap->msm_heap_ops && msm_heap->msm_heap_ops->add_memory) + return msm_heap->msm_heap_ops->add_memory(heap, sgt); + + return -ENOTSUPP; +} +EXPORT_SYMBOL(msm_ion_heap_add_memory); + +int msm_ion_heap_remove_memory(int heap_id, struct sg_table *sgt) +{ + struct ion_heap *heap = ion_heap_by_id(heap_id); + struct msm_ion_heap *msm_heap; + + if (IS_ERR(heap)) + return PTR_ERR(heap); + + msm_heap = to_msm_ion_heap(heap); + + if (msm_heap->msm_heap_ops && msm_heap->msm_heap_ops->remove_memory) + return msm_heap->msm_heap_ops->remove_memory(heap, sgt); + + return -ENOTSUPP; +} +EXPORT_SYMBOL(msm_ion_heap_remove_memory); + static int msm_ion_get_heap_type_from_dt_node(struct device_node *node, int *heap_type) { diff --git a/drivers/staging/android/ion/heaps/msm_ion_priv.h b/drivers/staging/android/ion/heaps/msm_ion_priv.h index ee44a54c388a..96dcdb91d53d 100644 --- a/drivers/staging/android/ion/heaps/msm_ion_priv.h +++ b/drivers/staging/android/ion/heaps/msm_ion_priv.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright (C) 2011 Google, Inc. - * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved. */ #ifndef _MSM_ION_PRIV_H @@ -87,6 +87,11 @@ struct ion_platform_heap { * @heap_drain: called to asynchronously drain a certain amount of * memory that was prefetched for the heap at an earlier * point in time. + * @add_memory: called to add memory to an ION heap. Subsequent + * allocations may be satisfied utilizing newly added + * memory. + * @remove_memory: called to remove memory from an ION heap. Subsequent + * allocations will fail if the heap no longer has memory. * @debug_show: called when the heap debug file is read to add any heap * specific debug info to output */ @@ -97,6 +102,8 @@ struct msm_ion_heap_ops { int (*heap_drain)(struct ion_heap *heap, struct ion_prefetch_region *regions, int nr_regions); + int (*add_memory)(struct ion_heap *heap, struct sg_table *sgt); + int (*remove_memory)(struct ion_heap *heap, struct sg_table *sgt); int (*debug_show)(struct ion_heap *heap, struct seq_file *s, void *unused); }; diff --git a/include/linux/msm_ion.h b/include/linux/msm_ion.h index 76f9b24f608e..743840ace66b 100644 --- a/include/linux/msm_ion.h +++ b/include/linux/msm_ion.h @@ -8,6 +8,7 @@ #include #include +#include #include struct ion_prefetch_region { @@ -39,6 +40,10 @@ int get_ion_flags(u32 vmid); bool msm_ion_heap_is_secure(int heap_id); +int msm_ion_heap_add_memory(int heap_id, struct sg_table *sgt); + +int msm_ion_heap_remove_memory(int heap_id, struct sg_table *sgt); + #else static inline struct device *msm_ion_heap_device_by_id(int heap_id) @@ -81,5 +86,15 @@ static inline bool msm_ion_heap_is_secure(int heap_id) return false; } +static inline int msm_ion_heap_add_memory(int heap_id, struct sg_table *sgt) +{ + return -ENODEV; +} + +static inline int msm_ion_heap_remove_memory(int heap_id, struct sg_table *sgt) +{ + return -ENODEV; +} + #endif /* CONFIG_ION_MSM_HEAPS */ #endif /* _MSM_ION_H */