Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp404557rbb; Sat, 24 Feb 2024 05:44:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXl8I85X6cx0SyaU30APe0BoADxdPr1Gze5Uxf3cSCRtb+3/qry+pruvRmLcmQNZlP1v3Cl1LsfZHWucoEMbb94cED9yvhEGtCVWvgnRg== X-Google-Smtp-Source: AGHT+IFX8/GvyTziha+fLQuP8sAWLiu1XI4Ycq8yqsRXf4b1173pkuoPIexaTv8TVXi1NAhQaJAn X-Received: by 2002:a05:622a:144:b0:42e:5afe:1be8 with SMTP id v4-20020a05622a014400b0042e5afe1be8mr2613218qtw.26.1708782297904; Sat, 24 Feb 2024 05:44:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708782297; cv=pass; d=google.com; s=arc-20160816; b=IGGkdSINTrDGxeFzRSmS1bTz3JmUW25J7hq4G8JQ1VVP81mKr+gh+vwsekHiwDlxJk 6qGaeGlLCFYFRk29HSwwyRhjdTDKkPsrhOiYFrWJN0ixZnObgBynQ2Jn9B02rPE1dsAl q2mXsKuGdjRInn662uchYLOwhHE3/R3HfFNdOitN70FNTLXHMHhN2lGbaK4sDThD01z4 QKNRGqLju+ESETUow3faUKKRjNkm1bj9fRbgMcsUU8y7xcxYFKm6oTDAT1rEpfSysZ8A SaNc7vRUR5CSiGSaf2T1q6fdLN5NIHjm4rpzeosPMBSyYardjkfk5YdNixWie80+U4rH wWCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature; bh=pqRcbBAqvfSKnUOk9c3d+4kL/52c1/J+n8W594i5WY8=; fh=+gUIO59EkJywcscu17EZfBK5djWClgChODLH3gNInaI=; b=z/jTRKzU7bn3UMQ9KHp/RhZLrC9g6ToTKkImud/YEwvl+L8nhC+nuevTW4brSlL6fH njJ1v7+qQ3o6NoZ53jqgu0EQBWjuolNZDmBTWZjMj3mLfPgkPJjPlpQMSr7sQcta1Wy5 5k6ycq8p00BbUz0o2ik0LGJwUQ2ZBPnPcViIkNtmgDeSBXq0ej+ylA6t/nIdz4q+mAw8 2OXcaqg0IkU+TweICgqnkvdBUfMC2PEn5AqjF8kxxGnA086yqQOqG+gdZ7jUOE0WMBfn 2uKVcJ2To6lhRbhhis3s54l0aLIaGJ/NrBVoaJ1USLT3rvWHc77rPmYjLFUzdYKF2BJk svXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fIOWso8E; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-79644-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l9-20020a05622a050900b0042dd90f55e4si1157886qtx.276.2024.02.24.05.44.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 05:44:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79644-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fIOWso8E; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-79644-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A64AE1C20CFA for ; Sat, 24 Feb 2024 13:44:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55E98405F4; Sat, 24 Feb 2024 13:44:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fIOWso8E" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 B1D5810A3C for ; Sat, 24 Feb 2024 13:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708782291; cv=none; b=NxAK053dBKUdZ/0Nk6yBg7kJ4dTUydvSNwqE5bntdXZwPdni2n8b0Obo3SBXF9NfFmhrxyK4UJm8iTEdZQh4xbJVvV6UgTD5wh0EJtmx3+rXXX+w3/AHAkgX11EmemeMbIVHu3RscsNRCdR4eU9LC0C0iOH3N+LBR3ZmqP0QiSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708782291; c=relaxed/simple; bh=nG+obRKdw0yvvqlnDsaNozeboGfRgpCdGMDN11jV5B0=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=phS98vsKsKiRb2h4YBDdjUMcIcbeOiBhFapP6OI9QZ9mv0K75Q7HUT4aLAvMxuCXNAWZSu6JWdcXO3zpHlnJ/gi0PHqBnJFPODo5VYDLsAzmCLwT6RJXGMiKImLzxJFDfRGOuWyQ6tAtX3vPADoAZ+8BXKS0TJdNN4bPfQy+oms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fIOWso8E; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708782288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pqRcbBAqvfSKnUOk9c3d+4kL/52c1/J+n8W594i5WY8=; b=fIOWso8ENpp8u6jHyqNrYkIBiwh/Phf4lobsndt4QaMszoUWnD0M5nGD0zAN1LkHxwlJAD 1Nsw7b5vDnY7JO7yYfSAiB+gAbmffN6Le3jBjzK5dqHC2lNPTFAiST/L2av2PQctRkodru zhxGl+ewzQhg3G3oKI3PLOeBt5rh+m4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-22GyvL7FPbqby95jzhAIBA-1; Sat, 24 Feb 2024 08:44:47 -0500 X-MC-Unique: 22GyvL7FPbqby95jzhAIBA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A483E85A58A; Sat, 24 Feb 2024 13:44:46 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5576E10800; Sat, 24 Feb 2024 13:44:46 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id 373DF30C1B8F; Sat, 24 Feb 2024 13:44:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id 328893FB4E; Sat, 24 Feb 2024 14:44:46 +0100 (CET) Date: Sat, 24 Feb 2024 14:44:46 +0100 (CET) From: Mikulas Patocka To: Arnd Bergmann cc: Alasdair Kergon , Mike Snitzer , dm-devel@lists.linux.dev, Arnd Bergmann , Eric Biggers , Yu Zhe , linux-kernel@vger.kernel.org Subject: Re: [PATCH] dm-integrity: reduce stack usage for recheck In-Reply-To: <20240224121228.1904859-1-arnd@kernel.org> Message-ID: References: <20240224121228.1904859-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Hi On Sat, 24 Feb 2024, Arnd Bergmann wrote: > From: Arnd Bergmann > > 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 > --- > 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 >