Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-7.1/block-integrity' into for-7.1/block

Merge in integrity changes which are also landing in the VFS tree as
dependencies for fs related changes.

* for-7.1/block-integrity:
block: pass a maxlen argument to bio_iov_iter_bounce
block: add fs_bio_integrity helpers
block: make max_integrity_io_size public
block: prepare generation / verification helpers for fs usage
block: add a bdev_has_integrity_csum helper
block: factor out a bio_integrity_setup_default helper
block: factor out a bio_integrity_action helper

+247 -118
+1 -1
block/Makefile
··· 26 26 obj-$(CONFIG_IOSCHED_BFQ) += bfq.o 27 27 28 28 obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o \ 29 - bio-integrity-auto.o 29 + bio-integrity-auto.o bio-integrity-fs.o 30 30 obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o 31 31 obj-$(CONFIG_BLK_WBT) += blk-wbt.o 32 32 obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o
+11 -69
block/bio-integrity-auto.c
··· 39 39 container_of(work, struct bio_integrity_data, work); 40 40 struct bio *bio = bid->bio; 41 41 42 - blk_integrity_verify_iter(bio, &bid->saved_bio_iter); 42 + bio->bi_status = bio_integrity_verify(bio, &bid->saved_bio_iter); 43 43 bio_integrity_finish(bid); 44 44 bio_endio(bio); 45 45 } ··· 48 48 static bool bip_should_check(struct bio_integrity_payload *bip) 49 49 { 50 50 return bip->bip_flags & BIP_CHECK_FLAGS; 51 - } 52 - 53 - static bool bi_offload_capable(struct blk_integrity *bi) 54 - { 55 - return bi->metadata_size == bi->pi_tuple_size; 56 51 } 57 52 58 53 /** ··· 79 84 /** 80 85 * bio_integrity_prep - Prepare bio for integrity I/O 81 86 * @bio: bio to prepare 87 + * @action: preparation action needed (BI_ACT_*) 82 88 * 83 - * Checks if the bio already has an integrity payload attached. If it does, the 84 - * payload has been generated by another kernel subsystem, and we just pass it 85 - * through. 86 - * Otherwise allocates integrity payload and for writes the integrity metadata 87 - * will be generated. For reads, the completion handler will verify the 88 - * metadata. 89 + * Allocate the integrity payload. For writes, generate the integrity metadata 90 + * and for reads, setup the completion handler to verify the metadata. 91 + * 92 + * This is used for bios that do not have user integrity payloads attached. 89 93 */ 90 - bool bio_integrity_prep(struct bio *bio) 94 + void bio_integrity_prep(struct bio *bio, unsigned int action) 91 95 { 92 - struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 93 96 struct bio_integrity_data *bid; 94 - bool set_flags = true; 95 - gfp_t gfp = GFP_NOIO; 96 - 97 - if (!bi) 98 - return true; 99 - 100 - if (!bio_sectors(bio)) 101 - return true; 102 - 103 - /* Already protected? */ 104 - if (bio_integrity(bio)) 105 - return true; 106 - 107 - switch (bio_op(bio)) { 108 - case REQ_OP_READ: 109 - if (bi->flags & BLK_INTEGRITY_NOVERIFY) { 110 - if (bi_offload_capable(bi)) 111 - return true; 112 - set_flags = false; 113 - } 114 - break; 115 - case REQ_OP_WRITE: 116 - /* 117 - * Zero the memory allocated to not leak uninitialized kernel 118 - * memory to disk for non-integrity metadata where nothing else 119 - * initializes the memory. 120 - */ 121 - if (bi->flags & BLK_INTEGRITY_NOGENERATE) { 122 - if (bi_offload_capable(bi)) 123 - return true; 124 - set_flags = false; 125 - gfp |= __GFP_ZERO; 126 - } else if (bi->metadata_size > bi->pi_tuple_size) 127 - gfp |= __GFP_ZERO; 128 - break; 129 - default: 130 - return true; 131 - } 132 - 133 - if (WARN_ON_ONCE(bio_has_crypt_ctx(bio))) 134 - return true; 135 97 136 98 bid = mempool_alloc(&bid_pool, GFP_NOIO); 137 99 bio_integrity_init(bio, &bid->bip, &bid->bvec, 1); 138 100 bid->bio = bio; 139 101 bid->bip.bip_flags |= BIP_BLOCK_INTEGRITY; 140 - bio_integrity_alloc_buf(bio, gfp & __GFP_ZERO); 141 - 142 - bip_set_seed(&bid->bip, bio->bi_iter.bi_sector); 143 - 144 - if (set_flags) { 145 - if (bi->csum_type == BLK_INTEGRITY_CSUM_IP) 146 - bid->bip.bip_flags |= BIP_IP_CHECKSUM; 147 - if (bi->csum_type) 148 - bid->bip.bip_flags |= BIP_CHECK_GUARD; 149 - if (bi->flags & BLK_INTEGRITY_REF_TAG) 150 - bid->bip.bip_flags |= BIP_CHECK_REFTAG; 151 - } 102 + bio_integrity_alloc_buf(bio, action & BI_ACT_ZERO); 103 + if (action & BI_ACT_CHECK) 104 + bio_integrity_setup_default(bio); 152 105 153 106 /* Auto-generate integrity metadata if this is a write */ 154 107 if (bio_data_dir(bio) == WRITE && bip_should_check(&bid->bip)) 155 - blk_integrity_generate(bio); 108 + bio_integrity_generate(bio); 156 109 else 157 110 bid->saved_bio_iter = bio->bi_iter; 158 - return true; 159 111 } 160 112 EXPORT_SYMBOL(bio_integrity_prep); 161 113
+81
block/bio-integrity-fs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2025 Christoph Hellwig. 4 + */ 5 + #include <linux/blk-integrity.h> 6 + #include <linux/bio-integrity.h> 7 + #include "blk.h" 8 + 9 + struct fs_bio_integrity_buf { 10 + struct bio_integrity_payload bip; 11 + struct bio_vec bvec; 12 + }; 13 + 14 + static struct kmem_cache *fs_bio_integrity_cache; 15 + static mempool_t fs_bio_integrity_pool; 16 + 17 + unsigned int fs_bio_integrity_alloc(struct bio *bio) 18 + { 19 + struct fs_bio_integrity_buf *iib; 20 + unsigned int action; 21 + 22 + action = bio_integrity_action(bio); 23 + if (!action) 24 + return 0; 25 + 26 + iib = mempool_alloc(&fs_bio_integrity_pool, GFP_NOIO); 27 + bio_integrity_init(bio, &iib->bip, &iib->bvec, 1); 28 + 29 + bio_integrity_alloc_buf(bio, action & BI_ACT_ZERO); 30 + if (action & BI_ACT_CHECK) 31 + bio_integrity_setup_default(bio); 32 + return action; 33 + } 34 + 35 + void fs_bio_integrity_free(struct bio *bio) 36 + { 37 + struct bio_integrity_payload *bip = bio_integrity(bio); 38 + 39 + bio_integrity_free_buf(bip); 40 + mempool_free(container_of(bip, struct fs_bio_integrity_buf, bip), 41 + &fs_bio_integrity_pool); 42 + 43 + bio->bi_integrity = NULL; 44 + bio->bi_opf &= ~REQ_INTEGRITY; 45 + } 46 + 47 + void fs_bio_integrity_generate(struct bio *bio) 48 + { 49 + if (fs_bio_integrity_alloc(bio)) 50 + bio_integrity_generate(bio); 51 + } 52 + EXPORT_SYMBOL_GPL(fs_bio_integrity_generate); 53 + 54 + int fs_bio_integrity_verify(struct bio *bio, sector_t sector, unsigned int size) 55 + { 56 + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 57 + struct bio_integrity_payload *bip = bio_integrity(bio); 58 + 59 + /* 60 + * Reinitialize bip->bip_iter. 61 + * 62 + * This is for use in the submitter after the driver is done with the 63 + * bio. Requires the submitter to remember the sector and the size. 64 + */ 65 + memset(&bip->bip_iter, 0, sizeof(bip->bip_iter)); 66 + bip->bip_iter.bi_sector = sector; 67 + bip->bip_iter.bi_size = bio_integrity_bytes(bi, size >> SECTOR_SHIFT); 68 + return blk_status_to_errno(bio_integrity_verify(bio, &bip->bip_iter)); 69 + } 70 + 71 + static int __init fs_bio_integrity_init(void) 72 + { 73 + fs_bio_integrity_cache = kmem_cache_create("fs_bio_integrity", 74 + sizeof(struct fs_bio_integrity_buf), 0, 75 + SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); 76 + if (mempool_init_slab_pool(&fs_bio_integrity_pool, BIO_POOL_SIZE, 77 + fs_bio_integrity_cache)) 78 + panic("fs_bio_integrity: can't create pool\n"); 79 + return 0; 80 + } 81 + fs_initcall(fs_bio_integrity_init);
+64
block/bio-integrity.c
··· 7 7 */ 8 8 9 9 #include <linux/blk-integrity.h> 10 + #include <linux/t10-pi.h> 10 11 #include "blk.h" 11 12 12 13 struct bio_integrity_alloc { ··· 16 15 }; 17 16 18 17 static mempool_t integrity_buf_pool; 18 + 19 + static bool bi_offload_capable(struct blk_integrity *bi) 20 + { 21 + return bi->metadata_size == bi->pi_tuple_size; 22 + } 23 + 24 + unsigned int __bio_integrity_action(struct bio *bio) 25 + { 26 + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 27 + 28 + if (WARN_ON_ONCE(bio_has_crypt_ctx(bio))) 29 + return 0; 30 + 31 + switch (bio_op(bio)) { 32 + case REQ_OP_READ: 33 + if (bi->flags & BLK_INTEGRITY_NOVERIFY) { 34 + if (bi_offload_capable(bi)) 35 + return 0; 36 + return BI_ACT_BUFFER; 37 + } 38 + return BI_ACT_BUFFER | BI_ACT_CHECK; 39 + case REQ_OP_WRITE: 40 + /* 41 + * Flush masquerading as write? 42 + */ 43 + if (!bio_sectors(bio)) 44 + return 0; 45 + 46 + /* 47 + * Zero the memory allocated to not leak uninitialized kernel 48 + * memory to disk for non-integrity metadata where nothing else 49 + * initializes the memory. 50 + */ 51 + if (bi->flags & BLK_INTEGRITY_NOGENERATE) { 52 + if (bi_offload_capable(bi)) 53 + return 0; 54 + return BI_ACT_BUFFER | BI_ACT_ZERO; 55 + } 56 + 57 + if (bi->metadata_size > bi->pi_tuple_size) 58 + return BI_ACT_BUFFER | BI_ACT_CHECK | BI_ACT_ZERO; 59 + return BI_ACT_BUFFER | BI_ACT_CHECK; 60 + default: 61 + return 0; 62 + } 63 + } 64 + EXPORT_SYMBOL_GPL(__bio_integrity_action); 19 65 20 66 void bio_integrity_alloc_buf(struct bio *bio, bool zero_buffer) 21 67 { ··· 99 51 mempool_free(bv->bv_page, &integrity_buf_pool); 100 52 else 101 53 kfree(bvec_virt(bv)); 54 + } 55 + 56 + void bio_integrity_setup_default(struct bio *bio) 57 + { 58 + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 59 + struct bio_integrity_payload *bip = bio_integrity(bio); 60 + 61 + bip_set_seed(bip, bio->bi_iter.bi_sector); 62 + 63 + if (bi->csum_type) { 64 + bip->bip_flags |= BIP_CHECK_GUARD; 65 + if (bi->csum_type == BLK_INTEGRITY_CSUM_IP) 66 + bip->bip_flags |= BIP_IP_CHECKSUM; 67 + } 68 + if (bi->flags & BLK_INTEGRITY_REF_TAG) 69 + bip->bip_flags |= BIP_CHECK_REFTAG; 102 70 } 103 71 104 72 /**
+10 -7
block/bio.c
··· 1326 1326 } 1327 1327 } 1328 1328 1329 - static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter) 1329 + static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter, 1330 + size_t maxlen) 1330 1331 { 1331 - size_t total_len = iov_iter_count(iter); 1332 + size_t total_len = min(maxlen, iov_iter_count(iter)); 1332 1333 1333 1334 if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED))) 1334 1335 return -EINVAL; ··· 1367 1366 return 0; 1368 1367 } 1369 1368 1370 - static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter) 1369 + static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter, 1370 + size_t maxlen) 1371 1371 { 1372 - size_t len = min(iov_iter_count(iter), SZ_1M); 1372 + size_t len = min3(iov_iter_count(iter), maxlen, SZ_1M); 1373 1373 struct folio *folio; 1374 1374 1375 1375 folio = folio_alloc_greedy(GFP_KERNEL, &len); ··· 1409 1407 * bio_iov_iter_bounce - bounce buffer data from an iter into a bio 1410 1408 * @bio: bio to send 1411 1409 * @iter: iter to read from / write into 1410 + * @maxlen: maximum size to bounce 1412 1411 * 1413 1412 * Helper for direct I/O implementations that need to bounce buffer because 1414 1413 * we need to checksum the data or perform other operations that require ··· 1417 1414 * copies the data into it. Needs to be paired with bio_iov_iter_unbounce() 1418 1415 * called on completion. 1419 1416 */ 1420 - int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter) 1417 + int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen) 1421 1418 { 1422 1419 if (op_is_write(bio_op(bio))) 1423 - return bio_iov_iter_bounce_write(bio, iter); 1424 - return bio_iov_iter_bounce_read(bio, iter); 1420 + return bio_iov_iter_bounce_write(bio, iter, maxlen); 1421 + return bio_iov_iter_bounce_read(bio, iter, maxlen); 1425 1422 } 1426 1423 1427 1424 static void bvec_unpin(struct bio_vec *bv, bool mark_dirty)
+4 -2
block/blk-mq.c
··· 3143 3143 struct request_queue *q = bdev_get_queue(bio->bi_bdev); 3144 3144 struct blk_plug *plug = current->plug; 3145 3145 const int is_sync = op_is_sync(bio->bi_opf); 3146 + unsigned int integrity_action; 3146 3147 struct blk_mq_hw_ctx *hctx; 3147 3148 unsigned int nr_segs; 3148 3149 struct request *rq; ··· 3196 3195 if (!bio) 3197 3196 goto queue_exit; 3198 3197 3199 - if (!bio_integrity_prep(bio)) 3200 - goto queue_exit; 3198 + integrity_action = bio_integrity_action(bio); 3199 + if (integrity_action) 3200 + bio_integrity_prep(bio, integrity_action); 3201 3201 3202 3202 blk_mq_bio_issue_init(q, bio); 3203 3203 if (blk_mq_attempt_bio_merge(q, bio, nr_segs))
-13
block/blk-settings.c
··· 123 123 return 0; 124 124 } 125 125 126 - /* 127 - * Maximum size of I/O that needs a block layer integrity buffer. Limited 128 - * by the number of intervals for which we can fit the integrity buffer into 129 - * the buffer size. Because the buffer is a single segment it is also limited 130 - * by the maximum segment size. 131 - */ 132 - static inline unsigned int max_integrity_io_size(struct queue_limits *lim) 133 - { 134 - return min_t(unsigned int, lim->max_segment_size, 135 - (BLK_INTEGRITY_MAX_SIZE / lim->integrity.metadata_size) << 136 - lim->integrity.interval_exp); 137 - } 138 - 139 126 static int blk_validate_integrity_limits(struct queue_limits *lim) 140 127 { 141 128 struct blk_integrity *bi = &lim->integrity;
+4 -2
block/blk.h
··· 699 699 const struct blk_holder_ops *hops, struct file *bdev_file); 700 700 int bdev_permission(dev_t dev, blk_mode_t mode, void *holder); 701 701 702 - void blk_integrity_generate(struct bio *bio); 703 - void blk_integrity_verify_iter(struct bio *bio, struct bvec_iter *saved_iter); 702 + void bio_integrity_generate(struct bio *bio); 703 + blk_status_t bio_integrity_verify(struct bio *bio, 704 + struct bvec_iter *saved_iter); 705 + 704 706 void blk_integrity_prepare(struct request *rq); 705 707 void blk_integrity_complete(struct request *rq, unsigned int nr_bytes); 706 708
+6 -6
block/t10-pi.c
··· 372 372 } 373 373 } 374 374 375 - void blk_integrity_generate(struct bio *bio) 375 + void bio_integrity_generate(struct bio *bio) 376 376 { 377 377 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 378 378 struct bio_integrity_payload *bip = bio_integrity(bio); ··· 404 404 } 405 405 } 406 406 407 - void blk_integrity_verify_iter(struct bio *bio, struct bvec_iter *saved_iter) 407 + blk_status_t bio_integrity_verify(struct bio *bio, struct bvec_iter *saved_iter) 408 408 { 409 409 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 410 410 struct bio_integrity_payload *bip = bio_integrity(bio); ··· 439 439 } 440 440 kunmap_local(kaddr); 441 441 442 - if (ret) { 443 - bio->bi_status = ret; 444 - return; 445 - } 442 + if (ret) 443 + return ret; 446 444 } 445 + 446 + return BLK_STS_OK; 447 447 } 448 448 449 449 void blk_integrity_prepare(struct request *rq)
+4 -2
drivers/nvdimm/btt.c
··· 1435 1435 { 1436 1436 struct bio_integrity_payload *bip = bio_integrity(bio); 1437 1437 struct btt *btt = bio->bi_bdev->bd_disk->private_data; 1438 + unsigned int integrity_action; 1438 1439 struct bvec_iter iter; 1439 1440 unsigned long start; 1440 1441 struct bio_vec bvec; 1441 1442 int err = 0; 1442 1443 bool do_acct; 1443 1444 1444 - if (!bio_integrity_prep(bio)) 1445 - return; 1445 + integrity_action = bio_integrity_action(bio); 1446 + if (integrity_action) 1447 + bio_integrity_prep(bio, integrity_action); 1446 1448 1447 1449 do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue); 1448 1450 if (do_acct)
+1 -1
fs/iomap/direct-io.c
··· 351 351 bio->bi_end_io = iomap_dio_bio_end_io; 352 352 353 353 if (dio->flags & IOMAP_DIO_BOUNCE) 354 - ret = bio_iov_iter_bounce(bio, dio->submit.iter); 354 + ret = bio_iov_iter_bounce(bio, dio->submit.iter, BIO_MAX_SIZE); 355 355 else 356 356 ret = bio_iov_iter_get_pages(bio, dio->submit.iter, 357 357 alignment - 1);
+9 -3
include/linux/bio-integrity.h
··· 78 78 int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter); 79 79 int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta); 80 80 void bio_integrity_unmap_user(struct bio *bio); 81 - bool bio_integrity_prep(struct bio *bio); 81 + void bio_integrity_prep(struct bio *bio, unsigned int action); 82 82 void bio_integrity_advance(struct bio *bio, unsigned int bytes_done); 83 83 void bio_integrity_trim(struct bio *bio); 84 84 int bio_integrity_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp_mask); ··· 104 104 { 105 105 } 106 106 107 - static inline bool bio_integrity_prep(struct bio *bio) 107 + static inline void bio_integrity_prep(struct bio *bio, unsigned int action) 108 108 { 109 - return true; 110 109 } 111 110 112 111 static inline int bio_integrity_clone(struct bio *bio, struct bio *bio_src, ··· 143 144 144 145 void bio_integrity_alloc_buf(struct bio *bio, bool zero_buffer); 145 146 void bio_integrity_free_buf(struct bio_integrity_payload *bip); 147 + void bio_integrity_setup_default(struct bio *bio); 148 + 149 + unsigned int fs_bio_integrity_alloc(struct bio *bio); 150 + void fs_bio_integrity_free(struct bio *bio); 151 + void fs_bio_integrity_generate(struct bio *bio); 152 + int fs_bio_integrity_verify(struct bio *bio, sector_t sector, 153 + unsigned int size); 146 154 147 155 #endif /* _LINUX_BIO_INTEGRITY_H */
+1 -1
include/linux/bio.h
··· 474 474 extern void bio_set_pages_dirty(struct bio *bio); 475 475 extern void bio_check_pages_dirty(struct bio *bio); 476 476 477 - int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter); 477 + int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen); 478 478 void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty); 479 479 480 480 extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,
+23 -5
include/linux/blk-integrity.h
··· 8 8 9 9 struct request; 10 10 11 - /* 12 - * Maximum contiguous integrity buffer allocation. 13 - */ 14 - #define BLK_INTEGRITY_MAX_SIZE SZ_2M 15 - 16 11 enum blk_integrity_flags { 17 12 BLK_INTEGRITY_NOVERIFY = 1 << 0, 18 13 BLK_INTEGRITY_NOGENERATE = 1 << 1, ··· 174 179 return (struct bio_vec){ }; 175 180 } 176 181 #endif /* CONFIG_BLK_DEV_INTEGRITY */ 182 + 183 + enum bio_integrity_action { 184 + BI_ACT_BUFFER = (1u << 0), /* allocate buffer */ 185 + BI_ACT_CHECK = (1u << 1), /* generate / verify PI */ 186 + BI_ACT_ZERO = (1u << 2), /* zero buffer */ 187 + }; 188 + 189 + /** 190 + * bio_integrity_action - return the integrity action needed for a bio 191 + * @bio: bio to operate on 192 + * 193 + * Returns the mask of integrity actions (BI_ACT_*) that need to be performed 194 + * for @bio. 195 + */ 196 + unsigned int __bio_integrity_action(struct bio *bio); 197 + static inline unsigned int bio_integrity_action(struct bio *bio) 198 + { 199 + if (!blk_get_integrity(bio->bi_bdev->bd_disk)) 200 + return 0; 201 + if (bio_integrity(bio)) 202 + return 0; 203 + return __bio_integrity_action(bio); 204 + } 177 205 178 206 #endif /* _LINUX_BLK_INTEGRITY_H */
+28 -6
include/linux/blkdev.h
··· 1480 1480 return bdev->bd_disk->queue->limits.features & BLK_FEAT_SYNCHRONOUS; 1481 1481 } 1482 1482 1483 + static inline bool bdev_has_integrity_csum(struct block_device *bdev) 1484 + { 1485 + struct queue_limits *lim = bdev_limits(bdev); 1486 + 1487 + return IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) && 1488 + lim->integrity.csum_type != BLK_INTEGRITY_CSUM_NONE; 1489 + } 1490 + 1483 1491 static inline bool bdev_stable_writes(struct block_device *bdev) 1484 1492 { 1485 - struct request_queue *q = bdev_get_queue(bdev); 1486 - 1487 - if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) && 1488 - q->limits.integrity.csum_type != BLK_INTEGRITY_CSUM_NONE) 1489 - return true; 1490 - return q->limits.features & BLK_FEAT_STABLE_WRITES; 1493 + return bdev_has_integrity_csum(bdev) || 1494 + (bdev_limits(bdev)->features & BLK_FEAT_STABLE_WRITES); 1491 1495 } 1492 1496 1493 1497 static inline bool blk_queue_write_cache(struct request_queue *q) ··· 1882 1878 unsigned *segs, unsigned max_bytes) 1883 1879 { 1884 1880 return bio_split_io_at(bio, lim, segs, max_bytes, lim->dma_alignment); 1881 + } 1882 + 1883 + /* 1884 + * Maximum contiguous integrity buffer allocation. 1885 + */ 1886 + #define BLK_INTEGRITY_MAX_SIZE SZ_2M 1887 + 1888 + /* 1889 + * Maximum size of I/O that needs a block layer integrity buffer. Limited 1890 + * by the number of intervals for which we can fit the integrity buffer into 1891 + * the buffer size. Because the buffer is a single segment it is also limited 1892 + * by the maximum segment size. 1893 + */ 1894 + static inline unsigned int max_integrity_io_size(struct queue_limits *lim) 1895 + { 1896 + return min_t(unsigned int, lim->max_segment_size, 1897 + (BLK_INTEGRITY_MAX_SIZE / lim->integrity.metadata_size) << 1898 + lim->integrity.interval_exp); 1885 1899 } 1886 1900 1887 1901 #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { }