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: 13953785 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 5271814A635 for ; Wed, 29 Jan 2025 14:10:52 +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=1738159855; cv=none; b=qLFPyMtPlojyxgpInqGr2VdoR7OQj3AcOPKimsPUfQJgKEzaVWPT74gEr2STcN6rZdN82b+TS5V77JZHicAUCBpsR4NV3bQfaKvnZeV6TvyNyyPs0e7xS+zNs182cCAHTXP64NH6Rker+BeSgZUFdMQidrtZ/IVqBkJEDXqIaJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159855; 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=i4Gg3dASfP5Laku+9tq4YVCcHJiAVFtjOu3HzFuj6ap/DmC4Pb0ek/JFeDm2/OmiGGkV8jrzD1e7u2sjPy6pDNypUw0FRFrWr3qH7b6X0EOSr6qddOKaf5bzF4NgwBIJ6RoYqXadM9j5c1KRIrfXo3IAccc9Gbwe38DOTQX44vs= 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.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="XTt+YwcR" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20250129141045epoutp0261ffc2d69b9c6a33367f1663854edf76~fLyuIDHFR1148811488epoutp02W for ; Wed, 29 Jan 2025 14:10:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20250129141045epoutp0261ffc2d69b9c6a33367f1663854edf76~fLyuIDHFR1148811488epoutp02W 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-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOJsWRmVeSWpSXmKPExsWy7bCmuu5js1npBu8PK1msvtvPZjGpfwa7 xYUfjUwWNw/sZLJYufook8Wfh4YWR/+/B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vS4eJ2O2br6yvxLJedkXiqxFGckGmoxFxUnAgCrqL8v/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;