From patchwork Wed Jan 29 14:02:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 13953780 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 193E114BFA2 for ; Wed, 29 Jan 2025 14:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159854; cv=none; b=Q9qNKNjjJ7E7Ge6GIbcXv+rAaFb5zW6kzHZnQN3HZqsQ00ma9EN3Ju+n310RVfhQjsSKKIuJFoy/WEjWuI33vXkjIuYDHt/t4I1ncwhTtijaGvsBPXbJTQUztQjRSCUjpQf5Ru6Cy9kPpczH+Fu6szESPl5lEbkZhbvXdSsglUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159854; c=relaxed/simple; bh=ajn1j+0tB+pF1R0+jI46+yhVfWhQDnPwmhHlxKBlxiY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=bqJgga13oGm71WecxKwI7puDHaSrkLLJYaWci1CMLK7NqVoS0K9boQ/M1zZ+cp7h9JwVbM/kkH/022yu9bpLru2WVyRTRMf+l2zdj+vqrZvJv7Lh57wxBNlKc8kmXgMfTZMvNv2HdavRMdaLSyJ5BXhMiO8mqxqof5C6HO9nfsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=TQLU2r7+; arc=none smtp.client-ip=203.254.224.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="TQLU2r7+" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20250129141044epoutp02d96b6761240c1c8c9bf9adda2d6d5737~fLytZgg0g1150511505epoutp02R for ; Wed, 29 Jan 2025 14:10:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20250129141044epoutp02d96b6761240c1c8c9bf9adda2d6d5737~fLytZgg0g1150511505epoutp02R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1738159844; bh=AMUYor/IDGZ7ZFAsT4Kc2pGHG8vzwbC6ZzYXNLikuqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TQLU2r7+p+TvwAKCfn/V8OWd5TzJ5y3w2QQ3q5jJvwrE9BHB2o+hYRLzN8Jbzzrrc DBIQBt5hZoaMN4IJkEvDJnHoRU4AvDwT6dGfRKNcCzuIhkwu7VknYZvmhUmD0HDDZT qfqcTvU8bJJpQMbkqsfIRZASdwseJjuIw15h++EY= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20250129141043epcas5p2e62587576b16e52a71f8b4be4d30e192~fLys1vr541652016520epcas5p27; Wed, 29 Jan 2025 14:10:43 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.174]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4YjkZp04zVz4x9Pr; Wed, 29 Jan 2025 14:10:42 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 78.E1.19933.1E63A976; Wed, 29 Jan 2025 23:10:41 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20250129141041epcas5p4f2a5c78d6abfc3190b174cc1a32b0b12~fLyqr7nzf1416814168epcas5p4g; Wed, 29 Jan 2025 14:10:41 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20250129141041epsmtrp2a9ef58e027346b3a4e486623bd99a331~fLyqrKfp51194411944epsmtrp2K; Wed, 29 Jan 2025 14:10:41 +0000 (GMT) X-AuditID: b6c32a4a-b87c770000004ddd-9a-679a36e12706 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 2B.8F.23488.1E63A976; Wed, 29 Jan 2025 23:10:41 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250129141039epsmtip2abab78014ef8e4aa09be4d98b0930f73~fLyo0STZi2237422374epsmtip2c; Wed, 29 Jan 2025 14:10:39 +0000 (GMT) From: Kanchan Joshi 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 , Anuj Gupta Subject: [RFC 1/3] block: add integrity offload Date: Wed, 29 Jan 2025 19:32:05 +0530 Message-Id: <20250129140207.22718-2-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250129140207.22718-1-joshi.k@samsung.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJJsWRmVeSWpSXmKPExsWy7bCmuu5Ds1npBovPWVo0TfjLbLH6bj+b xaT+GewWF340MlncPL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OUTqmt0dJu1O/vkG8Pzi1OfLXt16GlLTdsv g332R/8cXuzN498xX1P6BJc3g5/CtGOS05+/UGIpzkg01GIuKk4EAPbj7qwBAwAA X-CMS-MailID: 20250129141041epcas5p4f2a5c78d6abfc3190b174cc1a32b0b12 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250129141041epcas5p4f2a5c78d6abfc3190b174cc1a32b0b12 References: <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 Co-developed-by: Anuj Gupta Signed-off-by: Anuj Gupta --- 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; From patchwork Wed Jan 29 14:02:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 13953781 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 850D21531E9 for ; Wed, 29 Jan 2025 14:10:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159854; cv=none; b=sKPXr0bMiYtXLy3bpVrDUMxJg//14ks9UtaRqMXmUUn05N2wBVM+E1BNPAuq+U0xREgfyO3agkNS/b0Q12yoBgWgHhf5+cAtbpffGU0Ml2DhawQk28Yit6F+gkmkdVozbVdZtzlFTeFWNjya9nCRrTKMcVyiK86fqZmULjtJfl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159854; c=relaxed/simple; bh=RwATSeYpEaFd9Xwcv/hMns0UMj49n44jf+AHHNL0c/Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=RThuv+JwfdPoLKMRQCf8l9vrxuiFTzLIi5t8HzXmknHx0T48VeHgMIYq1FNKufH+wITM2zRO1YVcWK9piB43GIO6teQWsnIr41VgMhG9uWMgSAy4C1CF1KdPHNuemNtk+mUrtQCt1Gmgxzwi00DfUYCnKnZqYWLnh2qeNinC0bI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=XTt+YwcR; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="XTt+YwcR" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250129141045epoutp0424d708e239e07adf6326a79d1b8ffc4d~fLyuHSQbm1870718707epoutp044 for ; Wed, 29 Jan 2025 14:10:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250129141045epoutp0424d708e239e07adf6326a79d1b8ffc4d~fLyuHSQbm1870718707epoutp044 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1738159845; bh=Fl4Rb8PzwWj7kcAlJT0UhpUfE7+NyjqHaHIxLHkLbzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XTt+YwcR3T3azIu1cVklbCeJUDdjAE65uZ7Pd9ObmOzMJfkRxQMMhdYfLHyOycCzh Gpj2SEDtugpnDlnsPxQBS7C2Fuxe98tigt4mJIQYB2cRDbUeP1jw5q/I4AcrevTjVy RF7EWtrcY24lYnOWvlfPT7W35wW6p4PHYkMc/xuk= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20250129141044epcas5p176546b9b902af22da2182bc0d81b6cae~fLytwGLo91214312143epcas5p1c; Wed, 29 Jan 2025 14:10:44 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.181]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4YjkZq4PjWz4x9Pq; Wed, 29 Jan 2025 14:10:43 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 9A.E1.19933.3E63A976; Wed, 29 Jan 2025 23:10:43 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20250129141043epcas5p3676d3c9dcf9f70939056cab89e24cca4~fLysUSG3N2144421444epcas5p36; Wed, 29 Jan 2025 14:10:43 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20250129141043epsmtrp2e609f30144db30a1ddb5c31fc626a3c8~fLysTmTVM1194411944epsmtrp2L; Wed, 29 Jan 2025 14:10:43 +0000 (GMT) X-AuditID: b6c32a4a-b87c770000004ddd-a0-679a36e3a8f4 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 12.F5.18949.3E63A976; Wed, 29 Jan 2025 23:10:43 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250129141041epsmtip27a53dcffcf25ca7a51363a5391580a6e~fLyqq5WuM2314623146epsmtip2Q; Wed, 29 Jan 2025 14:10:41 +0000 (GMT) From: Kanchan Joshi 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 Subject: [RFC 2/3] nvme: support integrity offload Date: Wed, 29 Jan 2025 19:32:06 +0530 Message-Id: <20250129140207.22718-3-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250129140207.22718-1-joshi.k@samsung.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOJsWRmVeSWpSXmKPExsWy7bCmuu5js1npBu8PK1msvtvPZjGpfwa7 xYUfjUwWNw/sZLJYufook8Wfh4YWR/+/BUoeus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J2O2br6yvxLJedkXiqxFGckGmoxFxUnAgCrqL8v/AIAAA== X-CMS-MailID: 20250129141043epcas5p3676d3c9dcf9f70939056cab89e24cca4 X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250129141043epcas5p3676d3c9dcf9f70939056cab89e24cca4 References: <20250129140207.22718-1-joshi.k@samsung.com> Register the integrity offload with the block layer if it is supported by the device. Serve incoming offload requests by setting PRACT and GUARD check. Signed-off-by: Kanchan Joshi --- drivers/nvme/host/core.c | 24 ++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f4b8d6a0984a..1fae0a6a932e 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -984,6 +984,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, { u16 control = 0; u32 dsmgmt = 0; + u8 type; if (req->cmd_flags & REQ_FUA) control |= NVME_RW_FUA; @@ -1022,7 +1023,21 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, return BLK_STS_NOTSUPP; control |= NVME_RW_PRINFO_PRACT; } + if (req->cmd_flags & REQ_INTEGRITY_OFFLOAD) { + type = ns->head->pi_offload_type; + if (type == BLK_INTEGRITY_OFFLOAD_NONE || + (type == BLK_INTEGRITY_OFFLOAD_BUF && + !blk_integrity_rq(req))) { + WARN_ON_ONCE(1); + return BLK_STS_NOTSUPP; + } + + control |= NVME_RW_PRINFO_PRACT | + NVME_RW_PRINFO_PRCHK_GUARD; + /* skip redundant processing for offload */ + goto out; + } if (bio_integrity_flagged(req->bio, BIP_CHECK_GUARD)) control |= NVME_RW_PRINFO_PRCHK_GUARD; if (bio_integrity_flagged(req->bio, BIP_CHECK_REFTAG)) { @@ -1037,6 +1052,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, } } +out: cmnd->rw.control = cpu_to_le16(control); cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt); return 0; @@ -1846,6 +1862,14 @@ static bool nvme_init_integrity(struct nvme_ns_head *head, bi->tuple_size = head->ms; bi->pi_offset = info->pi_offset; + if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE) { + if (head->ms == head->pi_size) + bi->offload_type = BLK_INTEGRITY_OFFLOAD_NO_BUF; + else + bi->offload_type = BLK_INTEGRITY_OFFLOAD_BUF; + head->pi_offload_type = bi->offload_type; + } + return true; } diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 7be92d07430e..add04583b040 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -476,6 +476,7 @@ struct nvme_ns_head { u16 pi_size; u8 pi_type; u8 guard_type; + u8 pi_offload_type; struct list_head entry; struct kref ref; bool shared; From patchwork Wed Jan 29 14:02:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchan Joshi X-Patchwork-Id: 13953782 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A1211A9B40 for ; Wed, 29 Jan 2025 14:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159857; cv=none; b=HoezRMeqiJtatSRofeUp1koFyd7Q4fveVqcVFPb/zwL3TUuynHTjbLUDjlzRI1ZjcUcI0oGM+eQu4+ZnAfp/8ld87+06N/DC36TV1exNZzz/NtsfQkf1HKExSSQjTxyoAqSh5Yape9JFKSAJkVubPrIf9gmq7Iy6YTEXFPARWrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159857; c=relaxed/simple; bh=AdkfWA6lJaUIlOkpVnTFbRzROWLDA1Mk/RYZC8J2drY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=VoGDSuvT5jkpZLb6pUNle1zoeXEQrIyD2fEEKJvmD2MTK5B1249B9fwN8HYPlKm2OwWqKYfGW3Hbw04b/m7SDlHjDkZ3YP2AJ8uB2UZAYCKf/e7erR12yKODIR5emxHLwZWSlMxNN+1h5vylAaC2EV4wH9fHZI2Wp8NcbTbgsGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=sGEQobN0; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="sGEQobN0" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250129141047epoutp044c251e15e439768c6733bfd68eff178c~fLywe0KSo1870718707epoutp047 for ; Wed, 29 Jan 2025 14:10:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250129141047epoutp044c251e15e439768c6733bfd68eff178c~fLywe0KSo1870718707epoutp047 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1738159847; bh=ST7TI/y+PLKSL5LRzxWbv6tzS6BXzdbRGX2mF/YjYwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sGEQobN0AF2XCIM9GZZwNH3d70TGLDWzdaOoplRnKiRs7rzPEHqQCxns2nq4tsi30 z25p4SHy1zFyZ67e1xTdH4CPYbNpkzD0sZ3sFSyDcBXSMkYxyj1m1bEhHbTE2pE2xM mW5u8ZesysBNr8wdpkt0Y8ueyj0zp7xjS9Jm60Ck= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20250129141046epcas5p35eaafd908a19ad7c36fcdc9a75542852~fLyvdQ5lh2837028370epcas5p3U; Wed, 29 Jan 2025 14:10:46 +0000 (GMT) Received: from epsmgec5p1-new.samsung.com (unknown [182.195.38.180]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4YjkZs31rfz4x9Pp; Wed, 29 Jan 2025 14:10:45 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmgec5p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 30.9F.29212.5E63A976; Wed, 29 Jan 2025 23:10:45 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20250129141044epcas5p422461bd3630814884c91fc0f4207edde~fLyt7beoy1416814168epcas5p4m; Wed, 29 Jan 2025 14:10:44 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20250129141044epsmtrp1ab9dd28959447241d4bccf0273e947d4~fLyt6hsYP0553305533epsmtrp18; Wed, 29 Jan 2025 14:10:44 +0000 (GMT) X-AuditID: b6c32a50-7ebff7000000721c-8a-679a36e51763 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id E2.F5.18949.4E63A976; Wed, 29 Jan 2025 23:10:44 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250129141043epsmtip2f7ed1e3bfa59072eb1baeff6ac801a89~fLysVmGYX2314623146epsmtip2R; Wed, 29 Jan 2025 14:10:43 +0000 (GMT) From: Kanchan Joshi 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 Subject: [RFC 3/3] btrfs: add checksum offload Date: Wed, 29 Jan 2025 19:32:07 +0530 Message-Id: <20250129140207.22718-4-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250129140207.22718-1-joshi.k@samsung.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBJsWRmVeSWpSXmKPExsWy7bCmlu5Ts1npBh/+CVqsvtvPZjGpfwa7 xYUfjUwWNw/sZLJYufook8Wfh4YWR/+/BUoeusZosfeWtsWlxyvYLeYve8ruwO0xsfkdu8fl s6Uem1Z1snlsXlLvsftmA5tH35ZVjB7rt1xl8ZiweSOrx+dNcgGcUdk2GamJKalFCql5yfkp mXnptkrewfHO8aZmBoa6hpYW5koKeYm5qbZKLj4Bum6ZOUCnKimUJeaUAoUCEouLlfTtbIry S0tSFTLyi0tslVILUnIKTAr0ihNzi0vz0vXyUkusDA0MjEyBChOyM/qnHWEpuCNf0bJjJ3sD 4xmpLkZODgkBE4lzzYfYuhi5OIQE9jBKvN54nxHC+cQo8WX5OTaQKiGBb4wSf3ZxwHQsPHuA BaJoL6PEtb75UO2fGSWm3twDlOHgYBPQlLgwuRSkQUQgQ+L46VnMIDXMArMZJda1/mcGSQgL 6En0zmhkArFZBFQlGi6+B9vGK2Ah8WvSEyaIbfISMy99ZwexOQUsJXa/m8sEUSMocXLmExYQ mxmopnnrbLAFEgJzOSRutn1gh2h2kZh0fz0zhC0s8er4Fqi4lMTL/jYoO1viwaMHLBB2jcSO zX2sELa9RMOfG6wgzzADPbN+lz7ELj6J3t8gt3EAlfBKdLQJQVQrStyb9BSqU1zi4YwlULaH xOM/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FhTnpucWGxYY5aWW6xUn5haX5qXrJefnbmIE R4eW1g7GPas+6B1iZOJgPMQowcGsJMIbe25GuhBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHeb697 U4QE0hNLUrNTUwtSi2CyTBycUg1Mwn6M7zQPie1OerCqzidX6an866Y87ddtMr7vW+YFxxn+ jjDgWXf67dFXc+f8UTmkV8gprq1/4uPy+c/LYhLOWnke9QnaErjG80d735rJBSG+ExWmNn52 PxEjuPXpqXdbL2VciywO03h7R7frRb50+UnjXn6zhG2VIQcXZfwLiStIUdZxYQn6lGXZfuWF orLVxJPqSZZ56lUbnrUpKBy0ed58lfPnrSUTJQ5Nby5MXT2NK+L7eiX2ZZ8/l/GtF5xzQ0px 33mTxf6vJL+k3rz24NG6iIfRrft0nj9aXbR8dpX8tlcmG4ur9Wc8ik9/e/botvPnGdmuHzG8 uWUGR/CUOGs74+8av0QK561asb3TX4mlOCPRUIu5qDgRACWg5cX9AgAA X-CMS-MailID: 20250129141044epcas5p422461bd3630814884c91fc0f4207edde X-Msg-Generator: CA CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250129141044epcas5p422461bd3630814884c91fc0f4207edde References: <20250129140207.22718-1-joshi.k@samsung.com> Add new mount option 'datsum_offload'. When passed - Data checksumming at the FS level is disabled. - Data checksumming at the device level is enabled. This is done by setting REQ_INTEGRITY_OFFLOAD flag for data I/O if the underlying device is capable. Signed-off-by: Kanchan Joshi --- fs/btrfs/bio.c | 12 ++++++++++++ fs/btrfs/fs.h | 1 + fs/btrfs/super.c | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 7ea6f0b43b95..811d89c64991 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -5,6 +5,7 @@ */ #include +#include #include "bio.h" #include "ctree.h" #include "volumes.h" @@ -424,6 +425,15 @@ static void btrfs_clone_write_end_io(struct bio *bio) bio_put(bio); } +static void btrfs_prep_csum_offload_hw(struct btrfs_device *dev, struct bio *bio) +{ + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); + + if (btrfs_test_opt(dev->fs_info, DATASUM_OFFLOAD) && + bi && bi->offload_type != BLK_INTEGRITY_OFFLOAD_NONE) + bio->bi_opf |= REQ_INTEGRITY_OFFLOAD; +} + static void btrfs_submit_dev_bio(struct btrfs_device *dev, struct bio *bio) { if (!dev || !dev->bdev || @@ -435,6 +445,8 @@ static void btrfs_submit_dev_bio(struct btrfs_device *dev, struct bio *bio) } bio_set_dev(bio, dev->bdev); + if (!(bio->bi_opf & REQ_META)) + btrfs_prep_csum_offload_hw(dev, bio); /* * For zone append writing, bi_sector must point the beginning of the diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 79a1a3d6f04d..88e493967100 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -228,6 +228,7 @@ enum { BTRFS_MOUNT_NOSPACECACHE = (1ULL << 30), BTRFS_MOUNT_IGNOREMETACSUMS = (1ULL << 31), BTRFS_MOUNT_IGNORESUPERFLAGS = (1ULL << 32), + BTRFS_MOUNT_DATASUM_OFFLOAD = (1ULL << 33), }; /* diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 7dfe5005129a..d0d5b35c2df9 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -121,6 +121,7 @@ enum { Opt_treelog, Opt_user_subvol_rm_allowed, Opt_norecovery, + Opt_datasum_offload, /* Rescue options */ Opt_rescue, @@ -223,6 +224,7 @@ static const struct fs_parameter_spec btrfs_fs_parameters[] = { fsparam_string("compress-force", Opt_compress_force_type), fsparam_flag_no("datacow", Opt_datacow), fsparam_flag_no("datasum", Opt_datasum), + fsparam_flag_no("datasum_offload", Opt_datasum_offload), fsparam_flag("degraded", Opt_degraded), fsparam_string("device", Opt_device), fsparam_flag_no("discard", Opt_discard), @@ -323,6 +325,10 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param) btrfs_clear_opt(ctx->mount_opt, NODATASUM); } break; + case Opt_datasum_offload: + btrfs_set_opt(ctx->mount_opt, NODATASUM); + btrfs_set_opt(ctx->mount_opt, DATASUM_OFFLOAD); + break; case Opt_datacow: if (result.negated) { btrfs_clear_opt(ctx->mount_opt, COMPRESS); @@ -1057,6 +1063,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) seq_puts(seq, ",degraded"); if (btrfs_test_opt(info, NODATASUM)) seq_puts(seq, ",nodatasum"); + if (btrfs_test_opt(info, DATASUM_OFFLOAD)) + seq_puts(seq, ",datasum_offload"); if (btrfs_test_opt(info, NODATACOW)) seq_puts(seq, ",nodatacow"); if (btrfs_test_opt(info, NOBARRIER)) @@ -1434,6 +1442,7 @@ static void btrfs_emit_options(struct btrfs_fs_info *info, btrfs_info_if_set(info, old, NODATASUM, "setting nodatasum"); btrfs_info_if_set(info, old, DEGRADED, "allowing degraded mounts"); btrfs_info_if_set(info, old, NODATASUM, "setting nodatasum"); + btrfs_info_if_set(info, old, DATASUM_OFFLOAD, "setting datasum offload to the device"); btrfs_info_if_set(info, old, SSD, "enabling ssd optimizations"); btrfs_info_if_set(info, old, SSD_SPREAD, "using spread ssd allocation scheme"); btrfs_info_if_set(info, old, NOBARRIER, "turning off barriers");