hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/block/blk-integrity.c
....@@ -1,23 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * blk-integrity.c - Block layer data integrity extensions
34 *
45 * Copyright (C) 2007, 2008 Oracle Corporation
56 * Written by: Martin K. Petersen <martin.petersen@oracle.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License version
9
- * 2 as published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful, but
12
- * WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; see the file COPYING. If not, write to
18
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19
- * USA.
20
- *
217 */
228
239 #include <linux/blkdev.h>
....@@ -49,12 +35,8 @@
4935 bio_for_each_integrity_vec(iv, bio, iter) {
5036
5137 if (prev) {
52
- if (!BIOVEC_PHYS_MERGEABLE(&ivprv, &iv))
38
+ if (!biovec_phys_mergeable(q, &ivprv, &iv))
5339 goto new_segment;
54
-
55
- if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv))
56
- goto new_segment;
57
-
5840 if (seg_size + iv.bv_len > queue_max_segment_size(q))
5941 goto new_segment;
6042
....@@ -95,12 +77,8 @@
9577 bio_for_each_integrity_vec(iv, bio, iter) {
9678
9779 if (prev) {
98
- if (!BIOVEC_PHYS_MERGEABLE(&ivprv, &iv))
80
+ if (!biovec_phys_mergeable(q, &ivprv, &iv))
9981 goto new_segment;
100
-
101
- if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv))
102
- goto new_segment;
103
-
10482 if (sg->length + iv.bv_len > queue_max_segment_size(q))
10583 goto new_segment;
10684
....@@ -205,7 +183,6 @@
205183
206184 return true;
207185 }
208
-EXPORT_SYMBOL(blk_integrity_merge_rq);
209186
210187 bool blk_integrity_merge_bio(struct request_queue *q, struct request *req,
211188 struct bio *bio)
....@@ -234,7 +211,6 @@
234211
235212 return true;
236213 }
237
-EXPORT_SYMBOL(blk_integrity_merge_bio);
238214
239215 struct integrity_sysfs_entry {
240216 struct attribute attr;
....@@ -373,6 +349,7 @@
373349 &integrity_device_entry.attr,
374350 NULL,
375351 };
352
+ATTRIBUTE_GROUPS(integrity);
376353
377354 static const struct sysfs_ops integrity_ops = {
378355 .show = &integrity_attr_show,
....@@ -380,7 +357,7 @@
380357 };
381358
382359 static struct kobj_type integrity_ktype = {
383
- .default_attrs = integrity_attrs,
360
+ .default_groups = integrity_groups,
384361 .sysfs_ops = &integrity_ops,
385362 };
386363
....@@ -389,10 +366,21 @@
389366 return BLK_STS_OK;
390367 }
391368
369
+static void blk_integrity_nop_prepare(struct request *rq)
370
+{
371
+}
372
+
373
+static void blk_integrity_nop_complete(struct request *rq,
374
+ unsigned int nr_bytes)
375
+{
376
+}
377
+
392378 static const struct blk_integrity_profile nop_profile = {
393379 .name = "nop",
394380 .generate_fn = blk_integrity_nop_fn,
395381 .verify_fn = blk_integrity_nop_fn,
382
+ .prepare_fn = blk_integrity_nop_prepare,
383
+ .complete_fn = blk_integrity_nop_complete,
396384 };
397385
398386 /**
....@@ -404,7 +392,7 @@
404392 * send/receive integrity metadata it must use this function to register
405393 * the capability with the block layer. The template is a blk_integrity
406394 * struct with values appropriate for the underlying hardware. See
407
- * Documentation/block/data-integrity.txt.
395
+ * Documentation/block/data-integrity.rst.
408396 */
409397 void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
410398 {
....@@ -418,7 +406,14 @@
418406 bi->tuple_size = template->tuple_size;
419407 bi->tag_size = template->tag_size;
420408
421
- disk->queue->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES;
409
+ blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
410
+
411
+#ifdef CONFIG_BLK_INLINE_ENCRYPTION
412
+ if (disk->queue->ksm) {
413
+ pr_warn("blk-integrity: Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n");
414
+ blk_ksm_unregister(disk->queue);
415
+ }
416
+#endif
422417 }
423418 EXPORT_SYMBOL(blk_integrity_register);
424419
....@@ -431,8 +426,15 @@
431426 */
432427 void blk_integrity_unregister(struct gendisk *disk)
433428 {
434
- disk->queue->backing_dev_info->capabilities &= ~BDI_CAP_STABLE_WRITES;
435
- memset(&disk->queue->integrity, 0, sizeof(struct blk_integrity));
429
+ struct blk_integrity *bi = &disk->queue->integrity;
430
+
431
+ if (!bi->profile)
432
+ return;
433
+
434
+ /* ensure all bios are off the integrity workqueue */
435
+ blk_flush_integrity();
436
+ blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue);
437
+ memset(bi, 0, sizeof(*bi));
436438 }
437439 EXPORT_SYMBOL(blk_integrity_unregister);
438440