Skip to content

Commit 73b0140

Browse files
weiny2torvalds
authored andcommitted
mm/gup: change GUP fast to use flags rather than a write 'bool'
To facilitate additional options to get_user_pages_fast() change the singular write parameter to be gup_flags. This patch does not change any functionality. New functionality will follow in subsequent patches. Some of the get_user_pages_fast() call sites were unchanged because they already passed FOLL_WRITE or 0 for the write parameter. NOTE: It was suggested to change the ordering of the get_user_pages_fast() arguments to ensure that callers were converted. This breaks the current GUP call site convention of having the returned pages be the final parameter. So the suggestion was rejected. Link: http://lkml.kernel.org/r/20190328084422.29911-4-ira.weiny@intel.com Link: http://lkml.kernel.org/r/20190317183438.2057-4-ira.weiny@intel.com Signed-off-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Mike Marshall <hubcap@omnibond.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Hogan <jhogan@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Rich Felker <dalias@libc.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b798bec commit 73b0140

34 files changed

Lines changed: 73 additions & 57 deletions

File tree

‎arch/mips/mm/gup.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
235235
* get_user_pages_fast() - pin user pages in memory
236236
* @start: starting user address
237237
* @nr_pages: number of pages from start to pin
238-
* @write: whether pages will be written to
238+
* @gup_flags: flags modifying pin behaviour
239239
* @pages: array that receives pointers to the pages pinned.
240240
* Should be at least nr_pages long.
241241
*
@@ -247,8 +247,8 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
247247
* requested. If nr_pages is 0 or negative, returns 0. If no pages
248248
* were pinned, returns -errno.
249249
*/
250-
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
251-
struct page **pages)
250+
int get_user_pages_fast(unsigned long start, int nr_pages,
251+
unsigned int gup_flags, struct page **pages)
252252
{
253253
struct mm_struct *mm = current->mm;
254254
unsigned long addr, len, end;
@@ -273,7 +273,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
273273
next = pgd_addr_end(addr, end);
274274
if (pgd_none(pgd))
275275
goto slow;
276-
if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
276+
if (!gup_pud_range(pgd, addr, next, gup_flags & FOLL_WRITE,
277+
pages, &nr))
277278
goto slow;
278279
} while (pgdp++, addr = next, addr != end);
279280
local_irq_enable();
@@ -289,7 +290,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
289290
pages += nr;
290291

291292
ret = get_user_pages_unlocked(start, (end - start) >> PAGE_SHIFT,
292-
pages, write ? FOLL_WRITE : 0);
293+
pages, gup_flags);
293294

294295
/* Have to be a bit careful with return values */
295296
if (nr > 0) {

‎arch/powerpc/kvm/book3s_64_mmu_hv.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
600600
/* If writing != 0, then the HPTE must allow writing, if we get here */
601601
write_ok = writing;
602602
hva = gfn_to_hva_memslot(memslot, gfn);
603-
npages = get_user_pages_fast(hva, 1, writing, pages);
603+
npages = get_user_pages_fast(hva, 1, writing ? FOLL_WRITE : 0, pages);
604604
if (npages < 1) {
605605
/* Check if it's an I/O mapping */
606606
down_read(&current->mm->mmap_sem);
@@ -1193,7 +1193,7 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa,
11931193
if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
11941194
goto err;
11951195
hva = gfn_to_hva_memslot(memslot, gfn);
1196-
npages = get_user_pages_fast(hva, 1, 1, pages);
1196+
npages = get_user_pages_fast(hva, 1, FOLL_WRITE, pages);
11971197
if (npages < 1)
11981198
goto err;
11991199
page = pages[0];

‎arch/powerpc/kvm/e500_mmu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
783783
if (!pages)
784784
return -ENOMEM;
785785

786-
ret = get_user_pages_fast(cfg->array, num_pages, 1, pages);
786+
ret = get_user_pages_fast(cfg->array, num_pages, FOLL_WRITE, pages);
787787
if (ret < 0)
788788
goto free_pages;
789789

‎arch/s390/kvm/interrupt.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,7 @@ static int kvm_s390_adapter_map(struct kvm *kvm, unsigned int id, __u64 addr)
23762376
ret = -EFAULT;
23772377
goto out;
23782378
}
2379-
ret = get_user_pages_fast(map->addr, 1, 1, &map->page);
2379+
ret = get_user_pages_fast(map->addr, 1, FOLL_WRITE, &map->page);
23802380
if (ret < 0)
23812381
goto out;
23822382
BUG_ON(ret != 1);

‎arch/sh/mm/gup.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
204204
* get_user_pages_fast() - pin user pages in memory
205205
* @start: starting user address
206206
* @nr_pages: number of pages from start to pin
207-
* @write: whether pages will be written to
207+
* @gup_flags: flags modifying pin behaviour
208208
* @pages: array that receives pointers to the pages pinned.
209209
* Should be at least nr_pages long.
210210
*
@@ -216,8 +216,8 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
216216
* requested. If nr_pages is 0 or negative, returns 0. If no pages
217217
* were pinned, returns -errno.
218218
*/
219-
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
220-
struct page **pages)
219+
int get_user_pages_fast(unsigned long start, int nr_pages,
220+
unsigned int gup_flags, struct page **pages)
221221
{
222222
struct mm_struct *mm = current->mm;
223223
unsigned long addr, len, end;
@@ -241,7 +241,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
241241
next = pgd_addr_end(addr, end);
242242
if (pgd_none(pgd))
243243
goto slow;
244-
if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
244+
if (!gup_pud_range(pgd, addr, next, gup_flags & FOLL_WRITE,
245+
pages, &nr))
245246
goto slow;
246247
} while (pgdp++, addr = next, addr != end);
247248
local_irq_enable();
@@ -261,7 +262,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
261262

