History

x86, mm: unify exit paths in gup_pte_range()

All exit paths from gup_pte_range() require pte_unmap() of the original pte page before returning. Refactor the code to have a single exit point to do the unmap. This mirrors the flow of the generic gup_pte_range() in mm/gup.c.

Dan Williams committed 9 years ago

Commit b2e593e1 parent ef947b21 file · +20 −19Browse files

Unified · Split

arch/x86/mm/gup.c+20−19
@@ -106,36 +106,35 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr, · 105 unmodified lines
106106 unsigned long end, int write, struct page **pages, int *nr)
107107 {
108108 struct dev_pagemap *pgmap = NULL;
109− int nr_start = *nr;
110− pte_t *ptep;
109+ int nr_start = *nr, ret = 0;
110+ pte_t *ptep, *ptem;
111111
112− ptep = pte_offset_map(&pmd, addr);
112+ /*
113+ * Keep the original mapped PTE value (ptem) around since we
114+ * might increment ptep off the end of the page when finishing
115+ * our loop iteration.
116+ */
117+ ptem = ptep = pte_offset_map(&pmd, addr);
113118 do {
114119 pte_t pte = gup_get_pte(ptep);
115120 struct page *page;
116121
117122 /* Similar to the PMD case, NUMA hinting must take slow path */
118− if (pte_protnone(pte)) {
119− pte_unmap(ptep);
120− return 0;
121− }
123+ if (pte_protnone(pte))
124+ break;
122125
123− if (!pte_allows_gup(pte_val(pte), write)) {
124− pte_unmap(ptep);
125− return 0;
126− }
126+ if (!pte_allows_gup(pte_val(pte), write))
127+ break;
127128
128129 if (pte_devmap(pte)) {
129130 pgmap = get_dev_pagemap(pte_pfn(pte), pgmap);
130131 if (unlikely(!pgmap)) {
131132 undo_dev_pagemap(nr, nr_start, pages);
132− pte_unmap(ptep);
133− return 0;
133+ break;
134134 }
135− } else if (pte_special(pte)) {
136− pte_unmap(ptep);
137− return 0;
138− }
135+ } else if (pte_special(pte))
136+ break;
137+
139138 VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
140139 page = pte_page(pte);
141140 get_page(page);
@@ -145,9 +144,11 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr, · 3 unmodified lines
145144 (*nr)++;
146145
147146 } while (ptep++, addr += PAGE_SIZE, addr != end);
148− pte_unmap(ptep - 1);
147+ if (addr == end)
148+ ret = 1;
149+ pte_unmap(ptem);
149150
150− return 1;
151+ return ret;
151152 }
152153
153154 static inline void get_head_page_multiple(struct page *page, int nr)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t