From: Steven Rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org> To: LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> Cc: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, "Darrick J. Wong" <darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>, David Airlie <airlied-cv59FeDIM0c@public.gmane.org>, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, linux-xfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jason Gunthorpe <jgg-uk2M96/98Pc@public.gmane.org>, Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>, Ben Skeggs <bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>, Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>, Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>, Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Subject: [RFC][PATCH] kernel.h: Add generic roundup_64() macro Date: Thu, 23 May 2019 10:00:13 -0400 [thread overview] Message-ID: <20190523100013.52a8d2a6@gandalf.local.home> (raw) From: Steven Rostedt (VMware) <rostedt@goodmis.org> In discussing a build failure on x86_32 due to the use of roundup() on a 64 bit number, I realized that there's no generic equivalent roundup_64(). It is implemented in two separate places in the kernel, but there really should be just one that all can use. Although the other implementations are a static inline function, this implementation is a macro to allow the use of typeof(x) to denote the type that is being used. If the build is on a 64 bit machine, then the roundup_64() macro will just default back to roundup(). But for 32 bit machines, it will use the version that is will not cause issues with dividing a 64 bit number on a 32 bit machine. Link: http://lkml.kernel.org/r/20190522145450.25ff483d@gandalf.local.home Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> --- diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 34a998012bf6..cdacfe1f732c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -143,14 +143,6 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo) kfree(nvbo); } -static inline u64 -roundup_64(u64 x, u32 y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static void nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags, int *align, u64 *size) diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index edbd5a210df2..13de9d49bd52 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -207,13 +207,6 @@ static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev) #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL) #define xfs_stack_trace() dump_stack() -static inline uint64_t roundup_64(uint64_t x, uint32_t y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static inline uint64_t howmany_64(uint64_t x, uint32_t y) { x += y - 1; diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74b1ee9027f5..cd0063629357 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -115,6 +115,20 @@ (((x) + (__y - 1)) / __y) * __y; \ } \ ) + +#if BITS_PER_LONG == 32 +# define roundup_64(x, y) ( \ +{ \ + typeof(y) __y = y; \ + typeof(x) __x = (x) + (__y - 1); \ + do_div(__x, __y); \ + __x * __y; \ +} \ +) +#else +# define roundup_64(x, y) roundup(x, y) +#endif + /** * rounddown - round down to next specified multiple * @x: the value to round _______________________________________________ Nouveau mailing list Nouveau@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/nouveau
WARNING: multiple messages have this Message-ID (diff)
From: Steven Rostedt <rostedt@goodmis.org> To: LKML <linux-kernel@vger.kernel.org> Cc: Ben Skeggs <bskeggs@redhat.com>, David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>, Leon Romanovsky <leon@kernel.org>, Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@ziepe.ca>, "Darrick J. Wong" <darrick.wong@oracle.com>, linux-xfs@vger.kernel.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-rdma@vger.kernel.org, Linus Torvalds <torvalds@linux-foundation.org>, Andrew Morton <akpm@linux-foundation.org> Subject: [RFC][PATCH] kernel.h: Add generic roundup_64() macro Date: Thu, 23 May 2019 10:00:13 -0400 [thread overview] Message-ID: <20190523100013.52a8d2a6@gandalf.local.home> (raw) From: Steven Rostedt (VMware) <rostedt@goodmis.org> In discussing a build failure on x86_32 due to the use of roundup() on a 64 bit number, I realized that there's no generic equivalent roundup_64(). It is implemented in two separate places in the kernel, but there really should be just one that all can use. Although the other implementations are a static inline function, this implementation is a macro to allow the use of typeof(x) to denote the type that is being used. If the build is on a 64 bit machine, then the roundup_64() macro will just default back to roundup(). But for 32 bit machines, it will use the version that is will not cause issues with dividing a 64 bit number on a 32 bit machine. Link: http://lkml.kernel.org/r/20190522145450.25ff483d@gandalf.local.home Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> --- diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 34a998012bf6..cdacfe1f732c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -143,14 +143,6 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo) kfree(nvbo); } -static inline u64 -roundup_64(u64 x, u32 y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static void nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags, int *align, u64 *size) diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index edbd5a210df2..13de9d49bd52 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -207,13 +207,6 @@ static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev) #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL) #define xfs_stack_trace() dump_stack() -static inline uint64_t roundup_64(uint64_t x, uint32_t y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static inline uint64_t howmany_64(uint64_t x, uint32_t y) { x += y - 1; diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74b1ee9027f5..cd0063629357 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -115,6 +115,20 @@ (((x) + (__y - 1)) / __y) * __y; \ } \ ) + +#if BITS_PER_LONG == 32 +# define roundup_64(x, y) ( \ +{ \ + typeof(y) __y = y; \ + typeof(x) __x = (x) + (__y - 1); \ + do_div(__x, __y); \ + __x * __y; \ +} \ +) +#else +# define roundup_64(x, y) roundup(x, y) +#endif + /** * rounddown - round down to next specified multiple * @x: the value to round
next reply other threads:[~2019-05-23 14:00 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-23 14:00 Steven Rostedt [this message] 2019-05-23 14:00 ` [RFC][PATCH] kernel.h: Add generic roundup_64() macro Steven Rostedt 2019-05-23 15:10 ` Linus Torvalds 2019-05-23 15:27 ` Steven Rostedt [not found] ` <20190523112740.7167aba4-f9ZlEuEWxVcJvu8Pb33WZ0EMvNT87kid@public.gmane.org> 2019-05-23 16:51 ` Linus Torvalds 2019-05-23 16:51 ` Linus Torvalds 2019-05-23 17:36 ` Steven Rostedt 2019-05-23 21:19 ` Linus Torvalds 2019-05-24 15:11 ` Roger Willcocks 2019-05-24 15:26 ` Steven Rostedt 2019-05-24 16:30 ` Nikolay Borisov [not found] ` <bd4a85fc-dc56-aae0-4986-003ad4a11ef4-IBi9RG/b67k@public.gmane.org> 2019-05-24 16:36 ` Steven Rostedt 2019-05-24 16:36 ` Steven Rostedt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190523100013.52a8d2a6@gandalf.local.home \ --to=rostedt-nx8x9ylhiw1afugrpc6u6w@public.gmane.org \ --cc=airlied-cv59FeDIM0c@public.gmane.org \ --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \ --cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \ --cc=daniel-/w4YWyX8dFk@public.gmane.org \ --cc=darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \ --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \ --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \ --cc=jgg-uk2M96/98Pc@public.gmane.org \ --cc=leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \ --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=linux-xfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \ --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.