From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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.lore.kernel.org (Postfix) with ESMTPS id 17BEEC77B75 for ; Sat, 6 May 2023 12:25:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=+K1rFBYTE39zIRfc+tbOjaBi+YMVjkknrvePMsq+Xzg=; b=W+U6c+8o7KZ2gc nsNKwWnqWBTWpx6fh7Pgzw2qJv53Av2Mqsh5uF9m1EVku+z5dyJBQcY6T7PdswAJQi4ESyWCAdrkt IkXqS6OUHe/geaWkyc9CiP20BHRv289RL5usDR+HwlgyZLfRDK3PE4daaG04NrGUMeXu1VU2gOoL+ Fpsj9VYhcltfQP0cuDq8ErO9ihMSGHCR5tDp1FAXx9F0lDL/RWHAZ0KHiObPBz3cX1/OZ7ODqkQaS y37NnQigcE+PqS0hRXwHMshb820VW9ZoJfifI1u8PWUiFO/Z7H/TKe7vV3AgJuYfj2Isq2VJ7g+3R 8BmPF1R2MSuwO/hLvAYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pvGxo-00DOA3-20; Sat, 06 May 2023 12:24:36 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pvGxi-00DO9M-2l for linux-mtd@lists.infradead.org; Sat, 06 May 2023 12:24:33 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f19b9d5358so27903085e9.1 for ; Sat, 06 May 2023 05:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683375868; x=1685967868; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZXMu9XhyUgA5r3iTebqKjw72HhkdRp9Ey4llH49+JM0=; b=W2b+Ywaawz6z8MAH/a2AOjPLUJ6jWy9pL6gIUHhAcxhI19CGysYfookylTFfB+/mui 5ykH+LAnxZPJWrGhVFZw+Re4s4Tvg027+Ev7WYMhFRr0K+1ca/+27ajTlMKd6skKIJIz kVA2zagn7v6Z621aP7eJynCz8VYNDOiFCPABHCQM5hj6A5u5rUU4YVQ2asQnMh7kq0Oh NNIfTzfLTnXez6+qIvT4RhTRmShQlZ9Q7ACJD+v0VQ6j3N/gfJTW+sG9zykqt0RqyRct kk0+kbPEgplbEtt2g8xaBx2l0UZqMFtZoT5URpLz7AC0Mv3NvKCJ+0MUss4QBvYEgCeq nSXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683375868; x=1685967868; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZXMu9XhyUgA5r3iTebqKjw72HhkdRp9Ey4llH49+JM0=; b=ZXAOy6Z0P0sC9egw1ufHpyevkpaQclyzLEFbwN18lPK0267NFY8cTs25S+rqgfF0Ji CxkRofRU2IWDW6OIKZBgU6n8AKdgXh39PA2y5v/XGTMVzsgJD3yRNzCtOrmwmiL8XgCY RXxoMoA/exfXhxDvmu00eQJGvOKgrc4a42UY/sBw3W7R+Zc5KrxQaKgqtMyvuKWkufF7 hjTkzd4IgQIWU7EUREwZjDUVkJkawfBOOprUu5zY7K/5TXTmIziFZggDHQLqJ30WVkY8 4B47FJQ549iR/01htRjUM62k2/4KFmzKfqaWJGq/EFAgyUf7dzg5wjRr8ahqGLRemT1r EhZQ== X-Gm-Message-State: AC+VfDxE6O5rDgxmhjGZkHjZ4EmfVninH1M97JAzAHkHLmQjhMm+lZi3 NL93NWCc5lmGGya9NtZO3pK/UEdVkp4= X-Google-Smtp-Source: ACHHUZ7lL8EH4fH1fY3FNvefzXrML8HRfgPHvYaPc2W9+3uw2WRmJW+RavMeJGer3IydXL41cytAxw== X-Received: by 2002:a7b:c30d:0:b0:3f1:745d:821 with SMTP id k13-20020a7bc30d000000b003f1745d0821mr3149884wmj.23.1683375868405; Sat, 06 May 2023 05:24:28 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id y24-20020a05600c365800b003f31da39b62sm10680788wmq.18.2023.05.06.05.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 05:24:28 -0700 (PDT) From: Christian Marangi To: David Woodhouse , Richard Weinberger , Fabian Frederick , Nick Desaulniers , Christian Marangi , Christian Brauner , KaiGai Kohei , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Tim Gardner , kernel test robot , Ron Economos , Nathan Chancellor , stable@vger.kernel.org Subject: [PATCH] jffs2: reduce stack usage in jffs2_build_xattr_subsystem() Date: Sat, 6 May 2023 06:56:12 +0200 Message-Id: <20230506045612.16616-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230506_052430_918921_5F49CC01 X-CRM114-Status: GOOD ( 16.86 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org From: Fabian Frederick Use kcalloc() for allocation/flush of 128 pointers table to reduce stack usage. Function now returns -ENOMEM or 0 on success. stackusage Before: ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 1208 dynamic,bounded After: ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 192 dynamic,bounded Also update definition when CONFIG_JFFS2_FS_XATTR is not enabled Tested with an MTD mount point and some user set/getfattr. Many current target on OpenWRT also suffer from a compilation warning (that become an error with CONFIG_WERROR) with the following output: fs/jffs2/xattr.c: In function 'jffs2_build_xattr_subsystem': fs/jffs2/xattr.c:887:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] 887 | } | ^ Using dynamic allocation fix this compilation warning. Fixes: c9f700f840bd ("[JFFS2][XATTR] using 'delete marker' for xdatum/xref deletion") Reported-by: Tim Gardner Reported-by: kernel test robot Reported-by: Ron Economos Reported-by: Nathan Chancellor Reviewed-by: Nick Desaulniers Signed-off-by: Fabian Frederick Signed-off-by: Christian Marangi Cc: stable@vger.kernel.org --- fs/jffs2/build.c | 5 ++++- fs/jffs2/xattr.c | 13 +++++++++---- fs/jffs2/xattr.h | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c index 837cd55fd4c5..6ae9d6fefb86 100644 --- a/fs/jffs2/build.c +++ b/fs/jffs2/build.c @@ -211,7 +211,10 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c) ic->scan_dents = NULL; cond_resched(); } - jffs2_build_xattr_subsystem(c); + ret = jffs2_build_xattr_subsystem(c); + if (ret) + goto exit; + c->flags &= ~JFFS2_SB_FLAG_BUILDING; dbg_fsbuild("FS build complete\n"); diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c index aa4048a27f31..3b6bdc9a49e1 100644 --- a/fs/jffs2/xattr.c +++ b/fs/jffs2/xattr.c @@ -772,10 +772,10 @@ void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c) } #define XREF_TMPHASH_SIZE (128) -void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) +int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) { struct jffs2_xattr_ref *ref, *_ref; - struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE]; + struct jffs2_xattr_ref **xref_tmphash; struct jffs2_xattr_datum *xd, *_xd; struct jffs2_inode_cache *ic; struct jffs2_raw_node_ref *raw; @@ -784,9 +784,12 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING)); + xref_tmphash = kcalloc(XREF_TMPHASH_SIZE, + sizeof(struct jffs2_xattr_ref *), GFP_KERNEL); + if (!xref_tmphash) + return -ENOMEM; + /* Phase.1 : Merge same xref */ - for (i=0; i < XREF_TMPHASH_SIZE; i++) - xref_tmphash[i] = NULL; for (ref=c->xref_temp; ref; ref=_ref) { struct jffs2_xattr_ref *tmp; @@ -884,6 +887,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) "%u of xref (%u dead, %u orphan) found.\n", xdatum_count, xdatum_unchecked_count, xdatum_orphan_count, xref_count, xref_dead_count, xref_orphan_count); + kfree(xref_tmphash); + return 0; } struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, diff --git a/fs/jffs2/xattr.h b/fs/jffs2/xattr.h index 720007b2fd65..1b5030a3349d 100644 --- a/fs/jffs2/xattr.h +++ b/fs/jffs2/xattr.h @@ -71,7 +71,7 @@ static inline int is_xattr_ref_dead(struct jffs2_xattr_ref *ref) #ifdef CONFIG_JFFS2_FS_XATTR extern void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c); -extern void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c); +extern int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c); extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c); extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, @@ -103,7 +103,7 @@ extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t); #else #define jffs2_init_xattr_subsystem(c) -#define jffs2_build_xattr_subsystem(c) +#define jffs2_build_xattr_subsystem(c) (0) #define jffs2_clear_xattr_subsystem(c) #define jffs2_xattr_do_crccheck_inode(c, ic) -- 2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/