Skip to content

Commit 9d17855

Browse files
committed
Merge tag 'md-next-20230814-resend' into loongarch-next
LoongArch architecture changes for 6.5 (raid5/6 optimization) depend on the md changes to fix build and work, so merge them to create a base.
2 parents 2dde18c + 0d0bd28 commit 9d17855

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1309
-765
lines changed

block/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
menuconfig BLOCK
66
bool "Enable the block layer" if EXPERT
77
default y
8+
select FS_IOMAP
89
select SBITMAP
910
help
1011
Provide block layer support for the kernel.

block/bio-integrity.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,38 @@ void bio_integrity_free(struct bio *bio)
123123
int bio_integrity_add_page(struct bio *bio, struct page *page,
124124
unsigned int len, unsigned int offset)
125125
{
126+
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
126127
struct bio_integrity_payload *bip = bio_integrity(bio);
127128

128-
if (bip->bip_vcnt >= bip->bip_max_vcnt) {
129-
printk(KERN_ERR "%s: bip_vec full\n", __func__);
129+
if (((bip->bip_iter.bi_size + len) >> SECTOR_SHIFT) >
130+
queue_max_hw_sectors(q))
130131
return 0;
131-
}
132132

133-
if (bip->bip_vcnt &&
134-
bvec_gap_to_prev(&bdev_get_queue(bio->bi_bdev)->limits,
135-
&bip->bip_vec[bip->bip_vcnt - 1], offset))
136-
return 0;
133+
if (bip->bip_vcnt > 0) {
134+
struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1];
135+
bool same_page = false;
136+
137+
if (bvec_try_merge_hw_page(q, bv, page, len, offset,
138+
&same_page)) {
139+
bip->bip_iter.bi_size += len;
140+
return len;
141+
}
142+
143+
if (bip->bip_vcnt >=
144+
min(bip->bip_max_vcnt, queue_max_integrity_segments(q)))
145+
return 0;
146+
147+
/*
148+
* If the queue doesn't support SG gaps and adding this segment
149+
* would create a gap, disallow it.
150+
*/
151+
if (bvec_gap_to_prev(&q->limits, bv, offset))
152+
return 0;
153+
}
137154

138155
bvec_set_page(&bip->bip_vec[bip->bip_vcnt], page, len, offset);
139156
bip->bip_vcnt++;
157+
bip->bip_iter.bi_size += len;
140158

141159
return len;
142160
}
@@ -199,8 +217,6 @@ bool bio_integrity_prep(struct bio *bio)
199217
unsigned long start, end;
200218
unsigned int len, nr_pages;
201219
unsigned int bytes, offset, i;
202-
unsigned int intervals;
203-
blk_status_t status;
204220

205221
if (!bi)
206222
return true;
@@ -224,12 +240,10 @@ bool bio_integrity_prep(struct bio *bio)
224240
!(bi->flags & BLK_INTEGRITY_GENERATE))
225241
return true;
226242
}
227-
intervals = bio_integrity_intervals(bi, bio_sectors(bio));
228243

