Skip to content

Commit

Permalink
Merge tag 'mips_fixes_4.19_2' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/git/mips/linux

Paul writes:
  "A few MIPS fixes for 4.19:

   - Avoid suboptimal placement of our VDSO when using the legacy mmap
     layout, which can prevent statically linked programs that were able
     to allocate large amounts of memory using the brk syscall prior to
     the introduction of our VDSO from functioning correctly.

   - Fix up CONFIG_CMDLINE handling for platforms which ought to ignore
     DT arguments but have incorrectly used them & lost other arguments
     since v3.16.

   - Fix a path in MAINTAINERS to use valid wildcards.

   - Fixup a regression from v4.17 in memset() for systems using
     CPU_DADDI_WORKAROUNDS."

* tag 'mips_fixes_4.19_2' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux:
  MIPS: memset: Fix CPU_DADDI_WORKAROUNDS `small_fixup' regression
  MAINTAINERS: MIPS/LOONGSON2 ARCHITECTURE - Use the normal wildcard style
  MIPS: Fix CONFIG_CMDLINE handling
  MIPS: VDSO: Always map near top of user memory
  • Loading branch information
Greg Kroah-Hartman committed Oct 10, 2018
2 parents 64c5e53 + 148b9ab commit 701f2eb
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 28 deletions.
3 changes: 2 additions & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -9657,7 +9657,8 @@ MIPS/LOONGSON2 ARCHITECTURE
M: Jiaxun Yang <jiaxun.yang@flygoat.com>
L: linux-mips@linux-mips.org
S: Maintained
F: arch/mips/loongson64/*{2e/2f}*
F: arch/mips/loongson64/fuloong-2e/
F: arch/mips/loongson64/lemote-2f/
F: arch/mips/include/asm/mach-loongson64/
F: drivers/*/*loongson2*
F: drivers/*/*/*loongson2*
Expand Down
10 changes: 5 additions & 5 deletions arch/mips/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <linux/atomic.h>
#include <linux/cpumask.h>
#include <linux/sizes.h>
#include <linux/threads.h>

#include <asm/cachectl.h>
Expand Down Expand Up @@ -80,11 +81,10 @@ extern unsigned int vced_count, vcei_count;

#endif

/*
* One page above the stack is used for branch delay slot "emulation".
* See dsemul.c for details.
*/
#define STACK_TOP ((TASK_SIZE & PAGE_MASK) - PAGE_SIZE)
#define VDSO_RANDOMIZE_SIZE (TASK_IS_32BIT_ADDR ? SZ_1M : SZ_256M)

extern unsigned long mips_stack_top(void);
#define STACK_TOP mips_stack_top()

/*
* This decides where the kernel will search for a free chunk of vm
Expand Down
25 changes: 25 additions & 0 deletions arch/mips/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#include <linux/nmi.h>
#include <linux/cpu.h>

#include <asm/abi.h>
#include <asm/asm.h>
#include <asm/bootinfo.h>
#include <asm/cpu.h>
#include <asm/dsemul.h>
#include <asm/dsp.h>
#include <asm/fpu.h>
#include <asm/irq.h>
#include <asm/mips-cps.h>
#include <asm/msa.h>
#include <asm/pgtable.h>
#include <asm/mipsregs.h>
Expand Down Expand Up @@ -645,6 +647,29 @@ unsigned long get_wchan(struct task_struct *task)
return pc;
}

unsigned long mips_stack_top(void)
{
unsigned long top = TASK_SIZE & PAGE_MASK;

/* One page for branch delay slot "emulation" */
top -= PAGE_SIZE;

/* Space for the VDSO, data page & GIC user page */
top -= PAGE_ALIGN(current->thread.abi->vdso->size);
top -= PAGE_SIZE;
top -= mips_gic_present() ? PAGE_SIZE : 0;

/* Space for cache colour alignment */
if (cpu_has_dc_aliases)
top -= shm_align_mask + 1;

/* Space to randomize the VDSO base */
if (current->flags & PF_RANDOMIZE)
top -= VDSO_RANDOMIZE_SIZE;

return top;
}

/*
* Don't forget that the stack pointer must be aligned on a 8 bytes
* boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
Expand Down
48 changes: 28 additions & 20 deletions arch/mips/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,34 @@ static void __init arch_mem_init(char **cmdline_p)
struct memblock_region *reg;
extern void plat_mem_setup(void);

/*
* Initialize boot_command_line to an innocuous but non-empty string in
* order to prevent early_init_dt_scan_chosen() from copying
* CONFIG_CMDLINE into it without our knowledge. We handle
* CONFIG_CMDLINE ourselves below & don't want to duplicate its
* content because repeating arguments can be problematic.
*/
strlcpy(boot_command_line, " ", COMMAND_LINE_SIZE);

/* call board setup routine */
plat_mem_setup();

/*
* Make sure all kernel memory is in the maps. The "UP" and
* "DOWN" are opposite for initdata since if it crosses over
* into another memory section you don't want that to be
* freed when the initdata is freed.
*/
arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
BOOT_MEM_RAM);
arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
BOOT_MEM_INIT_RAM);

pr_info("Determined physical RAM map:\n");
print_memory_map();

#if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
#else
Expand Down Expand Up @@ -873,26 +901,6 @@ static void __init arch_mem_init(char **cmdline_p)
}
#endif
#endif

/* call board setup routine */
plat_mem_setup();

/*
* Make sure all kernel memory is in the maps. The "UP" and
* "DOWN" are opposite for initdata since if it crosses over
* into another memory section you don't want that to be
* freed when the initdata is freed.
*/
arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
BOOT_MEM_RAM);
arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
BOOT_MEM_INIT_RAM);

pr_info("Determined physical RAM map:\n");
print_memory_map();

strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);

*cmdline_p = command_line;
Expand Down
18 changes: 17 additions & 1 deletion arch/mips/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/random.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/timekeeper_internal.h>
Expand Down Expand Up @@ -97,6 +98,21 @@ void update_vsyscall_tz(void)
}
}

static unsigned long vdso_base(void)
{
unsigned long base;

/* Skip the delay slot emulation page */
base = STACK_TOP + PAGE_SIZE;

if (current->flags & PF_RANDOMIZE) {
base += get_random_int() & (VDSO_RANDOMIZE_SIZE - 1);
base = PAGE_ALIGN(base);
}

return base;
}

int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
{
struct mips_vdso_image *image = current->thread.abi->vdso;
Expand Down Expand Up @@ -137,7 +153,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
if (cpu_has_dc_aliases)
size += shm_align_mask + 1;

base = get_unmapped_area(NULL, 0, size, 0, 0);
base = get_unmapped_area(NULL, vdso_base(), size, 0, 0);
if (IS_ERR_VALUE(base)) {
ret = base;
goto out;
Expand Down
4 changes: 3 additions & 1 deletion arch/mips/lib/memset.S
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@
* unset_bytes = end_addr - current_addr + 1
* a2 = t1 - a0 + 1
*/
.set reorder
PTR_SUBU a2, t1, a0
PTR_ADDIU a2, 1
jr ra
PTR_ADDIU a2, 1
.set noreorder

.endm

Expand Down

0 comments on commit 701f2eb

Please sign in to comment.