All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] arc: remove CONFIG_SET_FS
@ 2022-02-01 14:55 Sergey Matyukevich
  2022-02-01 14:55 ` [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user Sergey Matyukevich
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Sergey Matyukevich @ 2022-02-01 14:55 UTC (permalink / raw)
  To: linux-snps-arc
  Cc: Vineet Gupta, Vladimir Isaev, Christoph Hellwig, Sergey Matyukevich

Hi all,

This patch series removes SET_FS support for arc.

Sergey Matyukevich (3):
  arc: use BUILD_BUG for invalid sizes in get_user/put_user
  arc: provide __{get,put}_kernel_nofault
  arc: remove set_fs()

 arch/arc/Kconfig                   |  1 -
 arch/arc/include/asm/segment.h     | 20 -------------
 arch/arc/include/asm/thread_info.h |  3 --
 arch/arc/include/asm/uaccess.h     | 48 ++++++++++++++++++++----------
 4 files changed, 32 insertions(+), 40 deletions(-)
 delete mode 100644 arch/arc/include/asm/segment.h

-- 
2.35.0


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user
  2022-02-01 14:55 [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Sergey Matyukevich
@ 2022-02-01 14:55 ` Sergey Matyukevich
  2022-02-01 15:08   ` Christoph Hellwig
  2022-02-01 14:55 ` [RFC PATCH 2/3] arc: provide __{get,put}_kernel_nofault Sergey Matyukevich
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Sergey Matyukevich @ 2022-02-01 14:55 UTC (permalink / raw)
  To: linux-snps-arc
  Cc: Vineet Gupta, Vladimir Isaev, Christoph Hellwig,
	Sergey Matyukevich, Sergey Matyukevich

From: Sergey Matyukevich <sergey.matyukevich@synopsys.com>

Use BUILD_BUG for compile-time check of invalid sizes passed
to get_user/put_user functions.

Signed-off-by: Sergey Matyukevich <sergey.matyukevich@synopsys.com>
---
 arch/arc/include/asm/uaccess.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h
index 783bfdb3bfa3..9d1205bf90f1 100644
--- a/arch/arc/include/asm/uaccess.h
+++ b/arch/arc/include/asm/uaccess.h
@@ -62,6 +62,7 @@
 	case 2: __arc_get_user_one(*(k), u, "ldw", __ret); break;	\
 	case 4: __arc_get_user_one(*(k), u, "ld", __ret);  break;	\
 	case 8: __arc_get_user_one_64(*(k), u, __ret);     break;	\
+	default: BUILD_BUG();                                   \
 	}							\
 	__ret;							\
 })
@@ -123,6 +124,7 @@
 	case 2: __arc_put_user_one(*(k), u, "stw", __ret); break;	\
 	case 4: __arc_put_user_one(*(k), u, "st", __ret);  break;	\
 	case 8: __arc_put_user_one_64(*(k), u, __ret);     break;	\
+	default: BUILD_BUG();                                   \
 	}							\
 	__ret;							\
 })
