public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Kanchan Joshi <joshi.k@samsung.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Qu Wenruo <wqu@suse.com>, Goldwyn Rodrigues <rgoldwyn@suse.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH 7/7] xfs: implement block-metadata based data checksums
Date: Mon, 3 Feb 2025 14:20:31 -0800	[thread overview]
Message-ID: <20250203222031.GB134507@frogsfrogsfrogs> (raw)
In-Reply-To: <20250203094322.1809766-8-hch@lst.de>

On Mon, Feb 03, 2025 at 10:43:11AM +0100, Christoph Hellwig wrote:
> This is a quick hack to demonstrate how data checksumming can be
> implemented when it can be stored in the out of line metadata for each
> logical block.  It builds on top of the previous PI infrastructure
> and instead of generating/verifying protection information it simply
> generates and verifies a crc32c checksum and stores it in the non-PI

PI can do crc32c now?  I thought it could only do that old crc16 from
like 15 years ago and crc64?  If we try to throw crc32c at a device,
won't it then reject the "incorrect" checksums?  Or is there some other
magic in here where it works and I'm just too out of date to know?

<shrug>

The crc32c generation and validation looks decent though we're
definitely going to want an inode flag so that we're not stuck with
stable page writes.

--D

> metadata.  It misses a feature bit in the superblock, checking that
> enough size is available in the metadata and many other things.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/xfs_data_csum.c | 79 ++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 76 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/xfs/xfs_data_csum.c b/fs/xfs/xfs_data_csum.c
> index d9d3620654b1..862388803398 100644
> --- a/fs/xfs/xfs_data_csum.c
> +++ b/fs/xfs/xfs_data_csum.c
> @@ -14,6 +14,73 @@
>  #include <linux/blk-integrity.h>
>  #include <linux/bio-integrity.h>
>  
> +static inline void *xfs_csum_buf(struct bio *bio)
> +{
> +	return bvec_virt(bio_integrity(bio)->bip_vec);
> +}
> +
> +static inline __le32
> +xfs_data_csum(
> +	void			*data,
> +	unsigned int		len)
> +{
> +	return xfs_end_cksum(crc32c(XFS_CRC_SEED, data, len));
> +}
> +
> +static void
> +__xfs_data_csum_generate(
> +	struct bio		*bio)
> +{
> +	unsigned int		ssize = bdev_logical_block_size(bio->bi_bdev);
> +	__le32			*csum_buf = xfs_csum_buf(bio);
> +	struct bvec_iter_all	iter;
> +	struct bio_vec		*bv;
> +	int			c = 0;
> +
> +	bio_for_each_segment_all(bv, bio, iter) {
> +		void		*p;
> +		unsigned int	off;
> +
> +		p = bvec_kmap_local(bv);
> +		for (off = 0; off < bv->bv_len; off += ssize)
> +			csum_buf[c++] = xfs_data_csum(p + off, ssize);
> +		kunmap_local(p);
> +	}
> +}
> +
> +static int
> +__xfs_data_csum_verify(
> +	struct bio		*bio,
> +	struct xfs_inode	*ip,
> +	xfs_off_t		file_offset)
> +{
> +	unsigned int		ssize = bdev_logical_block_size(bio->bi_bdev);
> +	__le32			*csum_buf = xfs_csum_buf(bio);
> +	int			c = 0;
> +	struct bvec_iter_all	iter;
> +	struct bio_vec		*bv;
> +
> +	bio_for_each_segment_all(bv, bio, iter) {
> +		void		*p;
> +		unsigned int	off;
> +
> +		p = bvec_kmap_local(bv);
> +		for (off = 0; off < bv->bv_len; off += ssize) {
> +			if (xfs_data_csum(p + off, ssize) != csum_buf[c++]) {
> +				kunmap_local(p);
> +				xfs_warn(ip->i_mount,
> +"checksum mismatch at inode 0x%llx offset %lld",
> +					ip->i_ino, file_offset);
> +				return -EFSBADCRC;
> +			}
> +			file_offset += ssize;
> +		}
> +		kunmap_local(p);
> +	}
> +
> +	return 0;
> +}
> +
>  void *
>  xfs_data_csum_alloc(
>  	struct bio		*bio)
> @@ -53,11 +120,14 @@ xfs_data_csum_generate(
>  {
>  	struct blk_integrity	*bi = blk_get_integrity(bio->bi_bdev->bd_disk);
>  
> -	if (!bi || !bi->csum_type)
> +	if (!bi)
>  		return;
>  
>  	xfs_data_csum_alloc(bio);
> -	blk_integrity_generate(bio);
> +	if (!bi->csum_type)
> +		__xfs_data_csum_generate(bio);
> +	else
> +		blk_integrity_generate(bio);
>  }
>  
>  int
> @@ -67,7 +137,10 @@ xfs_data_csum_verify(
>  	struct bio		*bio = &ioend->io_bio;
>  	struct blk_integrity	*bi = blk_get_integrity(bio->bi_bdev->bd_disk);
>  
> -	if (!bi || !bi->csum_type)
> +	if (!bi)
>  		return 0;
> +	if (!bi->csum_type)
> +		return __xfs_data_csum_verify(&ioend->io_bio,
> +				XFS_I(ioend->io_inode), ioend->io_offset);
>  	return blk_integrity_verify_all(bio, ioend->io_sector);
>  }
> -- 
> 2.45.2
> 
> 

  reply	other threads:[~2025-02-03 22:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03  9:43 PI and data checksumming for XFS Christoph Hellwig
2025-02-03  9:43 ` [PATCH 1/7] block: support integrity generation and verification from file systems Christoph Hellwig
2025-02-03 19:47   ` Martin K. Petersen
2025-04-21  2:30   ` Anuj gupta
2025-02-03  9:43 ` [PATCH 2/7] iomap: introduce iomap_read_folio_ops Christoph Hellwig
2025-02-03  9:43 ` [PATCH 3/7] iomap: add bioset in iomap_read_folio_ops for filesystems to use own bioset Christoph Hellwig
2025-02-03 22:23   ` Darrick J. Wong
2025-02-04  4:58     ` Christoph Hellwig
2025-03-13 13:53   ` Matthew Wilcox
2025-03-14 16:53     ` Darrick J. Wong
2025-03-17  5:52     ` Christoph Hellwig
2025-02-03  9:43 ` [PATCH 4/7] iomap: support ioends for reads Christoph Hellwig
2025-02-03 22:24   ` Darrick J. Wong
2025-02-03  9:43 ` [PATCH 5/7] iomap: limit buffered I/O size to 128M Christoph Hellwig
2025-02-03 22:22   ` Darrick J. Wong
2025-02-03  9:43 ` [PATCH 6/7] xfs: support T10 protection information Christoph Hellwig
2025-02-03 22:21   ` Darrick J. Wong
2025-02-03  9:43 ` [PATCH 7/7] xfs: implement block-metadata based data checksums Christoph Hellwig
2025-02-03 22:20   ` Darrick J. Wong [this message]
2025-02-04  5:00     ` Christoph Hellwig
2025-02-04 18:36       ` Darrick J. Wong
2025-02-06  6:05         ` Christoph Hellwig
2025-02-03 19:51 ` PI and data checksumming for XFS Martin K. Petersen

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 \
    --in-reply-to=20250203222031.GB134507@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=hch@lst.de \
    --cc=joshi.k@samsung.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=rgoldwyn@suse.com \
    --cc=wqu@suse.com \
    /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