All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH, RFC] um: remove set_fs
@ 2021-07-09 13:38 Christoph Hellwig
  2021-07-09 14:47 ` Johannes Berg
  0 siblings, 1 reply; 12+ messages in thread
From: Christoph Hellwig @ 2021-07-09 13:38 UTC (permalink / raw)
  To: richard, anton.ivanov; +Cc: linux-um

Remove address space overrides using set_fs() for user mode Linux.

Compile tested only.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/um/Kconfig                   |  1 -
 arch/um/include/asm/thread_info.h |  4 ----
 arch/um/include/asm/uaccess.h     | 21 +++++++++++++++++++--
 arch/um/kernel/skas/uaccess.c     | 23 -----------------------
 arch/x86/um/asm/segment.h         |  8 --------
 5 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index 57cfd9a1c082..2a87f46259c8 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -19,7 +19,6 @@ config UML
 	select GENERIC_IRQ_SHOW
 	select GENERIC_CPU_DEVICES
 	select HAVE_GCC_PLUGINS
-	select SET_FS
 	select TTY # Needed for line.c
 
 config MMU
diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h
index 3b1cb8b3b186..1395cbd7e340 100644
--- a/arch/um/include/asm/thread_info.h
+++ b/arch/um/include/asm/thread_info.h
@@ -22,9 +22,6 @@ struct thread_info {
 	__u32			cpu;		/* current CPU */
 	int			preempt_count;  /* 0 => preemptable,
 						   <0 => BUG */
-	mm_segment_t		addr_limit;	/* thread address space:
-					 	   0-0xBFFFFFFF for user
-						   0-0xFFFFFFFF for kernel */
 	struct thread_info	*real_thread;    /* Points to non-IRQ stack */
 	unsigned long aux_fp_regs[FP_SIZE];	/* auxiliary fp_regs to save/restore
 						   them out-of-band */
@@ -36,7 +33,6 @@ struct thread_info {
 	.flags =		0,		\
 	.cpu =		0,			\
 	.preempt_count = INIT_PREEMPT_COUNT,	\
-	.addr_limit =	KERNEL_DS,		\
 	.real_thread = NULL,			\
 }
 
diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h
index fe66d659acad..85e0275c714b 100644
--- a/arch/um/include/asm/uaccess.h
+++ b/arch/um/include/asm/uaccess.h
@@ -8,6 +8,7 @@
 #define __UM_UACCESS_H
 
 #include <asm/elf.h>
+#include <asm/unaligned.h>
 
 #define __under_task_size(addr, size) \
 	(((unsigned long) (addr) < TASK_SIZE) && \
@@ -42,8 +43,24 @@ static inline int __access_ok(unsigned long addr, unsigned long size)
 {
 	return __addr_range_nowrap(addr, size) &&
 		(__under_task_size(addr, size) ||
-		__access_ok_vsyscall(addr, size) ||
-		uaccess_kernel());
+		 __access_ok_vsyscall(addr, size));
 }
 
+/* no pagefaults for kernel addresses in um */
+#define HAVE_GET_KERNEL_NOFAULT 1
+
+#define __get_kernel_nofault(dst, src, type, err_label)			\
+do {									\
+	*((type *)dst) = get_unaligned((type *)(src));			\
+	if (0) /* make sure the label looks used to the compiler */	\
+		goto err_label;						\
+} while (0)
+
+#define __put_kernel_nofault(dst, src, type, err_label)			\
+do {									\
+	put_unaligned(*((type *)src), (type *)(dst));			\
+	if (0) /* make sure the label looks used to the compiler */	\
+		goto err_label;						\
+} while (0)
+
 #endif
diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c
index 2dec915abe6f..f716ba0e66ee 100644
--- a/arch/um/kernel/skas/uaccess.c
+++ b/arch/um/kernel/skas/uaccess.c
@@ -145,11 +145,6 @@ static int copy_chunk_from_user(unsigned long from, int len, void *arg)
 
 unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
-	if (uaccess_kernel()) {
-		memcpy(to, (__force void*)from, n);
-		return 0;
-	}
-
 	return buffer_op((unsigned long) from, n, 0, copy_chunk_from_user, &to);
 }
 EXPORT_SYMBOL(raw_copy_from_user);
@@ -165,11 +160,6 @@ static int copy_chunk_to_user(unsigned long to, int len, void *arg)
 
 unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
-	if (uaccess_kernel()) {
-		memcpy((__force void *) to, from, n);
-		return 0;
-	}
-
 	return buffer_op((unsigned long) to, n, 1, copy_chunk_to_user, &from);
 }
 EXPORT_SYMBOL(raw_copy_to_user);
@@ -193,11 +183,6 @@ long __strncpy_from_user(char *dst, const char __user *src, long count)
 	long n;
 	char *ptr = dst;
 
-	if (uaccess_kernel()) {
-		strncpy(dst, (__force void *) src, count);
-		return strnlen(dst, count);
-	}
-
 	n = buffer_op((unsigned long) src, count, 0, strncpy_chunk_from_user,
 		      &ptr);
 	if (n != 0)
@@ -214,11 +199,6 @@ static int clear_chunk(unsigned long addr, int len, void *unused)
 
 unsigned long __clear_user(void __user *mem, unsigned long len)
 {
-	if (uaccess_kernel()) {
-		memset((__force void*)mem, 0, len);
-		return 0;
-	}
-
 	return buffer_op((unsigned long) mem, len, 1, clear_chunk, NULL);
 }
 EXPORT_SYMBOL(__clear_user);
@@ -239,9 +219,6 @@ long __strnlen_user(const void __user *str, long len)
 {
 	int count = 0, n;
 
-	if (uaccess_kernel())
-		return strnlen((__force char*)str, len) + 1;
-
 	n = buffer_op((unsigned long) str, len, 0, strnlen_chunk, &count);
 	if (n == 0)
 		return count + 1;
diff --git a/arch/x86/um/asm/segment.h b/arch/x86/um/asm/segment.h
index 453db377150d..2ef507bc6989 100644
--- a/arch/x86/um/asm/segment.h
+++ b/arch/x86/um/asm/segment.h
@@ -8,12 +8,4 @@ extern int host_gdt_entry_tls_min;
 #define GDT_ENTRY_TLS_MIN host_gdt_entry_tls_min
 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
 
-typedef struct {
-	unsigned long seg;
-} mm_segment_t;
-
-#define MAKE_MM_SEG(s)	((mm_segment_t) { (s) })
-#define KERNEL_DS	MAKE_MM_SEG(~0UL)
-#define USER_DS		MAKE_MM_SEG(TASK_SIZE)
-
 #endif
-- 
2.30.2


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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-07-09 13:38 [PATCH, RFC] um: remove set_fs Christoph Hellwig
@ 2021-07-09 14:47 ` Johannes Berg
  2021-07-09 16:57   ` Christoph Hellwig
  2021-08-23  7:04   ` Christoph Hellwig
  0 siblings, 2 replies; 12+ messages in thread