-- 
2.35.0


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [RFC PATCH 2/3] arc: provide __{get,put}_kernel_nofault
  2022-02-01 14:55 [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Sergey Matyukevich
  2022-02-01 14:55 ` [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user Sergey Matyukevich
@ 2022-02-01 14:55 ` Sergey Matyukevich
  2022-02-01 15:10   ` Christoph Hellwig
  2022-02-01 14:55 ` [RFC PATCH 3/3] arc: remove set_fs() Sergey Matyukevich
  2022-02-02  5:14 ` [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Vineet Gupta
  3 siblings, 1 reply; 10+ messages in thread
From: Sergey Matyukevich @ 2022-02-01 14:55 UTC (permalink / raw)
  To: linux-snps-arc
  Cc: Vineet Gupta, Vladimir Isaev, Christoph Hellwig,
	Sergey Matyukevich, Sergey Matyukevich

From: Sergey Matyukevich <sergey.matyukevich@synopsys.com>

Implement the non-faulting kernel access helpers directly
instead of using uaccess routines under set_fs(KERNEL_DS).

Signed-off-by: Sergey Matyukevich <sergey.matyukevich@synopsys.com>
---
 arch/arc/include/asm/uaccess.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h
index 9d1205bf90f1..c14b692a0a4e 100644
--- a/arch/arc/include/asm/uaccess.h
+++ b/arch/arc/include/asm/uaccess.h
@@ -657,6 +657,28 @@ static inline unsigned long __arc_clear_user(void __user *to, unsigned long n)
 	return res;
 }
 
+#define HAVE_GET_KERNEL_NOFAULT
+
+#define __get_kernel_nofault(dst, src, type, err_label)			\
+	do {								\
+		long __err;						\
+									\
+		__err = __get_user_fn(sizeof(type), (type *)(src),	\
+				      (type *)(dst));			\
+		if (unlikely(__err))					\
+			goto err_label;					\
+	} while (0)
+
+#define __put_kernel_nofault(dst, src, type, err_label)			\
+	do {								\
+		long __err;						\
+									\
+		__err = __put_user_fn(sizeof(type), (type *)(dst),	\
+				      (type *)(src));			\
+		if (unlikely(__err))					\
+			goto err_label;					\
+	} while (0)
+
 #ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE
 
 #define INLINE_COPY_TO_USER
-- 
2.35.0


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [RFC PATCH 3/3] arc: remove set_fs()
  2022-02-01 14:55 [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Sergey Matyukevich
  2022-02-01 14:55 ` [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user Sergey Matyukevich
  2022-02-01 14:55 ` [RFC PATCH 2/3] arc: provide __{get,put}_kernel_nofault Sergey Matyukevich
@ 2022-02-01 14:55 ` Sergey Matyukevich
  2022-02-01 15:11   ` Christoph Hellwig
  2022-02-02  5:14 ` [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Vineet Gupta
  3 siblings, 1 reply; 10+ messages in thread
From: Sergey Matyukevich @ 2022-02-01 14:55 UTC (permalink / raw)
  To: linux-snps-arc
  Cc: Vineet Gupta, Vladimir Isaev, Christoph Hellwig,
	Sergey Matyukevich, Sergey Matyukevich

From: Sergey Matyukevich <sergey.matyukevich@synopsys.com>

Kernel __{get,put}_kernel_nofault operations are implemented for ARC.
There are no other remaining arch/arc specific callers of set_fs().
So just remove it and all the supporting code.

Signed-off-by: Sergey Matyukevich <sergey.matyukevich@synopsys.com>
---
 arch/arc/Kconfig                   |  1 -
 arch/arc/include/asm/segment.h     | 20 --------------------
 arch/arc/include/asm/thread_info.h |  3 ---
 arch/arc/include/asm/uaccess.h     | 24 ++++++++----------------
 4 files changed, 8 insertions(+), 40 deletions(-)
 delete mode 100644 arch/arc/include/asm/segment.h

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 3c2a4753d09b..e0a60a27e14d 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -45,7 +45,6 @@ config ARC
 	select PCI_SYSCALL if PCI
 	select PERF_USE_VMALLOC if ARC_CACHE_VIPT_ALIASING
 	select HAVE_ARCH_JUMP_LABEL if ISA_ARCV2 && !CPU_ENDIAN_BE32
-	select SET_FS
 	select TRACE_IRQFLAGS_SUPPORT
 
 config LOCKDEP_SUPPORT
diff --git a/arch/arc/include/asm/segment.h b/arch/arc/include/asm/segment.h
deleted file mode 100644
index 871f8ab11bfd..000000000000
--- a/arch/arc/include/asm/segment.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
- */
-
-#ifndef __ASMARC_SEGMENT_H
-#define __ASMARC_SEGMENT_H
-
-#ifndef __ASSEMBLY__
-
-typedef unsigned long mm_segment_t;
-
-#define MAKE_MM_SEG(s)	((mm_segment_t) { (s) })
-
-#define KERNEL_DS		MAKE_MM_SEG(0)
-#define USER_DS			MAKE_MM_SEG(TASK_SIZE)
-#define uaccess_kernel()	(get_fs() == KERNEL_DS)
-
-#endif /* __ASSEMBLY__ */
-#endif /* __ASMARC_SEGMENT_H */
diff --git a/arch/arc/include/asm/thread_info.h b/arch/arc/include/asm/thread_info.h
index d36863e34bfc..1e0b2e3914d5 100644
--- a/arch/arc/include/asm/thread_info.h
+++ b/arch/arc/include/asm/thread_info.h
@@ -27,7 +27,6 @@
 #ifndef __ASSEMBLY__
 
 #include <linux/thread_info.h>
-#include <asm/segment.h>
 
 /*
  * low level task data that entry.S needs immediate access to
@@ -40,7 +39,6 @@ struct thread_info {
 	unsigned long flags;		/* low level flags */
 	int preempt_count;		/* 0 => preemptable, <0 => BUG */
 	struct task_struct *task;	/* main task structure */
-	mm_segment_t addr_limit;	/* thread address space */
 	__u32 cpu;			/* current CPU */
 	unsigned long thr_ptr;		/* TLS ptr */
 };
@@ -56,7 +54,6 @@ struct thread_info {
 	.flags      = 0,			\
 	.cpu        = 0,			\
 	.preempt_count  = INIT_PREEMPT_COUNT,	\
-	.addr_limit = KERNEL_DS,		\
 }
 
 static inline __attribute_const__ struct thread_info *current_thread_info(void)
diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h
index c14b692a0a4e..f07eaf17afaf 100644
--- a/arch/arc/include/asm/uaccess.h
+++ b/arch/arc/include/asm/uaccess.h
@@ -23,14 +23,9 @@
 
 #include <linux/string.h>	/* for generic string functions */
 
-
-#define __kernel_ok		(uaccess_kernel())
-
 /*
- * Algorithmically, for __user_ok() we want do:
+ * Algorithmically, for __access_ok() we want do:
  * 	(start < TASK_SIZE) && (start+len < TASK_SIZE)
- * where TASK_SIZE could either be retrieved from thread_info->addr_limit or
- * emitted directly in code.
  *
  * This can however be rewritten as follows:
  *	(len <= TASK_SIZE) && (start+len < TASK_SIZE)
@@ -41,16 +36,14 @@
  * The reason for rewriting being, for majority of cases, @len is generally
  * compile time constant, causing first sub-expression to be compile time
  * subsumed.
- *
- * The second part would generate weird large LIMMs e.g. (0x6000_0000 - 0x10),
- * so we check for TASK_SIZE using get_fs() since the addr_limit load from mem
- * would already have been done at this call site for __kernel_ok()
- *
  */
-#define __user_ok(addr, sz)	(((sz) <= TASK_SIZE) && \
-				 ((addr) <= (get_fs() - (sz))))
-#define __access_ok(addr, sz)	(unlikely(__kernel_ok) || \
-				 likely(__user_ok((addr), (sz))))
+static inline int __access_ok(unsigned long addr, unsigned long size)
+{
+	__chk_user_ptr(addr);
+	return size <= TASK_SIZE && addr <= TASK_SIZE - size;
+}
+
+#define __access_ok	__access_ok
 
 /*********** Single byte/hword/word copies ******************/
 
