From 1e691b71e028c10661de813534a719ec56134895 Mon Sep 17 00:00:00 2001 From: David Cohen Date: Wed, 19 Oct 2011 15:41:04 +0300 Subject: [PATCH] [PORT FROM R2] atomisp: avoid concurrent access of hrt_isp_css_mm_set_user_ptr() BZ: 17272 Function hrt_isp_css_mm_alloc() depends on global variables set by hrt_isp_css_mm_set_user_ptr() which creates need to use both functions in sequence by same user. As accel API uses it concurrently with atomisp_qbuf(), it causes a possible racing condition between both. This patch creates a new way to call hrt_isp_css_mm_alloc() without needing to set global variables. Accel API makes use of this new way avoiding the possible racing condition. Change-Id: If8f4c1bb60e647b1973856ebdd1ea3a7e31648b6 Orig-Change-Id: I16e59afb336c395392fa3fca899d58a690875eb2 Signed-off-by: David Cohen Reviewed-on: http://android.intel.com:8080/23196 Tested-by: Koski, Anttu Reviewed-by: Gupta, Lokesh Reviewed-by: Koski, Anttu Reviewed-by: Wang, Wen W Reviewed-by: Le Thenaff, Erwan Reviewed-by: buildbot Tested-by: buildbot Reviewed-on: http://android.intel.com:8080/27990 Reviewed-by: Tuominen, TeemuX --- drivers/media/video/atomisp/atomisp_cmd.c | 5 ++--- .../video/atomisp/css/hrt/hive_isp_css_mm_hrt.h | 2 ++ .../media/video/atomisp/hrt/hive_isp_css_mm_hrt.c | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/media/video/atomisp/atomisp_cmd.c b/drivers/media/video/atomisp/atomisp_cmd.c index 6ff3453..e286ea4 100644 --- a/drivers/media/video/atomisp/atomisp_cmd.c +++ b/drivers/media/video/atomisp/atomisp_cmd.c @@ -3531,9 +3531,8 @@ int atomisp_acc_set_arg(struct atomisp_device *isp, pgnr = (size + (PAGE_SIZE - 1)) >> PAGE_SHIFT; mutex_lock(&isp->isp_lock); - hrt_isp_css_mm_set_user_ptr((unsigned int)fw_arg->value, pgnr); - frame_ptr = hrt_isp_css_mm_alloc(size); - hrt_isp_css_mm_set_user_ptr(0, 0); + frame_ptr = hrt_isp_css_mm_alloc_user_ptr(size, + (unsigned int)fw_arg->value, pgnr); mutex_unlock(&isp->isp_lock); if (IS_ERR_OR_NULL(frame_ptr)) { diff --git a/drivers/media/video/atomisp/css/hrt/hive_isp_css_mm_hrt.h b/drivers/media/video/atomisp/css/hrt/hive_isp_css_mm_hrt.h index 58cf772..bbe7ba1 100644 --- a/drivers/media/video/atomisp/css/hrt/hive_isp_css_mm_hrt.h +++ b/drivers/media/video/atomisp/css/hrt/hive_isp_css_mm_hrt.h @@ -34,6 +34,8 @@ int hrt_isp_css_mm_set(void *virt_addr, int c, size_t bytes); /* Allocate memory, returns a virtual address */ void *hrt_isp_css_mm_alloc(size_t bytes); +void *hrt_isp_css_mm_alloc_user_ptr(size_t bytes, unsigned int userptr, + unsigned int num_pages); void *hrt_isp_css_mm_alloc_cached(size_t bytes); /* allocate memory and initialize with zeros, diff --git a/drivers/media/video/atomisp/hrt/hive_isp_css_mm_hrt.c b/drivers/media/video/atomisp/hrt/hive_isp_css_mm_hrt.c index daa076d..c6583fe 100644 --- a/drivers/media/video/atomisp/hrt/hive_isp_css_mm_hrt.c +++ b/drivers/media/video/atomisp/hrt/hive_isp_css_mm_hrt.c @@ -81,29 +81,41 @@ void hrt_isp_css_mm_set_user_ptr(unsigned int userptr, unsigned int num_pages) my_num_pages = num_pages; } -void *hrt_isp_css_mm_alloc(size_t bytes) +static void *__hrt_isp_css_mm_alloc(size_t bytes, unsigned int userptr, + unsigned int num_pages) { if (!init_done) hrt_isp_css_mm_init(); - if (my_userptr == 0) + if (userptr == 0) return (void *)hmm_alloc(bytes, HMM_BO_PRIVATE, 0, 0, HMM_UNCACHED); else { - if (my_num_pages < ((__page_align(bytes)) >> PAGE_SHIFT)) + if (num_pages < ((__page_align(bytes)) >> PAGE_SHIFT)) v4l2_err(&atomisp_dev, "user space memory size is less" " than the expected size..\n"); - else if (my_num_pages > ((__page_align(bytes)) >> PAGE_SHIFT)) + else if (num_pages > ((__page_align(bytes)) >> PAGE_SHIFT)) v4l2_err(&atomisp_dev, "user space memory size is" " large than the expected size..\n"); return (void *)hmm_alloc(bytes, HMM_BO_USER, 0, - my_userptr, HMM_UNCACHED); + userptr, HMM_UNCACHED); } } +void *hrt_isp_css_mm_alloc(size_t bytes) +{ + return __hrt_isp_css_mm_alloc(bytes, my_userptr, my_num_pages); +} + +void *hrt_isp_css_mm_alloc_user_ptr(size_t bytes, unsigned int userptr, + unsigned int num_pages) +{ + return __hrt_isp_css_mm_alloc(bytes, userptr, num_pages); +} + void *hrt_isp_css_mm_alloc_cached(size_t bytes) { if (!init_done) -- 2.7.4