From: Johannes Berg @ 2021-07-09 14:47 UTC (permalink / raw)
  To: Christoph Hellwig, richard, anton.ivanov; +Cc: linux-um

On Fri, 2021-07-09 at 15:38 +0200, Christoph Hellwig wrote:
> Remove address space overrides using set_fs() for user mode Linux.
> 
> Compile tested only.

Seems to survive my normal (wireless related) tests :)

But I don't really understand what any of it does, so ...

In particular, why no pagefaults for kernel addresses?

johannes


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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-07-09 14:47 ` Johannes Berg
@ 2021-07-09 16:57   ` Christoph Hellwig
  2021-08-23  7:04   ` Christoph Hellwig
  1 sibling, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2021-07-09 16:57 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Christoph Hellwig, richard, anton.ivanov, linux-um

On Fri, Jul 09, 2021 at 04:47:34PM +0200, Johannes Berg wrote:
> Seems to survive my normal (wireless related) tests :)
> 
> But I don't really understand what any of it does, so ...
> 
> In particular, why no pagefaults for kernel addresses?

No idea.  But the existing uaccess_kernel() versions of the user copy
routines assume it, so this patch just keeps that behavior when switching
to the proper helpers.

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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-07-09 14:47 ` Johannes Berg
  2021-07-09 16:57   ` Christoph Hellwig
@ 2021-08-23  7:04   ` Christoph Hellwig
  2021-08-23  7:14     ` Anton Ivanov
  2021-08-23  8:28     ` Anton Ivanov
  1 sibling, 2 replies; 12+ messages in thread
From: Christoph Hellwig @ 2021-08-23  7:04 UTC (permalink / raw)
  To: Johannes Berg, richard, anton.ivanov; +Cc: linux-um

Richard, Anton - any comments?

