From: Kanchan Joshi <joshi.k@samsung.com>
To: josef@toxicpanda.com, dsterba@suse.com, clm@fb.com,
axboe@kernel.dk, kbusch@kernel.org, hch@lst.de
Cc: linux-btrfs@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-block@vger.kernel.org, gost.dev@samsung.com,
Kanchan Joshi <joshi.k@samsung.com>,
Anuj Gupta <anuj20.g@samsung.com>
Subject: [RFC 1/3] block: add integrity offload
Date: Wed, 29 Jan 2025 19:32:05 +0530 [thread overview]
Message-ID: <20250129140207.22718-2-joshi.k@samsung.com> (raw)
In-Reply-To: <20250129140207.22718-1-joshi.k@samsung.com>
Add a 'offload_type' that is populated by the integrity providers
(e.g., drivers) based on the underlying capability/configuration.
- BLK_INTEGRITY_OFFLOAD_NONE: indicates offload capability is absent.
- BLK_INTEGRITY_OFFLOAD_NO_BUF: offload for which integrity buffer is
not needed.
- BLK_INTEGRITY_OFFLOAD_BUF: offload for which integrity buffer is
needed.
Make block layer skip certain processing (checksum generate/verify,
reftag remapping) that is not compatible with the offload.
Users (e.g., filesystems) can send the flag REQ_INTEGRITY_OFFLOAD to
ask for the offload.
Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
Co-developed-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
---
block/bio-integrity.c | 42 ++++++++++++++++++++++++++++++++++++++-
block/t10-pi.c | 7 +++++++
include/linux/blk_types.h | 3 +++
include/linux/blkdev.h | 7 +++++++
4 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 5d81ad9a3d20..05872b5ad9aa 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -413,6 +413,41 @@ int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta)
return ret;
}
+static bool bio_integrity_offload(struct bio *bio)
+{
+ struct bio_integrity_payload *bip;
+ struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
+ unsigned int len;
+ void *buf;
+ gfp_t gfp = GFP_NOIO;
+
+ if (bi->offload_type == BLK_INTEGRITY_OFFLOAD_NO_BUF)
+ return true;
+
+ /* Allocate kernel buffer for protection data */
+ len = bio_integrity_bytes(bi, bio_sectors(bio));
+ buf = kmalloc(len, gfp | __GFP_ZERO);
+ if (unlikely(buf == NULL))
+ goto err_end_io;
+
+ bip = bio_integrity_alloc(bio, gfp, 1);
+ if (IS_ERR(bip)) {
+ kfree(buf);
+ goto err_end_io;
+ }
+
+ bip->bip_flags |= BIP_BLOCK_INTEGRITY;
+ if (bio_integrity_add_page(bio, virt_to_page(buf), len,
+ offset_in_page(buf)) < len)
+ goto err_end_io;
+
+ return true;
+
+err_end_io:
+ bio->bi_status = BLK_STS_RESOURCE;
+ bio_endio(bio);
+ return false;
+}
/**
* bio_integrity_prep - Prepare bio for integrity I/O
* @bio: bio to prepare
@@ -443,6 +478,10 @@ bool bio_integrity_prep(struct bio *bio)
if (bio_integrity(bio))
return true;
+ if (bio->bi_opf & REQ_INTEGRITY_OFFLOAD &&
+ bi->offload_type != BLK_INTEGRITY_OFFLOAD_NONE)
+ return bio_integrity_offload(bio);
+
switch (bio_op(bio)) {
case REQ_OP_READ:
if (bi->flags & BLK_INTEGRITY_NOVERIFY)
@@ -522,7 +561,8 @@ static void bio_integrity_verify_fn(struct work_struct *work)
container_of(work, struct bio_integrity_payload, bip_work);
struct bio *bio = bip->bip_bio;
- blk_integrity_verify(bio);
+ if (!(bio->bi_opf & REQ_INTEGRITY_OFFLOAD))
+ blk_integrity_verify(bio);
kfree(bvec_virt(bip->bip_vec));
bio_integrity_free(bio);
diff --git a/block/t10-pi.c b/block/t10-pi.c
index 2d05421f0fa5..9eca1ad5d5e6 100644
--- a/block/t10-pi.c
+++ b/block/t10-pi.c
@@ -452,6 +452,9 @@ void blk_integrity_prepare(struct request *rq)
if (!(bi->flags & BLK_INTEGRITY_REF_TAG))
return;
+ if ((rq->cmd_flags & REQ_INTEGRITY_OFFLOAD) &&
+ (bi->offload_type != BLK_INTEGRITY_OFFLOAD_NONE))
+ return;
if (bi->csum_type == BLK_INTEGRITY_CSUM_CRC64)
ext_pi_type1_prepare(rq);
@@ -466,6 +469,10 @@ void blk_integrity_complete(struct request *rq, unsigned int nr_bytes)
if (!(bi->flags & BLK_INTEGRITY_REF_TAG))
return;
+ if ((rq->cmd_flags & REQ_INTEGRITY_OFFLOAD) &&
+ (bi->offload_type != BLK_INTEGRITY_OFFLOAD_NONE))
+ return;
+
if (bi->csum_type == BLK_INTEGRITY_CSUM_CRC64)
ext_pi_type1_complete(rq, nr_bytes);
else
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index dce7615c35e7..65615dbc3e2d 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -378,6 +378,7 @@ enum req_flag_bits {
__REQ_DRV, /* for driver use */
__REQ_FS_PRIVATE, /* for file system (submitter) use */
__REQ_ATOMIC, /* for atomic write operations */
+ __REQ_INTEGRITY_OFFLOAD,/* I/O that wants HW integrity offload */
/*
* Command specific flags, keep last:
*/
@@ -399,6 +400,8 @@ enum req_flag_bits {
#define REQ_NOMERGE (__force blk_opf_t)(1ULL << __REQ_NOMERGE)
#define REQ_IDLE (__force blk_opf_t)(1ULL << __REQ_IDLE)
#define REQ_INTEGRITY (__force blk_opf_t)(1ULL << __REQ_INTEGRITY)
+#define REQ_INTEGRITY_OFFLOAD \
+ (__force blk_opf_t)(1ULL << __REQ_INTEGRITY_OFFLOAD)
#define REQ_FUA (__force blk_opf_t)(1ULL << __REQ_FUA)
#define REQ_PREFLUSH (__force blk_opf_t)(1ULL << __REQ_PREFLUSH)
#define REQ_RAHEAD (__force blk_opf_t)(1ULL << __REQ_RAHEAD)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 7ac153e4423a..ef061eb4cb73 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -113,6 +113,12 @@ enum blk_integrity_checksum {
BLK_INTEGRITY_CSUM_CRC64 = 3,
} __packed ;
+enum blk_integrity_offload {
+ BLK_INTEGRITY_OFFLOAD_NONE = 0,
+ BLK_INTEGRITY_OFFLOAD_NO_BUF = 1,
+ BLK_INTEGRITY_OFFLOAD_BUF = 2,
+} __packed;
+
struct blk_integrity {
unsigned char flags;
enum blk_integrity_checksum csum_type;
@@ -120,6 +126,7 @@ struct blk_integrity {
unsigned char pi_offset;
unsigned char interval_exp;
unsigned char tag_size;
+ unsigned char offload_type;
};
typedef unsigned int __bitwise blk_mode_t;
--
2.25.1
next prev parent reply other threads:[~2025-01-29 14:10 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250129141039epcas5p11feb1be4124c0db3c5223325924183a3@epcas5p1.samsung.com>
2025-01-29 14:02 ` [RFC 0/3] Btrfs checksum offload Kanchan Joshi
2025-01-29 14:02 ` Kanchan Joshi [this message]
2025-01-29 14:02 ` [RFC 2/3] nvme: support integrity offload Kanchan Joshi
2025-01-29 14:02 ` [RFC 3/3] btrfs: add checksum offload Kanchan Joshi
2025-01-29 21:27 ` Qu Wenruo
2025-01-29 14:55 ` [RFC 0/3] Btrfs " Johannes Thumshirn
2025-01-31 10:19 ` Kanchan Joshi
2025-01-31 10:29 ` Johannes Thumshirn
2025-02-03 13:25 ` Kanchan Joshi
2025-02-03 13:40 ` Johannes Thumshirn
2025-02-03 14:03 ` Kanchan Joshi
2025-02-03 14:41 ` Johannes Thumshirn
2025-01-29 15:28 ` Keith Busch
2025-01-29 15:40 ` Christoph Hellwig
2025-01-29 18:03 ` Keith Busch
2025-01-30 12:54 ` Christoph Hellwig
2025-01-29 15:35 ` Christoph Hellwig
2025-01-30 9:22 ` Kanchan Joshi
2025-01-30 12:53 ` Christoph Hellwig
2025-01-31 10:29 ` Kanchan Joshi
2025-01-31 10:42 ` Christoph Hellwig
2025-01-29 15:55 ` Mark Harmstone
2025-01-29 19:02 ` Goffredo Baroncelli
2025-01-30 9:33 ` Daniel Vacek
2025-01-30 20:21 ` Martin K. Petersen
2025-01-31 7:44 ` Christoph Hellwig
2025-02-03 19:31 ` Martin K. Petersen
2025-02-04 5:12 ` Christoph Hellwig
2025-02-04 12:52 ` Martin K. Petersen
2025-02-04 13:49 ` Christoph Hellwig
2025-02-05 2:31 ` Martin K. Petersen
2025-02-03 13:24 ` Kanchan Joshi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250129140207.22718-2-joshi.k@samsung.com \
--to=joshi.k@samsung.com \
--cc=anuj20.g@samsung.com \
--cc=axboe@kernel.dk \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=gost.dev@samsung.com \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox