[PW_SID:1086311] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access#1825
[PW_SID:1086311] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access#1825linux-riscv-bot wants to merge 10 commits into
Conversation
Until commit f5a1a53 ("lib: introduce copy_struct_from_user() helper"), lib/usercopy.c was containing only the out-line version of user copy fonctions. That commit added function check_zeroed_user() into the same file. Move that function into a new file named usercheck.c, so that next patch can change usercopy.c build to a conditional build. Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
…efery Among the 21 architectures supported by the kernel, 16 define both INLINE_COPY_TO_USER and INLINE_COPY_FROM_USER while the 5 other ones don't define any of the two. To simplify and reduce risk of mistakes, convert them to a single kconfig item named CONFIG_ARCH_WANTS_NOINLINE_COPY which will be selected by the 5 architectures that don't want inlined copy. To minimise complication in a later patch, also remove ifdefery and replace it with IS_ENABLED(). Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
fixup_umip_exception() calls copy_to_user() and checks whether the returned value is strictly positive. A subsequent patch will change the return of copy_to_user() to return -EFAULT in case of error. Change the test to checking that the result is not 0. At the time being copy_to_user() return an unsigned value so 'strictly positive' is the same as 'not 0'. Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Today there are approximately 3000 calls for copy_to_user() and
3000 calls to copy_from_user().
The majority of callers of copy_{to/from}_user() don't care about the
return value, they only check whether it is 0 or not, and when it is
not 0 they handle it as a -EACCES.
In order to allow better optimisation of copy_{to/from}_user() when
the size of the copy is known at build time, create new fonctions
named copy_{to/from}_user_partial() to be used by the few callers
that are interested in partial copies and need to now how many
bytes remain at the end of the copy.
For the time being it is just the same as copy_{to/from}_user().
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
In a subsequent patch, copy_{to/from}_user() will be modified to
return -EFAULT when copy fails.
Among the 6000 calls to copy_{to/from}_user(), around 2% rely on
copy_{to/from}_user() doing partial copies and returning amount of not
copied bytes. Change those users to copy_{to/from}_user_partial().
This change was done based on whether callers assign the returned value
to a variable or just check whether the return value is 0 or not.
Several of them only use it for debug to print the amount of bytes not
copied. Those could maybe be changed to stop reporting that amount and
not be converted to partial copy.
Some not trivial handling might have been unecessarily converted. This
is not a problem and they can be converted back later for better
performance.
The callers where located with following commands then reviewed one by
one:
sed -i s/"return copy_to_user("/"return copy_to_user_partial("/g `git grep -l "return copy_to_user("`
sed -i s/" = copy_to_user("/" = copy_to_user_partial("/g `git grep -l " = copy_to_user("`
sed -i s/" += copy_to_user("/" += copy_to_user_partial("/g `git grep -l " += copy_to_user("`
sed -i s/" -= copy_to_user("/" -= copy_to_user_partial("/g `git grep -l " -= copy_to_user("`
Then the same was done with copy_from_user().
During the review, patterns like the following were rejected and kept
as is:
- return copy_to_user(osf_stat, &tmp, sizeof(tmp)) ? -EFAULT : 0;
+ return copy_to_user_partial(osf_stat, &tmp, sizeof(tmp)) ? -EFAULT : 0;
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Now that copy_{to/from}_user_partial() are used by callers which expect
partial copy with number of not copied bytes as return value, change
copy_{to/from}_user() to return an int, and return -EFAULT when the
copy is not complete.
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
At the time being, x86 and arm64 are missing unsafe_copy_from_user(). Add it. Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
At the time being, x86 and arm64 are missing unsafe_copy_from_user(). Add it. Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
…r access
copy_{to/from}_user() is a heavy function optimised for copy of large
blocs of memory between user and kernel space.
When the number of bytes to be copied is known at build time and small,
using scoped user access removes the burden of that optimisation.
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery" |
|
Patch 8: "[RFC,v1,8/9] arm64: Add unsafe_copy_from_user()" |
|
Patch 8: "[RFC,v1,8/9] arm64: Add unsafe_copy_from_user()" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
|
Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access" |
7e5dc03 to
c37daaa
Compare
PR for series 1086311 applied to workflow
Name: uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1086311
Version: 1