Commit cbdabc70 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

mtd: cfi: convert inline functions to macros

commit 9e343e87 upstream.

The map_word_() functions, dating back to linux-2.6.8, try to perform
bitwise operations on a 'map_word' structure. This may have worked
with compilers that were current then (gcc-3.4 or earlier), but end
up being rather inefficient on any version I could try now (gcc-4.4 or
higher). Specifically we hit a problem analyzed in gcc PR81715 where we
fail to reuse the stack space for local variables.

This can be seen immediately in the stack consumption for
cfi_staa_erase_varsize() and other functions that (with CONFIG_KASAN)
can be up to 2200 bytes. Changing the inline functions into macros brings
this down to 1280 bytes.  Without KASAN, the same problem exists, but
the stack consumption is lower to start with, my patch shrinks it from
920 to 496 bytes on with arm-linux-gnueabi-gcc-5.4, and saves around
1KB in .text size for cfi_cmdset_0020.c, as it avoids copying map_word
structures for each call to one of these helpers.

With the latest gcc-8 snapshot, the problem is fixed in upstream gcc,
but nobody uses that yet, so we should still work around it in mainline
kernels and probably backport the workaround to stable kernels as well.
We had a couple of other functions that suffered from the same gcc bug,
and all of those had a simpler workaround involving dummy variables
in the inline function. Unfortunately that did not work here, the
macro hack was the best I could come up with.

It would also be helpful to have someone to a little performance testing
on the patch, to see how much it helps in terms of CPU utilitzation.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 198a7dda
...@@ -270,75 +270,67 @@ void map_destroy(struct mtd_info *mtd); ...@@ -270,75 +270,67 @@ void map_destroy(struct mtd_info *mtd);
#define INVALIDATE_CACHED_RANGE(map, from, size) \ #define INVALIDATE_CACHED_RANGE(map, from, size) \
do { if (map->inval_cache) map->inval_cache(map, from, size); } while (0) do { if (map->inval_cache) map->inval_cache(map, from, size); } while (0)
#define map_word_equal(map, val1, val2) \
static inline int map_word_equal(struct map_info *map, map_word val1, map_word val2) ({ \
{ int i, ret = 1; \
int i; for (i = 0; i < map_words(map); i++) \
if ((val1).x[i] != (val2).x[i]) { \
for (i = 0; i < map_words(map); i++) { ret = 0; \
if (val1.x[i] != val2.x[i]) break; \
return 0; } \
} ret; \
})
return 1;
} #define map_word_and(map, val1, val2) \
({ \
static inline map_word map_word_and(struct map_info *map, map_word val1, map_word val2) map_word r; \
{ int i; \
map_word r; for (i = 0; i < map_words(map); i++) \
int i; r.x[i] = (val1).x[i] & (val2).x[i]; \
r; \
for (i = 0; i < map_words(map); i++) })
r.x[i] = val1.x[i] & val2.x[i];
#define map_word_clr(map, val1, val2) \
return r; ({ \
} map_word r; \
int i; \
static inline map_word map_word_clr(struct map_info *map, map_word val1, map_word val2) for (i = 0; i < map_words(map); i++) \
{ r.x[i] = (val1).x[i] & ~(val2).x[i]; \
map_word r; r; \
int i; })
for (i = 0; i < map_words(map); i++) #define map_word_or(map, val1, val2) \
r.x[i] = val1.x[i] & ~val2.x[i]; ({ \
map_word r; \
return r; int i; \
} for (i = 0; i < map_words(map); i++) \
r.x[i] = (val1).x[i] | (val2).x[i]; \
static inline map_word map_word_or(struct map_info *map, map_word val1, map_word val2) r; \
{ })
map_word r;
int i; #define map_word_andequal(map, val1, val2, val3) \
({ \
for (i = 0; i < map_words(map); i++) int i, ret = 1; \
r.x[i] = val1.x[i] | val2.x[i]; for (i = 0; i < map_words(map); i++) { \
if (((val1).x[i] & (val2).x[i]) != (val2).x[i]) { \
return r; ret = 0; \
} break; \
} \
static inline int map_word_andequal(struct map_info *map, map_word val1, map_word val2, map_word val3) } \
{ ret; \
int i; })
for (i = 0; i < map_words(map); i++) { #define map_word_bitsset(map, val1, val2) \
if ((val1.x[i] & val2.x[i]) != val3.x[i]) ({ \
return 0; int i, ret = 0; \
} for (i = 0; i < map_words(map); i++) { \
if ((val1).x[i] & (val2).x[i]) { \
return 1; ret = 1; \
} break; \
} \
static inline int map_word_bitsset(struct map_info *map, map_word val1, map_word val2) } \
{ ret; \
int i; })
for (i = 0; i < map_words(map); i++) {
if (val1.x[i] & val2.x[i])
return 1;
}
return 0;
}
static inline map_word map_word_load(struct map_info *map, const void *ptr) static inline map_word map_word_load(struct map_info *map, const void *ptr)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment