The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	 dm-devel@lists.linux.dev, Arnd Bergmann <arnd@arndb.de>,
	 Eric Biggers <ebiggers@google.com>, Yu Zhe <yuzhe@nfschina.com>,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dm-integrity: reduce stack usage for recheck
Date: Sat, 24 Feb 2024 14:44:46 +0100 (CET)	[thread overview]
Message-ID: <b36796cd-e6f-b964-fe0-5a77114aa710@redhat.com> (raw)
In-Reply-To: <20240224121228.1904859-1-arnd@kernel.org>

Hi


On Sat, 24 Feb 2024, Arnd Bergmann wrote:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> The newly added integrity_recheck() function has another larger stack
> allocation, just like its caller integrity_metadata(). When it gets
> inlined, the combination of the two exceeds the warning limit for 32-bit
> architectures and possibly risks an overflow when this is called from
> a deep call chain through a file system:
> 
> drivers/md/dm-integrity.c:1767:13: error: stack frame size (1048) exceeds limit (1024) in 'integrity_metadata' [-Werror,-Wframe-larger-than]
>  1767 | static void integrity_metadata(struct work_struct *w)
> 
> Since the caller at this point is done using its checksum buffer,
> just reuse the same buffer in the new function to avoid the double
> allocation.

OK, thanks.

But, the function integrity_recheck shouldn't be inlined at all, because 
it is only called on authentication error. So, I'll post your patch with 
"noinline" being added.

Mikulas

> Fixes: c88f5e553fe3 ("dm-integrity: recheck the integrity tag after a failure")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/md/dm-integrity.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
> index 143f6c223b0e..82023f1f3df0 100644
> --- a/drivers/md/dm-integrity.c
> +++ b/drivers/md/dm-integrity.c
> @@ -1691,14 +1691,13 @@ static void integrity_sector_checksum(struct dm_integrity_c *ic, sector_t sector
>  	get_random_bytes(result, ic->tag_size);
>  }
>  
> -static void integrity_recheck(struct dm_integrity_io *dio)
> +static void integrity_recheck(struct dm_integrity_io *dio, char *checksum)
>  {
>  	struct bio *bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io));
>  	struct dm_integrity_c *ic = dio->ic;
>  	struct bvec_iter iter;
>  	struct bio_vec bv;
>  	sector_t sector, logical_sector, area, offset;
> -	char checksum_onstack[max_t(size_t, HASH_MAX_DIGESTSIZE, MAX_TAG_SIZE)];
>  	struct page *page;
>  	void *buffer;
>  
> @@ -1735,8 +1734,8 @@ static void integrity_recheck(struct dm_integrity_io *dio)
>  			}
>  
>  			integrity_sector_checksum(ic, logical_sector, buffer,
> -						  checksum_onstack);
> -			r = dm_integrity_rw_tag(ic, checksum_onstack, &dio->metadata_block,
> +						  checksum);
> +			r = dm_integrity_rw_tag(ic, checksum, &dio->metadata_block,
>  						&dio->metadata_offset, ic->tag_size, TAG_CMP);
>  			if (r) {
>  				if (r > 0) {
> @@ -1851,7 +1850,7 @@ static void integrity_metadata(struct work_struct *w)
>  						checksums_ptr - checksums, dio->op == REQ_OP_READ ? TAG_CMP : TAG_WRITE);
>  			if (unlikely(r)) {
>  				if (r > 0) {
> -					integrity_recheck(dio);
> +					integrity_recheck(dio, checksums);
>  					goto skip_io;
>  				}
>  				if (likely(checksums != checksums_onstack))
> -- 
> 2.39.2
> 


  reply	other threads:[~2024-02-24 13:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-24 12:12 [PATCH] dm-integrity: reduce stack usage for recheck Arnd Bergmann
2024-02-24 13:44 ` Mikulas Patocka [this message]
2024-02-24 13:48   ` Mikulas Patocka

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=b36796cd-e6f-b964-fe0-5a77114aa710@redhat.com \
    --to=mpatocka@redhat.com \
    --cc=agk@redhat.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=dm-devel@lists.linux.dev \
    --cc=ebiggers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snitzer@kernel.org \
    --cc=yuzhe@nfschina.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