remove set_fs for UML
Subsystems (3)
Hi Richard and Anton,
this series removes address space overrides using set_fs for UML.
Diffstat:
um/Kconfig | 1 - um/include/asm/thread_info.h | 4 ---- um/include/asm/uaccess.h | 21 +++++++++++++++++++-- um/kernel/skas/uaccess.c | 25 ------------------------- x86/include/asm/mtrr.h | 8 +------- x86/kernel/setup.c | 7 ++++++- x86/um/asm/segment.h | 8 -------- 7 files changed, 26 insertions(+), 48 deletions(-)
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
PATCH 1/2 x86/mtrr: remove the mtrr_bp_init stub
Add an IS_ENABLED check in setup_arch and call pat_disable directly if MTRRs are not supported. This allows to remove the <asm/memtype.h> include in <asm/mtrr.h>, which pull in lowlevel x86 headers that should not be included for UML builds and will cause build warnings with a futher patch.
--- arch/x86/include/asm/mtrr.h | 8 +------- arch/x86/kernel/setup.c | 7 ++++++- 2 files changed, 7 insertions(+), 8 deletions(-)
arch/x86/include/asm/mtrr.h +1 -7
@@ -24,8 +24,8 @@#define _ASM_X86_MTRR_H#include <uapi/asm/mtrr.h> -#include <asm/memtype.h> +void mtrr_bp_init (void );/* * The following functions are for use by other drivers that cannot use
@@ -43,7 +43,6 @@ extern int mtrr_del(int reg, unsigned long base, unsigned long size);extern int mtrr_del_page (int reg,unsigned long base,unsigned long size);extern void mtrr_centaur_report_mcr (int mcr,u32 lo,u32 hi);extern void mtrr_ap_init (void ); -extern void mtrr_bp_init (void );extern void set_mtrr_aps_delayed_init (void );extern void mtrr_aps_init (void );extern void mtrr_bp_restore (void );
@@ -84,11 +83,6 @@ static inline int mtrr_trim_uncached_memory(unsigned long end_pfn)static inline void mtrr_centaur_report_mcr (int mcr,u32 lo,u32 hi) { } -static inline void mtrr_bp_init (void ) -{ -pat_disable ("PAT support disabled because CONFIG_MTRR is disabled in the kernel." ); -} -#define mtrr_ap_init () do {} while (0)#define set_mtrr_aps_delayed_init () do {} while (0)#define mtrr_aps_init () do {} while (0)
arch/x86/kernel/setup.c +6 -1
@@ -40,6 +40,7 @@#include <asm/kasan.h> #include <asm/kaslr.h> #include <asm/mce.h> +#include <asm/memtype.h> #include <asm/mtrr.h> #include <asm/realmode.h> #include <asm/olpc_ofw.h>
@@ -979,7 +980,11 @@ void __init setup_arch(char **cmdline_p) max_pfn =e820__end_of_ram_pfn ();/* update e820 for memory not covered by WB MTRRs */ -mtrr_bp_init (); +if (IS_ENABLED (CONFIG_MTRR )) +mtrr_bp_init (); +else +pat_disable ("PAT support disabled because CONFIG_MTRR is disabled in the kernel." ); +if (mtrr_trim_uncached_memory (max_pfn)) max_pfn =e820__end_of_ram_pfn ();
Signature · 7 lines
2.30.2 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
[tip: x86/misc] x86/mtrr: Remove the mtrr_bp_init() stub
The following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: 4d5cff69fbddbbefef2903faa48263cc5d3ca382 Gitweb: https://git.kernel.org/tip/4d5cff69fbddbbefef2903faa48263cc5d3ca382 Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 15 Dec 2021 17:56:11 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Wed, 22 Dec 2021 19:50:26 +01:00
x86/mtrr: Remove the mtrr_bp_init() stub
Add an IS_ENABLED() check in setup_arch() and call pat_disable() directly if MTRRs are not supported. This allows to remove the <asm/memtype.h> include in <asm/mtrr.h>, which pull in lowlevel x86 headers that should not be included for UML builds and will cause build warnings with a following patch.
--- arch/x86/include/asm/mtrr.h | 8 +------- arch/x86/kernel/setup.c | 7 ++++++- arch/x86/kvm/mmu/spte.c | 1 + 3 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/include/asm/mtrr.h +1 -7
@@ -24,8 +24,8 @@#define _ASM_X86_MTRR_H#include <uapi/asm/mtrr.h> -#include <asm/memtype.h> +void mtrr_bp_init (void );/* * The following functions are for use by other drivers that cannot use
@@ -43,7 +43,6 @@ extern int mtrr_del(int reg, unsigned long base, unsigned long size);extern int mtrr_del_page (int reg,unsigned long base,unsigned long size);extern void mtrr_centaur_report_mcr (int mcr,u32 lo,u32 hi);extern void mtrr_ap_init (void ); -extern void mtrr_bp_init (void );extern void set_mtrr_aps_delayed_init (void );extern void mtrr_aps_init (void );extern void mtrr_bp_restore (void );
@@ -84,11 +83,6 @@ static inline int mtrr_trim_uncached_memory(unsigned long end_pfn)static inline void mtrr_centaur_report_mcr (int mcr,u32 lo,u32 hi) { } -static inline void mtrr_bp_init (void ) -{ -pat_disable ("PAT support disabled because CONFIG_MTRR is disabled in the kernel." ); -} -#define mtrr_ap_init () do {} while (0)#define set_mtrr_aps_delayed_init () do {} while (0)#define mtrr_aps_init () do {} while (0)
arch/x86/kernel/setup.c +6 -1
@@ -40,6 +40,7 @@#include <asm/kasan.h> #include <asm/kaslr.h> #include <asm/mce.h> +#include <asm/memtype.h> #include <asm/mtrr.h> #include <asm/realmode.h> #include <asm/olpc_ofw.h>
@@ -979,7 +980,11 @@ void __init setup_arch(char **cmdline_p) max_pfn =e820__end_of_ram_pfn ();/* update e820 for memory not covered by WB MTRRs */ -mtrr_bp_init (); +if (IS_ENABLED (CONFIG_MTRR )) +mtrr_bp_init (); +else +pat_disable ("PAT support disabled because CONFIG_MTRR is disabled in the kernel." ); +if (mtrr_trim_uncached_memory (max_pfn)) max_pfn =e820__end_of_ram_pfn ();
arch/x86/kvm/mmu/spte.c +1 -0
@@ -16,6 +16,7 @@#include "spte.h" #include <asm/e820/api.h> +#include <asm/memtype.h> #include <asm/vmx.h> static bool __read_mostly enable_mmio_caching = true;
PATCH 2/2 um: remove set_fs
In reply to Christoph HellwigRemove address space overrides using set_fs() for User Mode Linux. Note that just like the existing kernel access case of the uaccess routines the new nofault kernel handlers do not actually have any exception handling. This is probably broken, but not change to the status quo.
--- 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 | 25 ------------------------- arch/x86/um/asm/segment.h | 8 -------- 5 files changed, 19 insertions(+), 40 deletions(-)
arch/um/Kconfig +0 -1
@@ -21,7 +21,6 @@ config UML select GENERIC_IRQ_SHOW select GENERIC_CPU_DEVICES select HAVE_GCC_PLUGINS - select SET_FS select TRACE_IRQFLAGS_SUPPORT select TTY # Needed for line.c select HAVE_ARCH_VMAP_STACK
arch/um/include/asm/thread_info.h +0 -4
@@ -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, \ }
arch/um/include/asm/uaccess.h +19 -2
@@ -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) && \
@@ -39,8 +40,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
arch/um/kernel/skas/uaccess.c +0 -25
@@ -146,11 +146,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);
@@ -166,11 +161,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);
@@ -196,12 +186,6 @@ long strncpy_from_user(char *dst, const char __user *src, long count)if (!access_ok (src,1 ))return -EFAULT ; - -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 )
@@ -218,11 +202,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);
@@ -245,10 +224,6 @@ long strnlen_user(const char __user *str, long len)if (!access_ok (str,1 ))return -EFAULT ; - -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 ;
arch/x86/um/asm/segment.h +0 -8
@@ -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
Signature · 7 lines
2.30.2 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Richard Weinberger
maintainerChristoph,
----- Ursprüngliche Mail -----
Quoted 11 lines
Von: "hch" <[email protected]>
An: "richard" <[email protected]>, "anton ivanov" <[email protected]>
CC: "x86" <[email protected]>, "linux-um" <[email protected]>, "linux-kernel" <[email protected]>
Gesendet: Mittwoch, 15. Dezember 2021 17:56:10
Betreff: removeset_fsfor UMLHi Richard and Anton,
this series removes address space overrides using
set_fsfor UML.Diffstat:
Quoted 8 lines
um/Kconfig | 1 - um/include/asm/thread_info.h | 4 ---- um/include/asm/uaccess.h | 21 +++++++++++++++++++-- um/kernel/skas/uaccess.c | 25 ------------------------- x86/include/asm/mtrr.h | 8 +------- x86/kernel/setup.c | 7 ++++++- x86/um/asm/segment.h | 8 -------- 7 files changed, 26 insertions(+), 48 deletions(-)
So far UML seems to work with these changes applied. :-)
I have applied both patches to my UML tree for now, I assume x86 maintainers are fine with patch 1/2?
Thanks.
//richard
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Quoted 3 lines · Richard Weinberger
So far UML seems to work with these changes applied. :-)
I have applied both patches to my UML tree for now, I assume x86 maintainers are fine with patch 1/2?
Looks like patch 1 needs this fixup for some configurations, where pci.h doesn't get pulled into kvm by other means.
But we probably want an ACK from the x86 maintainers to be sure anyway..
arch/x86/kvm/mmu/spte.c +1 -0
@@ -16,6 +16,7 @@#include "spte.h" #include <asm/e820/api.h> +#include <asm/memtype.h> #include <asm/vmx.h> static bool __read_mostly enable_mmio_caching = true;
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Quoted 9 lines · hch
Quoted 3 lines · Richard Weinberger
So far UML seems to work with these changes applied. :-)
I have applied both patches to my UML tree for now, I assume x86 maintainers are fine with patch 1/2?Looks like patch 1 needs this fixup for some configurations, where
pci.hdoesn't get pulled into kvm by other means.But we probably want an ACK from the x86 maintainers to be sure anyway..
I don't see why not so
Should I take the first one along with this hunk below?
Quoted 12 lines
arch/x86/kvm/mmu/spte.c +1
-0@@ -16,6 +16,7 @@#include "spte.h" #include <asm/e820/api.h> +#include <asm/memtype.h> #include <asm/vmx.h> static bool __read_mostly enable_mmio_caching = true;
Signature · 9 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-umRichard Weinberger
maintainerBoris,
----- Ursprüngliche Mail -----
Quoted 17 lines
Von: "bp" <[email protected]>
An: "hch" <[email protected]>
CC: "richard" <[email protected]>, "anton ivanov" <[email protected]>, "x86" <[email protected]>, "linux-um" <[email protected]>, "linux-kernel" <[email protected]>
Gesendet: Mittwoch, 22. Dezember 2021 14:55:39
Betreff: Re: removeset_fsfor UMLQuoted 9 lines · hch
Quoted 4 lines · Richard Weinberger
So far UML seems to work with these changes applied. :-)
I have applied both patches to my UML tree for now, I assume x86 maintainers are fine with
patch 1/2?Looks like patch 1 needs this fixup for some configurations, where
pci.hdoesn't get pulled into kvm by other means.
Quoted 7 lines
Quoted 1 line
But we probably want an ACK from the x86 maintainers to be sure anyway..
I don't see why not so
Acked-by Borislav Petkov <[email protected]>Should I take the first one along with this hunk below?
Would be great!
When I'll drop "x86/mtrr: remove the mtrr_bp_init stub" from the UML tree.
Thanks,
//richard
Borislav Petkov
maintainerQuoted 2 lines · Richard Weinberger
Would be great!
When I'll drop "x86/mtrr: remove themtrr_bp_initstub" from the UML tree.
Done.
Thx.
Signature · 9 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-umQuoted 23 lines · Richard Weinberger
Christoph,
----- Ursprüngliche Mail -----
Quoted 11 lines
Von: "hch" <[email protected]>
An: "richard" <[email protected]>, "anton ivanov" <[email protected]>
CC: "x86" <[email protected]>, "linux-um" <[email protected]>, "linux-kernel" <[email protected]>
Gesendet: Mittwoch, 15. Dezember 2021 17:56:10
Betreff: removeset_fsfor UMLHi Richard and Anton,
this series removes address space overrides using
set_fsfor UML.Diffstat:
Quoted 8 lines
um/Kconfig | 1 - um/include/asm/thread_info.h | 4 ---- um/include/asm/uaccess.h | 21 +++++++++++++++++++-- um/kernel/skas/uaccess.c | 25 ------------------------- x86/include/asm/mtrr.h | 8 +------- x86/kernel/setup.c | 7 ++++++- x86/um/asm/segment.h | 8 -------- 7 files changed, 26 insertions(+), 48 deletions(-)
Quoted 3 lines
So far UML seems to work with these changes applied. :-)
I have applied both patches to my UML tree for now, I assume x86 maintainers are fine with patch 1/2?
Hmmm... AFAICS, the right thing to do would be to have __get_kernel_nofault and __put_kernel_nofault in arch/x86/um/asm/something. The question is how to avoid duplicating the x86 implementation of those (along with the asm-goto fun, etc.)...
But Christoph is right, it's not a new problem. As far as I'm concerned, that series looks fine.
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um