229244
/* Allocate kernel buffer for protection data */
230-
len = intervals * bi->tuple_size;
245+
len = bio_integrity_bytes(bi, bio_sectors(bio));
231246
buf = kmalloc(len, GFP_NOIO);
232-
status = BLK_STS_RESOURCE;
233247
if (unlikely(buf == NULL)) {
234248
printk(KERN_ERR "could not allocate integrity buffer\n");
235249
goto err_end_io;
@@ -244,41 +258,29 @@ bool bio_integrity_prep(struct bio *bio)
244258
if (IS_ERR(bip)) {
245259
printk(KERN_ERR "could not allocate data integrity bioset\n");
246260
kfree(buf);
247-
status = BLK_STS_RESOURCE;
248261
goto err_end_io;
249262
}
250263

251264
bip->bip_flags |= BIP_BLOCK_INTEGRITY;
252-
bip->bip_iter.bi_size = len;
253265
bip_set_seed(bip, bio->bi_iter.bi_sector);
254266

255267
if (bi->flags & BLK_INTEGRITY_IP_CHECKSUM)
256268
bip->bip_flags |= BIP_IP_CHECKSUM;
257269

258270
/* Map it */
259271
offset = offset_in_page(buf);
260-
for (i = 0 ; i < nr_pages ; i++) {
261-
int ret;
272+
for (i = 0; i < nr_pages && len > 0; i++) {
262273
bytes = PAGE_SIZE - offset;
263274

264-
if (len <= 0)
265-
break;
266-
267275
if (bytes > len)
268276
bytes = len;
269277

270-
ret = bio_integrity_add_page(bio, virt_to_page(buf),
271-
bytes, offset);
272-
273-
if (ret == 0) {
278+
if (bio_integrity_add_page(bio, virt_to_page(buf),
279+
bytes, offset) < bytes) {
274280
printk(KERN_ERR "could not attach integrity payload\n");
275-
status = BLK_STS_RESOURCE;
276281
goto err_end_io;
277282
}
278283

279-
if (ret < bytes)
280-
break;
281-
282284
buf += bytes;
283285
len -= bytes;
284286
offset = 0;
@@ -294,10 +296,9 @@ bool bio_integrity_prep(struct bio *bio)
294296
return true;
295297

296298
err_end_io:
297-
bio->bi_status = status;
299+
bio->bi_status = BLK_STS_RESOURCE;
298300
bio_endio(bio);
299301
return false;
300-
301302
}
302303
EXPORT_SYMBOL(bio_integrity_prep);
303304

block/bio.c

Lines changed: 64 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -606,15 +606,15 @@ struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask)
606606
}
607607
EXPORT_SYMBOL(bio_kmalloc);
608608

609-
void zero_fill_bio(struct bio *bio)
609+
void zero_fill_bio_iter(struct bio *bio, struct bvec_iter start)
610610
{
611611
struct bio_vec bv;
612612
struct bvec_iter iter;
613613

614-
bio_for_each_segment(bv, bio, iter)
614+
__bio_for_each_segment(bv, bio, iter, start)
615615
memzero_bvec(&bv);
616616
}
617-
EXPORT_SYMBOL(zero_fill_bio);
617+
EXPORT_SYMBOL(zero_fill_bio_iter);
618618

619619
/**
620620
* bio_truncate - truncate the bio to small size of @new_size
@@ -903,9 +903,8 @@ static inline bool bio_full(struct bio *bio, unsigned len)
903903
return false;
904904
}
905905

906-
static inline bool page_is_mergeable(const struct bio_vec *bv,
907-
struct page *page, unsigned int len, unsigned int off,
908-
bool *same_page)
906+
static bool bvec_try_merge_page(struct bio_vec *bv, struct page *page,
907+
unsigned int len, unsigned int off, bool *same_page)
909908
{
910909
size_t bv_end = bv->bv_offset + bv->bv_len;
911910
phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + bv_end - 1;
@@ -919,61 +918,26 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
919918
return false;
920919

921920
*same_page = ((vec_end_addr & PAGE_MASK) == page_addr);
922-
if (*same_page)
923-
return true;
924-
else if (IS_ENABLED(CONFIG_KMSAN))
925-
return false;
926-
return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
927-
}
928-
929-
/**
930-
* __bio_try_merge_page - try appending data to an existing bvec.
931-
* @bio: destination bio
932-
* @page: start page to add
933-
* @len: length of the data to add
934-
* @off: offset of the data relative to @page
935-
* @same_page: return if the segment has been merged inside the same page
936-
*
937-
* Try to add the data at @page + @off to the last bvec of @bio. This is a
938-
* useful optimisation for file systems with a block size smaller than the
939-
* page size.
940-
*
941-
* Warn if (@len, @off) crosses pages in case that @same_page is true.
942-
*
943-
* Return %true on success or %false on failure.
944-
*/
945-
static bool __bio_try_merge_page(struct bio *bio, struct page *page,
946-
unsigned int len, unsigned int off, bool *same_page)
947-
{
948-
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
949-
return false;
950-
951-
if (bio->bi_vcnt > 0) {
952-
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
953-
954-
if (page_is_mergeable(bv, page, len, off, same_page)) {
955-
if (bio->bi_iter.bi_size > UINT_MAX - len) {
956-
*same_page = false;
957-
return false;
958-
}
959-
bv->bv_len += len;
960-
bio->bi_iter.bi_size += len;
961-
return true;
962-
}
921+
if (!*same_page) {
922+
if (IS_ENABLED(CONFIG_KMSAN))
923+
return false;
924+
if (bv->bv_page + bv_end / PAGE_SIZE != page + off / PAGE_SIZE)
925+
return false;
963926
}
964-
return false;
927+
928+
bv->bv_len += len;
929+
return true;
965930
}
966931

967932
/*
968933
* Try to merge a page into a segment, while obeying the hardware segment
969934
* size limit. This is not for normal read/write bios, but for passthrough
970935
* or Zone Append operations that we can't split.
971936
*/
972-
static bool bio_try_merge_hw_seg(struct request_queue *q, struct bio *bio,
973-
struct page *page, unsigned len,
974-
unsigned offset, bool *same_page)
937+
bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
938+
struct page *page, unsigned len, unsigned offset,
939+
bool *same_page)
975940
{
976-
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
977941
unsigned long mask = queue_segment_boundary(q);
978942
phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
979943
phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;
@@ -982,7 +946,7 @@ static bool bio_try_merge_hw_seg(struct request_queue *q, struct bio *bio,
982946
return false;
983947
if (bv->bv_len + len > queue_max_segment_size(q))
984948
return false;
985-
return __bio_try_merge_page(bio, page, len, offset, same_page);
949+
return bvec_try_merge_page(bv, page, len, offset, same_page);
986950
}
987951

988952
/**
@@ -1002,33 +966,33 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio,
1002966
struct page *page, unsigned int len, unsigned int offset,
1003967
unsigned int max_sectors, bool *same_page)
1004968
{
1005-
struct bio_vec *bvec;
1006-
1007969
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
1008970
return 0;
1009971

1010-
if (((bio->bi_iter.bi_size + len) >> 9) > max_sectors)
972+
if (((bio->bi_iter.bi_size + len) >> SECTOR_SHIFT) > max_sectors)
1011973
return 0;
1012974

1013975
if (bio->bi_vcnt > 0) {
1014-
if (bio_try_merge_hw_seg(q, bio, page, len, offset, same_page))
976+
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
977+
978+
if (bvec_try_merge_hw_page(q, bv, page, len, offset,
979+
same_page)) {
980+
bio->bi_iter.bi_size += len;
1015981
return len;
982+
}
983+
984+
if (bio->bi_vcnt >=
985+
min(bio->bi_max_vecs, queue_max_segments(q)))
986+
return 0;
1016987

1017988
/*
1018989
* If the queue doesn't support SG gaps and adding this segment
1019990
* would create a gap, disallow it.
1020991
*/
1021-
bvec = &bio->bi_io_vec[bio->bi_vcnt - 1];
1022-
if (bvec_gap_to_prev(&q->limits, bvec, offset))
992+
if (bvec_gap_to_prev(&q->limits, bv, offset))
1023993
return 0;
1024994
}
1025995

1026-
if (bio_full(bio, len))
1027-
return 0;
1028-
1029-
if (bio->bi_vcnt >= queue_max_segments(q))
1030-
return 0;
1031-
1032996
bvec_set_page(&bio->bi_io_vec[bio->bi_vcnt], page, len, offset);
1033997
bio->bi_vcnt++;
1034998
bio->bi_iter.bi_size += len;
@@ -1129,11 +1093,21 @@ int bio_add_page(struct bio *bio, struct page *page,
11291093
{
11301094
bool same_page = false;
11311095

1132-
if (!__bio_try_merge_page(bio, page, len, offset, &same_page)) {
1133-
if (bio_full(bio, len))
1134-
return 0;
1135-
__bio_add_page(bio, page, len, offset);
1096+
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
1097+
return 0;
1098+
if (bio->bi_iter.bi_size > UINT_MAX - len)
1099+
return 0;
1100+
1101+
if (bio->bi_vcnt > 0 &&
1102+
bvec_try_merge_page(&bio->bi_io_vec[bio->bi_vcnt - 1],
1103+
page, len, offset, &same_page)) {
1104+
bio->bi_iter.bi_size += len;
1105+
return len;
11361106
}
1107+
1108+
if (bio->bi_vcnt >= bio->bi_max_vecs)
1109+
return 0;
1110+
__bio_add_page(bio, page, len, offset);
11371111
return len;
11381112
}
11391113
EXPORT_SYMBOL(bio_add_page);
@@ -1207,13 +1181,18 @@ static int bio_iov_add_page(struct bio *bio, struct page *page,
12071181
{
12081182
bool same_page = false;
12091183

1210-
if (!__bio_try_merge_page(bio, page, len, offset, &same_page)) {
1211-
__bio_add_page(bio, page, len, offset);
1184+
if (WARN_ON_ONCE(bio->bi_iter.bi_size > UINT_MAX - len))
1185+
return -EIO;
1186+
1187+
if (bio->bi_vcnt > 0 &&
1188+
bvec_try_merge_page(&bio->bi_io_vec[bio->bi_vcnt - 1],
1189+
page, len, offset, &same_page)) {
1190+
bio->bi_iter.bi_size += len;
1191+
if (same_page)
1192+
bio_release_page(bio, page);
12121193
return 0;
12131194
}
1214-
1215-
if (same_page)
1216-
bio_release_page(bio, page);
1195+
__bio_add_page(bio, page, len, offset);
12171196
return 0;
12181197
}
12191198

@@ -1252,7 +1231,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
12521231
struct page **pages = (struct page **)bv;
12531232
ssize_t size, left;
12541233
unsigned len, i = 0;
1255-
size_t offset, trim;
1234+
size_t offset;
12561235
int ret = 0;
12571236

12581237
/*
@@ -1281,10 +1260,12 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
12811260

12821261
nr_pages = DIV_ROUND_UP(offset + size, PAGE_SIZE);
12831262

1284-
trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1);
1285-
iov_iter_revert(iter, trim);
1263+
if (bio->bi_bdev) {
1264+
size_t trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1);
1265+
iov_iter_revert(iter, trim);
1266+
size -= trim;
1267+
}
12861268

1287-
size -= trim;
12881269
if (unlikely(!size)) {
12891270
ret = -EFAULT;
12901271
goto out;
@@ -1337,6 +1318,9 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
13371318
{
13381319
int ret = 0;
13391320

1321+
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
1322+
return -EIO;
1323+
13401324
if (iov_iter_is_bvec(iter)) {
13411325
bio_iov_bvec_set(bio, iter);
13421326
iov_iter_advance(iter, bio->bi_iter.bi_size);
@@ -1490,6 +1474,7 @@ void bio_set_pages_dirty(struct bio *bio)
14901474
set_page_dirty_lock(bvec->bv_page);
14911475
}
14921476
}
1477+
EXPORT_SYMBOL_GPL(bio_set_pages_dirty);
14931478

14941479
/*
14951480
* bio_check_pages_dirty() will check that all the BIO's pages are still dirty.
@@ -1549,6 +1534,7 @@ void bio_check_pages_dirty(struct bio *bio)
15491534
spin_unlock_irqrestore(&bio_dirty_lock, flags);
15501535
schedule_work(&bio_dirty_work);
15511536
}
1537+
EXPORT_SYMBOL_GPL(bio_check_pages_dirty);
15521538

15531539
static inline bool bio_remaining_done(struct bio *bio)
15541540
{

0 commit comments

Comments
 (0)