From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751708AbbIOWyQ (ORCPT ); Tue, 15 Sep 2015 18:54:16 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:36909 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994AbbIOWyO convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2015 18:54:14 -0400 From: Michal Nazarewicz To: Andrew Morton , Tejun Heo Cc: John Stultz , LKML , Ingo Molnar , "Steven Rostedt \(Red Hat\)" , Peter Zijlstra , Masami Hiramatsu , Prarit Bhargava , Richard Cochran , Thomas Gleixner , "Theodore Ts'o" , Andreas Dilger , Dave Chinner , Joe Perches , Linus Torvalds Subject: Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values In-Reply-To: <20150915142120.7a2f7ac90b2d69b4879b68d7@linux-foundation.org> Organization: http://mina86.com/ References: <1442279124-7309-1-git-send-email-john.stultz@linaro.org> <20150915014936.GA25658@htj.duckdns.org> <20150915034632.GB25658@htj.duckdns.org> <20150915142120.7a2f7ac90b2d69b4879b68d7@linux-foundation.org> User-Agent: Notmuch/0.19+53~g2e63a09 (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd;KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:150915:tj@kernel.org::32EMH69OIJAVYGlz:00000Jn3 X-Hashcash: 1:20:150915:joe@perches.com::kfHSJ34+gzidR6Ri:000bPL X-Hashcash: 1:20:150915:mingo@kernel.org::K8zNycjFsc2ZH8U0:01i+u X-Hashcash: 1:20:150915:prarit@redhat.com::Rtbh7c9ZPUeY314L:000000000000000000000000000000000000000000001hFx X-Hashcash: 1:20:150915:tytso@mit.edu::op3vvex61jEgIF10:00001xd+ X-Hashcash: 1:20:150915:richardcochran@gmail.com::oupJpni3ZmLtUJE7:000000000000000000000000000000000000026bl X-Hashcash: 1:20:150915:linux-kernel@vger.kernel.org::WHFhxWpCNcmDgZku:00000000000000000000000000000000022LQ X-Hashcash: 1:20:150915:john.stultz@linaro.org::R/EA2Mn3ri6duTFB:0000000000000000000000000000000000000003inZ X-Hashcash: 1:20:150915:peterz@infradead.org::1ZY82TkLQMsRBojr:0000000000000000000000000000000000000000041Ga X-Hashcash: 1:20:150915:adilger.kernel@dilger.ca::3PlUjrDy6/RWGt3U:00000000000000000000000000000000000005HSW X-Hashcash: 1:20:150915:tglx@linutronix.de::+M/J9TfIdkXxnaUQ:00000000000000000000000000000000000000000005flT X-Hashcash: 1:20:150915:torvalds@linux-foundation.org::yzCx/tUXY3mZlP02:000000000000000000000000000000005EGK X-Hashcash: 1:20:150915:dchinner@redhat.com::M9ohl8ZKauzrJ+7h:0000000000000000000000000000000000000000006i4y X-Hashcash: 1:20:150915:masami.hiramatsu.pt@hitachi.com::e/FELdc6sUI2EBaY:0000000000000000000000000000007hOn X-Hashcash: 1:20:150915:akpm@linux-foundation.org::xnshSchYBJSY5rXM:000000000000000000000000000000000000AI5x X-Hashcash: 1:20:150915:rostedt@goodmis.org::yaY9jUgWg07T6WM/:000000000000000000000000000000000000000000Ek2m Date: Wed, 16 Sep 2015 00:54:09 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15 2015, Andrew Morton wrote: > On Mon, 14 Sep 2015 23:46:32 -0400 Tejun Heo wrote: > >> Anyways, let's please get abs() working for all types, one way or the >> other. > > That would be by far the best solution, of course. > > This seems to work OK: > > --- a/include/linux/kernel.h~a > +++ a/include/linux/kernel.h > @@ -207,8 +207,11 @@ extern int _cond_resched(void); > * for those. > */ > #define abs(x) ({ \ > - long ret; \ > - if (sizeof(x) == sizeof(long)) { \ > + s64 ret; \ > + if (sizeof(x) == sizeof(s64)) { \ > + s64 __x = (x); \ > + ret = (__x < 0) ? -__x : __x; \ > + } else if (sizeof(x) == sizeof(long)) { \ > long __x = (x); \ > ret = (__x < 0) ? -__x : __x; \ > } else { \ If the return type is an issue, we can use __builtin_choose_expr, no? #define abs(x) __builtin_choose_expr(sizeof(x) == sizeof(s64), abs64(x), ({ \ long ret; \ if (sizeof(x) == sizeof(long)) { \ long __x = (x); \ ret = (__x < 0) ? -__x : __x; \ } else { \ int __x = (x); \ ret = (__x < 0) ? -__x : __x; \ } \ ret; \ })) This is awkward but will make even printk happy. > > Test case: > > --- /dev/null > +++ a/lib/xx.c > @@ -0,0 +1,33 @@ > +#include > + > +#define newabs(x) ({ \ > + s64 ret; \ > + if (sizeof(x) == sizeof(s64)) { \ > + s64 __x = (x); \ > + ret = (__x < 0) ? -__x : __x; \ > + } else if (sizeof(x) == sizeof(long)) { \ > + long __x = (x); \ > + ret = (__x < 0) ? -__x : __x; \ > + } else { \ > + int __x = (x); \ > + ret = (__x < 0) ? -__x : __x; \ > + } \ > + ret; \ > + }) > + > +#define oldabs(x) ({ \ > + long ret; \ > + if (sizeof(x) == sizeof(long)) { \ > + long __x = (x); \ > + ret = (__x < 0) ? -__x : __x; \ > + } else { \ > + int __x = (x); \ > + ret = (__x < 0) ? -__x : __x; \ > + } \ > + ret; \ > + }) > + > +int foo(int x) > +{ > + return oldabs(x); > +} > diff -puN lib/Makefile~b lib/Makefile > --- a/lib/Makefile~b > +++ a/lib/Makefile > @@ -13,7 +13,7 @@ lib-y := ctype.o string.o vsprintf.o cmd > sha1.o md5.o irq_regs.o argv_split.o \ > proportions.o flex_proportions.o ratelimit.o show_mem.o \ > is_single_threaded.o plist.o decompress.o kobject_uevent.o \ > - earlycpio.o seq_buf.o nmi_backtrace.o > + earlycpio.o seq_buf.o nmi_backtrace.o xx.o > > obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o > lib-$(CONFIG_MMU) += ioremap.o > > > on i386, xx.o's text is 68 bytes with either newabs() or oldabs(). > > > lib/percpu_counter.o's text does get larger with newabs(). That's > because __percpu_counter_compare() is doing abs() on an s64, doh. > -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o) ooo +---------ooO--(_)--Ooo--