On Fri, Jul 09, 2021 at 04:47:34PM +0200, Johannes Berg wrote:
> On Fri, 2021-07-09 at 15:38 +0200, Christoph Hellwig wrote:
> > Remove address space overrides using set_fs() for user mode Linux.
> > 
> > Compile tested only.
> 
> Seems to survive my normal (wireless related) tests :)
> 
> But I don't really understand what any of it does, so ...
> 
> In particular, why no pagefaults for kernel addresses?
> 
> johannes
---end quoted text---

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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-23  7:04   ` Christoph Hellwig
@ 2021-08-23  7:14     ` Anton Ivanov
  2021-08-23  8:28     ` Anton Ivanov
  1 sibling, 0 replies; 12+ messages in thread
From: Anton Ivanov @ 2021-08-23  7:14 UTC (permalink / raw)
  To: Christoph Hellwig, Johannes Berg, richard; +Cc: linux-um

On 23/08/2021 08:04, Christoph Hellwig wrote:
> Richard, Anton - any comments?
> 
> On Fri, Jul 09, 2021 at 04:47:34PM +0200, Johannes Berg wrote:
>> On Fri, 2021-07-09 at 15:38 +0200, Christoph Hellwig wrote:
>>> Remove address space overrides using set_fs() for user mode Linux.
>>>
>>> Compile tested only.
>>
>> Seems to survive my normal (wireless related) tests :)
>>
>> But I don't really understand what any of it does, so ...
>>
>> In particular, why no pagefaults for kernel addresses?
>>
>> johannes
> ---end quoted text---
> 

I will have a look at it today. Sorry, snowed under OVS/OVN.

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-23  7:04   ` Christoph Hellwig
  2021-08-23  7:14     ` Anton Ivanov
@ 2021-08-23  8:28     ` Anton Ivanov
  2021-08-23 12:17       ` Christoph Hellwig
  1 sibling, 1 reply; 12+ messages in thread
From: Anton Ivanov @ 2021-08-23  8:28 UTC (permalink / raw)
  To: Christoph Hellwig, Johannes Berg, richard; +Cc: linux-um



On 23/08/2021 08:04, Christoph Hellwig wrote:
> Richard, Anton - any comments?
> 
> On Fri, Jul 09, 2021 at 04:47:34PM +0200, Johannes Berg wrote:
>> On Fri, 2021-07-09 at 15:38 +0200, Christoph Hellwig wrote:
>>> Remove address space overrides using set_fs() for user mode Linux.
>>>
>>> Compile tested only.
>>
>> Seems to survive my normal (wireless related) tests :)
>>
>> But I don't really understand what any of it does, so ...
>>
>> In particular, why no pagefaults for kernel addresses?
>>
>> johannes
> ---end quoted text---
> 
> _______________________________________________
> linux-um mailing list
> linux-um@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-um
> 

In first read - you do not want to do that.

buffer_op is slow (even with all the tweaks we have done to that). It is one of the reasons UML userspace is slower than it should be.

The primary reason for that is that it never copies more than a page at a time and pages in/out a page at a time.

We retain reasonable kernel speed because we bypass it for kernel - "if (uaccess_kernel())".

Unless I am missing something, this change will use the slow path currently used for userspace for the kernel.

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-23  8:28     ` Anton Ivanov
@ 2021-08-23 12:17       ` Christoph Hellwig
  2021-08-23 12:29         ` Anton Ivanov
  0 siblings, 1 reply; 12+ messages in thread
From: Christoph Hellwig @ 2021-08-23 12:17 UTC (permalink / raw)
  To: Anton Ivanov; +Cc: Christoph Hellwig, Johannes Berg, richard, linux-um

On Mon, Aug 23, 2021 at 09:28:37AM +0100, Anton Ivanov wrote:
> In first read - you do not want to do that.
>
> buffer_op is slow (even with all the tweaks we have done to that). It is one of the reasons UML userspace is slower than it should be.
>
> The primary reason for that is that it never copies more than a page at a time and pages in/out a page at a time.
>
> We retain reasonable kernel speed because we bypass it for kernel - "if (uaccess_kernel())".
>
> Unless I am missing something, this change will use the slow path currently used for userspace for the kernel.

uaccess_kernel() is not the fast path, it is the exception path when
someone uses the uaccess helper on kernel pointer after doing a
set_fs(KERNEL_DS).  And this path is entirel gone once CONFIG_SET_FS
is not set and replaced with calls to __get_kernel_nofault /
__put_kernel_nofault.

In other words - very little generated code actually changes with
this patch, except for the context switch path, which gets simplified.

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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-23 12:17       ` Christoph Hellwig
@ 2021-08-23 12:29         ` Anton Ivanov
  2021-08-26 19:15           ` Richard Weinberger
  0 siblings, 1 reply; 12+ messages in thread
From: Anton Ivanov @ 2021-08-23 12:29 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Johannes Berg, richard, linux-um


On 23/08/2021 13:17, Christoph Hellwig wrote:
> On Mon, Aug 23, 2021 at 09:28:37AM +0100, Anton Ivanov wrote:
>> In first read - you do not want to do that.
>>
>> buffer_op is slow (even with all the tweaks we have done to that). It is one of the reasons UML userspace is slower than it should be.
>>
>> The primary reason for that is that it never copies more than a page at a time and pages in/out a page at a time.
>>
>> We retain reasonable kernel speed because we bypass it for kernel - "if (uaccess_kernel())".
>>
>> Unless I am missing something, this change will use the slow path currently used for userspace for the kernel.
> uaccess_kernel() is not the fast path, it is the exception path when
> someone uses the uaccess helper on kernel pointer after doing a
> set_fs(KERNEL_DS).  And this path is entirel gone once CONFIG_SET_FS
> is not set and replaced with calls to __get_kernel_nofault /
> __put_kernel_nofault.

OK. Cool.

>
> In other words - very little generated code actually changes with
> this patch, except for the context switch path, which gets simplified.

I am going to test it and play with it later.

Thanks for the explanation.

Brgds,

>
> _______________________________________________
> linux-um mailing list
> linux-um@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-um
>
-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/


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


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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-23 12:29         ` Anton Ivanov
@ 2021-08-26 19:15           ` Richard Weinberger
  2021-08-26 21:12             ` Anton Ivanov
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Weinberger @ 2021-08-26 19:15 UTC (permalink / raw)
  To: anton ivanov; +Cc: hch, Johannes Berg, linux-um

