hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings
[linux-2.6-microblaze.git] / include / linux / mm.h
index 77e64e3..64a71bf 100644 (file)
@@ -1300,6 +1300,27 @@ static inline bool page_maybe_dma_pinned(struct page *page)
                GUP_PIN_COUNTING_BIAS;
 }
 
+static inline bool is_cow_mapping(vm_flags_t flags)
+{
+       return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
+}
+
+/*
+ * This should most likely only be called during fork() to see whether we
+ * should break the cow immediately for a page on the src mm.
+ */
+static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
+                                         struct page *page)
+{
+       if (!is_cow_mapping(vma->vm_flags))
+               return false;
+
+       if (!atomic_read(&vma->vm_mm->has_pinned))
+               return false;
+
+       return page_maybe_dma_pinned(page);
+}
+
 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
 #define SECTION_IN_PAGE_FLAGS
 #endif