From: Anuj Gupta <[email protected]>
To: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected]
Cc: [email protected], [email protected],
[email protected], Kanchan Joshi <[email protected]>
Subject: [PATCH v2 10/10] nvme: add handling for user integrity buffer
Date: Wed, 26 Jun 2024 15:37:00 +0530 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
From: Kanchan Joshi <[email protected]>
Create a new helper that contains the handling for both kernel and user
generated integrity buffer.
For user provided integrity buffer, convert bip flags
(guard/reftag/apptag checks) to protocol specific flags. Also pass
apptag and reftag down.
Signed-off-by: Kanchan Joshi <[email protected]>
---
drivers/nvme/host/core.c | 85 ++++++++++++++++++++++++++++------------
1 file changed, 60 insertions(+), 25 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ab0429644fe3..d17428a2b1dd 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -870,6 +870,13 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
return BLK_STS_OK;
}
+static void nvme_set_app_tag(struct nvme_command *cmnd, u16 apptag)
+{
+ cmnd->rw.apptag = cpu_to_le16(apptag);
+ /* use 0xfff as mask so that apptag is used in entirety*/
+ cmnd->rw.appmask = cpu_to_le16(0xffff);
+}
+
static void nvme_set_ref_tag(struct nvme_ns *ns, struct nvme_command *cmnd,
struct request *req)
{
@@ -927,6 +934,55 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
return BLK_STS_OK;
}
+static blk_status_t nvme_setup_rw_meta(struct nvme_ns *ns, struct request *req,
+ struct nvme_command *cmnd, u16 *control,
+ enum nvme_opcode op)
+{
+ struct bio_integrity_payload *bip = bio_integrity(req->bio);
+
+ if (!bip || !(bip->bip_flags & BIP_INTEGRITY_USER)) {
+ /*
+ * If formated with metadata, the block layer always provides a
+ * metadata buffer if CONFIG_BLK_DEV_INTEGRITY is enabled. Else
+ * we enable the PRACT bit for protection information or set the
+ * namespace capacity to zero to prevent any I/O.
+ */
+ if (!blk_integrity_rq(req)) {
+ if (WARN_ON_ONCE(!nvme_ns_has_pi(ns->head)))
+ return BLK_STS_NOTSUPP;
+ *control |= NVME_RW_PRINFO_PRACT;
+ }
+
+ switch (ns->head->pi_type) {
+ case NVME_NS_DPS_PI_TYPE3:
+ *control |= NVME_RW_PRINFO_PRCHK_GUARD;
+ break;
+ case NVME_NS_DPS_PI_TYPE1:
+ case NVME_NS_DPS_PI_TYPE2:
+ *control |= NVME_RW_PRINFO_PRCHK_GUARD |
+ NVME_RW_PRINFO_PRCHK_REF;
+ if (op == nvme_cmd_zone_append)
+ *control |= NVME_RW_APPEND_PIREMAP;
+ nvme_set_ref_tag(ns, cmnd, req);
+ break;
+ }
+ } else {
+ unsigned short bip_flags = bip->bip_flags;
+
+ if (bip_flags & BIP_USER_CHK_GUARD)
+ *control |= NVME_RW_PRINFO_PRCHK_GUARD;
+ if (bip_flags & BIP_USER_CHK_REFTAG) {
+ *control |= NVME_RW_PRINFO_PRCHK_REF;
+ nvme_set_ref_tag(ns, cmnd, req);
+ }
+ if (bip_flags & BIP_USER_CHK_APPTAG) {
+ *control |= NVME_RW_PRINFO_PRCHK_APP;
+ nvme_set_app_tag(cmnd, bip->apptag);
+ }
+ }
+ return 0;
+}
+
/*
* NVMe does not support a dedicated command to issue an atomic write. A write
* which does adhere to the device atomic limits will silently be executed
@@ -963,6 +1019,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
{
u16 control = 0;
u32 dsmgmt = 0;
+ blk_status_t ret;
if (req->cmd_flags & REQ_FUA)
control |= NVME_RW_FUA;
@@ -990,31 +1047,9 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
cmnd->rw.appmask = 0;
if (ns->head->ms) {
- /*
- * If formated with metadata, the block layer always provides a
- * metadata buffer if CONFIG_BLK_DEV_INTEGRITY is enabled. Else
- * we enable the PRACT bit for protection information or set the
- * namespace capacity to zero to prevent any I/O.
- */
- if (!blk_integrity_rq(req)) {
- if (WARN_ON_ONCE(!nvme_ns_has_pi(ns->head)))
- return BLK_STS_NOTSUPP;
- control |= NVME_RW_PRINFO_PRACT;
- }
-
- switch (ns->head->pi_type) {
- case NVME_NS_DPS_PI_TYPE3:
- control |= NVME_RW_PRINFO_PRCHK_GUARD;
- break;
- case NVME_NS_DPS_PI_TYPE1:
- case NVME_NS_DPS_PI_TYPE2:
- control |= NVME_RW_PRINFO_PRCHK_GUARD |
- NVME_RW_PRINFO_PRCHK_REF;
- if (op == nvme_cmd_zone_append)
- control |= NVME_RW_APPEND_PIREMAP;
- nvme_set_ref_tag(ns, cmnd, req);
- break;
- }
+ ret = nvme_setup_rw_meta(ns, req, cmnd, &control, op);
+ if (unlikely(ret))
+ return ret;
}
cmnd->rw.control = cpu_to_le16(control);
--
2.25.1
next prev parent reply other threads:[~2024-06-26 11:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20240626101415epcas5p3b06a963aa0b0196d6599fb86c90bc38c@epcas5p3.samsung.com>
2024-06-26 10:06 ` [PATCH v2 00/10] Read/Write with meta/integrity Anuj Gupta
[not found] ` <CGME20240626101511epcas5p31c95b67da58d408c371c49f8719140fc@epcas5p3.samsung.com>
2024-06-26 10:06 ` [PATCH v2 01/10] block: change rq_integrity_vec to respect the iterator Anuj Gupta
[not found] ` <CGME20240626101513epcas5p10b3f8470148abb10ce3edfb90814cd94@epcas5p1.samsung.com>
2024-06-26 10:06 ` [PATCH v2 02/10] block: set bip_vcnt correctly Anuj Gupta
2024-06-28 6:04 ` Christoph Hellwig
2024-06-28 20:35 ` Jens Axboe
[not found] ` <CGME20240626101516epcas5p19fb40e8231d1832cab3d031672f0109e@epcas5p1.samsung.com>
2024-06-26 10:06 ` [PATCH v2 03/10] block: copy bip_max_vcnt vecs instead of bip_vcnt during clone Anuj Gupta
2024-06-27 6:14 ` Christoph Hellwig
[not found] ` <CGME20240626101518epcas5p17e046bca77b218fc6914ddeb182eb42e@epcas5p1.samsung.com>
2024-06-26 10:06 ` [PATCH v2 04/10] block: Handle meta bounce buffer correctly in case of split Anuj Gupta
2024-06-27 6:16 ` Christoph Hellwig
[not found] ` <CGME20240626101519epcas5p163b0735c1604a228196f0e8c14773005@epcas5p1.samsung.com>
2024-06-26 10:06 ` [PATCH v2 05/10] block: introduce BIP_CLONED flag Anuj Gupta
2024-06-27 6:21 ` Christoph Hellwig
2024-06-27 12:09 ` Christoph Hellwig
[not found] ` <CGME20240626101521epcas5p42b0c1c0e123996b199e058bae9a69123@epcas5p4.samsung.com>
2024-06-26 10:06 ` [PATCH v2 06/10] block: modify bio_integrity_map_user to accept iov_iter as argument Anuj Gupta
2024-06-27 6:23 ` Christoph Hellwig
[not found] ` <CGME20240626101523epcas5p2616cf568575685bd251d28fc1398d4cd@epcas5p2.samsung.com>
2024-06-26 10:06 ` [PATCH v2 07/10] block: define meta io descriptor Anuj Gupta
2024-06-27 6:22 ` Christoph Hellwig
[not found] ` <CGME20240626101525epcas5p4dbcef84714e4e9214b951fe2ff649521@epcas5p4.samsung.com>
2024-06-26 10:06 ` [PATCH v2 08/10] io_uring/rw: add support to send meta along with read/write Anuj Gupta
2024-06-26 17:17 ` Gabriel Krisman Bertazi
2024-07-01 14:09 ` Anuj gupta
[not found] ` <CGME20240626101527epcas5p23e10a6701f552d16bd6a999418009ba0@epcas5p2.samsung.com>
2024-06-26 10:06 ` [PATCH v2 09/10] block: add support to pass user meta buffer Anuj Gupta
[not found] ` <CGME20240626101529epcas5p49976c46701337830c400cefd8f074b40@epcas5p4.samsung.com>
2024-06-26 10:07 ` Anuj Gupta [this message]
2024-06-27 6:29 ` [PATCH v2 10/10] nvme: add handling for user integrity buffer Christoph Hellwig
2024-06-27 6:05 ` [PATCH v2 00/10] Read/Write with meta/integrity Christoph Hellwig
2024-06-27 19:12 ` Kanchan Joshi
2024-06-28 20:36 ` (subset) " Jens Axboe
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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