Skip to content

Commit da042a3

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: split integrity support out of bio.h
Split struct bio_integrity_payload and the related prototypes out of bio.h into a separate bio-integrity.h header so that it is only pulled in by the few places that need it. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Anuj Gupta <[email protected]> Reviewed-by: Kanchan Joshi <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1a50d14 commit da042a3

File tree

9 files changed

+161
-159
lines changed

9 files changed

+161
-159
lines changed

block/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
#include <linux/mm.h>
66
#include <linux/swap.h>
7-
#include <linux/bio.h>
7+
#include <linux/bio-integrity.h>
88
#include <linux/blkdev.h>
99
#include <linux/uio.h>
1010
#include <linux/iocontext.h>

block/blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef BLK_INTERNAL_H
33
#define BLK_INTERNAL_H
44

5+
#include <linux/bio-integrity.h>
56
#include <linux/blk-crypto.h>
67
#include <linux/memblock.h> /* for max_pfn/max_low_pfn */
78
#include <linux/sched/sysctl.h>

block/bounce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <linux/export.h>
1111
#include <linux/swap.h>
1212
#include <linux/gfp.h>
13-
#include <linux/bio.h>
13+
#include <linux/bio-integrity.h>
1414
#include <linux/pagemap.h>
1515
#include <linux/mempool.h>
1616
#include <linux/blkdev.h>

drivers/md/dm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "dm-uevent.h"
1212
#include "dm-ima.h"
1313

14+
#include <linux/bio-integrity.h>
1415
#include <linux/init.h>
1516
#include <linux/module.h>
1617
#include <linux/mutex.h>

drivers/nvme/host/ioctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2011-2014, Intel Corporation.
44
* Copyright (c) 2017-2021 Christoph Hellwig.
55
*/
6+
#include <linux/bio-integrity.h>
67
#include <linux/ptrace.h> /* for force_successful_syscall_return */
78
#include <linux/nvme_ioctl.h>
89
#include <linux/io_uring/cmd.h>

drivers/scsi/sd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
* than the level indicated above to trigger output.
3434
*/
3535

36+
#include <linux/bio-integrity.h>
3637
#include <linux/module.h>
3738
#include <linux/fs.h>
3839
#include <linux/kernel.h>
3940
#include <linux/mm.h>
40-
#include <linux/bio.h>
41+
#include <linux/bio-integrity.h>
4142
#include <linux/hdreg.h>
4243
#include <linux/errno.h>
4344
#include <linux/idr.h>

