* [PATCH] kdev_t: Always inline major/minor helper functions @ 2020-12-23 15:30 Josh Poimboeuf 2020-12-23 18:06 ` Randy Dunlap 2021-01-04 12:28 ` Peter Zijlstra 0 siblings, 2 replies; 9+ messages in thread From: Josh Poimboeuf @ 2020-12-23 15:30 UTC (permalink / raw) To: Andrew Morton; +Cc: linux-kernel, Peter Zijlstra, Randy Dunlap Silly GCC doesn't always inline these trivial functions. Fixes the following warning: arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled Reported-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> --- include/linux/kdev_t.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/kdev_t.h b/include/linux/kdev_t.h index 85b5151911cf..4856706fbfeb 100644 --- a/include/linux/kdev_t.h +++ b/include/linux/kdev_t.h @@ -21,61 +21,61 @@ }) /* acceptable for old filesystems */ -static inline bool old_valid_dev(dev_t dev) +static __always_inline bool old_valid_dev(dev_t dev) { return MAJOR(dev) < 256 && MINOR(dev) < 256; } -static inline u16 old_encode_dev(dev_t dev) +static __always_inline u16 old_encode_dev(dev_t dev) { return (MAJOR(dev) << 8) | MINOR(dev); } -static inline dev_t old_decode_dev(u16 val) +static __always_inline dev_t old_decode_dev(u16 val) { return MKDEV((val >> 8) & 255, val & 255); } -static inline u32 new_encode_dev(dev_t dev) +static __always_inline u32 new_encode_dev(dev_t dev) { unsigned major = MAJOR(dev); unsigned minor = MINOR(dev); return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12); } -static inline dev_t new_decode_dev(u32 dev) +static __always_inline dev_t new_decode_dev(u32 dev) { unsigned major = (dev & 0xfff00) >> 8; unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00); return MKDEV(major, minor); } -static inline u64 huge_encode_dev(dev_t dev) +static __always_inline u64 huge_encode_dev(dev_t dev) { return new_encode_dev(dev); } -static inline dev_t huge_decode_dev(u64 dev) +static __always_inline dev_t huge_decode_dev(u64 dev) { return new_decode_dev(dev); } -static inline int sysv_valid_dev(dev_t dev) +static __always_inline int sysv_valid_dev(dev_t dev) { return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18); } -static inline u32 sysv_encode_dev(dev_t dev) +static __always_inline u32 sysv_encode_dev(dev_t dev) { return MINOR(dev) | (MAJOR(dev) << 18); } -static inline unsigned sysv_major(u32 dev) +static __always_inline unsigned sysv_major(u32 dev) { return (dev >> 18) & 0x3fff; } -static inline unsigned sysv_minor(u32 dev) +static __always_inline unsigned sysv_minor(u32 dev) { return dev & 0x3ffff; } -- 2.29.2 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] kdev_t: Always inline major/minor helper functions 2020-12-23 15:30 [PATCH] kdev_t: Always inline major/minor helper functions Josh Poimboeuf @ 2020-12-23 18:06 ` Randy Dunlap 2021-01-04 12:28 ` Peter Zijlstra 1 sibling, 0 replies; 9+ messages in thread From: Randy Dunlap @ 2020-12-23 18:06 UTC (permalink / raw) To: Josh Poimboeuf, Andrew Morton; +Cc: linux-kernel, Peter Zijlstra On 12/23/20 7:30 AM, Josh Poimboeuf wrote: > Silly GCC doesn't always inline these trivial functions. > > Fixes the following warning: > > arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested Thanks. > --- > include/linux/kdev_t.h | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) ~Randy ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] kdev_t: Always inline major/minor helper functions 2020-12-23 15:30 [PATCH] kdev_t: Always inline major/minor helper functions Josh Poimboeuf 2020-12-23 18:06 ` Randy Dunlap @ 2021-01-04 12:28 ` Peter Zijlstra 2021-01-04 15:31 ` Josh Poimboeuf 1 sibling, 1 reply; 9+ messages in thread From: Peter Zijlstra @ 2021-01-04 12:28 UTC (permalink / raw) To: Josh Poimboeuf; +Cc: Andrew Morton, linux-kernel, Randy Dunlap On Wed, Dec 23, 2020 at 09:30:48AM -0600, Josh Poimboeuf wrote: > Silly GCC doesn't always inline these trivial functions. > > Fixes the following warning: > > arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> The alternative is something like: diff --git a/arch/x86/kernel/sys_ia32.c b/arch/x86/kernel/sys_ia32.c index 6cf65397d225..6ca3da08dbcb 100644 --- a/arch/x86/kernel/sys_ia32.c +++ b/arch/x86/kernel/sys_ia32.c @@ -133,18 +133,23 @@ static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat) { typeof(ubuf->st_uid) uid = 0; typeof(ubuf->st_gid) gid = 0; + u64 dev, rdev; + SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid)); SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid)); + dev = huge_encode_dev(stat->dev); + rdev = huge_encode_dev(stat->rdev); + if (!user_write_access_begin(ubuf, sizeof(struct stat64))) return -EFAULT; - unsafe_put_user(huge_encode_dev(stat->dev), &ubuf->st_dev, Efault); + unsafe_put_user(dev, &ubuf->st_dev, Efault); unsafe_put_user(stat->ino, &ubuf->__st_ino, Efault); unsafe_put_user(stat->ino, &ubuf->st_ino, Efault); unsafe_put_user(stat->mode, &ubuf->st_mode, Efault); unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault); unsafe_put_user(uid, &ubuf->st_uid, Efault); unsafe_put_user(gid, &ubuf->st_gid, Efault); - unsafe_put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev, Efault); + unsafe_put_user(rdev, &ubuf->st_rdev, Efault); unsafe_put_user(stat->size, &ubuf->st_size, Efault); unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault); unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault); ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] kdev_t: Always inline major/minor helper functions 2021-01-04 12:28 ` Peter Zijlstra @ 2021-01-04 15:31 ` Josh Poimboeuf 2021-01-04 15:53 ` [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS Peter Zijlstra 0 siblings, 1 reply; 9+ messages in thread From: Josh Poimboeuf @ 2021-01-04 15:31 UTC (permalink / raw) To: Peter Zijlstra; +Cc: Andrew Morton, linux-kernel, Randy Dunlap On Mon, Jan 04, 2021 at 01:28:25PM +0100, Peter Zijlstra wrote: > On Wed, Dec 23, 2020 at 09:30:48AM -0600, Josh Poimboeuf wrote: > > Silly GCC doesn't always inline these trivial functions. > > > > Fixes the following warning: > > > > arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled > > > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> > > The alternative is something like: I like your approach better, it avoids __always_inline sprawl. Peter, care to submit a proper patch? Andrew, can you drop mine? > > diff --git a/arch/x86/kernel/sys_ia32.c b/arch/x86/kernel/sys_ia32.c > index 6cf65397d225..6ca3da08dbcb 100644 > --- a/arch/x86/kernel/sys_ia32.c > +++ b/arch/x86/kernel/sys_ia32.c > @@ -133,18 +133,23 @@ static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat) > { > typeof(ubuf->st_uid) uid = 0; > typeof(ubuf->st_gid) gid = 0; > + u64 dev, rdev; > + > SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid)); > SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid)); > + dev = huge_encode_dev(stat->dev); > + rdev = huge_encode_dev(stat->rdev); > + > if (!user_write_access_begin(ubuf, sizeof(struct stat64))) > return -EFAULT; > - unsafe_put_user(huge_encode_dev(stat->dev), &ubuf->st_dev, Efault); > + unsafe_put_user(dev, &ubuf->st_dev, Efault); > unsafe_put_user(stat->ino, &ubuf->__st_ino, Efault); > unsafe_put_user(stat->ino, &ubuf->st_ino, Efault); > unsafe_put_user(stat->mode, &ubuf->st_mode, Efault); > unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault); > unsafe_put_user(uid, &ubuf->st_uid, Efault); > unsafe_put_user(gid, &ubuf->st_gid, Efault); > - unsafe_put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev, Efault); > + unsafe_put_user(rdev, &ubuf->st_rdev, Efault); > unsafe_put_user(stat->size, &ubuf->st_size, Efault); > unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault); > unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault); > -- Josh ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS 2021-01-04 15:31 ` Josh Poimboeuf @ 2021-01-04 15:53 ` Peter Zijlstra 2021-01-04 16:19 ` Randy Dunlap 2021-01-04 17:24 ` Josh Poimboeuf 0 siblings, 2 replies; 9+ messages in thread From: Peter Zijlstra @ 2021-01-04 15:53 UTC (permalink / raw) To: Josh Poimboeuf; +Cc: Andrew Morton, linux-kernel, Randy Dunlap, x86 On Mon, Jan 04, 2021 at 09:31:27AM -0600, Josh Poimboeuf wrote: > Peter, care to submit a proper patch? Here goes.. --- Subject: x86/compat: Pull huge_encode_dev() outside of UACCESS From: Peter Zijlstra <peterz@infradead.org> Date: Mon, 4 Jan 2021 13:28:25 +0100 Fixes the following warning: arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled Reported-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- arch/x86/kernel/sys_ia32.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/sys_ia32.c +++ b/arch/x86/kernel/sys_ia32.c @@ -133,18 +133,23 @@ static int cp_stat64(struct stat64 __use { typeof(ubuf->st_uid) uid = 0; typeof(ubuf->st_gid) gid = 0; + u64 dev, rdev; + SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid)); SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid)); + dev = huge_encode_dev(stat->dev); + rdev = huge_encode_dev(stat->rdev); + if (!user_write_access_begin(ubuf, sizeof(struct stat64))) return -EFAULT; - unsafe_put_user(huge_encode_dev(stat->dev), &ubuf->st_dev, Efault); + unsafe_put_user(dev, &ubuf->st_dev, Efault); unsafe_put_user(stat->ino, &ubuf->__st_ino, Efault); unsafe_put_user(stat->ino, &ubuf->st_ino, Efault); unsafe_put_user(stat->mode, &ubuf->st_mode, Efault); unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault); unsafe_put_user(uid, &ubuf->st_uid, Efault); unsafe_put_user(gid, &ubuf->st_gid, Efault); - unsafe_put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev, Efault); + unsafe_put_user(rdev, &ubuf->st_rdev, Efault); unsafe_put_user(stat->size, &ubuf->st_size, Efault); unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault); unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault); ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS 2021-01-04 15:53 ` [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS Peter Zijlstra @ 2021-01-04 16:19 ` Randy Dunlap 2021-01-04 17:24 ` Josh Poimboeuf 1 sibling, 0 replies; 9+ messages in thread From: Randy Dunlap @ 2021-01-04 16:19 UTC (permalink / raw) To: Peter Zijlstra, Josh Poimboeuf; +Cc: Andrew Morton, linux-kernel, x86 On 1/4/21 7:53 AM, Peter Zijlstra wrote: > On Mon, Jan 04, 2021 at 09:31:27AM -0600, Josh Poimboeuf wrote: >> Peter, care to submit a proper patch? > > Here goes.. > > --- > Subject: x86/compat: Pull huge_encode_dev() outside of UACCESS > From: Peter Zijlstra <peterz@infradead.org> > Date: Mon, 4 Jan 2021 13:28:25 +0100 > > Fixes the following warning: > > arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested Thanks. > --- > arch/x86/kernel/sys_ia32.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > --- a/arch/x86/kernel/sys_ia32.c > +++ b/arch/x86/kernel/sys_ia32.c > @@ -133,18 +133,23 @@ static int cp_stat64(struct stat64 __use > { > typeof(ubuf->st_uid) uid = 0; > typeof(ubuf->st_gid) gid = 0; > + u64 dev, rdev; > + > SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid)); > SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid)); > + dev = huge_encode_dev(stat->dev); > + rdev = huge_encode_dev(stat->rdev); > + > if (!user_write_access_begin(ubuf, sizeof(struct stat64))) > return -EFAULT; > - unsafe_put_user(huge_encode_dev(stat->dev), &ubuf->st_dev, Efault); > + unsafe_put_user(dev, &ubuf->st_dev, Efault); > unsafe_put_user(stat->ino, &ubuf->__st_ino, Efault); > unsafe_put_user(stat->ino, &ubuf->st_ino, Efault); > unsafe_put_user(stat->mode, &ubuf->st_mode, Efault); > unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault); > unsafe_put_user(uid, &ubuf->st_uid, Efault); > unsafe_put_user(gid, &ubuf->st_gid, Efault); > - unsafe_put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev, Efault); > + unsafe_put_user(rdev, &ubuf->st_rdev, Efault); > unsafe_put_user(stat->size, &ubuf->st_size, Efault); > unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault); > unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault); > -- ~Randy ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS 2021-01-04 15:53 ` [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS Peter Zijlstra 2021-01-04 16:19 ` Randy Dunlap @ 2021-01-04 17:24 ` Josh Poimboeuf 2021-01-04 23:14 ` Josh Poimboeuf 1 sibling, 1 reply; 9+ messages in thread From: Josh Poimboeuf @ 2021-01-04 17:24 UTC (permalink / raw) To: Peter Zijlstra; +Cc: Andrew Morton, linux-kernel, Randy Dunlap, x86 On Mon, Jan 04, 2021 at 04:53:47PM +0100, Peter Zijlstra wrote: > On Mon, Jan 04, 2021 at 09:31:27AM -0600, Josh Poimboeuf wrote: > > Peter, care to submit a proper patch? > > Here goes.. > > --- > Subject: x86/compat: Pull huge_encode_dev() outside of UACCESS > From: Peter Zijlstra <peterz@infradead.org> > Date: Mon, 4 Jan 2021 13:28:25 +0100 > > Fixes the following warning: > > arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> -- Josh ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS 2021-01-04 17:24 ` Josh Poimboeuf @ 2021-01-04 23:14 ` Josh Poimboeuf 2021-01-04 23:55 ` Randy Dunlap 0 siblings, 1 reply; 9+ messages in thread From: Josh Poimboeuf @ 2021-01-04 23:14 UTC (permalink / raw) To: Peter Zijlstra; +Cc: Andrew Morton, linux-kernel, Randy Dunlap, x86 On Mon, Jan 04, 2021 at 11:24:23AM -0600, Josh Poimboeuf wrote: > On Mon, Jan 04, 2021 at 04:53:47PM +0100, Peter Zijlstra wrote: > > On Mon, Jan 04, 2021 at 09:31:27AM -0600, Josh Poimboeuf wrote: > > > Peter, care to submit a proper patch? > > > > Here goes.. > > > > --- > > Subject: x86/compat: Pull huge_encode_dev() outside of UACCESS > > From: Peter Zijlstra <peterz@infradead.org> > > Date: Mon, 4 Jan 2021 13:28:25 +0100 > > > > Fixes the following warning: > > > > arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled > > > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> > > Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Actually the other patch was already merged into Linus' tree. Maybe add a revert of the other patch to this one? -- Josh ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS 2021-01-04 23:14 ` Josh Poimboeuf @ 2021-01-04 23:55 ` Randy Dunlap 0 siblings, 0 replies; 9+ messages in thread From: Randy Dunlap @ 2021-01-04 23:55 UTC (permalink / raw) To: Josh Poimboeuf, Peter Zijlstra; +Cc: Andrew Morton, linux-kernel, x86 On 1/4/21 3:14 PM, Josh Poimboeuf wrote: > On Mon, Jan 04, 2021 at 11:24:23AM -0600, Josh Poimboeuf wrote: >> On Mon, Jan 04, 2021 at 04:53:47PM +0100, Peter Zijlstra wrote: >>> On Mon, Jan 04, 2021 at 09:31:27AM -0600, Josh Poimboeuf wrote: >>>> Peter, care to submit a proper patch? >>> >>> Here goes.. >>> >>> --- >>> Subject: x86/compat: Pull huge_encode_dev() outside of UACCESS >>> From: Peter Zijlstra <peterz@infradead.org> >>> Date: Mon, 4 Jan 2021 13:28:25 +0100 >>> >>> Fixes the following warning: >>> >>> arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call to new_encode_dev() with UACCESS enabled >>> >>> Reported-by: Randy Dunlap <rdunlap@infradead.org> >>> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> >> >> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> > > Actually the other patch was already merged into Linus' tree. > > Maybe add a revert of the other patch to this one? > Glad you noticed. I reverted the kdev_t patch and applied Peter's patch and it still tested OK, so (still): Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested -- ~Randy ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-01-04 23:57 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-12-23 15:30 [PATCH] kdev_t: Always inline major/minor helper functions Josh Poimboeuf 2020-12-23 18:06 ` Randy Dunlap 2021-01-04 12:28 ` Peter Zijlstra 2021-01-04 15:31 ` Josh Poimboeuf 2021-01-04 15:53 ` [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS Peter Zijlstra 2021-01-04 16:19 ` Randy Dunlap 2021-01-04 17:24 ` Josh Poimboeuf 2021-01-04 23:14 ` Josh Poimboeuf 2021-01-04 23:55 ` Randy Dunlap
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).