Re: [PATCH] MIPS: optimise non-EVA kernel user memory accesses

2015-06-05 Thread Ralf Baechle
On Sun, May 24, 2015 at 04:31:44PM +0100, Paul Burton wrote:
> Date:   Sun, 24 May 2015 16:31:44 +0100
> From: Paul Burton 
> To: linux-m...@linux-mips.org
> CC: Paul Burton , Markos Chandras
>  , Ralf Baechle ,
>  linux-kernel@vger.kernel.org

Thanks, applied.

Btw, I don't think such deeply MIPS-specific patches need to be cc'ed to
lkml.  That list's volume is already high enough as it is.

  Ralf
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] MIPS: optimise non-EVA kernel user memory accesses

2015-06-05 Thread Ralf Baechle
On Sun, May 24, 2015 at 04:31:44PM +0100, Paul Burton wrote:
 Date:   Sun, 24 May 2015 16:31:44 +0100
 From: Paul Burton paul.bur...@imgtec.com
 To: linux-m...@linux-mips.org
 CC: Paul Burton paul.bur...@imgtec.com, Markos Chandras
  markos.chand...@imgtec.com, Ralf Baechle r...@linux-mips.org,
  linux-kernel@vger.kernel.org

Thanks, applied.

Btw, I don't think such deeply MIPS-specific patches need to be cc'ed to
lkml.  That list's volume is already high enough as it is.

  Ralf
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] MIPS: optimise non-EVA kernel user memory accesses

2015-05-24 Thread Paul Burton
Commits ac1d8590d3ae (MIPS: asm: uaccess: Use EVA instructions
wrappers), 05c6516005c4 (MIPS: asm: uaccess: Add EVA support to
copy_{in, to,from}_user) & e3a9b07a9caf (MIPS: asm: uaccess: Add EVA
support for str*_user operations) added checks to various user memory
access functions & macros in order to determine whether to perform
standard memory accesses or their EVA userspace equivalents. In kernels
built without support for EVA these checks are entirely redundant. Avoid
emitting them & allow the compiler to optimise out the EVA userspace
code in such kernels by checking config_enabled(CONFIG_EVA).

This reduces the size of a malta_defconfig kernel built using GCC 4.9.2
by approximately 33KB (from 5995072 to 5962304 bytes).

Signed-off-by: Paul Burton 
Cc: Markos Chandras 
Cc: Ralf Baechle 
Cc: linux-kernel@vger.kernel.org
Cc: linux-m...@linux-mips.org
---

 arch/mips/include/asm/uaccess.h | 47 +++--
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index bf8b324..6ed061d 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -78,6 +78,21 @@ extern u64 __ua_limit;
 
 #define segment_eq(a, b)   ((a).seg == (b).seg)
 
