aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/mm.h2
-rw-r--r--mm/internal.h1
-rw-r--r--mm/memory.c43
3 files changed, 14 insertions, 32 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index e41795bba95d..45ee5b5a343d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1231,7 +1231,7 @@ struct page *follow_page(struct vm_area_struct *, unsigned long address,
1231#define FOLL_WRITE 0x01 /* check pte is writable */ 1231#define FOLL_WRITE 0x01 /* check pte is writable */
1232#define FOLL_TOUCH 0x02 /* mark page accessed */ 1232#define FOLL_TOUCH 0x02 /* mark page accessed */
1233#define FOLL_GET 0x04 /* do get_page on page */ 1233#define FOLL_GET 0x04 /* do get_page on page */
1234#define FOLL_ANON 0x08 /* give ZERO_PAGE if no pgtable */ 1234#define FOLL_DUMP 0x08 /* give error on hole if it would be zero */
1235 1235
1236typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr, 1236typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
1237 void *data); 1237 void *data);
diff --git a/mm/internal.h b/mm/internal.h
index 166765cd58d6..d41475078b20 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -252,6 +252,7 @@ static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
252 252
253#define GUP_FLAGS_WRITE 0x01 253#define GUP_FLAGS_WRITE 0x01
254#define GUP_FLAGS_FORCE 0x02 254#define GUP_FLAGS_FORCE 0x02
255#define GUP_FLAGS_DUMP 0x04
255 256
256int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 257int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
257 unsigned long start, int len, int flags, 258 unsigned long start, int len, int flags,
diff --git a/mm/memory.c b/mm/memory.c
index a8430ff13837..532a55bce6a4 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1174,41 +1174,22 @@ no_page:
1174 pte_unmap_unlock(ptep, ptl); 1174 pte_unmap_unlock(ptep, ptl);
1175 if (!pte_none(pte)) 1175 if (!pte_none(pte))
1176 return page; 1176 return page;
1177 /* Fall through to ZERO_PAGE handling */ 1177
1178no_page_table: 1178no_page_table:
1179 /* 1179 /*
1180 * When core dumping an enormous anonymous area that nobody 1180 * When core dumping an enormous anonymous area that nobody
1181 * has touched so far, we don't want to allocate page tables. 1181 * has touched so far, we don't want to allocate unnecessary pages or
1182 * page tables. Return error instead of NULL to skip handle_mm_fault,
1183 * then get_dump_page() will return NULL to leave a hole in the dump.
1184 * But we can only make this optimization where a hole would surely
1185 * be zero-filled if handle_mm_fault() actually did handle it.
1182 */ 1186 */
1183 if (flags & FOLL_ANON) { 1187 if ((flags & FOLL_DUMP) &&
1184 page = ZERO_PAGE(0); 1188 (!vma->vm_ops || !vma->vm_ops->fault))
1185 if (flags & FOLL_GET) 1189 return ERR_PTR(-EFAULT);
1186 get_page(page);
1187 BUG_ON(flags & FOLL_WRITE);
1188 }
1189 return page; 1190 return page;
1190} 1191}
1191 1192
1192/* Can we do the FOLL_ANON optimization? */
1193static inline int use_zero_page(struct vm_area_struct *vma)
1194{
1195 /*
1196 * We don't want to optimize FOLL_ANON for make_pages_present()
1197 * when it tries to page in a VM_LOCKED region. As to VM_SHARED,
1198 * we want to get the page from the page tables to make sure
1199 * that we serialize and update with any other user of that
1200 * mapping.
1201 */
1202 if (vma->vm_flags & (VM_LOCKED | VM_SHARED))
1203 return 0;
1204 /*
1205 * And if we have a fault routine, it's not an anonymous region.
1206 */
1207 return !vma->vm_ops || !vma->vm_ops->fault;
1208}
1209
1210
1211
1212int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 1193int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1213 unsigned long start, int nr_pages, int flags, 1194 unsigned long start, int nr_pages, int flags,
1214 struct page **pages, struct vm_area_struct **vmas) 1195 struct page **pages, struct vm_area_struct **vmas)
@@ -1288,8 +1269,8 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1288 foll_flags = FOLL_TOUCH; 1269 foll_flags = FOLL_TOUCH;
1289 if (pages) 1270 if (pages)
1290 foll_flags |= FOLL_GET; 1271 foll_flags |= FOLL_GET;
1291 if (!write && use_zero_page(vma)) 1272 if (flags & GUP_FLAGS_DUMP)
1292 foll_flags |= FOLL_ANON; 1273 foll_flags |= FOLL_DUMP;
1293 1274
1294 do { 1275 do {
1295 struct page *page; 1276 struct page *page;
@@ -1446,7 +1427,7 @@ struct page *get_dump_page(unsigned long addr)
1446 struct page *page; 1427 struct page *page;
1447 1428
1448 if (__get_user_pages(current, current->mm, addr, 1, 1429 if (__get_user_pages(current, current->mm, addr, 1,
1449 GUP_FLAGS_FORCE, &page, &vma) < 1) 1430 GUP_FLAGS_FORCE | GUP_FLAGS_DUMP, &page, &vma) < 1)
1450 return NULL; 1431 return NULL;
1451 if (page == ZERO_PAGE(0)) { 1432 if (page == ZERO_PAGE(0)) {
1452 page_cache_release(page); 1433 page_cache_release(page);