From patchwork Fri Aug 23 10:38:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anuj Gupta X-Patchwork-Id: 13774992 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 DCDD8187855 for ; Fri, 23 Aug 2024 10:48:54 +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=1724410136; cv=none; b=GX4WpZfAtslJAWGR2Pr10lbbQnQdqX80Fx3H/jyjLrTrFTXDFYmfFH0UqGCa57/0pGWOkQal2BuWrpJV3SnF2178k5MbKVupK1dEvx0t2FSYyC9t8YZDEcFyYiyEg0r4cKjULAHBCKNBYBCRdZFf7ji0kxiQHul7nFEkasMrjVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724410136; c=relaxed/simple; bh=d8uLLwSdbzE5G1fR2VMdUPEYeU0UD3cRDnuIOnqv5P4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=A4y9XFMopzOA5EzW2Cbkh+AsYFjmATjSnIqcdIOErH+QfUYk5lUlsbAzGhf7zIlgpkdIFRVXJUkMz0k/+f1J5GUj0zaaXoe8ZnX2OclOGjpE6WOnmDks0Ai6K0RsEZeY2qpHWlh8kfQBLS5xAsrWNAfoR1IvfgsE7ywKGfjlFWA= 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=Zi/TY8EA; 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="Zi/TY8EA" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240823104852epoutp0282fccb39a1221884e3643641dd8b52e4~uVeEgimtk1185311853epoutp02U for ; Fri, 23 Aug 2024 10:48:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240823104852epoutp0282fccb39a1221884e3643641dd8b52e4~uVeEgimtk1185311853epoutp02U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1724410132; bh=YAT9f3XY8IKgq4WGMiK0V4o2WovD1lxpk8P5rBhzxR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zi/TY8EA4txsjwhM/vQbcI663nD8acr+pVTsqZg9o4LAx+BMurmS8TPsWrc2qvn3f AZix6GMsf784zmL6M3zfzBCbhu5kdll2tZAacIuMY3iNeUio9A19pItbqVZe0zPhkB M9fDUgfbZNeW+Vs0jwEBlvLJWucYPvPm/9m1j1VA= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20240823104852epcas5p424c5a420f83babade5eb18c7b817db39~uVeEBmsGG1746017460epcas5p4S; Fri, 23 Aug 2024 10:48:52 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.180]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4WqxdG4j1Yz4x9Pv; Fri, 23 Aug 2024 10:48:50 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 7F.28.09642.21968C66; Fri, 23 Aug 2024 19:48:50 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20240823104639epcas5p11dbab393122841419368a86b4bd5c04b~uVcIMnAqt0371903719epcas5p1h; Fri, 23 Aug 2024 10:46:39 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240823104639epsmtrp2a5af888759a8b81fe7731ecd1c213759~uVcILd2ID0163301633epsmtrp2m; Fri, 23 Aug 2024 10:46:39 +0000 (GMT) X-AuditID: b6c32a4b-613ff700000025aa-8d-66c86912ad23 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 5D.50.19367.F8868C66; Fri, 23 Aug 2024 19:46:39 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240823104636epsmtip20ab42e1096e1e413e32f65d84bf4f0bb~uVcFxtx0q1442714427epsmtip2y; Fri, 23 Aug 2024 10:46:36 +0000 (GMT) From: Anuj Gupta To: axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, martin.petersen@oracle.com, asml.silence@gmail.com, krisman@suse.de Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, gost.dev@samsung.com, linux-scsi@vger.kernel.org, Anuj Gupta Subject: [PATCH v3 10/10] scsi: add support for user-meta interface Date: Fri, 23 Aug 2024 16:08:11 +0530 Message-Id: <20240823103811.2421-12-anuj20.g@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823103811.2421-1-anuj20.g@samsung.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJJsWRmVeSWpSXmKPExsWy7bCmpq5Q5ok0g2sn5S2aJvxltpizahuj xeq7/WwWNw/sZLJYufook8W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Xb5433F1Obz f/uXXLR+y8Uh+vbx/l/sQfesD1+b9vi8EktxRqKhFnNRcSIAVsx/6QADAAA= X-CMS-MailID: 20240823104639epcas5p11dbab393122841419368a86b4bd5c04b X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240823104639epcas5p11dbab393122841419368a86b4bd5c04b References: <20240823103811.2421-1-anuj20.g@samsung.com> Add support for sending user-meta buffer. Set tags to be checked using flags specified by user/block-layer user and underlying DIF/DIX configuration. Introduce BLK_INTEGRITY_APP_TAG to specify apptag. This provides a way for upper layers to specify apptag checking. Signed-off-by: Anuj Gupta --- block/bio-integrity.c | 2 ++ drivers/scsi/sd.c | 25 +++++++++++++++++++++++-- drivers/scsi/sd_dif.c | 2 +- include/linux/blk-integrity.h | 1 + 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 02b766c2e57d..ff7de4fe74c4 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -492,6 +492,8 @@ bool bio_integrity_prep(struct bio *bio) bip->bip_flags |= BIP_CHECK_GUARD; if (bi->flags & BLK_INTEGRITY_REF_TAG) bip->bip_flags |= BIP_CHECK_REFTAG; + if (bi->flags & BLK_INTEGRITY_APP_TAG) + bip->bip_flags |= BIP_CHECK_APPTAG; if (bio_integrity_add_page(bio, virt_to_page(buf), len, offset_in_page(buf)) < len) { printk(KERN_ERR "could not attach integrity payload\n"); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 699f4f9674d9..6ebef140cec2 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -803,6 +803,23 @@ static unsigned int sd_prot_flag_mask(unsigned int prot_op) return flag_mask[prot_op]; } +/* + * Can't check reftag alone or apptag alone + */ +static bool sd_prot_flags_valid(struct scsi_cmnd *scmd) +{ + struct request *rq = scsi_cmd_to_rq(scmd); + struct bio *bio = rq->bio; + + if (bio_integrity_flagged(bio, BIP_CHECK_REFTAG) && + !bio_integrity_flagged(bio, BIP_CHECK_APPTAG)) + return false; + if (!bio_integrity_flagged(bio, BIP_CHECK_REFTAG) && + bio_integrity_flagged(bio, BIP_CHECK_APPTAG)) + return false; + return true; +} + static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd, unsigned int dix, unsigned int dif) { @@ -815,14 +832,16 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd, if (bio_integrity_flagged(bio, BIP_IP_CHECKSUM)) scmd->prot_flags |= SCSI_PROT_IP_CHECKSUM; - if (bio_integrity_flagged(bio, BIP_CTRL_NOCHECK) == false) + if (bio_integrity_flagged(bio, BIP_CTRL_NOCHECK) == false && + (bio_integrity_flagged(bio, BIP_CHECK_GUARD))) scmd->prot_flags |= SCSI_PROT_GUARD_CHECK; } if (dif != T10_PI_TYPE3_PROTECTION) { /* DIX/DIF Type 0, 1, 2 */ scmd->prot_flags |= SCSI_PROT_REF_INCREMENT; - if (bio_integrity_flagged(bio, BIP_CTRL_NOCHECK) == false) + if ((bio_integrity_flagged(bio, BIP_CTRL_NOCHECK) == false) && + (!dix || bio_integrity_flagged(bio, BIP_CHECK_REFTAG))) scmd->prot_flags |= SCSI_PROT_REF_CHECK; } @@ -1374,6 +1393,8 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); dld = sd_cdl_dld(sdkp, cmd); + if (!sd_prot_flags_valid(cmd)) + goto fail; if (dif || dix) protect = sd_setup_protect_cmnd(cmd, dix, dif); else diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c index ae6ce6f5d622..6c53e3b9d7d7 100644 --- a/drivers/scsi/sd_dif.c +++ b/drivers/scsi/sd_dif.c @@ -50,7 +50,7 @@ void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim) bi->csum_type = BLK_INTEGRITY_CSUM_CRC; if (type != T10_PI_TYPE3_PROTECTION) - bi->flags |= BLK_INTEGRITY_REF_TAG; + bi->flags |= BLK_INTEGRITY_REF_TAG | BLK_INTEGRITY_APP_TAG; bi->tuple_size = sizeof(struct t10_pi_tuple); diff --git a/include/linux/blk-integrity.h b/include/linux/blk-integrity.h index 2ff65c933c50..865e0c4a7255 100644 --- a/include/linux/blk-integrity.h +++ b/include/linux/blk-integrity.h @@ -13,6 +13,7 @@ enum blk_integrity_flags { BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, BLK_INTEGRITY_REF_TAG = 1 << 3, BLK_INTEGRITY_STACKED = 1 << 4, + BLK_INTEGRITY_APP_TAG = 1 << 5, }; const char *blk_integrity_profile_name(struct blk_integrity *bi);