262263
ret = get_user_pages_unlocked(start,
263264
(end - start) >> PAGE_SHIFT, pages,
264-
write ? FOLL_WRITE : 0);
265+
gup_flags);
265266

266267
/* Have to be a bit careful with return values */
267268
if (nr > 0) {

‎arch/sparc/mm/gup.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
245245
return nr;
246246
}
247247

248-
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
249-
struct page **pages)
248+
int get_user_pages_fast(unsigned long start, int nr_pages,
249+
unsigned int gup_flags, struct page **pages)
250250
{
251251
struct mm_struct *mm = current->mm;
252252
unsigned long addr, len, end;
@@ -303,7 +303,8 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
303303
next = pgd_addr_end(addr, end);
304304
if (pgd_none(pgd))
305305
goto slow;
306-
if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
306+
if (!gup_pud_range(pgd, addr, next, gup_flags & FOLL_WRITE,
307+
pages, &nr))
307308
goto slow;
308309
} while (pgdp++, addr = next, addr != end);
309310

@@ -324,7 +325,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
324325

325326
ret = get_user_pages_unlocked(start,
326327
(end - start) >> PAGE_SHIFT, pages,
327-
write ? FOLL_WRITE : 0);
328+
gup_flags);
328329

329330
/* Have to be a bit careful with return values */
330331
if (nr > 0) {

‎arch/x86/kvm/paging_tmpl.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
140140
pt_element_t *table;
141141
struct page *page;
142142

143-
npages = get_user_pages_fast((unsigned long)ptep_user, 1, 1, &page);
143+
npages = get_user_pages_fast((unsigned long)ptep_user, 1, FOLL_WRITE, &page);
144144
/* Check if the user is doing something meaningless. */
145145
if (unlikely(npages != 1))
146146
return -EFAULT;

‎arch/x86/kvm/svm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
18051805
return NULL;
18061806

18071807
/* Pin the user virtual address. */
1808-
npinned = get_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages);
1808+
npinned = get_user_pages_fast(uaddr, npages, FOLL_WRITE, pages);
18091809
if (npinned != npages) {
18101810
pr_err("SEV: Failure locking %lu pages.\n", npages);
18111811
goto err;

‎drivers/fpga/dfl-afu-dma-region.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,
102102
goto unlock_vm;
103103
}
104104

105-
pinned = get_user_pages_fast(region->user_addr, npages, 1,
105+
pinned = get_user_pages_fast(region->user_addr, npages, FOLL_WRITE,
106106
region->pages);
107107
if (pinned < 0) {
108108
ret = pinned;

‎drivers/gpu/drm/via/via_dmablit.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
243243
if (NULL == vsg->pages)
244244
return -ENOMEM;
245245
ret = get_user_pages_fast((unsigned long)xfer->mem_addr,
246-
vsg->num_pages, vsg->direction == DMA_FROM_DEVICE,
246+
vsg->num_pages,
247+
vsg->direction == DMA_FROM_DEVICE ? FOLL_WRITE : 0,
247248
vsg->pages);
248249
if (ret != vsg->num_pages) {
249250
if (ret < 0)

0 commit comments

Comments
 (0)