kdev_t: Always inline major/minor helper functions
PATCH 1/1 kdev_t: Always inline major/minor helper functions
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
--- include/linux/kdev_t.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
include/linux/kdev_t.h +11 -11
@@ -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 ; }
Signature · 1 line
2.29.2
Quoted 8 lines · Josh Poimboeuf
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 tonew_encode_dev()with UACCESS enabledReported-by Randy Dunlap <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>
Thanks.
Quoted 3 lines
--- include/linux/kdev_t.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
~Randy
Quoted 8 lines · Josh Poimboeuf
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 tonew_encode_dev()with UACCESS enabledReported-by Randy Dunlap <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>
The alternative is something like:
arch/x86/kernel/sys_ia32.c +7 -2
@@ -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);
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Josh Poimboeuf
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 tonew_encode_dev()with UACCESS enabledReported-by Randy Dunlap <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>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?
Quoted 32 lines
arch/x86/kernel/sys_ia32.c +7
-2@@ -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);
Signature · 1 line
Josh
PATCH 1/1 x86/compat: Pull huge_encode_dev() outside of UACCESS
Quoted 1 line · Josh Poimboeuf
Peter, care to submit a proper patch?
Here goes..
---
Subject: x86/compat: Pull huge_encode_dev() outside of UACCESS
From: Peter Zijlstra <[email protected]>
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
--- arch/x86/kernel/sys_ia32.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/kernel/sys_ia32.c +7 -2
@@ -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);
Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS
Quoted 10 lines · Peter Zijlstra
Quoted 1 line · Josh Poimboeuf
Peter, care to submit a proper patch?
Here goes..
---
Subject: x86/compat: Pullhuge_encode_dev()outside of UACCESS
From: Peter Zijlstra <[email protected]>
Date: Mon, 4 Jan 2021 13:28:25 +0100
Quoted 6 lines
Fixes the following warning:
arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call tonew_encode_dev()with UACCESS enabledReported-by Randy Dunlap <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Thanks.
Quoted 33 lines
--- arch/x86/kernel/sys_ia32.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)arch/x86/kernel/sys_ia32.c +7
-2@@ -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);
Signature · 1 line
~Randy
Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS
In reply to Peter ZijlstraQuoted 10 lines · Peter Zijlstra
Quoted 1 line · Josh Poimboeuf
Peter, care to submit a proper patch?
Here goes..
---
Subject: x86/compat: Pullhuge_encode_dev()outside of UACCESS
From: Peter Zijlstra <[email protected]>
Date: Mon, 4 Jan 2021 13:28:25 +0100
Quoted 6 lines
Fixes the following warning:
arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call tonew_encode_dev()with UACCESS enabledReported-by Randy Dunlap <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Signature · 1 line
Josh
Re: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS
Quoted 11 lines · Josh Poimboeuf
Quoted 10 lines · Peter Zijlstra
Quoted 1 line · Josh Poimboeuf
Peter, care to submit a proper patch?
Here goes..
---
Subject: x86/compat: Pullhuge_encode_dev()outside of UACCESS
From: Peter Zijlstra <[email protected]>
Date: Mon, 4 Jan 2021 13:28:25 +0100
Quoted 8 lines
Quoted 6 lines
Fixes the following warning:
arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call tonew_encode_dev()with UACCESS enabledReported-by Randy Dunlap <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Josh Poimboeuf <[email protected]>
Actually the other patch was already merged into Linus' tree.
Maybe add a revert of the other patch to this one?
Signature · 1 line
Josh
Randy Dunlap
Acked-byRe: [PATCH] x86/compat: Pull huge_encode_dev() outside of UACCESS
Quoted 16 lines · Josh Poimboeuf
Quoted 15 lines · Josh Poimboeuf
Quoted 14 lines · Peter Zijlstra
Quoted 1 line · Josh Poimboeuf
Peter, care to submit a proper patch?
Here goes..
---
Subject: x86/compat: Pullhuge_encode_dev()outside of UACCESS
From: Peter Zijlstra <[email protected]>
Date: Mon, 4 Jan 2021 13:28:25 +0100Fixes the following warning:
arch/x86/kernel/sys_ia32.o: warning: objtool: cp_stat64()+0xd8: call tonew_encode_dev()with UACCESS enabled
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Reported-by Randy Dunlap <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Josh Poimboeuf <[email protected]>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):
Signature · 1 line
~Randy