@@ -691,7 +684,6 @@ extern unsigned long arc_clear_user_noinline(void __user *to,
 #define __clear_user(d, n)		arc_clear_user_noinline(d, n)
 #endif
 
-#include <asm/segment.h>
 #include <asm-generic/uaccess.h>
 
 #endif
-- 
2.35.0


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user
  2022-02-01 14:55 ` [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user Sergey Matyukevich
@ 2022-02-01 15:08   ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2022-02-01 15:08 UTC (permalink / raw)
  To: Sergey Matyukevich
  Cc: linux-snps-arc, Vineet Gupta, Vladimir Isaev, Christoph Hellwig,
	Sergey Matyukevich

On Tue, Feb 01, 2022 at 05:55:36PM +0300, Sergey Matyukevich wrote:
> From: Sergey Matyukevich <sergey.matyukevich@synopsys.com>
> 
> Use BUILD_BUG for compile-time check of invalid sizes passed
> to get_user/put_user functions.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC PATCH 2/3] arc: provide __{get,put}_kernel_nofault
  2022-02-01 14:55 ` [RFC PATCH 2/3] arc: provide __{get,put}_kernel_nofault Sergey Matyukevich
@ 2022-02-01 15:10   ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2022-02-01 15:10 UTC (permalink / raw)
  To: Sergey Matyukevich
  Cc: linux-snps-arc, Vineet Gupta, Vladimir Isaev, Christoph Hellwig,
	Sergey Matyukevich

On Tue, Feb 01, 2022 at 05:55:37PM +0300, Sergey Matyukevich wrote:
> From: Sergey Matyukevich <sergey.matyukevich@synopsys.com>
> 
> Implement the non-faulting kernel access helpers directly
> instead of using uaccess routines under set_fs(KERNEL_DS).
> 
> Signed-off-by: Sergey Matyukevich <sergey.matyukevich@synopsys.com>
> ---
>  arch/arc/include/asm/uaccess.h | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h
> index 9d1205bf90f1..c14b692a0a4e 100644
> --- a/arch/arc/include/asm/uaccess.h
> +++ b/arch/arc/include/asm/uaccess.h
> @@ -657,6 +657,28 @@ static inline unsigned long __arc_clear_user(void __user *to, unsigned long n)
>  	return res;
>  }
>  
> +#define HAVE_GET_KERNEL_NOFAULT
> +
> +#define __get_kernel_nofault(dst, src, type, err_label)			\
> +	do {								\

Normal kernel style doesn't indent the do { } while inside of
function-like macros.

Otherwise this looks good.

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC PATCH 3/3] arc: remove set_fs()
  2022-02-01 14:55 ` [RFC PATCH 3/3] arc: remove set_fs() Sergey Matyukevich
@ 2022-02-01 15:11   ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2022-02-01 15:11 UTC (permalink / raw)
  To: Sergey Matyukevich
  Cc: linux-snps-arc, Vineet Gupta, Vladimir Isaev, Christoph Hellwig,
	Sergey Matyukevich

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC PATCH 0/3] arc: remove CONFIG_SET_FS
  2022-02-01 14:55 [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Sergey Matyukevich
                   ` (2 preceding siblings ...)
  2022-02-01 14:55 ` [RFC PATCH 3/3] arc: remove set_fs() Sergey Matyukevich
@ 2022-02-02  5:14 ` Vineet Gupta
  2022-02-15 21:04   ` Sergey Matyukevich
  3 siblings, 1 reply; 10+ messages in thread
From: Vineet Gupta @ 2022-02-02  5:14 UTC (permalink / raw)
  To: Sergey Matyukevich, linux-snps-arc
  Cc: Vineet Gupta, Vladimir Isaev, Christoph Hellwig

On 2/1/22 06:55, Sergey Matyukevich wrote:
> Hi all,
>
> This patch series removes SET_FS support for arc.
>
> Sergey Matyukevich (3):
>    arc: use BUILD_BUG for invalid sizes in get_user/put_user
>    arc: provide __{get,put}_kernel_nofault
>    arc: remove set_fs()
>
>   arch/arc/Kconfig                   |  1 -
>   arch/arc/include/asm/segment.h     | 20 -------------
>   arch/arc/include/asm/thread_info.h |  3 --
>   arch/arc/include/asm/uaccess.h     | 48 ++++++++++++++++++++----------
>   4 files changed, 32 insertions(+), 40 deletions(-)
>   delete mode 100644 arch/arc/include/asm/segment.h

Nit - in future please use uppercase "ARC" for prefixing patches.

Added to for-next.

Thx,
-Vineet

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC PATCH 0/3] arc: remove CONFIG_SET_FS
  2022-02-02  5:14 ` [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Vineet Gupta
@ 2022-02-15 21:04   ` Sergey Matyukevich
  2022-02-18  4:03     ` Vineet Gupta
  0 siblings, 1 reply; 10+ messages in thread
From: Sergey Matyukevich @ 2022-02-15 21:04 UTC (permalink / raw)
  To: Vineet Gupta; +Cc: linux-snps-arc, Vladimir Isaev, Christoph Hellwig

Hi Vineet,

> > Hi all,
> > 
> > This patch series removes SET_FS support for arc.
> > 
> > Sergey Matyukevich (3):
> >    arc: use BUILD_BUG for invalid sizes in get_user/put_user
> >    arc: provide __{get,put}_kernel_nofault
> >    arc: remove set_fs()
> > 
> >   arch/arc/Kconfig                   |  1 -
> >   arch/arc/include/asm/segment.h     | 20 -------------
> >   arch/arc/include/asm/thread_info.h |  3 --
> >   arch/arc/include/asm/uaccess.h     | 48 ++++++++++++++++++++----------
> >   4 files changed, 32 insertions(+), 40 deletions(-)
> >   delete mode 100644 arch/arc/include/asm/segment.h
> 
> Nit - in future please use uppercase "ARC" for prefixing patches.
> 
> Added to for-next.

IIUC it makes sense to drop this patch series from your for-next branch.
These changes have been superseded by generic approach posted by
Arnd Bergmann, see:
https://lore.kernel.org/linux-arch/CAHk-=whXYWoP6of7js=f4zov62on97mNFRSVRWhY75WoGM6CoQ@mail.gmail.com/T/#t

I tested patches by Arnd on ARC700/ARCHS platforms, so far so good.

Regards,
Sergey

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC PATCH 0/3] arc: remove CONFIG_SET_FS
  2022-02-15 21:04   ` Sergey Matyukevich
@ 2022-02-18  4:03     ` Vineet Gupta
  0 siblings, 0 replies; 10+ messages in thread