+/*
+ * eva_kernel_access() - determine whether kernel memory access on an EVA 
system
+ *
+ * Determines whether memory accesses should be performed to kernel memory
+ * on a system using Extended Virtual Addressing (EVA).
+ *
+ * Return: true if a kernel memory access on an EVA system, else false.
+ */
+static inline bool eva_kernel_access(void)
+{
+   if (!config_enabled(CONFIG_EVA))
+   return false;
+
+   return segment_eq(get_fs(), get_ds());
+}
 
 /*
  * Is a address valid? This does a straighforward calculation rather
@@ -281,7 +296,7 @@ do {
\
 ({ \
int __gu_err;   \
\
-   if (segment_eq(get_fs(), get_ds())) {   \
+   if (eva_kernel_access()) {  \
__get_kernel_common((x), size, ptr);\
} else {\
__chk_user_ptr(ptr);\
@@ -297,7 +312,7 @@ do {
\
\
might_fault();  \
if (likely(access_ok(VERIFY_READ,  __gu_ptr, size))) {  \
-   if (segment_eq(get_fs(), get_ds())) \
+   if (eva_kernel_access())\
__get_kernel_common((x), size, __gu_ptr);   \
else\
__get_user_common((x), size, __gu_ptr); \
@@ -422,7 +437,7 @@ do {
\
int __pu_err = 0;   \
\
__pu_val = (x); \
-   if (segment_eq(get_fs(), get_ds())) {   \
+   if (eva_kernel_access()) {  \
__put_kernel_common(ptr, size); \
} else {\
__chk_user_ptr(ptr);\
@@ -439,7 +454,7 @@ do {
\
\
might_fault();  \
if (likely(access_ok(VERIFY_WRITE,  __pu_addr, size))) {\
-   if (segment_eq(get_fs(), get_ds())) \
+   if (eva_kernel_access())\
__put_kernel_common(__pu_addr, size);   \
else\
__put_user_common(__pu_addr, size); \
@@ -833,7 +848,7 @@ extern size_t __copy_user(void *__to, const void *__from, 
size_t __n);
__cu_from = (from); \
__cu_len = (n); \
might_fault();  \
-   if (segment_eq(get_fs(), get_ds())) \
+  

[PATCH] MIPS: optimise non-EVA kernel user memory accesses

2015-05-24 Thread Paul Burton
Commits ac1d8590d3ae (MIPS: asm: uaccess: Use EVA instructions
wrappers), 05c6516005c4 (MIPS: asm: uaccess: Add EVA support to
copy_{in, to,from}_user)  e3a9b07a9caf (MIPS: asm: uaccess: Add EVA
support for str*_user operations) added checks to various user memory
access functions  macros in order to determine whether to perform
standard memory accesses or their EVA userspace equivalents. In kernels
built without support for EVA these checks are entirely redundant. Avoid
emitting them  allow the compiler to optimise out the EVA userspace
code in such kernels by checking config_enabled(CONFIG_EVA).

This reduces the size of a malta_defconfig kernel built using GCC 4.9.2
by approximately 33KB (from 5995072 to 5962304 bytes).

Signed-off-by: Paul Burton paul.bur...@imgtec.com
Cc: Markos Chandras markos.chand...@imgtec.com
Cc: Ralf Baechle r...@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-m...@linux-mips.org
---

 arch/mips/include/asm/uaccess.h | 47 +++--
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index bf8b324..6ed061d 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -78,6 +78,21 @@ extern u64 __ua_limit;
 
 #define segment_eq(a, b)   ((a).seg == (b).seg)
 
+/*
+ * eva_kernel_access() - determine whether kernel memory access on an EVA 
system
+ *
+ * Determines whether memory accesses should be performed to kernel memory
+ * on a system using Extended Virtual Addressing (EVA).
+ *
+ * Return: true if a kernel memory access on an EVA system, else false.
+ */
+static inline bool eva_kernel_access(void)
+{
+   if (!config_enabled(CONFIG_EVA))
+   return false;
+
+   return segment_eq(get_fs(), get_ds());
+}
 
 /*
  * Is a address valid? This does a straighforward calculation rather
@@ -281,7 +296,7 @@ do {
\
 ({ \
int __gu_err;   \
\
-   if (segment_eq(get_fs(), get_ds())) {   \
+   if (eva_kernel_access()) {  \
__get_kernel_common((x), size, ptr);\
} else {\
__chk_user_ptr(ptr);\
@@ -297,7 +312,7 @@ do {
\
\
might_fault();  \
if (likely(access_ok(VERIFY_READ,  __gu_ptr, size))) {  \
-   if (segment_eq(get_fs(), get_ds())) \
+   if (eva_kernel_access())\
__get_kernel_common((x), size, __gu_ptr);   \
else\
__get_user_common((x), size, __gu_ptr); \
@@ -422,7 +437,7 @@ do {
\
int __pu_err = 0;   \
\
__pu_val = (x); \
-   if (segment_eq(get_fs(), get_ds())) {   \
+   if (eva_kernel_access()) {  \
__put_kernel_common(ptr, size); \
} else {\
__chk_user_ptr(ptr);\
@@ -439,7 +454,7 @@ do {
\
\
might_fault();  \
if (likely(access_ok(VERIFY_WRITE,  __pu_addr, size))) {\
-   if (segment_eq(get_fs(), get_ds())) \
+   if (eva_kernel_access())\
__put_kernel_common(__pu_addr, size);   \
else\
__put_user_common(__pu_addr, size); \
@@ -833,7 +848,7 @@ extern size_t __copy_user(void *__to, const void *__from, 
size_t __n);
__cu_from = (from); \
__cu_len = (n); \
might_fault();  \
-   if