x86: MPX fixes for tip
Subsystems (6)
cover x86: MPX fixes for tip
This fixes up an issue turned up by smatch as well as some build issues on non-x86 architectures with the new hooks we added for MPX.
PATCH 3/3 make arch_unmap()/etc... available to all architectures.
From: Dave Hansen <[email protected]>
The x86 MPX patch set calls arch_unmap() and arch_bprm_mm_init() from fs/exec.c, so we need at least a stub for them in all architectures. They are only called under an #ifdef for CONFIG_MMU=y, so we can at least restict this to architectures with MMU support.
blackfin/c6x have no MMU support, so do not call arch_unmap(). They also do not include mm_hooks.h or mmu_context.h at all and do not need to be touched.
s390, um and unicore32 do not use asm-generic/mm_hooks.h, so got their own arch_unmap() versions. (I also moved um's arch_dup_mmap() to be closer to the other mm_hooks.h functions).
xtensa only includs mm_hooks when MMU=y, which should be fine since arch_unmap() is called only from MMU=y code.
For the rest, we use the stub copies of these functions in asm-generic/mm_hook.h.
I cross compiled defconfigs for cris (to check NOMMU) and s390 to make sure that this works. I also checked a 64-bit build of UML and all my normal x86 builds including PARAVIRT on and off.
---
b/arch/s390/include/asm/mmu_context.h | 11 +++++++++++ b/arch/um/include/asm/mmu_context.h | 24 +++++++++++++++++++----- b/arch/unicore32/include/asm/mmu_context.h | 11 +++++++++++ b/include/asm-generic/mm_hooks.h | 17 ++++++++++++++--- b/include/asm-generic/mmu_context.h | 6 ------ 5 files changed, 55 insertions(+), 14 deletions(-)
arch/s390/include/asm/mmu_context.h renamed from arch/s390/include/asm/mmu_context.h~mm_hooks +11 -0
@@ -120,4 +120,15 @@ static inline void arch_exit_mmap(struct { } +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} + +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +#endif /* __S390_MMU_CONTEXT_H */
arch/um/include/asm/mmu_context.h renamed from arch/um/include/asm/mmu_context.h~mm_hooks +19 -5
@@ -10,7 +10,26 @@#include <asm/mmu.h> extern void uml_setup_stubs (struct mm_struct *mm); +/* +* Needed since we do not use the asm-generic/mm_hooks.h: +*/ +static inline void arch_dup_mmap (struct mm_struct *oldmm,struct mm_struct *mm) +{ +uml_setup_stubs (mm); +}extern void arch_exit_mmap (struct mm_struct *mm); +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +/* +* end asm-generic/mm_hooks.h functions +*/ #define deactivate_mm (tsk,mm) do { } while (0)
@@ -41,11 +60,6 @@ static inline void switch_mm(struct mm_s } } -static inline void arch_dup_mmap (struct mm_struct *oldmm,struct mm_struct *mm) -{ -uml_setup_stubs (mm); -} -static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {
arch/unicore32/include/asm/mmu_context.h renamed from arch/unicore32/include/asm/mmu_context.h~mm_hooks +11 -0
@@ -86,4 +86,15 @@ static inline void arch_dup_mmap(struct { } +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} + +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +#endif
include/asm-generic/mm_hooks.h renamed from include/asm-generic/mm_hooks.h~mm_hooks +14 -3
@@ -1,7 +1,7 @@/* -* Define generic no-op hooks for arch_dup_mmap and arch_exit_mmap, to -* be included in asm-FOO/mmu_context.h for any arch FOO which doesn't -* need to hook these. +* Define generic no-op hooks for arch_dup_mmap, arch_exit_mmap +* and arch_unmap to be included in asm-FOO/mmu_context.h for any +* arch FOO which doesn't need to hook these. */ #ifndef _ASM_GENERIC_MM_HOOKS_H#define _ASM_GENERIC_MM_HOOKS_H
@@ -15,4 +15,15 @@ static inline void arch_exit_mmap(struct { } +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} + +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +#endif /* _ASM_GENERIC_MM_HOOKS_H */
include/asm-generic/mmu_context.h renamed from include/asm-generic/mmu_context.h~mm_hooks +0 -6
@@ -47,10 +47,4 @@ static inline void arch_bprm_mm_init(str { } -static inline void arch_unmap (struct mm_struct *mm, -struct vm_area_struct *vma, -unsigned long start,unsigned long end) -{ -} -#endif /* __ASM_GENERIC_MMU_CONTEXT_H */
_
PATCH 1/3 x86 mpx: change return type of get_reg_offset()
In reply to Dave HansenFrom: Dave Hansen <[email protected]>
get_reg_offset() used to return the register contents themselves instead of the register offset. When it did that, it was an unsigned long. I changed it to return an integer _offset_ instead of the register. But, I neglected to change the return type of the function or the variables in which we store the result of the call.
This fixes up the code to clear up the warnings from the smatch bot:
New smatch warnings:arch/x86/mm/mpx.c:178 mpx_get_addr_ref() warn: unsigned 'addr_offset' is never less than zero. arch/x86/mm/mpx.c:184 mpx_get_addr_ref() warn: unsigned 'base_offset' is never less than zero. arch/x86/mm/mpx.c:188 mpx_get_addr_ref() warn: unsigned 'indx_offset' is never less than zero. arch/x86/mm/mpx.c:196 mpx_get_addr_ref() warn: unsigned 'addr_offset' is never less than zero.
---
b/arch/x86/mm/mpx.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/x86/mm/mpx.c renamed from arch/x86/mm/mpx.c~mpx_get_addr_ref-as-int +4 -5
@@ -102,8 +102,8 @@ enum reg_type { REG_TYPE_BASE, }; -static unsigned long get_reg_offset (struct insn *insn,struct pt_regs *regs, -enum reg_type type) +static int get_reg_offset (struct insn *insn,struct pt_regs *regs, +enum reg_type type) {int regno =0 ;
@@ -174,9 +174,8 @@ static unsigned long get_reg_offset(stru*/ static void __user *mpx_get_addr_ref (struct insn *insn,struct pt_regs *regs) { -unsigned long addr, addr_offset; -unsigned long base, base_offset; -unsigned long indx, indx_offset; +unsigned long addr, base, indx; +int addr_offset, base_offset, indx_offset;insn_byte_t sib;insn_get_modrm (insn);
_
PATCH 2/3 x86: cleanly separate use of asm-generic/mm_hooks.h
In reply to Dave HansenFrom: Dave Hansen <[email protected]>
asm-generic/mm_hooks.h provides some generic fillers for the 90% of architectures that do not need to hook some mmap-mainipulation functions. A comment inside says:
Quoted 3 lines
Define generic no-op hooks for
arch_dup_mmapandarch_exit_mmap, to be included inasm-FOO/mmu_context.hfor any arch FOO which doesn't need to hook these.
So, does x86 need to hook these? It depends on CONFIG_PARAVIRT. We *conditionally* include this generic header if we have CONFIG_PARAVIRT=n. That's madness.
With this patch, x86 stops using asm-generic/mmu_hooks.h entirely. We use our own copies of the functions. The paravirt code provides some stubs if it is disabled, and we always call those stubs in our x86-private versions of arch_exit_mmap() and arch_dup_mmap().
---
b/arch/x86/include/asm/mmu_context.h | 13 +++++++++++-- b/arch/x86/include/asm/paravirt.h | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/include/asm/mmu_context.h renamed from arch/x86/include/asm/mmu_context.h~dmess-x86-mmu_hooks +11 -2
@@ -12,8 +12,6 @@#include <asm/paravirt.h> #include <asm/mpx.h> #ifndef CONFIG_PARAVIRT -#include <asm-generic/mm_hooks.h> -static inline void paravirt_activate_mm (struct mm_struct *prev,struct mm_struct *next) {
@@ -103,6 +101,17 @@ do { \ } while (0)#endif +static inline void arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ +paravirt_arch_dup_mmap (oldmm, mm); +} + +static inline void arch_exit_mmap (struct mm_struct *mm) +{ +paravirt_arch_exit_mmap (mm); +} +static inline void arch_bprm_mm_init (struct mm_struct *mm,struct vm_area_struct *vma) {
arch/x86/include/asm/paravirt.h renamed from arch/x86/include/asm/paravirt.h~dmess-x86-mmu_hooks +13 -3
@@ -330,13 +330,13 @@ static inline void paravirt_activate_mm(PVOP_VCALL2 (pv_mmu_ops.activate_mm, prev, next); } -static inline void arch_dup_mmap (struct mm_struct *oldmm, -struct mm_struct *mm) +static inline void paravirt_arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) {PVOP_VCALL2 (pv_mmu_ops.dup_mmap, oldmm, mm); } -static inline void arch_exit_mmap (struct mm_struct *mm) +static inline void paravirt_arch_exit_mmap (struct mm_struct *mm) {PVOP_VCALL1 (pv_mmu_ops.exit_mmap, mm); }
@@ -986,5 +986,15 @@ extern void default_banner(void);#endif /* __ASSEMBLY__ */ #else /* CONFIG_PARAVIRT */ # define default_banner x86_init_noop +#ifndef __ASSEMBLY__ +static inline void paravirt_arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ +} + +static inline void paravirt_arch_exit_mmap (struct mm_struct *mm) +{ +} +#endif /* __ASSEMBLY__ */ #endif /* !CONFIG_PARAVIRT */ #endif /* _ASM_X86_PARAVIRT_H */
_
tip-bot for Dave Hansen
merge bot[tip:x86/mpx] x86 mpx: Change return type of get_reg_offset()
In reply to Dave Hansenx86 mpx: Change return type of get_reg_offset()
Commit-ID: 68c009c4137927fd4ffd3e653bb5209d752c1d42 Gitweb: http://git.kernel.org/tip/68c009c4137927fd4ffd3e653bb5209d752c1d42 Author: Dave Hansen <[email protected]> AuthorDate: Tue, 18 Nov 2014 10:23:43 -0800 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 19 Nov 2014 11:54:12 +0100
x86 mpx: Change return type of get_reg_offset()
get_reg_offset() used to return the register contents themselves instead of the register offset. When it did that, it was an unsigned long. I changed it to return an integer _offset_ instead of the register. But, I neglected to change the return type of the function or the variables in which we store the result of the call.
This fixes up the code to clear up the warnings from the smatch bot:
New smatch warnings:arch/x86/mm/mpx.c:178 mpx_get_addr_ref() warn: unsigned 'addr_offset' is never less than zero. arch/x86/mm/mpx.c:184 mpx_get_addr_ref() warn: unsigned 'base_offset' is never less than zero. arch/x86/mm/mpx.c:188 mpx_get_addr_ref() warn: unsigned 'indx_offset' is never less than zero. arch/x86/mm/mpx.c:196 mpx_get_addr_ref() warn: unsigned 'addr_offset' is never less than zero.
--- arch/x86/mm/mpx.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/x86/mm/mpx.c +4 -5
@@ -102,8 +102,8 @@ enum reg_type { REG_TYPE_BASE, }; -static unsigned long get_reg_offset (struct insn *insn,struct pt_regs *regs, -enum reg_type type) +static int get_reg_offset (struct insn *insn,struct pt_regs *regs, +enum reg_type type) {int regno =0 ;
@@ -174,9 +174,8 @@ static unsigned long get_reg_offset(struct insn *insn, struct pt_regs *regs,*/ static void __user *mpx_get_addr_ref (struct insn *insn,struct pt_regs *regs) { -unsigned long addr, addr_offset; -unsigned long base, base_offset; -unsigned long indx, indx_offset; +unsigned long addr, base, indx; +int addr_offset, base_offset, indx_offset;insn_byte_t sib;insn_get_modrm (insn);
tip-bot for Dave Hansen
merge bot[tip:x86/mpx] x86: Cleanly separate use of asm-generic/mm_hooks.h
In reply to Dave Hansenx86: Cleanly separate use of asm-generic/mm_hooks.h
Commit-ID: a1ea1c032b8f8c23d86ef4db6d061527e9417f19 Gitweb: http://git.kernel.org/tip/a1ea1c032b8f8c23d86ef4db6d061527e9417f19 Author: Dave Hansen <[email protected]> AuthorDate: Tue, 18 Nov 2014 10:23:49 -0800 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 19 Nov 2014 11:54:13 +0100
x86: Cleanly separate use of asm-generic/mm_hooks.h
asm-generic/mm_hooks.h provides some generic fillers for the 90% of architectures that do not need to hook some mmap-manipulation functions. A comment inside says:
Quoted 3 lines
Define generic no-op hooks for
arch_dup_mmapandarch_exit_mmap, to be included inasm-FOO/mmu_context.hfor any arch FOO which doesn't need to hook these.
So, does x86 need to hook these? It depends on CONFIG_PARAVIRT. We *conditionally* include this generic header if we have CONFIG_PARAVIRT=n. That's madness.
With this patch, x86 stops using asm-generic/mmu_hooks.h entirely. We use our own copies of the functions. The paravirt code provides some stubs if it is disabled, and we always call those stubs in our x86-private versions of arch_exit_mmap() and arch_dup_mmap().
--- arch/x86/include/asm/mmu_context.h | 13 +++++++++++-- arch/x86/include/asm/paravirt.h | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/include/asm/mmu_context.h +11 -2
@@ -12,8 +12,6 @@#include <asm/paravirt.h> #include <asm/mpx.h> #ifndef CONFIG_PARAVIRT -#include <asm-generic/mm_hooks.h> -static inline void paravirt_activate_mm (struct mm_struct *prev,struct mm_struct *next) {
@@ -103,6 +101,17 @@ do { \ } while (0)#endif +static inline void arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ +paravirt_arch_dup_mmap (oldmm, mm); +} + +static inline void arch_exit_mmap (struct mm_struct *mm) +{ +paravirt_arch_exit_mmap (mm); +} +static inline void arch_bprm_mm_init (struct mm_struct *mm,struct vm_area_struct *vma) {
arch/x86/include/asm/paravirt.h +13 -3
@@ -330,13 +330,13 @@ static inline void paravirt_activate_mm(struct mm_struct *prev,PVOP_VCALL2 (pv_mmu_ops.activate_mm, prev, next); } -static inline void arch_dup_mmap (struct mm_struct *oldmm, -struct mm_struct *mm) +static inline void paravirt_arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) {PVOP_VCALL2 (pv_mmu_ops.dup_mmap, oldmm, mm); } -static inline void arch_exit_mmap (struct mm_struct *mm) +static inline void paravirt_arch_exit_mmap (struct mm_struct *mm) {PVOP_VCALL1 (pv_mmu_ops.exit_mmap, mm); }
@@ -986,5 +986,15 @@ extern void default_banner(void);#endif /* __ASSEMBLY__ */ #else /* CONFIG_PARAVIRT */ # define default_banner x86_init_noop +#ifndef __ASSEMBLY__ +static inline void paravirt_arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ +} + +static inline void paravirt_arch_exit_mmap (struct mm_struct *mm) +{ +} +#endif /* __ASSEMBLY__ */ #endif /* !CONFIG_PARAVIRT */ #endif /* _ASM_X86_PARAVIRT_H */
tip-bot for Dave Hansen
merge bot[tip:x86/mpx] mm: Make arch_unmap()/bprm_mm_init() available to all architectures
In reply to Dave Hansenmm: Make arch_unmap()/bprm_mm_init() available to all architectures
Commit-ID: 62e88b1c00de9cb30d937841ed5debed871070b8 Gitweb: http://git.kernel.org/tip/62e88b1c00de9cb30d937841ed5debed871070b8 Author: Dave Hansen <[email protected]> AuthorDate: Tue, 18 Nov 2014 10:23:50 -0800 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 19 Nov 2014 11:54:13 +0100
mm: Make arch_unmap()/bprm_mm_init() available to all architectures
The x86 MPX patch set calls arch_unmap() and arch_bprm_mm_init() from fs/exec.c, so we need at least a stub for them in all architectures. They are only called under an #ifdef for CONFIG_MMU=y, so we can at least restict this to architectures with MMU support.
blackfin/c6x have no MMU support, so do not call arch_unmap(). They also do not include mm_hooks.h or mmu_context.h at all and do not need to be touched.
s390, um and unicore32 do not use asm-generic/mm_hooks.h, so got their own arch_unmap() versions. (I also moved um's arch_dup_mmap() to be closer to the other mm_hooks.h functions).
xtensa only includes mm_hooks when MMU=y, which should be fine since arch_unmap() is called only from MMU=y code.
For the rest, we use the stub copies of these functions in asm-generic/mm_hook.h.
I cross compiled defconfigs for cris (to check NOMMU) and s390 to make sure that this works. I also checked a 64-bit build of UML and all my normal x86 builds including PARAVIRT on and off.
--- arch/s390/include/asm/mmu_context.h | 11 +++++++++++ arch/um/include/asm/mmu_context.h | 24 +++++++++++++++++++----- arch/unicore32/include/asm/mmu_context.h | 11 +++++++++++ include/asm-generic/mm_hooks.h | 17 ++++++++++++++--- include/asm-generic/mmu_context.h | 6 ------ 5 files changed, 55 insertions(+), 14 deletions(-)
arch/s390/include/asm/mmu_context.h +11 -0
@@ -120,4 +120,15 @@ static inline void arch_exit_mmap(struct mm_struct *mm) { } +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} + +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +#endif /* __S390_MMU_CONTEXT_H */
arch/um/include/asm/mmu_context.h +19 -5
@@ -10,7 +10,26 @@#include <asm/mmu.h> extern void uml_setup_stubs (struct mm_struct *mm); +/* +* Needed since we do not use the asm-generic/mm_hooks.h: +*/ +static inline void arch_dup_mmap (struct mm_struct *oldmm,struct mm_struct *mm) +{ +uml_setup_stubs (mm); +}extern void arch_exit_mmap (struct mm_struct *mm); +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +/* +* end asm-generic/mm_hooks.h functions +*/ #define deactivate_mm (tsk,mm) do { } while (0)
@@ -41,11 +60,6 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, } } -static inline void arch_dup_mmap (struct mm_struct *oldmm,struct mm_struct *mm) -{ -uml_setup_stubs (mm); -} -static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {
arch/unicore32/include/asm/mmu_context.h +11 -0
@@ -86,4 +86,15 @@ static inline void arch_dup_mmap(struct mm_struct *oldmm, { } +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} + +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +#endif
include/asm-generic/mm_hooks.h +14 -3
@@ -1,7 +1,7 @@/* -* Define generic no-op hooks for arch_dup_mmap and arch_exit_mmap, to -* be included in asm-FOO/mmu_context.h for any arch FOO which doesn't -* need to hook these. +* Define generic no-op hooks for arch_dup_mmap, arch_exit_mmap +* and arch_unmap to be included in asm-FOO/mmu_context.h for any +* arch FOO which doesn't need to hook these. */ #ifndef _ASM_GENERIC_MM_HOOKS_H#define _ASM_GENERIC_MM_HOOKS_H
@@ -15,4 +15,15 @@ static inline void arch_exit_mmap(struct mm_struct *mm) { } +static inline void arch_unmap (struct mm_struct *mm, +struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +} + +static inline void arch_bprm_mm_init (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +} +#endif /* _ASM_GENERIC_MM_HOOKS_H */
include/asm-generic/mmu_context.h +0 -6
@@ -47,10 +47,4 @@ static inline void arch_bprm_mm_init(struct mm_struct *mm, { } -static inline void arch_unmap (struct mm_struct *mm, -struct vm_area_struct *vma, -unsigned long start,unsigned long end) -{ -} -#endif /* __ASM_GENERIC_MMU_CONTEXT_H */