From: Vineet Gupta @ 2022-02-18  4:03 UTC (permalink / raw)
  To: Sergey Matyukevich; +Cc: linux-snps-arc, Vladimir Isaev, Christoph Hellwig


> IIUC it makes sense to drop this patch series from your for-next branch.
> These changes have been superseded by generic approach posted by
> Arnd Bergmann, see:
> https://lore.kernel.org/linux-arch/CAHk-=whXYWoP6of7js=f4zov62on97mNFRSVRWhY75WoGM6CoQ@mail.gmail.com/T/#t
>
> I tested patches by Arnd on ARC700/ARCHS platforms, so far so good.

Yep I've been following that thread and have dropped your ARC patchset. 
Thx for testing. You can reply to Arnd with a
Tested-by: < your-name> #arc

-Vineet

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-02-18  4:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 14:55 [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Sergey Matyukevich
2022-02-01 14:55 ` [RFC PATCH 1/3] arc: use BUILD_BUG for invalid sizes in get_user/put_user Sergey Matyukevich
2022-02-01 15:08   ` Christoph Hellwig
2022-02-01 14:55 ` [RFC PATCH 2/3] arc: provide __{get,put}_kernel_nofault Sergey Matyukevich
2022-02-01 15:10   ` Christoph Hellwig
2022-02-01 14:55 ` [RFC PATCH 3/3] arc: remove set_fs() Sergey Matyukevich
2022-02-01 15:11   ` Christoph Hellwig
2022-02-02  5:14 ` [RFC PATCH 0/3] arc: remove CONFIG_SET_FS Vineet Gupta
2022-02-15 21:04   ` Sergey Matyukevich
2022-02-18  4:03     ` Vineet Gupta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.