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(-)
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.
Signed-off-by: Christoph Hellwig <[email protected]>
---
arch/x86/include/asm/mtrr.h | 8 +-------
arch/x86/kernel/setup.c | 7 ++++++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index 829df26fd7a3e..76d726074c163 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -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)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 6a190c7f4d71b..2f5129bd49dc4 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -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();
--
2.30.2
Remove 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.
Signed-off-by: Christoph Hellwig <[email protected]>
---
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(-)
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index c18b45f75d41f..aafdbb6e8059e 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -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
diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h
index 3b1cb8b3b1864..1395cbd7e340d 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 191ef36dd5439..17d18cfd82a51 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) && \
@@ -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
diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c
index a509be9110260..23775d01a2a61 100644
--- a/arch/um/kernel/skas/uaccess.c
+++ b/arch/um/kernel/skas/uaccess.c
@@ -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;
diff --git a/arch/x86/um/asm/segment.h b/arch/x86/um/asm/segment.h
index 453db377150d6..2ef507bc69890 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
Christoph,
----- Ursprüngliche Mail -----
> 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: remove set_fs for UML
> 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(-)
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
On Tue, Dec 21, 2021 at 10:05:03PM +0100, Richard Weinberger wrote:
> 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..
diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
index 0c76c45fdb686..fad546df0bbac 100644
--- a/arch/x86/kvm/mmu/spte.c
+++ b/arch/x86/kvm/mmu/spte.c
@@ -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;
On Wed, Dec 22, 2021 at 09:17:53AM +0100, hch wrote:
> On Tue, Dec 21, 2021 at 10:05:03PM +0100, Richard Weinberger wrote:
> > 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..
I don't see why not so
Acked-by: Borislav Petkov <[email protected]>
Should I take the first one along with this hunk below?
> diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
> index 0c76c45fdb686..fad546df0bbac 100644
> --- a/arch/x86/kvm/mmu/spte.c
> +++ b/arch/x86/kvm/mmu/spte.c
> @@ -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;
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Boris,
----- Ursprüngliche Mail -----
> 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: remove set_fs for UML
> On Wed, Dec 22, 2021 at 09:17:53AM +0100, hch wrote:
>> On Tue, Dec 21, 2021 at 10:05:03PM +0100, Richard Weinberger wrote:
>> > 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..
>
> 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
On Wed, Dec 22, 2021 at 05:55:59PM +0100, Richard Weinberger wrote:
> Would be great!
> When I'll drop "x86/mtrr: remove the mtrr_bp_init stub" from the UML tree.
Done.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
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.
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
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(-)
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index 829df26..76d7260 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -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)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 6a190c7..2f5129b 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -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();
diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
index 0c76c45..fad546d 100644
--- a/arch/x86/kvm/mmu/spte.c
+++ b/arch/x86/kvm/mmu/spte.c
@@ -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;
On Tue, Dec 21, 2021 at 10:05:03PM +0100, Richard Weinberger wrote:
> Christoph,
>
> ----- Urspr?ngliche Mail -----
> > 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: remove set_fs for UML
>
> > 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(-)
>
> 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.