Skip to contentSkip to conversation

m68knommu: switch to using asm-generic/uaccess.h

PATCH In review Greg Ungerer 3 participants 5 messages Sep 9, 2020

Subsystems (2)
lore
Share & tools
lore

Greg Ungerer

author maintainer
#0 lore raw

PATCH 1/1 m68knommu: switch to using asm-generic/uaccess.h

Switch to using the asm-generic/uaccess functions for non-MMU builds. Remove all the m68knommu local specific uaccess defines and macros.

There is nothing so special about the m68knommu targets that they cannot use all of the asm-generic uaccess support. Using the asm-generic uaccess definitions also resolves some of the existing problems with missing __user annotations in the m68knommu specific functions.

The elimination of all of the contents of uaccess_no.h means we can fold the uaccess_mm.h back into uaccess.h - and just have the single file now.

The resulting generated code ends up being slightly smaller (by a few hundred bytes) due to the compilers ability to better optimize load and stores without forcing its hand with asm statements.

Specifically trivial cases like this contrived example:

    get_user(x, ptr);
    x++;
    put_user(x, ptr);

end up now being optimized to a single instruction on m68k. More generally the compiler can avoid using a temporary register in many cases as well.

---
 arch/m68k/Kconfig                             |   1 +
 .../include/asm/{uaccess_mm.h => uaccess.h}   |   7 +
 arch/m68k/include/asm/uaccess_no.h            | 160 ------------------
 3 files changed, 8 insertions(+), 160 deletions(-)
 rename arch/m68k/include/asm/{uaccess_mm.h => uaccess.h} (98%)
 delete mode 100644 arch/m68k/include/asm/uaccess_no.h
arch/m68k/Kconfig +1 -0
index 6f2f38d05772..aefffebc0afa 100644
@@ -24,6 +24,7 @@ config M68K
 	select GENERIC_IOMAP
 	select GENERIC_STRNCPY_FROM_USER if MMU
 	select GENERIC_STRNLEN_USER if MMU
+	select UACCESS_MEMCPY if !MMU
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select HAVE_FUTEX_CMPXCHG if MMU && FUTEX
 	select HAVE_MOD_ARCH_SPECIFIC
arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +7 -0
similarity index 98%
rename from arch/m68k/include/asm/uaccess_mm.h
rename to arch/m68k/include/asm/uaccess.h
index 9ae9f8d05925..f98208ccbbcd 100644
@@ -2,12 +2,15 @@
 #ifndef __M68K_UACCESS_H
 #define __M68K_UACCESS_H
 
+#ifdef CONFIG_MMU
+
 /*
  * User space memory access functions
  */
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <asm/segment.h>
+#include <asm/extable.h>
 
 /* We let the MMU do all checking */
 static inline int access_ok(const void __user *addr,
@@ -387,4 +390,8 @@ unsigned long __clear_user(void __user *to, unsigned long n);
 
 #define clear_user	__clear_user
 
+#else /* !CONFIG_MMU */
+#include <asm-generic/uaccess.h>
+#endif
+
 #endif /* _M68K_UACCESS_H */
arch/m68k/include/asm/uaccess_no.h deleted +0 -160

160 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Greg,

Quoted 22 lines · Greg Ungerer

Switch to using the asm-generic/uaccess functions for non-MMU builds. Remove all the m68knommu local specific uaccess defines and macros.

There is nothing so special about the m68knommu targets that they cannot use all of the asm-generic uaccess support. Using the asm-generic uaccess definitions also resolves some of the existing problems with missing __user annotations in the m68knommu specific functions.

The elimination of all of the contents of uaccess_no.h means we can fold the uaccess_mm.h back into uaccess.h - and just have the single file now.

The resulting generated code ends up being slightly smaller (by a few hundred bytes) due to the compilers ability to better optimize load and stores without forcing its hand with asm statements.

Specifically trivial cases like this contrived example:

    get_user(x, ptr);
    x++;
    put_user(x, ptr);
Quoted 6 lines

end up now being optimized to a single instruction on m68k. More generally the compiler can avoid using a temporary register in many cases as well.

Thanks for your patch!

Quoted 8 lines

rename from arch/m68k/include/asm/uaccess_mm.h
rename to arch/m68k/include/asm/uaccess.h
index 9ae9f8d05925..f98208ccbbcd 100644

arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +0 -0
@@ -2,12 +2,15 @@
 #ifndef __M68K_UACCESS_H
 #define __M68K_UACCESS_H

arch/m68k/include/asm/uaccess.h line 13

Quoted 10 lines
arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +3 -0
 
+#ifdef CONFIG_MMU
+
 /*
  * User space memory access functions
  */
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <asm/segment.h>
+#include <asm/extable.h>

For a moment, I wondered where this new include came from...

Seems like git doesn't show what happened to the old arch/m68k/include/asm/uaccess.h file, which was overwritten by the rename:

    -/* SPDX-License-Identifier: GPL-2.0 */
    -#ifdef __uClinux__
    -#include <asm/uaccess_no.h>
    -#else
    -#include <asm/uaccess_mm.h>
    -#endif
    -#include <asm/extable.h>

There it is ;-)

arch/m68k/include/asm/uaccess.h unsigned long __clear_user(void __user *to, unsigned long n); · line 397

