View previous topic :: View next topic |
Author |
Message |
gexcite Tux's lil' helper
Joined: 24 Sep 2005 Posts: 116
|
Posted: Sat Oct 22, 2016 8:26 pm Post subject: Dirty COW |
|
|
Patch dla gentoo-sources-4.4.21 - gdyby ktoś potrzebował
U mnie działa
Code: |
diff -ruN a/include/linux/mm.h b/include/linux/mm.h
--- a/include/linux/mm.h 2016-10-22 21:50:23.000000000 +0200
+++ b/include/linux/mm.h 2016-10-22 22:07:45.853359937 +0200
@@ -2111,6 +2111,7 @@
#define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */
#define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */
#define FOLL_MLOCK 0x1000 /* lock present pages */
+#define FOLL_COW 0x4000 /* internal GUP flag */
typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
void *data);
diff -ruN a/mm/gup.c b/mm/gup.c
--- a/mm/gup.c 2016-01-11 00:01:32.000000000 +0100
+++ b/mm/gup.c 2016-10-22 22:12:01.131750073 +0200
@@ -58,6 +58,16 @@
return -EEXIST;
}
+/*
+ * FOLL_FORCE can write to even unwritable pte's, but only
+ * after we've gone through a COW cycle and they are dirty.
+ */
+static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
+{
+ return pte_write(pte) ||
+ ((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte));
+}
+
static struct page *follow_page_pte(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmd, unsigned int flags)
{
@@ -92,7 +102,7 @@
}
if ((flags & FOLL_NUMA) && pte_protnone(pte))
goto no_page;
- if ((flags & FOLL_WRITE) && !pte_write(pte)) {
+ if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, flags)) {
pte_unmap_unlock(ptep, ptl);
return NULL;
}
@@ -352,7 +362,7 @@
* reCOWed by userspace write).
*/
if ((ret & VM_FAULT_WRITE) && !(vma->vm_flags & VM_WRITE))
- *flags &= ~FOLL_WRITE;
+ *flags |= FOLL_COW;
return 0;
}
|
|
|
Back to top |
|
|
sebas86 Guru
Joined: 01 May 2005 Posts: 570 Location: Szczecinek / Szczecin
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|