From patchwork Wed Jun 26 04:59:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13712290 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5BA081E880 for ; Wed, 26 Jun 2024 04:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719377999; cv=none; b=pajtPhtNI3atBnWo6HtulD+cGDbUTcgCQQnR5oBYQvygWAA4War4w5Yr7x+Ll1o7wQlVEupxjcaxS0J6DvvIDtkv6z2q/Pq2SAO5z6/cJFNWwscMtSTTqCL6zq4uI73pn5cn7B91q4tAPPqwgDQd1aBva4r81+L3+L9bcBGufq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719377999; c=relaxed/simple; bh=FXwkkXbsX1GuoeRyGX/qHUpkKt3kgXT5A3NRUPKyRTg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cwH34+kgiC909ASjUx9+4ENopUWpWmMrwmnc8BcvZGUyBHRnTGUvYgtGyDphVZ8T4a6EY7KhCL+FaPQCZn6gKYTDSYjOP/D4FG/VHRyhPazenFAq98bD5AlI30jvLi6DuJHKvbCC10epMxJ1s8zK4S6ulEBlrjE5xhpwzhU59Eg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bMON78mw; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bMON78mw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=ELP71pxQA/Vn5sM3sDiIYif58GqHEEW44nTTvsbAT4I=; b=bMON78mwRV8xegwIHKW6/XQZ1F Ake3M33q9XdYu1o/fBVpRuc4OAmLZNut6iuSn+71Emz7pFjCENws1aW3oOajLtEW7XDzVdJx5Vzzg ryK8DyU9koWKfEhTmXNmmNTuaxhP71HnzC4VVxAoHEDlqq2brhuL6EU/7iR5CIO2DnFclTzFQfKE5 mwR/Tvn6gUYYN6m9xn5kB2VuZAIcyRY2MsGJF5mNQncGt+nxvpci6IxLMhPrVkQXOUj2TZptOF9de I4nnJVrycFiwxS1+JFmowU7YfxTs/8Ol46qR1KuCNdxbRKcZshfjN42tTiBGCRQRPVtUAuqXLxsMI 8r/nO8nw==; Received: from [2001:4bb8:2cd:5bfc:fac4:f2e7:8d6c:958e] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMKlA-00000005NkX-0QwJ; Wed, 26 Jun 2024 04:59:56 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , linux-block@vger.kernel.org Subject: [PATCH 1/5] block: only zero non-PI metadata tuples in bio_integrity_prep Date: Wed, 26 Jun 2024 06:59:34 +0200 Message-ID: <20240626045950.189758-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626045950.189758-1-hch@lst.de> References: <20240626045950.189758-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html The PI generation helpers already zero the app tag, so relax the zeroing to non-PI metadata. Signed-off-by: Christoph Hellwig Reviewed-by: Kanchan Joshi --- block/bio-integrity.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 173ffd4d623788..8c5991a1c535af 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -456,11 +456,11 @@ bool bio_integrity_prep(struct bio *bio) /* * Zero the memory allocated to not leak uninitialized kernel - * memory to disk. For PI this only affects the app tag, but - * for non-integrity metadata it affects the entire metadata - * buffer. + * memory to disk for non-integrity metadata where nothing else + * initializes the memory. */ - gfp |= __GFP_ZERO; + if (bi->csum_type == BLK_INTEGRITY_CSUM_NONE) + gfp |= __GFP_ZERO; } /* Allocate kernel buffer for protection data */ From patchwork Wed Jun 26 04:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13712291 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 F389313CFBC for ; Wed, 26 Jun 2024 04:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378001; cv=none; b=vGsrrK3oo+PQzqCCPC5kRzyun0Xsax0QZNJ4mRWQI2YRF3THkFrKpCndH+Oq40vD93rVhMB4HHrSOieGsUP8Oe8rLhN6oKud0jVTmdFoEcq436dHvdiuXvp+/vsVX52ocSmZFn9Dgmc5bEtE8vNsZWDLJrk68mYCZtBePRbHHak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378001; c=relaxed/simple; bh=OkUz3D4zTiO+M92ZwlVv+M7E3coDi1XTWr/8s2b1Q8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUNwGpsUc+cTBBAVgkmfIzv5zlHyb5U88MBrVA9xShuyh/O5WwpWwV9OSwkgdyqVRDvf9Fk2QK55h+sra45Bk1TMGBUAS5c36fz1a2nCBDnGlHPgCSrIJoubahS3fwbzIDiGkwgQHnf4MIpu+pdmfVlOmu1xzA/gzYjVdH1Svvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=m/brbMqs; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="m/brbMqs" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Lnzs8yVYRfhv6PKYE+JHT4C8PmQeaT+ZxW6JYLi2Evw=; b=m/brbMqsrEu0/KK99VfmITEFpW 1bhqfSJW5A3ZJxSOUHVHQ5wcu/LXV9tQqYUS/cQ0KrKMNw9sMn02SNiQmuNq2G6utEBst+09hCFLW isCmx5iY+I6nVa1KkcmCY4QqtbG+wLoGUaqTJa+zFEt6KuJiNvB2VQTFSIZAM4OJgHqGSKKqIIMTc DePWLGrA/9VWIV101Ow1+ADQ85Qk+U/recHXn0i4FCvfthTD5mpWx4HJkCRGQ5LFr2bggaJ8zyfLe 0ZlO8EJOobPywaA8GIUm273+GqNb3qZAK3LLDtNsdPCzHgthshDllQ3w1uxMoc8WFX+vvqPROsmI0 UrrH6qsw==; Received: from [2001:4bb8:2cd:5bfc:fac4:f2e7:8d6c:958e] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMKlC-00000005Nkm-49UC; Wed, 26 Jun 2024 04:59:59 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , linux-block@vger.kernel.org Subject: [PATCH 2/5] block: simplify adding the payload in bio_integrity_prep Date: Wed, 26 Jun 2024 06:59:35 +0200 Message-ID: <20240626045950.189758-3-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626045950.189758-1-hch@lst.de> References: <20240626045950.189758-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html bio_integrity_add_page can add physically contiguous regions of any size, so don't bother chunking up the kmalloced buffer. Signed-off-by: Christoph Hellwig Reviewed-by: Kanchan Joshi --- block/bio-integrity.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 8c5991a1c535af..2efab4b3957978 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -428,10 +428,8 @@ bool bio_integrity_prep(struct bio *bio) { struct bio_integrity_payload *bip; struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); + unsigned int len; void *buf; - unsigned long start, end; - unsigned int len, nr_pages; - unsigned int bytes, offset, i; gfp_t gfp = GFP_NOIO; if (!bi) @@ -471,12 +469,7 @@ bool bio_integrity_prep(struct bio *bio) goto err_end_io; } - end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT; - start = ((unsigned long) buf) >> PAGE_SHIFT; - nr_pages = end - start; - - /* Allocate bio integrity payload and integrity vectors */ - bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages); + bip = bio_integrity_alloc(bio, GFP_NOIO, 1); if (IS_ERR(bip)) { printk(KERN_ERR "could not allocate data integrity bioset\n"); kfree(buf); @@ -489,23 +482,10 @@ bool bio_integrity_prep(struct bio *bio) if (bi->csum_type == BLK_INTEGRITY_CSUM_IP) bip->bip_flags |= BIP_IP_CHECKSUM; - /* Map it */ - offset = offset_in_page(buf); - for (i = 0; i < nr_pages && len > 0; i++) { - bytes = PAGE_SIZE - offset; - - if (bytes > len) - bytes = len; - - if (bio_integrity_add_page(bio, virt_to_page(buf), - bytes, offset) < bytes) { - printk(KERN_ERR "could not attach integrity payload\n"); - goto err_end_io; - } - - buf += bytes; - len -= bytes; - offset = 0; + 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"); + goto err_end_io; } /* Auto-generate integrity metadata if this is a write */ From patchwork Wed Jun 26 04:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13712292 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A012E1411EB for ; Wed, 26 Jun 2024 05:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378004; cv=none; b=Nv81644tKllxf1OFcISOQczJwQbPTnB4RO+w5UrDKsSJDpLMNmn3u4m8yPTOOq/qCgCen0SNuZk2DNB2gOcM6skGNXSCL9Ais8Qk4J81gplJHSb2kQ46crn6/6hbZfbYweU8uxjeFkqsONSiMTiArAgYB/dmvOW+0u98HQYbBQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378004; c=relaxed/simple; bh=FdBOCXIwcT5j4YtBiY8rkX7d+qIIjkK1n4El5jSYJ6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EP1YXfQPm1zWsZITrr1UGaGxS/KVF/XmWJ6UFNYmfSPgCiNWhVu7a+ly9YzJ+NL+14wRTVoZgsj1dqgBmSVIg/4NEYYBfVoNy6U5pxQgbZ9kvLrlGMa8ReGwvftbjCqckOd9DS8qiBTrf2iXna1okW07+QKVpRqltEt2VhgAg+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=B/UW8Byx; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="B/UW8Byx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=XzP272gxGewxI5PdYCImorh/ghJpKV6N9gdcybQzjSM=; b=B/UW8ByxCKO429PN2s+QI+Q6g3 sknsqSlgBdfMClbhUFyJZ2xmm2k/HVe6+0tJSDzpe1wgLWnzjBb7yV4sxeXgch4+DRq8qH0AL50jg LwnNspDzfC+XWJ9+73/PWrgSSJ73jcZLNqCoEWcS/nQLWvbVz9wBAbwx+esI8IjMUhDI6c0+dX3O8 HsjgKG0SpGaCHLBLuDIPB5xay/mk+GGlagDVSaPG0QE5liJi/BHyuHZAoYbil2k+Hc6jjItts/85K /212OAcIp86QAf9MbieXsCKh0xTxfIVqR+FPsGzZ6/EQd2BvxFS8TY4dt+kaog7tu2DrjkPRy/GS2 Hm/YHdWA==; Received: from [2001:4bb8:2cd:5bfc:fac4:f2e7:8d6c:958e] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMKlF-00000005Nkv-3DS1; Wed, 26 Jun 2024 05:00:02 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , linux-block@vger.kernel.org Subject: [PATCH 3/5] block: remove allocation failure warnings in bio_integrity_prep Date: Wed, 26 Jun 2024 06:59:36 +0200 Message-ID: <20240626045950.189758-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626045950.189758-1-hch@lst.de> References: <20240626045950.189758-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Allocation failures already leave a stack trace, so don't spew another warning. Signed-off-by: Christoph Hellwig Reviewed-by: Kanchan Joshi --- block/bio-integrity.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 2efab4b3957978..1017984552baf8 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -465,13 +465,11 @@ bool bio_integrity_prep(struct bio *bio) len = bio_integrity_bytes(bi, bio_sectors(bio)); buf = kmalloc(len, gfp); if (unlikely(buf == NULL)) { - printk(KERN_ERR "could not allocate integrity buffer\n"); goto err_end_io; } bip = bio_integrity_alloc(bio, GFP_NOIO, 1); if (IS_ERR(bip)) { - printk(KERN_ERR "could not allocate data integrity bioset\n"); kfree(buf); goto err_end_io; } From patchwork Wed Jun 26 04:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13712293 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 6E8C91448EA for ; Wed, 26 Jun 2024 05:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378007; cv=none; b=R7xLPP6kK9agjR68UOQzogUZnShqihmbuAro6JX3cVxBFItGb8ls34e4VrjXFomAAfO1eshRVjc192fPwKfGG1VEIoE/vFcU4mz8GTY/uzZyVEeaBEBOp237txvy8w6ahjUvGb7eqParCc/dMhv0Ewi8cQUQHkYTgzBmPaGX8Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378007; c=relaxed/simple; bh=d2qtFQBF5PisLq7gjtFPOlkyXWy7jFP6hL08jZev124=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lq2z7ivvE+KSEBfZ1ZFiSv8N6Az0m8n2KsPmuQCx4A/piVppuXwM+onaHiq/3uq+il1LTVqen/NmFpW+eaT709IHb3l27ZF7GYT+Ab5oeUoIc+lViz5KdaPbUZd8sIDhwW1x+9x/ghBmqcOxuAzXgx2V9dcp6VopfPohny4EXSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=2rVxZfZX; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="2rVxZfZX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Sl/DNmEsMokbnraCCUVvgMV51n7Gs9kMcwiqNJuRN1o=; b=2rVxZfZXipyatMOOZsnO0NbfTH HUSjmTqiRit0jbvN9rTlLVGLai5tRdZmcHN3q9qFam6s0doxI5hndneI4fLtMOqQZBW/P0wMTVEd/ LHNqDfS3jHg3rnYazPxRcb6dv63Zpj8Mfcvxi/XC4QfvhBz3Th9UY8sXeAxNYweaUb/9OpOupuR6r BkLwdZYWrpcRR4FZcbncxQ66jRb0pXMOS9cahfqwQKx5HSTjEgGb3U4qG8IrjCgZ0RGjeewLnXXlc SUyEAcYa22ayUHwTWe+fjuZ4wKbz2DP5w2wk/mIsCkok8S6Z5GcDvrwYB8OnCqd7AiwEAIoEJD3bQ mR/ZAZSw==; Received: from [2001:4bb8:2cd:5bfc:fac4:f2e7:8d6c:958e] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMKlI-00000005NlX-2mce; Wed, 26 Jun 2024 05:00:05 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , linux-block@vger.kernel.org Subject: [PATCH 4/5] block: switch on bio operation in bio_integrity_prep Date: Wed, 26 Jun 2024 06:59:37 +0200 Message-ID: <20240626045950.189758-5-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626045950.189758-1-hch@lst.de> References: <20240626045950.189758-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Use a single switch to perform read and write specific checks and exit early for other operations instead of having two checks using different predicates. Signed-off-by: Christoph Hellwig Reviewed-by: Kanchan Joshi --- block/bio-integrity.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 1017984552baf8..3cd867b0544cf0 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -435,9 +435,6 @@ bool bio_integrity_prep(struct bio *bio) if (!bi) return true; - if (bio_op(bio) != REQ_OP_READ && bio_op(bio) != REQ_OP_WRITE) - return true; - if (!bio_sectors(bio)) return true; @@ -445,10 +442,12 @@ bool bio_integrity_prep(struct bio *bio) if (bio_integrity(bio)) return true; - if (bio_data_dir(bio) == READ) { + switch (bio_op(bio)) { + case REQ_OP_READ: if (bi->flags & BLK_INTEGRITY_NOVERIFY) return true; - } else { + break; + case REQ_OP_WRITE: if (bi->flags & BLK_INTEGRITY_NOGENERATE) return true; @@ -459,6 +458,9 @@ bool bio_integrity_prep(struct bio *bio) */ if (bi->csum_type == BLK_INTEGRITY_CSUM_NONE) gfp |= __GFP_ZERO; + break; + default: + return true; } /* Allocate kernel buffer for protection data */ From patchwork Wed Jun 26 04:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13712294 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 849561E880 for ; Wed, 26 Jun 2024 05:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378010; cv=none; b=CbGZSZ8JalSTDz4KFobkcP7U4oyZBYEGh9+VgaJssKUgxQCDtQVoJf3Sp8dAUuZphP8QQpoiObOq7ykJzUIfNgscBEbGYgZWKi7nX+V4xbczRteCrWCDrkyp3pSqrxZQRsYYOBl+2/FEvsVSY0sKyelfvqSlzMzJC+WU41Kn9rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719378010; c=relaxed/simple; bh=YpaS1a3u7APOfowCGPg6pLP8UCQQW9es3waUalKnR1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxdGgZALuFxuwsMydGB8CJdhZ8Iylibk2uDfhWdq+OZQeX9V9qgZVBrSYYKnsYpwMUvCFelvEGCCtEymhLFzoHRILEG4Zm3QziaKoIBEc3UKszLny+ndjvN15FweFJux1WsVetUzFcDXUkioJQakccLV/b1f16147Vc/6KKwqCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=x5yaCGGu; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="x5yaCGGu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=UCUhhybs5pM8wGyT8tlOjw97WIbK++tljHodc0MrKFQ=; b=x5yaCGGuqX4wdMhSBESK13j02U WdliwWxVlgoD38NbJALCDAWd6aP52IMp2uGuAMB8FDWI0lHgBL0R1INfJnUt4erOSUyEb0GGv6d8v 0yZ+he6ZuPUajlHQktWmbZAcURXDzSLKNjJzHEIUp7GJaZfItdayWSRggyTB60c8zTB6OpmOqFmOI IKYbyf0uYyjrbtpTA0f+RUYkyygEpphOesRenNfeoit4h8dlsMhWV+K7uAiXqZTYUqOeQpl68c8B0 FrGcDNiIfMIq8Czs8I9K1IOPJ5u7fXCmB4o9mBKYj19akEmUGP/kvzory2Oj1lOY5PSjyANjUZinX XO8hL0dg==; Received: from [2001:4bb8:2cd:5bfc:fac4:f2e7:8d6c:958e] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMKlL-00000005Nme-24vV; Wed, 26 Jun 2024 05:00:07 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , linux-block@vger.kernel.org Subject: [PATCH 5/5] block: remove bio_integrity_process Date: Wed, 26 Jun 2024 06:59:38 +0200 Message-ID: <20240626045950.189758-6-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240626045950.189758-1-hch@lst.de> References: <20240626045950.189758-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Move the bvec interation into the generate/verify helpers to avoid a bit of argument passing churn. Signed-off-by: Christoph Hellwig --- block/bio-integrity.c | 47 +---------------- block/blk.h | 7 +-- block/t10-pi.c | 97 +++++++++++++++++++++++++++-------- include/linux/blk-integrity.h | 9 ---- 4 files changed, 79 insertions(+), 81 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 3cd867b0544cf0..20bbfd5730dadd 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -374,44 +374,6 @@ int bio_integrity_map_user(struct bio *bio, void __user *ubuf, ssize_t bytes, } EXPORT_SYMBOL_GPL(bio_integrity_map_user); -/** - * bio_integrity_process - Process integrity metadata for a bio - * @bio: bio to generate/verify integrity metadata for - * @proc_iter: iterator to process - */ -static blk_status_t bio_integrity_process(struct bio *bio, - struct bvec_iter *proc_iter) -{ - struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); - struct blk_integrity_iter iter; - struct bvec_iter bviter; - struct bio_vec bv; - struct bio_integrity_payload *bip = bio_integrity(bio); - blk_status_t ret = BLK_STS_OK; - - iter.disk_name = bio->bi_bdev->bd_disk->disk_name; - iter.interval = 1 << bi->interval_exp; - iter.seed = proc_iter->bi_sector; - iter.prot_buf = bvec_virt(bip->bip_vec); - - __bio_for_each_segment(bv, bio, bviter, *proc_iter) { - void *kaddr = bvec_kmap_local(&bv); - - iter.data_buf = kaddr; - iter.data_size = bv.bv_len; - if (bio_data_dir(bio) == WRITE) - blk_integrity_generate(&iter, bi); - else - ret = blk_integrity_verify(&iter, bi); - kunmap_local(kaddr); - - if (ret) - break; - - } - return ret; -} - /** * bio_integrity_prep - Prepare bio for integrity I/O * @bio: bio to prepare @@ -490,7 +452,7 @@ bool bio_integrity_prep(struct bio *bio) /* Auto-generate integrity metadata if this is a write */ if (bio_data_dir(bio) == WRITE) - bio_integrity_process(bio, &bio->bi_iter); + blk_integrity_generate(bio); else bip->bio_iter = bio->bi_iter; return true; @@ -516,12 +478,7 @@ static void bio_integrity_verify_fn(struct work_struct *work) container_of(work, struct bio_integrity_payload, bip_work); struct bio *bio = bip->bip_bio; - /* - * At the moment verify is called bio's iterator was advanced - * during split and completion, we need to rewind iterator to - * it's original position. - */ - bio->bi_status = bio_integrity_process(bio, &bip->bio_iter); + blk_integrity_verify(bio); bio_integrity_free(bio); bio_endio(bio); } diff --git a/block/blk.h b/block/blk.h index d0a986d8ee507e..7917f86cca0ebd 100644 --- a/block/blk.h +++ b/block/blk.h @@ -9,7 +9,6 @@ #include #include "blk-crypto-internal.h" -struct blk_integrity_iter; struct elevator_type; /* Max future timer expiry for timeouts */ @@ -679,10 +678,8 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops, struct file *bdev_file); int bdev_permission(dev_t dev, blk_mode_t mode, void *holder); -void blk_integrity_generate(struct blk_integrity_iter *iter, - struct blk_integrity *bi); -blk_status_t blk_integrity_verify(struct blk_integrity_iter *iter, - struct blk_integrity *bi); +void blk_integrity_generate(struct bio *bio); +void blk_integrity_verify(struct bio *bio); void blk_integrity_prepare(struct request *rq); void blk_integrity_complete(struct request *rq, unsigned int nr_bytes); diff --git a/block/t10-pi.c b/block/t10-pi.c index cd7fa60d63ff21..425e2836f3e1d8 100644 --- a/block/t10-pi.c +++ b/block/t10-pi.c @@ -13,6 +13,15 @@ #include #include "blk.h" +struct blk_integrity_iter { + void *prot_buf; + void *data_buf; + sector_t seed; + unsigned int data_size; + unsigned short interval; + const char *disk_name; +}; + static __be16 t10_pi_csum(__be16 csum, void *data, unsigned int len, unsigned char csum_type) { @@ -364,33 +373,77 @@ static void ext_pi_type1_complete(struct request *rq, unsigned int nr_bytes) } } -void blk_integrity_generate(struct blk_integrity_iter *iter, - struct blk_integrity *bi) +void blk_integrity_generate(struct bio *bio) { - switch (bi->csum_type) { - case BLK_INTEGRITY_CSUM_CRC64: - ext_pi_crc64_generate(iter, bi); - break; - case BLK_INTEGRITY_CSUM_CRC: - case BLK_INTEGRITY_CSUM_IP: - t10_pi_generate(iter, bi); - break; - default: - break; + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); + struct bio_integrity_payload *bip = bio_integrity(bio); + struct blk_integrity_iter iter; + struct bvec_iter bviter; + struct bio_vec bv; + + iter.disk_name = bio->bi_bdev->bd_disk->disk_name; + iter.interval = 1 << bi->interval_exp; + iter.seed = bio->bi_iter.bi_sector; + iter.prot_buf = bvec_virt(bip->bip_vec); + bio_for_each_segment(bv, bio, bviter) { + void *kaddr = bvec_kmap_local(&bv); + + iter.data_buf = kaddr; + iter.data_size = bv.bv_len; + switch (bi->csum_type) { + case BLK_INTEGRITY_CSUM_CRC64: + ext_pi_crc64_generate(&iter, bi); + break; + case BLK_INTEGRITY_CSUM_CRC: + case BLK_INTEGRITY_CSUM_IP: + t10_pi_generate(&iter, bi); + break; + default: + break; + } + kunmap_local(kaddr); } } -blk_status_t blk_integrity_verify(struct blk_integrity_iter *iter, - struct blk_integrity *bi) +void blk_integrity_verify(struct bio *bio) { - switch (bi->csum_type) { - case BLK_INTEGRITY_CSUM_CRC64: - return ext_pi_crc64_verify(iter, bi); - case BLK_INTEGRITY_CSUM_CRC: - case BLK_INTEGRITY_CSUM_IP: - return t10_pi_verify(iter, bi); - default: - return BLK_STS_OK; + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); + struct bio_integrity_payload *bip = bio_integrity(bio); + struct blk_integrity_iter iter; + struct bvec_iter bviter; + struct bio_vec bv; + + /* + * At the moment verify is called bi_iter has been advanced during split + * and completion, so use the copy created during submission here. + */ + iter.disk_name = bio->bi_bdev->bd_disk->disk_name; + iter.interval = 1 << bi->interval_exp; + iter.seed = bip->bio_iter.bi_sector; + iter.prot_buf = bvec_virt(bip->bip_vec); + __bio_for_each_segment(bv, bio, bviter, bip->bio_iter) { + void *kaddr = bvec_kmap_local(&bv); + blk_status_t ret = BLK_STS_OK; + + iter.data_buf = kaddr; + iter.data_size = bv.bv_len; + switch (bi->csum_type) { + case BLK_INTEGRITY_CSUM_CRC64: + ret = ext_pi_crc64_verify(&iter, bi); + break; + case BLK_INTEGRITY_CSUM_CRC: + case BLK_INTEGRITY_CSUM_IP: + ret = t10_pi_verify(&iter, bi); + break; + default: + break; + } + kunmap_local(kaddr); + + if (ret) { + bio->bi_status = ret; + return; + } } } diff --git a/include/linux/blk-integrity.h b/include/linux/blk-integrity.h index d201140d77a336..2f015135f967d0 100644 --- a/include/linux/blk-integrity.h +++ b/include/linux/blk-integrity.h @@ -14,15 +14,6 @@ enum blk_integrity_flags { BLK_INTEGRITY_STACKED = 1 << 4, }; -struct blk_integrity_iter { - void *prot_buf; - void *data_buf; - sector_t seed; - unsigned int data_size; - unsigned short interval; - const char *disk_name; -}; - const char *blk_integrity_profile_name(struct blk_integrity *bi); bool queue_limits_stack_integrity(struct queue_limits *t, struct queue_limits *b);