Quoted 11 lines
arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +4 -0
 /* We let the MMU do all checking */
 static inline int access_ok(const void __user *addr,
@@ -387,4 +390,8 @@ unsigned long __clear_user(void __user *to, unsigned long n);
 
 #define clear_user     __clear_user
 
+#else /* !CONFIG_MMU */
+#include <asm-generic/uaccess.h>
+#endif
+
 #endif /* _M68K_UACCESS_H */

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#2 lore raw

Hi Geert,

Quoted 67 lines · Geert Uytterhoeven

Hi Greg,

Quoted 22 lines · Greg Ungerer

Switch to using the asm-generic/uaccess functions for non-MMU builds. Remove all the m68knommu local specific uaccess defines and macros.

There is nothing so special about the m68knommu targets that they cannot use all of the asm-generic uaccess support. Using the asm-generic uaccess definitions also resolves some of the existing problems with missing __user annotations in the m68knommu specific functions.

The elimination of all of the contents of uaccess_no.h means we can fold the uaccess_mm.h back into uaccess.h - and just have the single file now.

The resulting generated code ends up being slightly smaller (by a few hundred bytes) due to the compilers ability to better optimize load and stores without forcing its hand with asm statements.

Specifically trivial cases like this contrived example:

     get_user(x, ptr);
     x++;
     put_user(x, ptr);
Quoted 6 lines

end up now being optimized to a single instruction on m68k. More generally the compiler can avoid using a temporary register in many cases as well.

Thanks for your patch!

Quoted 8 lines

rename from arch/m68k/include/asm/uaccess_mm.h
rename to arch/m68k/include/asm/uaccess.h
index 9ae9f8d05925..f98208ccbbcd 100644

arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +0 -0
@@ -2,12 +2,15 @@
  #ifndef __M68K_UACCESS_H
  #define __M68K_UACCESS_H

arch/m68k/include/asm/uaccess.h line 13

Quoted 10 lines
arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +3 -0
 
+#ifdef CONFIG_MMU
+
  /*
   * User space memory access functions
   */
  #include <linux/compiler.h>
  #include <linux/types.h>
  #include <asm/segment.h>
+#include <asm/extable.h>

For a moment, I wondered where this new include came from...

Seems like git doesn't show what happened to the old arch/m68k/include/asm/uaccess.h file, which was overwritten by the rename:

     -/* SPDX-License-Identifier: GPL-2.0 */
     -#ifdef __uClinux__
     -#include <asm/uaccess_no.h>
     -#else
     -#include <asm/uaccess_mm.h>
     -#endif
     -#include <asm/extable.h>
Quoted 3 lines

There it is ;-)

Thanks Geert.

I noticed that in the diff too. I generated this one with
"git format-patch -1 -M -B" to make it easier to review. Otherwise you end up with all those identical lines being inserted and deleted.
But it makes that "#include <asm/extable.h>" appear to come out of nowhere.

Regards
Greg

Quoted 16 lines

arch/m68k/include/asm/uaccess.h unsigned long __clear_user(void __user *to, unsigned long n); · line 397

Quoted 11 lines
arch/m68k/include/asm/uaccess.h renamed from arch/m68k/include/asm/uaccess_mm.h +4 -0
  /* We let the MMU do all checking */
  static inline int access_ok(const void __user *addr,
@@ -387,4 +390,8 @@ unsigned long __clear_user(void __user *to, unsigned long n);
 
  #define clear_user     __clear_user
 
+#else /* !CONFIG_MMU */
+#include <asm-generic/uaccess.h>
+#endif
+
  #endif /* _M68K_UACCESS_H */

Gr{oetje,eeting}s,

Geert

Reviewed-by on v1 1/1
#3 lore raw
In reply to Greg Ungerer
Quoted 18 lines · Greg Ungerer

Switch to using the asm-generic/uaccess functions for non-MMU builds. Remove all the m68knommu local specific uaccess defines and macros.

There is nothing so special about the m68knommu targets that they cannot use all of the asm-generic uaccess support. Using the asm-generic uaccess definitions also resolves some of the existing problems with missing __user annotations in the m68knommu specific functions.

The elimination of all of the contents of uaccess_no.h means we can fold the uaccess_mm.h back into uaccess.h - and just have the single file now.

The resulting generated code ends up being slightly smaller (by a few hundred bytes) due to the compilers ability to better optimize load and stores without forcing its hand with asm statements.

Specifically trivial cases like this contrived example:

Quoted 7 lines
    get_user(x, ptr);
    x++;
    put_user(x, ptr);

end up now being optimized to a single instruction on m68k. More generally the compiler can avoid using a temporary register in many cases as well.

This looks great!

author maintainer
#4 lore raw
Quoted 23 lines · Christoph Hellwig
Quoted 22 lines · Greg Ungerer

Switch to using the asm-generic/uaccess functions for non-MMU builds. Remove all the m68knommu local specific uaccess defines and macros.

There is nothing so special about the m68knommu targets that they cannot use all of the asm-generic uaccess support. Using the asm-generic uaccess definitions also resolves some of the existing problems with missing __user annotations in the m68knommu specific functions.

The elimination of all of the contents of uaccess_no.h means we can fold the uaccess_mm.h back into uaccess.h - and just have the single file now.

The resulting generated code ends up being slightly smaller (by a few hundred bytes) due to the compilers ability to better optimize load and stores without forcing its hand with asm statements.

Specifically trivial cases like this contrived example:

     get_user(x, ptr);
     x++;
     put_user(x, ptr);
Quoted 7 lines
Quoted 3 lines

end up now being optimized to a single instruction on m68k. More generally the compiler can avoid using a temporary register in many cases as well.

This looks great!

Thanks Christoph.
I'll push this into the for-next branch of the m68knommu git tree.

Regards
Greg