@@ -11,7 +11,7 @@
#include <linux/export.h>
#include <linux/bio.h>
#include <linux/workqueue.h>
-#include <linux/slab.h>
+#include <uapi/linux/io_uring.h>
#include "blk.h"
static struct kmem_cache *bip_slab;
@@ -318,6 +318,35 @@ static unsigned int bvec_from_pages(struct bio_vec *bvec, struct page **pages,
return nr_bvecs;
}
+int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta)
+{
+ struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
+ u16 bip_flags = 0;
+ int ret;
+
+ if (!bi)
+ return -EINVAL;
+
+ if (meta->iter.count < bio_integrity_bytes(bi, bio_sectors(bio)))
+ return -EINVAL;
+
+ ret = bio_integrity_map_user(bio, &meta->iter, 0);
+ if (!ret) {
+ struct bio_integrity_payload *bip = bio_integrity(bio);
+
+ if (meta->flags & META_CHK_GUARD)
+ bip_flags |= BIP_USER_CHK_GUARD;
+ if (meta->flags & META_CHK_APPTAG)
+ bip_flags |= BIP_USER_CHK_APPTAG;
+ if (meta->flags & META_CHK_REFTAG)
+ bip_flags |= BIP_USER_CHK_REFTAG;
+
+ bip->bip_flags |= bip_flags;
+ bip->apptag = meta->apptag;
+ }
+ return ret;
+}
+
int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter,
u32 seed)
{
@@ -353,6 +353,15 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
task_io_account_write(bio->bi_iter.bi_size);
}
+ if (unlikely(iocb->ki_flags & IOCB_USE_META)) {
+ ret = bio_integrity_map_iter(bio, iocb->private);
+ WRITE_ONCE(iocb->private, NULL);
+ if (unlikely(ret)) {
+ bio_put(bio);
+ return ret;
+ }
+ }
+
if (iocb->ki_flags & IOCB_NOWAIT)
bio->bi_opf |= REQ_NOWAIT;
@@ -156,6 +156,8 @@ static void t10_pi_type1_prepare(struct request *rq)
/* Already remapped? */
if (bip->bip_flags & BIP_MAPPED_INTEGRITY)
break;
+ if (bip->bip_flags & BIP_INTEGRITY_USER)
+ break;
bip_for_each_vec(iv, bip, iter) {
unsigned int j;
@@ -205,6 +207,8 @@ static void t10_pi_type1_complete(struct request *rq, unsigned int nr_bytes)
struct bio_vec iv;
struct bvec_iter iter;
+ if (bip->bip_flags & BIP_INTEGRITY_USER)
+ break;
bip_for_each_vec(iv, bip, iter) {
unsigned int j;
void *p;
@@ -408,6 +412,8 @@ static void ext_pi_type1_prepare(struct request *rq)
/* Already remapped? */
if (bip->bip_flags & BIP_MAPPED_INTEGRITY)
break;
+ if (bip->bip_flags & BIP_INTEGRITY_USER)
+ break;
bip_for_each_vec(iv, bip, iter) {
unsigned int j;
@@ -329,6 +329,9 @@ enum bip_flags {
BIP_IP_CHECKSUM = 1 << 4, /* IP checksum */
BIP_INTEGRITY_USER = 1 << 5, /* Integrity payload is user address */
BIP_COPY_USER = 1 << 6, /* Kernel bounce buffer in use */
+ BIP_USER_CHK_GUARD = 1 << 7,
+ BIP_USER_CHK_APPTAG = 1 << 8,
+ BIP_USER_CHK_REFTAG = 1 << 9,
};
struct uio_meta {
@@ -348,6 +351,7 @@ struct bio_integrity_payload {
unsigned short bip_vcnt; /* # of integrity bio_vecs */
unsigned short bip_max_vcnt; /* integrity bio_vec slots */
unsigned short bip_flags; /* control flags */
+ u16 apptag; /* apptag */
struct bvec_iter bio_iter; /* for rewinding parent bio */
@@ -729,6 +733,7 @@ static inline bool bioset_initialized(struct bio_set *bs)
for_each_bio(_bio) \
bip_for_each_vec(_bvl, _bio->bi_integrity, _iter)
+int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta);
int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter, u32 seed);
extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
@@ -808,6 +813,11 @@ static inline int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter,
return -EINVAL;
}
+static inline int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta)
+{
+ return -EINVAL;
+}
+
#endif /* CONFIG_BLK_DEV_INTEGRITY */
/*