From: Greg Kroah-Hartman Date: Thu, 15 Jun 2017 09:45:54 +0000 (+0200) Subject: 4.9-stable patches X-Git-Tag: v4.9.33~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bafafb5a7a7b723ce99695db9d664c6a31d4ee35;p=thirdparty%2Fkernel%2Fstable-queue.git 4.9-stable patches added patches: log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch --- diff --git a/queue-4.9/log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch b/queue-4.9/log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch new file mode 100644 index 00000000000..238f0289dff --- /dev/null +++ b/queue-4.9/log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch @@ -0,0 +1,59 @@ +From 29905b52fad0854351f57bab867647e4982285bf Mon Sep 17 00:00:00 2001 +From: Ard Biesheuvel +Date: Thu, 2 Feb 2017 18:05:26 +0000 +Subject: log2: make order_base_2() behave correctly on const input value zero + +From: Ard Biesheuvel + +commit 29905b52fad0854351f57bab867647e4982285bf upstream. + +The function order_base_2() is defined (according to the comment block) +as returning zero on input zero, but subsequently passes the input into +roundup_pow_of_two(), which is explicitly undefined for input zero. + +This has gone unnoticed until now, but optimization passes in GCC 7 may +produce constant folded function instances where a constant value of +zero is passed into order_base_2(), resulting in link errors against the +deliberately undefined '____ilog2_NaN'. + +So update order_base_2() to adhere to its own documented interface. + +[ See + + http://marc.info/?l=linux-kernel&m=147672952517795&w=2 + + and follow-up discussion for more background. The gcc "optimization + pass" is really just broken, but now the GCC trunk problem seems to + have escaped out of just specially built daily images, so we need to + work around it in mainline. - Linus ] + +Signed-off-by: Ard Biesheuvel +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +Signed-off-by: Greg Kroah-Hartman + +--- + include/linux/log2.h | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +--- a/include/linux/log2.h ++++ b/include/linux/log2.h +@@ -194,6 +194,17 @@ unsigned long __rounddown_pow_of_two(uns + * ... and so on. + */ + +-#define order_base_2(n) ilog2(roundup_pow_of_two(n)) ++static inline __attribute_const__ ++int __order_base_2(unsigned long n) ++{ ++ return n > 1 ? ilog2(n - 1) + 1 : 0; ++} + ++#define order_base_2(n) \ ++( \ ++ __builtin_constant_p(n) ? ( \ ++ ((n) == 0 || (n) == 1) ? 0 : \ ++ ilog2((n) - 1) + 1) : \ ++ __order_base_2(n) \ ++) + #endif /* _LINUX_LOG2_H */ diff --git a/queue-4.9/series b/queue-4.9/series index d15be1766a5..ba9658cd678 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -31,3 +31,4 @@ pm-runtime-avoid-false-positive-warnings-from-might_sleep_if.patch jump-label-pass-kbuild_cflags-when-checking-for-asm-goto-support.patch shmem-fix-sleeping-from-atomic-context.patch kasan-respect-proc-sys-kernel-traceoff_on_warning.patch +log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch