ion: Handle the memory mapping correctly on x86
authorVinil Cheeramvelil <vinil.cheeramvelil@intel.com>
Wed, 8 Jul 2015 02:35:06 +0000 (10:35 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 27 Oct 2015 08:42:39 +0000 (16:42 +0800)
This patch modifies the ion page pool code to address
limitation in x86 PAT. When one physical page is mapped
to multiple virtual pages, the same cache policy
should be used. Add set_memory_wc/uc call to avoid aliases.
If not, all mappings will be cached(write back).

Change-Id: I98ee8902df0c80135dddfa998c4ca4c2bb44e40e
Signed-off-by: Zhebin Jin <zhebin.jin@intel.com>
Signed-off-by: Vinil Cheeramvelil <vinil.cheeramvelil@intel.com>
(cherry picked from commit 6db47cc7e2f1d8dd8fc84912202ed749d6781a76)

Conflicts:
drivers/staging/android/ion/Kconfig
drivers/staging/android/ion/ion_priv.h

drivers/staging/android/ion/Kconfig
drivers/staging/android/ion/ion_page_pool.c
drivers/staging/android/ion/ion_priv.h
drivers/staging/android/ion/ion_system_heap.c

index 521aa75270d0d32a3b5df84294fd023ba818fd68..6e48876befab267d16efc6423120793ea4bca98d 100644 (file)
@@ -64,3 +64,11 @@ config ION_SNAPSHOT_BUF_SHIFT
          Select ION snapshot buffer size as a power of 2
 
 endif
+
+config ION_POOL_CACHE_POLICY
+       bool "Ion set page pool cache policy"
+       depends on ION
+       default y if X86
+       help
+         Choose this option if need to explicity set cache policy of the
+         pages in the page pool.
index e3f651cd8a8601b0d131b1cc868a112463a66be3..e7b63486368298d9103960caeffec989cf2f179e 100644 (file)
@@ -34,6 +34,8 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool)
 
        if (!page)
                return NULL;
+       ion_page_pool_alloc_set_cache_policy(pool, page);
+
        ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order,
                                                DMA_BIDIRECTIONAL);
        return page;
@@ -42,6 +44,7 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool)
 static void ion_page_pool_free_pages(struct ion_page_pool *pool,
                                     struct page *page)
 {
+       ion_page_pool_free_set_cache_policy(pool, page);
        __free_pages(page, pool->order);
 }
 
@@ -117,6 +120,11 @@ void ion_page_pool_free(struct ion_page_pool *pool, struct page *page)
                ion_page_pool_free_pages(pool, page);
 }
 
+void ion_page_pool_free_immediate(struct ion_page_pool *pool, struct page *page)
+{
+       ion_page_pool_free_pages(pool, page);
+}
+
 static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
 {
        int total = 0;
index aaac72219b24d446de34d7a155a4100fc515f8a9..6c490e2ec5d1309cb27f846782fc0bda677b3726 100755 (executable)
@@ -26,7 +26,9 @@
 #include <linux/sched.h>
 #include <linux/shrinker.h>
 #include <linux/types.h>
-#include <linux/device.h>
+#ifdef CONFIG_ION_POOL_CACHE_POLICY
+#include <asm/cacheflush.h>
+#endif
 
 #include "ion.h"
 
@@ -417,6 +419,37 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order);
 void ion_page_pool_destroy(struct ion_page_pool *);
 void *ion_page_pool_alloc(struct ion_page_pool *);
 void ion_page_pool_free(struct ion_page_pool *, struct page *);
+void ion_page_pool_free_immediate(struct ion_page_pool *, struct page *);
+
+#ifdef CONFIG_ION_POOL_CACHE_POLICY
+static inline void ion_page_pool_alloc_set_cache_policy
+                               (struct ion_page_pool *pool,
+                               struct page *page){
+       void *va = page_address(page);
+
+       if (va)
+               set_memory_wc((unsigned long)va, 1 << pool->order);
+}
+
+static inline void ion_page_pool_free_set_cache_policy
+                               (struct ion_page_pool *pool,
+                               struct page *page){
+       void *va = page_address(page);
+
+       if (va)
+               set_memory_wb((unsigned long)va, 1 << pool->order);
+
+}
+#else
+static inline void ion_page_pool_alloc_set_cache_policy
+                               (struct ion_page_pool *pool,
+                               struct page *page){ }
+
+static inline void ion_page_pool_free_set_cache_policy
+                               (struct ion_page_pool *pool,
+                               struct page *page){ }
+#endif
+
 
 /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool
  * @pool:              the pool
index 2476b0358d11bf735c9763b027047ca4e88ca0ed..ac874fe6fd9603b63ae6de96dd9460d589865aad 100755 (executable)
@@ -92,10 +92,12 @@ static void free_buffer_page(struct ion_system_heap *heap,
 {
        bool cached = ion_buffer_cached(buffer);
 
-       if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)) {
+       if (!cached) {
                struct ion_page_pool *pool = heap->pools[order_to_index(order)];
-
-               ion_page_pool_free(pool, page);
+               if (buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)
+                       ion_page_pool_free_immediate(pool, page);
+               else
+                       ion_page_pool_free(pool, page);
        } else {
                __free_pages(page, order);
        }