Skip to content

Commit

Permalink
Merge iov-extract-base onto cifs/for-next
Browse files Browse the repository at this point in the history
Merge the two commits to provide iov_iter_extract_pages() onto the for-next
branch of git.samba.org/sfrench/cifs-2.6.git to use as a base for my
iteratorisation-of-cifs patches.

Signed-off-by: David Howells <dhowells@redhat.com>
  • Loading branch information
dhowells committed Jan 31, 2023
2 parents fea27f5 + 895d773 commit 153c046
Show file tree
Hide file tree
Showing 4 changed files with 369 additions and 15 deletions.
6 changes: 3 additions & 3 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,11 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page,
*/
static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
{
iov_iter_extraction_t extraction_flags = 0;
unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt;
unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt;
struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt;
struct page **pages = (struct page **)bv;
unsigned int gup_flags = 0;
ssize_t size, left;
unsigned len, i = 0;
size_t offset, trim;
Expand All @@ -1264,7 +1264,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
pages += entries_left * (PAGE_PTRS_PER_BVEC - 1);

if (bio->bi_bdev && blk_queue_pci_p2pdma(bio->bi_bdev->bd_disk->queue))
gup_flags |= FOLL_PCI_P2PDMA;
extraction_flags |= ITER_ALLOW_P2PDMA;

/*
* Each segment in the iov is required to be a block size multiple.
Expand All @@ -1275,7 +1275,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
*/
size = iov_iter_get_pages(iter, pages,
UINT_MAX - bio->bi_iter.bi_size,
nr_pages, &offset, gup_flags);
nr_pages, &offset, extraction_flags);
if (unlikely(size <= 0))
return size ? size : -EFAULT;

Expand Down
8 changes: 4 additions & 4 deletions block/blk-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ static struct bio *blk_rq_map_bio_alloc(struct request *rq,
static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
gfp_t gfp_mask)
{
iov_iter_extraction_t extraction_flags = 0;
unsigned int max_sectors = queue_max_hw_sectors(rq->q);
unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS);
unsigned int gup_flags = 0;
struct bio *bio;
int ret;
int j;
Expand All @@ -280,7 +280,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
return -ENOMEM;

if (blk_queue_pci_p2pdma(rq->q))
gup_flags |= FOLL_PCI_P2PDMA;
extraction_flags |= ITER_ALLOW_P2PDMA;

while (iov_iter_count(iter)) {
struct page **pages, *stack_pages[UIO_FASTIOV];
Expand All @@ -291,10 +291,10 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
if (nr_vecs <= ARRAY_SIZE(stack_pages)) {
pages = stack_pages;
bytes = iov_iter_get_pages(iter, pages, LONG_MAX,
nr_vecs, &offs, gup_flags);
nr_vecs, &offs, extraction_flags);
} else {
bytes = iov_iter_get_pages_alloc(iter, &pages,
LONG_MAX, &offs, gup_flags);
LONG_MAX, &offs, extraction_flags);
}
if (unlikely(bytes <= 0)) {
ret = bytes ? bytes : -EFAULT;
Expand Down
35 changes: 33 additions & 2 deletions include/linux/uio.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
struct page;
struct pipe_inode_info;

typedef unsigned int __bitwise iov_iter_extraction_t;

struct kvec {
void *iov_base; /* and that should *never* hold a userland pointer */
size_t iov_len;
Expand Down Expand Up @@ -252,12 +254,12 @@ void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray *
loff_t start, size_t count);
ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages,
size_t maxsize, unsigned maxpages, size_t *start,
unsigned gup_flags);
iov_iter_extraction_t extraction_flags);
ssize_t iov_iter_get_pages2(struct iov_iter *i, struct page **pages,
size_t maxsize, unsigned maxpages, size_t *start);
ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
struct page ***pages, size_t maxsize, size_t *start,
unsigned gup_flags);
iov_iter_extraction_t extraction_flags);
ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i, struct page ***pages,
size_t maxsize, size_t *start);
int iov_iter_npages(const struct iov_iter *i, int maxpages);
Expand Down Expand Up @@ -359,5 +361,34 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction,
.count = count
};
}
/* Flags for iov_iter_get/extract_pages*() */
/* Allow P2PDMA on the extracted pages */
#define ITER_ALLOW_P2PDMA ((__force iov_iter_extraction_t)0x01)

ssize_t iov_iter_extract_pages(struct iov_iter *i, struct page ***pages,
size_t maxsize, unsigned int maxpages,
iov_iter_extraction_t extraction_flags,
size_t *offset0);

/**
* iov_iter_extract_will_pin - Indicate how pages from the iterator will be retained
* @iter: The iterator
*
* Examine the iterator and indicate by returning true or false as to how, if
* at all, pages extracted from the iterator will be retained by the extraction
* function.
*
* %true indicates that the pages will have a pin placed in them that the
* caller must unpin. This is must be done for DMA/async DIO to force fork()
* to forcibly copy a page for the child (the parent must retain the original
* page).
*
* %false indicates that no measures are taken and that it's up to the caller
* to retain the pages.
*/
static inline bool iov_iter_extract_will_pin(const struct iov_iter *iter)
{
return user_backed_iter(iter);
}

#endif

0 comments on commit 153c046

Please sign in to comment.