143-jffs2-reduce-stack-usage-in-jffs2_build_xattr_subsys.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. From eee53f6eb7561f516b9c4bac829ce31c48096130 Mon Sep 17 00:00:00 2001
  2. From: Fabian Frederick <[email protected]>
  3. Date: Tue, 9 May 2017 22:30:03 +0200
  4. Subject: [PATCH] jffs2: reduce stack usage in jffs2_build_xattr_subsystem()
  5. Use kcalloc() for allocation/flush of 128 pointers table to
  6. reduce stack usage.
  7. Function now returns -ENOMEM or 0 on success.
  8. stackusage
  9. Before:
  10. ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 1208
  11. dynamic,bounded
  12. After:
  13. ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 192
  14. dynamic,bounded
  15. Also update definition when CONFIG_JFFS2_FS_XATTR is not enabled
  16. Tested with an MTD mount point and some user set/getfattr.
  17. Many current target on OpenWRT also suffer from a compilation warning
  18. (that become an error with CONFIG_WERROR) with the following output:
  19. fs/jffs2/xattr.c: In function 'jffs2_build_xattr_subsystem':
  20. fs/jffs2/xattr.c:887:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
  21. 887 | }
  22. | ^
  23. Using dynamic allocation fix this compilation warning.
  24. Fixes: c9f700f840bd ("[JFFS2][XATTR] using 'delete marker' for xdatum/xref deletion")
  25. Reported-by: Tim Gardner <[email protected]>
  26. Reported-by: kernel test robot <[email protected]>
  27. Reported-by: Ron Economos <[email protected]>
  28. Reported-by: Nathan Chancellor <[email protected]>
  29. Reviewed-by: Nick Desaulniers <[email protected]>
  30. Signed-off-by: Fabian Frederick <[email protected]>
  31. Signed-off-by: Christian Marangi <[email protected]>
  32. Cc: [email protected]
  33. ---
  34. fs/jffs2/build.c | 5 ++++-
  35. fs/jffs2/xattr.c | 13 +++++++++----
  36. fs/jffs2/xattr.h | 4 ++--
  37. 3 files changed, 15 insertions(+), 7 deletions(-)
  38. --- a/fs/jffs2/build.c
  39. +++ b/fs/jffs2/build.c
  40. @@ -211,7 +211,10 @@ static int jffs2_build_filesystem(struct
  41. ic->scan_dents = NULL;
  42. cond_resched();
  43. }
  44. - jffs2_build_xattr_subsystem(c);
  45. + ret = jffs2_build_xattr_subsystem(c);
  46. + if (ret)
  47. + goto exit;
  48. +
  49. c->flags &= ~JFFS2_SB_FLAG_BUILDING;
  50. dbg_fsbuild("FS build complete\n");
  51. --- a/fs/jffs2/xattr.c
  52. +++ b/fs/jffs2/xattr.c
  53. @@ -772,10 +772,10 @@ void jffs2_clear_xattr_subsystem(struct
  54. }
  55. #define XREF_TMPHASH_SIZE (128)
  56. -void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
  57. +int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
  58. {
  59. struct jffs2_xattr_ref *ref, *_ref;
  60. - struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE];
  61. + struct jffs2_xattr_ref **xref_tmphash;
  62. struct jffs2_xattr_datum *xd, *_xd;
  63. struct jffs2_inode_cache *ic;
  64. struct jffs2_raw_node_ref *raw;
  65. @@ -784,9 +784,12 @@ void jffs2_build_xattr_subsystem(struct
  66. BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
  67. + xref_tmphash = kcalloc(XREF_TMPHASH_SIZE,
  68. + sizeof(struct jffs2_xattr_ref *), GFP_KERNEL);
  69. + if (!xref_tmphash)
  70. + return -ENOMEM;
  71. +
  72. /* Phase.1 : Merge same xref */
  73. - for (i=0; i < XREF_TMPHASH_SIZE; i++)
  74. - xref_tmphash[i] = NULL;
  75. for (ref=c->xref_temp; ref; ref=_ref) {
  76. struct jffs2_xattr_ref *tmp;
  77. @@ -884,6 +887,8 @@ void jffs2_build_xattr_subsystem(struct
  78. "%u of xref (%u dead, %u orphan) found.\n",
  79. xdatum_count, xdatum_unchecked_count, xdatum_orphan_count,
  80. xref_count, xref_dead_count, xref_orphan_count);
  81. + kfree(xref_tmphash);
  82. + return 0;
  83. }
  84. struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
  85. --- a/fs/jffs2/xattr.h
  86. +++ b/fs/jffs2/xattr.h
  87. @@ -71,7 +71,7 @@ static inline int is_xattr_ref_dead(stru
  88. #ifdef CONFIG_JFFS2_FS_XATTR
  89. extern void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c);
  90. -extern void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
  91. +extern int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
  92. extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c);
  93. extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
  94. @@ -103,7 +103,7 @@ extern ssize_t jffs2_listxattr(struct de
  95. #else
  96. #define jffs2_init_xattr_subsystem(c)
  97. -#define jffs2_build_xattr_subsystem(c)
  98. +#define jffs2_build_xattr_subsystem(c) (0)
  99. #define jffs2_clear_xattr_subsystem(c)
  100. #define jffs2_xattr_do_crccheck_inode(c, ic)