From patchwork Wed Jun 26 10:06:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anuj Gupta X-Patchwork-Id: 13712787 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 236B117F50F for ; Wed, 26 Jun 2024 11:43:02 +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=1719402185; cv=none; b=XQmF5QNbW+LuRcd7H8q0m6LA7B1clB4P852IXa63XJ3m6gh/+R+efWqukyn1EaM9Pkfp0Ggg+HJvllKcDvhX69qkuJRpNv6tKeypb8aZPKYZA5uGw1TP+TMMSuC3QkoWiC5PgKf9pRPFhVC8sQ4GUfYDeYK7trW4GUfLfTA41Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719402185; c=relaxed/simple; bh=5jIjcP8xRXDjWvr2WGjD3BoRgUVdc77PFesx1qBBvyI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=XkilnDKjwmtXSE3290o3JqH4vSqoKNfw1TxoeFNU22LdgMQunUUGxG9cANQnQz2cOcggV7I0X9/oMvJmp0RYNb4ux12BUeT1NNzorTnnPdGFXX3MgLA5RgOfX1TySOQsR6NsZ6dlbpWwXGJtoPifgQgKsjwzEg/G/lNESQHk2hE= 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=TWQdpJWS; 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="TWQdpJWS" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240626114300epoutp042d27a9c4d5506b52e1342e2a9df8df60~ciyxaP2bc2386023860epoutp04c for ; Wed, 26 Jun 2024 11:43:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240626114300epoutp042d27a9c4d5506b52e1342e2a9df8df60~ciyxaP2bc2386023860epoutp04c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1719402180; bh=Ms96jkmQ0kuaCcPQfmnfod94T8OohipgnI02PQvTjo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWQdpJWSVXt6fwQA668mibYDtcPydd+2U1afNb6JaAAtiQ6PAgYRl7GzYoOEq7EVN jy6Q8RFKI4aDUCDClVHhnYMlXFzDtLMW2jjyLNcEDvIIRsIgD3w+ecY1W0oJ4OCpnP fGR6rcqssCgZIvHfRWfzsLnQcNpRtQe96NAVWWLU= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20240626114259epcas5p1b6818f7576e9665da59304f5e9b015e4~ciyw6V50m1003510035epcas5p1q; Wed, 26 Jun 2024 11:42:59 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.183]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4W8KZV1NqTz4x9Pq; Wed, 26 Jun 2024 11:42:58 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 36.48.09989.2CEFB766; Wed, 26 Jun 2024 20:42:58 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20240626101527epcas5p23e10a6701f552d16bd6a999418009ba0~chmVION0E2207822078epcas5p2-; Wed, 26 Jun 2024 10:15:27 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240626101527epsmtrp19e14a3ce1656ea45bee13c5af862a824~chmVGgijU1052710527epsmtrp1H; Wed, 26 Jun 2024 10:15:27 +0000 (GMT) X-AuditID: b6c32a4a-e57f970000002705-a4-667bfec2bc8f Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 5B.6A.19057.F3AEB766; Wed, 26 Jun 2024 19:15:27 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240626101525epsmtip1585e16aa5c4eb50dd6c82ce8c3bc9c15~chmTc1YNM0324303243epsmtip16; Wed, 26 Jun 2024 10:15:25 +0000 (GMT) From: Anuj Gupta To: asml.silence@gmail.com, mpatocka@redhat.com, axboe@kernel.dk, hch@lst.de, kbusch@kernel.org, martin.petersen@oracle.com Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Kanchan Joshi , Anuj Gupta Subject: [PATCH v2 09/10] block: add support to pass user meta buffer Date: Wed, 26 Jun 2024 15:36:59 +0530 Message-Id: <20240626100700.3629-10-anuj20.g@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626100700.3629-1-anuj20.g@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+NgFtrMJsWRmVeSWpSXmKPExsWy7bCmpu6hf9VpBoc/sVg0TfjLbDFn1TZG i9V3+9ksVq4+ymTxrvUci8XR/2/ZLCYdus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XSZ XL/ziWvjpIb9NsYpEV/nHvPZLaXEUpyRaKjFXFScCACHBxPA/QIAAA== X-CMS-MailID: 20240626101527epcas5p23e10a6701f552d16bd6a999418009ba0 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240626101527epcas5p23e10a6701f552d16bd6a999418009ba0 References: <20240626100700.3629-1-anuj20.g@samsung.com> From: Kanchan Joshi If iocb contains the meta, extract that and prepare the bip. Extend bip so that can it can carry three new integrity-check flags and application tag. Make sure that ->prepare_fn and ->complete_fn are skipped for user-owned meta buffer. Signed-off-by: Anuj Gupta Signed-off-by: Kanchan Joshi --- block/bio-integrity.c | 44 +++++++++++++++++++++++++++++++++++++++++++ block/fops.c | 28 ++++++++++++++++++++++++++- block/t10-pi.c | 6 ++++++ include/linux/bio.h | 10 ++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 38418be07139..599f39999174 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "blk.h" static struct kmem_cache *bip_slab; @@ -337,6 +338,49 @@ static unsigned int bvec_from_pages(struct bio_vec *bvec, struct page **pages, return nr_bvecs; } +static void bio_uio_meta_to_bip(struct bio *bio, struct uio_meta *meta) +{ + struct bio_integrity_payload *bip = bio_integrity(bio); + u16 bip_flags = 0; + + if (meta->flags & INTEGRITY_CHK_GUARD) + bip_flags |= BIP_USER_CHK_GUARD; + if (meta->flags & INTEGRITY_CHK_APPTAG) + bip_flags |= BIP_USER_CHK_APPTAG; + if (meta->flags & INTEGRITY_CHK_REFTAG) + bip_flags |= BIP_USER_CHK_REFTAG; + + bip->bip_flags |= bip_flags; + bip->apptag = meta->apptag; +} + +int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta) +{ + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); + unsigned int integrity_bytes; + int ret; + struct iov_iter it; + + if (!bi) + return -EINVAL; + /* + * original meta iterator can be bigger. + * process integrity info corresponding to current data buffer only. + */ + it = meta->iter; + integrity_bytes = bio_integrity_bytes(bi, bio_sectors(bio)); + if (it.count < integrity_bytes) + return -EINVAL; + + it.count = integrity_bytes; + ret = bio_integrity_map_user(bio, &it, 0); + if (!ret) { + bio_uio_meta_to_bip(bio, meta); + iov_iter_advance(&meta->iter, integrity_bytes); + } + return ret; +} + int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter, u32 seed) { diff --git a/block/fops.c b/block/fops.c index be36c9fbd500..6477424b4ebc 100644 --- a/block/fops.c +++ b/block/fops.c @@ -126,12 +126,13 @@ static void blkdev_bio_end_io(struct bio *bio) { struct blkdev_dio *dio = bio->bi_private; bool should_dirty = dio->flags & DIO_SHOULD_DIRTY; + bool is_async = !(dio->flags & DIO_IS_SYNC); if (bio->bi_status && !dio->bio.bi_status) dio->bio.bi_status = bio->bi_status; if (atomic_dec_and_test(&dio->ref)) { - if (!(dio->flags & DIO_IS_SYNC)) { + if (is_async) { struct kiocb *iocb = dio->iocb; ssize_t ret; @@ -154,6 +155,9 @@ static void blkdev_bio_end_io(struct bio *bio) } } + if (is_async && (dio->iocb->ki_flags & IOCB_HAS_META)) + bio_integrity_unmap_free_user(bio); + if (should_dirty) { bio_check_pages_dirty(bio); } else { @@ -231,6 +235,16 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, } bio->bi_opf |= REQ_NOWAIT; } + if (!is_sync && unlikely(iocb->ki_flags & IOCB_HAS_META)) { + ret = bio_integrity_map_iter(bio, iocb->private); + if (unlikely(ret)) { + bio_release_pages(bio, false); + bio_clear_flag(bio, BIO_REFFED); + bio_put(bio); + blk_finish_plug(&plug); + return ret; + } + } if (is_read) { if (dio->flags & DIO_SHOULD_DIRTY) @@ -288,6 +302,9 @@ static void blkdev_bio_end_io_async(struct bio *bio) ret = blk_status_to_errno(bio->bi_status); } + if (unlikely(iocb->ki_flags & IOCB_HAS_META)) + bio_integrity_unmap_free_user(bio); + iocb->ki_complete(iocb, ret); if (dio->flags & DIO_SHOULD_DIRTY) { @@ -348,6 +365,15 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, task_io_account_write(bio->bi_iter.bi_size); } + if (unlikely(iocb->ki_flags & IOCB_HAS_META)) { + ret = bio_integrity_map_iter(bio, iocb->private); + WRITE_ONCE(iocb->private, NULL); + if (unlikely(ret)) { + bio_put(bio); + return ret; + } + } + if (iocb->ki_flags & IOCB_ATOMIC) bio->bi_opf |= REQ_ATOMIC; diff --git a/block/t10-pi.c b/block/t10-pi.c index cd7fa60d63ff..38c3da245b11 100644 --- a/block/t10-pi.c +++ b/block/t10-pi.c @@ -131,6 +131,8 @@ static void t10_pi_type1_prepare(struct request *rq) /* Already remapped? */ if (bip->bip_flags & BIP_MAPPED_INTEGRITY) break; + if (bip->bip_flags & BIP_INTEGRITY_USER) + break; bip_for_each_vec(iv, bip, iter) { unsigned int j; @@ -180,6 +182,8 @@ static void t10_pi_type1_complete(struct request *rq, unsigned int nr_bytes) struct bio_vec iv; struct bvec_iter iter; + if (bip->bip_flags & BIP_INTEGRITY_USER) + break; bip_for_each_vec(iv, bip, iter) { unsigned int j; void *p; @@ -305,6 +309,8 @@ static void ext_pi_type1_prepare(struct request *rq) /* Already remapped? */ if (bip->bip_flags & BIP_MAPPED_INTEGRITY) break; + if (bip->bip_flags & BIP_INTEGRITY_USER) + break; bip_for_each_vec(iv, bip, iter) { unsigned int j; diff --git a/include/linux/bio.h b/include/linux/bio.h index 966e22a04996..ff22b627906d 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -330,6 +330,9 @@ enum bip_flags { BIP_INTEGRITY_USER = 1 << 5, /* Integrity payload is user address */ BIP_COPY_USER = 1 << 6, /* Kernel bounce buffer in use */ BIP_CLONED = 1 << 7, /* Indicates that bip is cloned */ + BIP_USER_CHK_GUARD = 1 << 8, + BIP_USER_CHK_APPTAG = 1 << 9, + BIP_USER_CHK_REFTAG = 1 << 10, }; struct uio_meta { @@ -349,6 +352,7 @@ struct bio_integrity_payload { unsigned short bip_vcnt; /* # of integrity bio_vecs */ unsigned short bip_max_vcnt; /* integrity bio_vec slots */ unsigned short bip_flags; /* control flags */ + u16 apptag; /* apptag */ struct bvec_iter bio_iter; /* for rewinding parent bio */ @@ -738,6 +742,7 @@ static inline bool bioset_initialized(struct bio_set *bs) bip_for_each_vec(_bvl, _bio->bi_integrity, _iter) int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter, u32 seed); +int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta); void bio_integrity_unmap_free_user(struct bio *bio); extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int); extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int); @@ -817,6 +822,11 @@ static inline int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter, return -EINVAL; } +static inline int bio_integrity_map_iter(struct bio *bio, struct uio_meta *meta) +{ + return -EINVAL; +} + static inline void bio_integrity_unmap_free_user(struct bio *bio) { }