[PORT FROM R2] atomisp: avoid concurrent access of hrt_isp_css_mm_set_user_ptr()
authorDavid Cohen <david.a.cohen@intel.com>
Wed, 19 Oct 2011 12:41:04 +0000 (15:41 +0300)
committerbuildbot <buildbot@intel.com>
Mon, 19 Dec 2011 13:27:32 +0000 (05:27 -0800)
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 <david.a.cohen@intel.com>
Reviewed-on: http://android.intel.com:8080/23196
Tested-by: Koski, Anttu <anttu.koski@intel.com>
Reviewed-by: Gupta, Lokesh <lokesh.gupta@intel.com>
Reviewed-by: Koski, Anttu <anttu.koski@intel.com>
Reviewed-by: Wang, Wen W <wen.w.wang@intel.com>
Reviewed-by: Le Thenaff, Erwan <erwan.le.thenaff@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Reviewed-on: http://android.intel.com:8080/27990
Reviewed-by: Tuominen, TeemuX <teemux.tuominen@intel.com>
drivers/media/video/atomisp/atomisp_cmd.c
drivers/media/video/atomisp/css/hrt/hive_isp_css_mm_hrt.h
drivers/media/video/atomisp/hrt/hive_isp_css_mm_hrt.c

index 6ff3453..e286ea4 100644 (file)
@@ -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)) {
index 58cf772..bbe7ba1 100644 (file)
@@ -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,
index daa076d..c6583fe 100644 (file)
@@ -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)