From patchwork Thu Jan 11 16:00:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13517576 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 534642943E for ; Thu, 11 Jan 2024 16:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="U0ERhN3a" Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-35d374bebe3so2556285ab.1 for ; Thu, 11 Jan 2024 08:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1704988950; x=1705593750; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wb8RmmOQHMK3RGx2kZv4ToZcis6slj97jx6CHPGBmCY=; b=U0ERhN3avCH+rshDGVc5xjBMYPjQrmgC/ke3+qA4KBblGYMoExebynzpInjGgY4hoi ukwHDRV6CFZfldW4aTjgT3twYosq8TV/sEfmaAI8wub8vfO/Zffu+rXjcQL2aGbwjeM8 CzXcyKniBvgcrKsrzS5HJpJ2wYzTf7zBFjfrpptycaiZWqHHS4Slr0IousKRV2ZqKy27 FB7epBogHyiHTYp8GSnux/IAYGsNHBBiEhdbStvLzgJkYaIq3RJ4iGBfdo1SAaxjVCo3 lAcatOxAWsy9f7JiJLuVQVD792fN/jKzZsSfJGjhcM3B4ov/reKOCVraoxmfZ/adzW9v xjcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704988950; x=1705593750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wb8RmmOQHMK3RGx2kZv4ToZcis6slj97jx6CHPGBmCY=; b=ZrLwsG59NNngc6rLhBbgbuDqqokmO7RLVmg9bTb15oO28EgaDRntDxJzy9Y+35hHu0 Uxs9ffWAr/LMX7JiHdtA+d9OfgMLThwyhS+rB3jlEi6cwFVv719hlmjThzA4Mk/OGXW7 sBHHVHYsI1Sm+9tyPFZQ88xR2gH7WbVKqYA8GKLTuDxFRThLLJ2vu5Rajh6vUM4MjtW7 1hL6JD6p0zL4u/Qp/ntoNB9JFuyx7y5FMGxSiWgOfJjoMXcgbRUXvfJH8oEebc+N+hFz 0A2ivAImmJwwsubvLDwAu9j9beotgt3CS6S2nyShjAeTMzmE4+dz/Cx39+joMzXhHmBR yUIw== X-Gm-Message-State: AOJu0YznzG1ufb9eGj9gyNj2E0RSxQf7Szo2de7kEP1uEd7gv0oXsppO tjp1miLmsXgB/8cY4EhN8n3WtHevDsvrdflBc01s4s1RFDsxaw== X-Google-Smtp-Source: AGHT+IF/BsaTJI9Ykrr2nPEOWTxMD881gwF89roTIL5hEccg+HH+/3RETmhusbyuqQbOIm++qYNTQg== X-Received: by 2002:a6b:dc18:0:b0:7be:e376:fc44 with SMTP id s24-20020a6bdc18000000b007bee376fc44mr2976530ioc.2.1704988950527; Thu, 11 Jan 2024 08:02:30 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id cl15-20020a0566383d0f00b0046e564817c1sm285450jab.33.2024.01.11.08.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 08:02:29 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: martin.petersen@oracle.com, Jens Axboe Subject: [PATCH 1/3] block/integrity: make profile optional Date: Thu, 11 Jan 2024 09:00:19 -0700 Message-ID: <20240111160226.1936351-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111160226.1936351-1-axboe@kernel.dk> References: <20240111160226.1936351-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If no profile is given, we set a 'nop' profile. But we already check for a NULL profile in most spots, so let's get rid of this wasted code. It's also considerably faster to check for a NULL handler rather than have an indirect call into a dummy function. Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig --- block/blk-integrity.c | 24 +----------------------- block/blk-mq.c | 8 +++++--- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index d4e9b4556d14..a1ea1794c7c8 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -326,28 +326,6 @@ const struct attribute_group blk_integrity_attr_group = { .attrs = integrity_attrs, }; -static blk_status_t blk_integrity_nop_fn(struct blk_integrity_iter *iter) -{ - return BLK_STS_OK; -} - -static void blk_integrity_nop_prepare(struct request *rq) -{ -} - -static void blk_integrity_nop_complete(struct request *rq, - unsigned int nr_bytes) -{ -} - -static const struct blk_integrity_profile nop_profile = { - .name = "nop", - .generate_fn = blk_integrity_nop_fn, - .verify_fn = blk_integrity_nop_fn, - .prepare_fn = blk_integrity_nop_prepare, - .complete_fn = blk_integrity_nop_complete, -}; - /** * blk_integrity_register - Register a gendisk as being integrity-capable * @disk: struct gendisk pointer to make integrity-aware @@ -367,7 +345,7 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template template->flags; bi->interval_exp = template->interval_exp ? : ilog2(queue_logical_block_size(disk->queue)); - bi->profile = template->profile ? template->profile : &nop_profile; + bi->profile = template->profile; bi->tuple_size = template->tuple_size; bi->tag_size = template->tag_size; diff --git a/block/blk-mq.c b/block/blk-mq.c index 421db29535ba..37268656aae9 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -834,7 +834,8 @@ static void blk_complete_request(struct request *req) return; #ifdef CONFIG_BLK_DEV_INTEGRITY - if (blk_integrity_rq(req) && req_op(req) == REQ_OP_READ) + if (blk_integrity_rq(req) && req_op(req) == REQ_OP_READ && + req->q->integrity.profile->complete_fn) req->q->integrity.profile->complete_fn(req, total_bytes); #endif @@ -905,7 +906,7 @@ bool blk_update_request(struct request *req, blk_status_t error, #ifdef CONFIG_BLK_DEV_INTEGRITY if (blk_integrity_rq(req) && req_op(req) == REQ_OP_READ && - error == BLK_STS_OK) + error == BLK_STS_OK && req->q->integrity.profile->complete_fn) req->q->integrity.profile->complete_fn(req, nr_bytes); #endif @@ -1268,7 +1269,8 @@ void blk_mq_start_request(struct request *rq) rq->mq_hctx->tags->rqs[rq->tag] = rq; #ifdef CONFIG_BLK_DEV_INTEGRITY - if (blk_integrity_rq(rq) && req_op(rq) == REQ_OP_WRITE) + if (blk_integrity_rq(rq) && req_op(rq) == REQ_OP_WRITE && + q->integrity.profile->prepare_fn) q->integrity.profile->prepare_fn(rq); #endif if (rq->bio && rq->bio->bi_opf & REQ_POLLED) From patchwork Thu Jan 11 16:00:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13517575 Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A4B44EB5C for ; Thu, 11 Jan 2024 16:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="kx7D6Lbb" Received: by mail-io1-f48.google.com with SMTP id ca18e2360f4ac-7bee9f626caso26766239f.0 for ; Thu, 11 Jan 2024 08:02:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1704988952; x=1705593752; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LW8hJRUCyJnXXFKg+bUvndErLDbE+w7TyMXWFjFowkQ=; b=kx7D6LbbedZHx3TzS/bMHBBCyRkNFYlzcYcm8ta89x6E2cEMuaf4EXN4YYKWEt+9yV gr2UoswxNFsgWyj2hILf7+ethNqEfSqBWY4KWRRgnyezJUpBw1DC+p3YOILDrdrmDjeb hC+s2GFyf7FGklaUikm/G6xMSer7fYAoNbON+h2Y6NNORMayju4+V1ZJvwRvdrBGFdc+ UQwfKRGqODdul4R4Mu0mYLbOlbdoxmtCiH0Pelp3d6/spILHv6tiXn4Jq48ALOAyyzqB 9sREBofCtzDUjivnD8ANnXXMrdt7p/pFA/++tCeWnAacXS6rLgKyb+3ejcGnBbcrCUL7 MvHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704988952; x=1705593752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LW8hJRUCyJnXXFKg+bUvndErLDbE+w7TyMXWFjFowkQ=; b=tY6k7sf2AAoO7BKF82foOOu/oyZVNSK+e+SXupoytfSnS8OaFoTf6dE+p1KjgOdh5D sPFcV3RDNhJ268lj9nBwCGlqcHsIPdvaWNYmCsCrQL9XUbCuULM4fANT2wXcDSQNAd/k EQHlwhIL8jKD8bOAFv3LNL3+5BNkOx9F8cpUnH3YpVENuX6RBDq140/xe1osfX2ezckp zF/bn+a1CaxNFKH98oWcXSH88w0kH+qheT/wgOCpfZImIvNqBTO/A3j4oTYY/cwW5t7E wNddDViXz5mqDFmocsUhw64VEzWTaGvNE/zhR8TpVioKgo+XQH4QJ3bBKsc8TKFmULdI 4cmA== X-Gm-Message-State: AOJu0Yw9tS595Veu9CiK3dlQ86EJ2fA42KVE5diRz+H8xkgiVi3yC01x SfiJXao78Wkf3GwCOT2g34lLcT1+3HiG+IVeU+nDDvTbRhQp+w== X-Google-Smtp-Source: AGHT+IF2eEbAxbphOSVC7Vjec4w3jveKEFYOuuDnETkuc3j1nbwELGk2/ugBlpLXWJKdboPMxMAkRA== X-Received: by 2002:a6b:f215:0:b0:7bf:f20:2c78 with SMTP id q21-20020a6bf215000000b007bf0f202c78mr1930989ioh.1.1704988952049; Thu, 11 Jan 2024 08:02:32 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id cl15-20020a0566383d0f00b0046e564817c1sm285450jab.33.2024.01.11.08.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 08:02:30 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: martin.petersen@oracle.com, Jens Axboe Subject: [PATCH 2/3] block/integrity: flag the queue if it has an integrity profile Date: Thu, 11 Jan 2024 09:00:20 -0700 Message-ID: <20240111160226.1936351-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111160226.1936351-1-axboe@kernel.dk> References: <20240111160226.1936351-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we don't set a dummy profile, if someone registers and actual profile, flag the queue as such. Signed-off-by: Jens Axboe --- block/blk-integrity.c | 14 +++++++++----- include/linux/blkdev.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index a1ea1794c7c8..974af93de2da 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -339,22 +339,25 @@ const struct attribute_group blk_integrity_attr_group = { */ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template) { - struct blk_integrity *bi = &disk->queue->integrity; + struct request_queue *q = disk->queue; + struct blk_integrity *bi = &q->integrity; bi->flags = BLK_INTEGRITY_VERIFY | BLK_INTEGRITY_GENERATE | template->flags; bi->interval_exp = template->interval_exp ? : - ilog2(queue_logical_block_size(disk->queue)); + ilog2(queue_logical_block_size(q)); bi->profile = template->profile; + if (bi->profile) + blk_queue_flag_set(QUEUE_FLAG_INTG_PROFILE, q); bi->tuple_size = template->tuple_size; bi->tag_size = template->tag_size; - blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue); + blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, q); #ifdef CONFIG_BLK_INLINE_ENCRYPTION - if (disk->queue->crypto_profile) { + if (q->crypto_profile) { pr_warn("blk-integrity: Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n"); - disk->queue->crypto_profile = NULL; + q->crypto_profile = NULL; } #endif } @@ -377,6 +380,7 @@ void blk_integrity_unregister(struct gendisk *disk) /* ensure all bios are off the integrity workqueue */ blk_flush_integrity(); blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue); + blk_queue_flag_clear(QUEUE_FLAG_INTG_PROFILE, disk->queue); memset(bi, 0, sizeof(*bi)); } EXPORT_SYMBOL(blk_integrity_unregister); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e1e705aef51e..de81642831bb 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -510,6 +510,7 @@ struct request_queue { /* Keep blk_queue_flag_name[] in sync with the definitions below */ #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */ #define QUEUE_FLAG_DYING 1 /* queue being torn down */ +#define QUEUE_FLAG_INTG_PROFILE 2 /* has integrity profile */ #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */ #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */ #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */ From patchwork Thu Jan 11 16:00:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13517577 Received: from mail-io1-f46.google.com (mail-io1-f46.google.com [209.85.166.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E8054F1E6 for ; Thu, 11 Jan 2024 16:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="qQqk/c/J" Received: by mail-io1-f46.google.com with SMTP id ca18e2360f4ac-7beeeb1ba87so21988739f.0 for ; Thu, 11 Jan 2024 08:02:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1704988954; x=1705593754; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UYe192ZhHeWYGGknBv+DYVuizUAzlkdUcrVhT1/dBe0=; b=qQqk/c/J8Dq6PvxuFJjxwBvyJArSLdVGhh7I0xBS5qJWfX4iItNAoZDWsrHysjRxZ6 rPJv+RRZveVEpX41ornl50+Jus1z3GL1qAX3b81SX5iVjB2qcuAKMc8rqEX3KsDuTOqt OjP5U54LL3unB2PW6Rhbnt/KtrnhsSvu6yYxF7+xxcX+trIvXoITtrjZwsRrnAZJKoyF aEg6vgz2ANQMi9w8HtiDyxIaSXhFstjGSVWJxoBQTH9ny/VOhZhs7YBiGcEeySihIHOC vqREm4RJfRyexdZLZ+bXXgqr4kk9kL9a5hYvVi8dzwp4DmjHi3F+cgTk93OgsxBq3cr/ 1dow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704988954; x=1705593754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UYe192ZhHeWYGGknBv+DYVuizUAzlkdUcrVhT1/dBe0=; b=qlttua1U8jkk2vn8aP2M4z4jC/trFTqRrr4c/aGm2Bj0lo6R/AKMv4WXoxn0K+fTho 0b/85wraxh+k0twDzPwFPVShdD9wlDdAdcvdq+35oLLR0roWtc/Dk48+dPxA69uVowWb +7l04X/Xm2A5e/1ADJ0WdxBFpuGCWZp1mispC8DKoKXF3bJmZhi+kcWWqBCq/jiEg5bk U+JdadEq5pmHGQrk6k6zrQDjEU2wnYcPqaLt/VbGh9BDPz2SOMY1RYEK8thzNMzoBctK 5cvC81W0mLIo01ZM+cFKg1yfjosbckmdKoFqvUylNiSUIfPyrQX8VoiqNKkzmWe9V6p/ t3Xg== X-Gm-Message-State: AOJu0YwoFDY578I2xpImpCorkpKKHzeCb731YAkXGdh9i+xsyNX+8qU3 V+hQGZLQF1x1Dy6JpmYn1bcIp2jXT5yXUmu5rAbQUiK+XkM3mA== X-Google-Smtp-Source: AGHT+IFpsk8Yy1x1miYM5rbQ64K11ggNvDAbSqhOn/iZ8jIyfEpZCAZbFlRVbVb6nS8no1dAuliT+A== X-Received: by 2002:a5d:9b05:0:b0:7be:ed2c:f8b with SMTP id y5-20020a5d9b05000000b007beed2c0f8bmr2673482ion.1.1704988953757; Thu, 11 Jan 2024 08:02:33 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id cl15-20020a0566383d0f00b0046e564817c1sm285450jab.33.2024.01.11.08.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 08:02:32 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: martin.petersen@oracle.com, Jens Axboe Subject: [PATCH 3/3] block: only call bio_integrity_prep() if necessary Date: Thu, 11 Jan 2024 09:00:21 -0700 Message-ID: <20240111160226.1936351-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111160226.1936351-1-axboe@kernel.dk> References: <20240111160226.1936351-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that the queue is flag as having an actual profile or not, avoid calling into the integrity code unless we have one. This removes some overhead from blk_mq_submit_bio() if BLK_DEV_INTEGRITY is enabled and we don't have any profiles attached, which is the default and expected case. Signed-off-by: Jens Axboe --- block/blk-mq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 37268656aae9..965e42a1bbde 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2961,7 +2961,8 @@ bool blk_mq_submit_bio(struct bio *bio) bio_set_ioprio(bio); - if (!bio_integrity_prep(bio)) + if (test_bit(QUEUE_FLAG_INTG_PROFILE, &q->queue_flags) && + !bio_integrity_prep(bio)) return false; if (plug) {