include/linux/bio-integrity.h

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_BIO_INTEGRITY_H
3+
#define _LINUX_BIO_INTEGRITY_H
4+
5+
#include <linux/bio.h>
6+
7+
enum bip_flags {
8+
BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */
9+
BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */
10+
BIP_CTRL_NOCHECK = 1 << 2, /* disable HBA integrity checking */
11+
BIP_DISK_NOCHECK = 1 << 3, /* disable disk integrity checking */
12+
BIP_IP_CHECKSUM = 1 << 4, /* IP checksum */
13+
BIP_INTEGRITY_USER = 1 << 5, /* Integrity payload is user address */
14+
BIP_COPY_USER = 1 << 6, /* Kernel bounce buffer in use */
15+
};
16+
17+
struct bio_integrity_payload {
18+
struct bio *bip_bio; /* parent bio */
19+
20+
struct bvec_iter bip_iter;
21+
22+
unsigned short bip_vcnt; /* # of integrity bio_vecs */
23+
unsigned short bip_max_vcnt; /* integrity bio_vec slots */
24+
unsigned short bip_flags; /* control flags */
25+
26+
struct bvec_iter bio_iter; /* for rewinding parent bio */
27+
28+
struct work_struct bip_work; /* I/O completion */
29+
30+
struct bio_vec *bip_vec;
31+
struct bio_vec bip_inline_vecs[];/* embedded bvec array */
32+
};
33+
34+
#ifdef CONFIG_BLK_DEV_INTEGRITY
35+
36+
#define bip_for_each_vec(bvl, bip, iter) \
37+
for_each_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
38+
39+
#define bio_for_each_integrity_vec(_bvl, _bio, _iter) \
40+
for_each_bio(_bio) \
41+
bip_for_each_vec(_bvl, _bio->bi_integrity, _iter)
42+
43+
static inline struct bio_integrity_payload *bio_integrity(struct bio *bio)
44+
{
45+
if (bio->bi_opf & REQ_INTEGRITY)
46+
return bio->bi_integrity;
47+
48+
return NULL;
49+
}
50+
51+
static inline bool bio_integrity_flagged(struct bio *bio, enum bip_flags flag)
52+
{
53+
struct bio_integrity_payload *bip = bio_integrity(bio);
54+
55+
if (bip)
56+
return bip->bip_flags & flag;
57+
58+
return false;
59+
}
60+
61+
static inline sector_t bip_get_seed(struct bio_integrity_payload *bip)
62+
{
63+
return bip->bip_iter.bi_sector;
64+
}
65+
66+
static inline void bip_set_seed(struct bio_integrity_payload *bip,
67+
sector_t seed)
68+
{
69+
bip->bip_iter.bi_sector = seed;
70+
}
71+
72+
struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, gfp_t gfp,
73+
unsigned int nr);
74+
int bio_integrity_add_page(struct bio *bio, struct page *page, unsigned int len,
75+
unsigned int offset);
76+
int bio_integrity_map_user(struct bio *bio, void __user *ubuf, ssize_t len, u32 seed);
77+
void bio_integrity_unmap_free_user(struct bio *bio);
78+
bool bio_integrity_prep(struct bio *bio);
79+
void bio_integrity_advance(struct bio *bio, unsigned int bytes_done);
80+
void bio_integrity_trim(struct bio *bio);
81+
int bio_integrity_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp_mask);
82+
int bioset_integrity_create(struct bio_set *bs, int pool_size);
83+
void bioset_integrity_free(struct bio_set *bs);
84+
void bio_integrity_init(void);
85+
86+
#else /* CONFIG_BLK_DEV_INTEGRITY */
87+
88+
static inline void *bio_integrity(struct bio *bio)
89+
{
90+
return NULL;
91+
}
92+
93+
static inline int bioset_integrity_create(struct bio_set *bs, int pool_size)
94+
{
95+
return 0;
96+
}
97+
98+
static inline void bioset_integrity_free(struct bio_set *bs)
99+
{
100+
}
101+
102+
static inline int bio_integrity_map_user(struct bio *bio, void __user *ubuf,
103+
ssize_t len, u32 seed)
104+
{
105+
return -EINVAL;
106+
}
107+
108+
static inline void bio_integrity_unmap_free_user(struct bio *bio)
109+
{
110+
}
111+
112+
static inline bool bio_integrity_prep(struct bio *bio)
113+
{
114+
return true;
115+
}
116+
117+
static inline int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
118+
gfp_t gfp_mask)
119+
{
120+
return 0;
121+
}
122+
123+
static inline void bio_integrity_advance(struct bio *bio,
124+
unsigned int bytes_done)
125+
{
126+
}
127+
128+
static inline void bio_integrity_trim(struct bio *bio)
129+
{
130+
}
131+
132+
static inline void bio_integrity_init(void)
133+
{
134+
}
135+
136+
static inline bool bio_integrity_flagged(struct bio *bio, enum bip_flags flag)
137+
{
138+
return false;
139+
}
140+
141+
static inline void *bio_integrity_alloc(struct bio *bio, gfp_t gfp,
142+
unsigned int nr)
143+
{
144+
return ERR_PTR(-EINVAL);
145+
}
146+
147+
static inline int bio_integrity_add_page(struct bio *bio, struct page *page,
148+
unsigned int len, unsigned int offset)
149+
{
150+
return 0;
151+
}
152+
#endif /* CONFIG_BLK_DEV_INTEGRITY */
153+
#endif /* _LINUX_BIO_INTEGRITY_H */

include/linux/bio.h

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -321,69 +321,6 @@ static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio)
321321
#define bio_for_each_folio_all(fi, bio) \
322322
for (bio_first_folio(&fi, bio, 0); fi.folio; bio_next_folio(&fi, bio))
323323