----- Ursprüngliche Mail -----
>> In other words - very little generated code actually changes with
>> this patch, except for the context switch path, which gets simplified.
> 
> I am going to test it and play with it later.

Did it survive your testing?
The changes look sane to me.

Thanks,
//richard

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

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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-26 19:15           ` Richard Weinberger
@ 2021-08-26 21:12             ` Anton Ivanov
  2021-08-26 22:04               ` Richard Weinberger
  0 siblings, 1 reply; 12+ messages in thread
From: Anton Ivanov @ 2021-08-26 21:12 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: hch, Johannes Berg, linux-um

On 26/08/2021 20:15, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
>>> In other words - very little generated code actually changes with
>>> this patch, except for the context switch path, which gets simplified.
>>
>> I am going to test it and play with it later.
> 
> Did it survive your testing?
> The changes look sane to me.
> 
> Thanks,
> //richard
> 

Does not crash, does not show any substantial differences in performance.

I am OK with it.

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-26 21:12             ` Anton Ivanov
@ 2021-08-26 22:04               ` Richard Weinberger
  2021-08-27  5:40                 ` hch
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Weinberger @ 2021-08-26 22:04 UTC (permalink / raw)
  To: anton ivanov; +Cc: hch, Johannes Berg, linux-um

----- Ursprüngliche Mail -----
> Von: "anton ivanov" <anton.ivanov@cambridgegreys.com>
> An: "richard" <richard@nod.at>
> CC: "hch" <hch@lst.de>, "Johannes Berg" <johannes@sipsolutions.net>, "linux-um" <linux-um@lists.infradead.org>
> Gesendet: Donnerstag, 26. August 2021 23:12:32
> Betreff: Re: [PATCH, RFC] um: remove set_fs

> On 26/08/2021 20:15, Richard Weinberger wrote:
>> ----- Ursprüngliche Mail -----
>>>> In other words - very little generated code actually changes with
>>>> this patch, except for the context switch path, which gets simplified.
>>>
>>> I am going to test it and play with it later.
>> 
>> Did it survive your testing?
>> The changes look sane to me.
>> 
>> Thanks,
>> //richard
>> 
> 
> Does not crash, does not show any substantial differences in performance.

Sounds like a decent patch. :-)
 
> I am OK with it.

So, let's be keen and merge it.

Thanks,
//richard

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

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

* Re: [PATCH, RFC] um: remove set_fs
  2021-08-26 22:04               ` Richard Weinberger
@ 2021-08-27  5:40                 ` hch
  0 siblings, 0 replies; 12+ messages in thread
From: hch @ 2021-08-27  5:40 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: anton ivanov, hch, Johannes Berg, linux-um

On Fri, Aug 27, 2021 at 12:04:20AM +0200, Richard Weinberger wrote:
> Sounds like a decent patch. :-)
>  
> > I am OK with it.
> 
> So, let's be keen and merge it.

With all the merge conflicts including the one with the asm-generic
tree that causes the TASK_SIZE_MAX redefinition it might be worth to
drop it and merge it for the next merge window instead.

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


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

end of thread, other threads:[~2021-08-27  5:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 13:38 [PATCH, RFC] um: remove set_fs Christoph Hellwig
2021-07-09 14:47 ` Johannes Berg
2021-07-09 16:57   ` Christoph Hellwig
2021-08-23  7:04   ` Christoph Hellwig
2021-08-23  7:14     ` Anton Ivanov
2021-08-23  8:28     ` Anton Ivanov
2021-08-23 12:17       ` Christoph Hellwig
2021-08-23 12:29         ` Anton Ivanov
2021-08-26 19:15           ` Richard Weinberger
2021-08-26 21:12             ` Anton Ivanov
2021-08-26 22:04               ` Richard Weinberger
2021-08-27  5:40                 ` hch

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.