324-
enum bip_flags {
325-
BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */
326-
BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */
327-
BIP_CTRL_NOCHECK = 1 << 2, /* disable HBA integrity checking */
328-
BIP_DISK_NOCHECK = 1 << 3, /* disable disk integrity checking */
329-
BIP_IP_CHECKSUM = 1 << 4, /* IP checksum */
330-
BIP_INTEGRITY_USER = 1 << 5, /* Integrity payload is user address */
331-
BIP_COPY_USER = 1 << 6, /* Kernel bounce buffer in use */
332-
};
333-
334-
/*
335-
* bio integrity payload
336-
*/
337-
struct bio_integrity_payload {
338-
struct bio *bip_bio; /* parent bio */
339-
340-
struct bvec_iter bip_iter;
341-
342-
unsigned short bip_vcnt; /* # of integrity bio_vecs */
343-
unsigned short bip_max_vcnt; /* integrity bio_vec slots */
344-
unsigned short bip_flags; /* control flags */
345-
346-
struct bvec_iter bio_iter; /* for rewinding parent bio */
347-
348-
struct work_struct bip_work; /* I/O completion */
349-
350-
struct bio_vec *bip_vec;
351-
struct bio_vec bip_inline_vecs[];/* embedded bvec array */
352-
};
353-
354-
#if defined(CONFIG_BLK_DEV_INTEGRITY)
355-
356-
static inline struct bio_integrity_payload *bio_integrity(struct bio *bio)
357-
{
358-
if (bio->bi_opf & REQ_INTEGRITY)
359-
return bio->bi_integrity;
360-
361-
return NULL;
362-
}
363-
364-
static inline bool bio_integrity_flagged(struct bio *bio, enum bip_flags flag)
365-
{
366-
struct bio_integrity_payload *bip = bio_integrity(bio);
367-
368-
if (bip)
369-
return bip->bip_flags & flag;
370-
371-
return false;
372-
}
373-
374-
static inline sector_t bip_get_seed(struct bio_integrity_payload *bip)
375-
{
376-
return bip->bip_iter.bi_sector;
377-
}
378-
379-
static inline void bip_set_seed(struct bio_integrity_payload *bip,
380-
sector_t seed)
381-
{
382-
bip->bip_iter.bi_sector = seed;
383-
}
384-
385-
#endif /* CONFIG_BLK_DEV_INTEGRITY */
386-
387324
void bio_trim(struct bio *bio, sector_t offset, sector_t size);
388325
extern struct bio *bio_split(struct bio *bio, int sectors,
389326
gfp_t gfp, struct bio_set *bs);
@@ -721,99 +658,6 @@ static inline bool bioset_initialized(struct bio_set *bs)
721658
return bs->bio_slab != NULL;
722659
}
723660

724-
#if defined(CONFIG_BLK_DEV_INTEGRITY)
725-
726-
#define bip_for_each_vec(bvl, bip, iter) \
727-
for_each_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
728-
729-
#define bio_for_each_integrity_vec(_bvl, _bio, _iter) \
730-
for_each_bio(_bio) \
731-
bip_for_each_vec(_bvl, _bio->bi_integrity, _iter)
732-
733-
int bio_integrity_map_user(struct bio *bio, void __user *ubuf, ssize_t len, u32 seed);
734-
void bio_integrity_unmap_free_user(struct bio *bio);
735-
extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
736-
extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
737-
extern bool bio_integrity_prep(struct bio *);
738-
extern void bio_integrity_advance(struct bio *, unsigned int);
739-
extern void bio_integrity_trim(struct bio *);
740-
extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t);
741-
extern int bioset_integrity_create(struct bio_set *, int);
742-
extern void bioset_integrity_free(struct bio_set *);
743-
extern void bio_integrity_init(void);
744-
745-
#else /* CONFIG_BLK_DEV_INTEGRITY */
746-
747-
static inline void *bio_integrity(struct bio *bio)
748-
{
749-
return NULL;
750-
}
751-
752-
static inline int bioset_integrity_create(struct bio_set *bs, int pool_size)
753-
{
754-
return 0;
755-
}
756-
757-
static inline void bioset_integrity_free (struct bio_set *bs)
758-
{
759-
return;
760-
}
761-
762-
static inline bool bio_integrity_prep(struct bio *bio)
763-
{
764-
return true;
765-
}
766-
767-
static inline int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
768-
gfp_t gfp_mask)
769-
{
770-
return 0;
771-
}
772-
773-
static inline void bio_integrity_advance(struct bio *bio,
774-
unsigned int bytes_done)
775-
{
776-
return;
777-
}
778-
779-
static inline void bio_integrity_trim(struct bio *bio)
780-
{
781-
return;
782-
}
783-
784-
static inline void bio_integrity_init(void)
785-
{
786-
return;
787-
}
788-
789-
static inline bool bio_integrity_flagged(struct bio *bio, enum bip_flags flag)
790-
{
791-
return false;
792-
}
793-
794-
static inline void *bio_integrity_alloc(struct bio * bio, gfp_t gfp,
795-
unsigned int nr)
796-
{
797-
return ERR_PTR(-EINVAL);
798-
}
799-
800-
static inline int bio_integrity_add_page(struct bio *bio, struct page *page,
801-
unsigned int len, unsigned int offset)
802-
{
803-
return 0;
804-
}
805-
806-
static inline int bio_integrity_map_user(struct bio *bio, void __user *ubuf,
807-
ssize_t len, u32 seed)
808-
{
809-
return -EINVAL;
810-
}
811-
static inline void bio_integrity_unmap_free_user(struct bio *bio)
812-
{
813-
}
814-
815-
#endif /* CONFIG_BLK_DEV_INTEGRITY */
816-
817661
/*
818662
* Mark a bio as polled. Note that for async polled IO, the caller must
819663
* expect -EWOULDBLOCK if we cannot allocate a request (or other resources).

include/linux/blk-integrity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _LINUX_BLK_INTEGRITY_H
44

55
#include <linux/blk-mq.h>
6+
#include <linux/bio-integrity.h>
67

78
struct request;
89

0 commit comments

Comments
 (0)