2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998, 1999, 2000 by Ralf Baechle
|
|
|
|
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
|
2013-03-25 22:40:49 +04:00
|
|
|
* Copyright (C) 2007 by Maciej W. Rozycki
|
|
|
|
* Copyright (C) 2011, 2012 MIPS Technologies, Inc.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
#include <asm/asm.h>
|
2005-09-10 00:32:31 +04:00
|
|
|
#include <asm/asm-offsets.h>
|
2016-11-07 14:14:15 +03:00
|
|
|
#include <asm/export.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/regdef.h>
|
|
|
|
|
2006-12-17 18:07:40 +03:00
|
|
|
#if LONGSIZE == 4
|
|
|
|
#define LONG_S_L swl
|
|
|
|
#define LONG_S_R swr
|
|
|
|
#else
|
|
|
|
#define LONG_S_L sdl
|
|
|
|
#define LONG_S_R sdr
|
|
|
|
#endif
|
|
|
|
|
2013-03-25 22:40:49 +04:00
|
|
|
#ifdef CONFIG_CPU_MICROMIPS
|
|
|
|
#define STORSIZE (LONGSIZE * 2)
|
|
|
|
#define STORMASK (STORSIZE - 1)
|
|
|
|
#define FILL64RG t8
|
|
|
|
#define FILLPTRG t7
|
|
|
|
#undef LONG_S
|
|
|
|
#define LONG_S LONG_SP
|
|
|
|
#else
|
|
|
|
#define STORSIZE LONGSIZE
|
|
|
|
#define STORMASK LONGMASK
|
|
|
|
#define FILL64RG a1
|
|
|
|
#define FILLPTRG t0
|
|
|
|
#endif
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
#define LEGACY_MODE 1
|
|
|
|
#define EVA_MODE 2
|
|
|
|
|
2014-01-03 14:11:45 +04:00
|
|
|
/*
|
|
|
|
* No need to protect it with EVA #ifdefery. The generated block of code
|
|
|
|
* will never be assembled if EVA is not enabled.
|
|
|
|
*/
|
|
|
|
#define __EVAFY(insn, reg, addr) __BUILD_EVA_INSN(insn##e, reg, addr)
|
|
|
|
#define ___BUILD_EVA_INSN(insn, reg, addr) __EVAFY(insn, reg, addr)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#define EX(insn,reg,addr,handler) \
|
2014-01-03 14:11:45 +04:00
|
|
|
.if \mode == LEGACY_MODE; \
|
|
|
|
9: insn reg, addr; \
|
|
|
|
.else; \
|
|
|
|
9: ___BUILD_EVA_INSN(insn, reg, addr); \
|
|
|
|
.endif; \
|
2013-01-22 15:59:30 +04:00
|
|
|
.section __ex_table,"a"; \
|
|
|
|
PTR 9b, handler; \
|
2005-04-17 02:20:36 +04:00
|
|
|
.previous
|
|
|
|
|
2014-01-03 14:11:45 +04:00
|
|
|
.macro f_fill64 dst, offset, val, fixup, mode
|
2013-03-25 22:40:49 +04:00
|
|
|
EX(LONG_S, \val, (\offset + 0 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 1 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 2 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 3 * STORSIZE)(\dst), \fixup)
|
|
|
|
#if ((defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4)) || !defined(CONFIG_CPU_MICROMIPS))
|
|
|
|
EX(LONG_S, \val, (\offset + 4 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 5 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 6 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 7 * STORSIZE)(\dst), \fixup)
|
|
|
|
#endif
|
|
|
|
#if (!defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4))
|
|
|
|
EX(LONG_S, \val, (\offset + 8 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 9 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 10 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 11 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 12 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 13 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 14 * STORSIZE)(\dst), \fixup)
|
|
|
|
EX(LONG_S, \val, (\offset + 15 * STORSIZE)(\dst), \fixup)
|
2006-12-17 18:07:40 +03:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.align 5
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
/*
|
|
|
|
* Macro to generate the __bzero{,_user} symbol
|
|
|
|
* Arguments:
|
|
|
|
* mode: LEGACY_MODE or EVA_MODE
|
|
|
|
*/
|
|
|
|
.macro __BUILD_BZERO mode
|
|
|
|
/* Initialize __memset if this is the first time we call this macro */
|
|
|
|
.ifnotdef __memset
|
|
|
|
.set __memset, 1
|
|
|
|
.hidden __memset /* Make sure it does not leak */
|
|
|
|
.endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-03-25 22:40:49 +04:00
|
|
|
sltiu t0, a2, STORSIZE /* very small region? */
|
2018-10-02 14:50:16 +03:00
|
|
|
.set noreorder
|
2014-01-03 13:23:16 +04:00
|
|
|
bnez t0, .Lsmall_memset\@
|
2018-04-17 18:40:02 +03:00
|
|
|
andi t0, a0, STORMASK /* aligned? */
|
2018-10-02 14:50:16 +03:00
|
|
|
.set reorder
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-03-25 22:40:49 +04:00
|
|
|
#ifdef CONFIG_CPU_MICROMIPS
|
|
|
|
move t8, a1 /* used by 'swp' instruction */
|
|
|
|
move t9, a1
|
|
|
|
#endif
|
2018-10-02 14:50:16 +03:00
|
|
|
.set noreorder
|
2007-10-23 15:43:25 +04:00
|
|
|
#ifndef CONFIG_CPU_DADDI_WORKAROUNDS
|
2005-04-17 02:20:36 +04:00
|
|
|
beqz t0, 1f
|
2018-04-17 18:40:02 +03:00
|
|
|
PTR_SUBU t0, STORSIZE /* alignment in bytes */
|
2007-10-23 15:43:25 +04:00
|
|
|
#else
|
|
|
|
.set noat
|
2013-03-25 22:40:49 +04:00
|
|
|
li AT, STORSIZE
|
2007-10-23 15:43:25 +04:00
|
|
|
beqz t0, 1f
|
2018-04-17 18:40:02 +03:00
|
|
|
PTR_SUBU t0, AT /* alignment in bytes */
|
2007-10-23 15:43:25 +04:00
|
|
|
.set at
|
|
|
|
#endif
|
2018-10-02 14:50:16 +03:00
|
|
|
.set reorder
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-01-22 13:58:50 +03:00
|
|
|
#ifndef CONFIG_CPU_NO_LOAD_STORE_LR
|
2007-11-25 13:47:56 +03:00
|
|
|
R10KCBARRIER(0(ra))
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef __MIPSEB__
|
2014-01-03 13:23:16 +04:00
|
|
|
EX(LONG_S_L, a1, (a0), .Lfirst_fixup\@) /* make word/dword aligned */
|
2014-11-19 11:58:10 +03:00
|
|
|
#else
|
2014-01-03 13:23:16 +04:00
|
|
|
EX(LONG_S_R, a1, (a0), .Lfirst_fixup\@) /* make word/dword aligned */
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
PTR_SUBU a0, t0 /* long align ptr */
|
|
|
|
PTR_ADDU a2, t0 /* correct size */
|
|
|
|
|
2020-01-22 13:58:50 +03:00
|
|
|
#else /* CONFIG_CPU_NO_LOAD_STORE_LR */
|
2014-11-18 12:04:34 +03:00
|
|
|
#define STORE_BYTE(N) \
|
|
|
|
EX(sb, a1, N(a0), .Lbyte_fixup\@); \
|
2018-10-02 14:50:16 +03:00
|
|
|
.set noreorder; \
|
2014-11-18 12:04:34 +03:00
|
|
|
beqz t0, 0f; \
|
2018-10-02 14:50:16 +03:00
|
|
|
PTR_ADDU t0, 1; \
|
|
|
|
.set reorder;
|
2014-11-18 12:04:34 +03:00
|
|
|
|
|
|
|
PTR_ADDU a2, t0 /* correct size */
|
|
|
|
PTR_ADDU t0, 1
|
|
|
|
STORE_BYTE(0)
|
|
|
|
STORE_BYTE(1)
|
|
|
|
#if LONGSIZE == 4
|
|
|
|
EX(sb, a1, 2(a0), .Lbyte_fixup\@)
|
|
|
|
#else
|
|
|
|
STORE_BYTE(2)
|
|
|
|
STORE_BYTE(3)
|
|
|
|
STORE_BYTE(4)
|
|
|
|
STORE_BYTE(5)
|
|
|
|
EX(sb, a1, 6(a0), .Lbyte_fixup\@)
|
|
|
|
#endif
|
|
|
|
0:
|
|
|
|
ori a0, STORMASK
|
|
|
|
xori a0, STORMASK
|
|
|
|
PTR_ADDIU a0, STORSIZE
|
2020-01-22 13:58:50 +03:00
|
|
|
#endif /* CONFIG_CPU_NO_LOAD_STORE_LR */
|
2005-04-17 02:20:36 +04:00
|
|
|
1: ori t1, a2, 0x3f /* # of full blocks */
|
|
|
|
xori t1, 0x3f
|
2018-10-02 14:50:16 +03:00
|
|
|
andi t0, a2, 0x40-STORSIZE
|
2014-01-03 13:23:16 +04:00
|
|
|
beqz t1, .Lmemset_partial\@ /* no block to fill */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
PTR_ADDU t1, a0 /* end address */
|
|
|
|
1: PTR_ADDIU a0, 64
|
2007-11-25 13:47:56 +03:00
|
|
|
R10KCBARRIER(0(ra))
|
2014-01-03 14:11:45 +04:00
|
|
|
f_fill64 a0, -64, FILL64RG, .Lfwd_fixup\@, \mode
|
2005-04-17 02:20:36 +04:00
|
|
|
bne t1, a0, 1b
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.Lmemset_partial\@:
|
2007-11-25 13:47:56 +03:00
|
|
|
R10KCBARRIER(0(ra))
|
2005-04-17 02:20:36 +04:00
|
|
|
PTR_LA t1, 2f /* where to start */
|
2013-03-25 22:40:49 +04:00
|
|
|
#ifdef CONFIG_CPU_MICROMIPS
|
|
|
|
LONG_SRL t7, t0, 1
|
|
|
|
#endif
|
2006-12-17 18:07:40 +03:00
|
|
|
#if LONGSIZE == 4
|
2013-03-25 22:40:49 +04:00
|
|
|
PTR_SUBU t1, FILLPTRG
|
2006-12-17 18:07:40 +03:00
|
|
|
#else
|
|
|
|
.set noat
|
2013-03-25 22:40:49 +04:00
|
|
|
LONG_SRL AT, FILLPTRG, 1
|
2006-12-17 18:07:40 +03:00
|
|
|
PTR_SUBU t1, AT
|
2007-10-23 15:43:25 +04:00
|
|
|
.set at
|
2006-12-17 18:07:40 +03:00
|
|
|
#endif
|
2018-10-02 14:50:16 +03:00
|
|
|
PTR_ADDU a0, t0 /* dest ptr */
|
2005-04-17 02:20:36 +04:00
|
|
|
jr t1
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
/* ... but first do longs ... */
|
2014-01-03 14:11:45 +04:00
|
|
|
f_fill64 a0, -64, FILL64RG, .Lpartial_fixup\@, \mode
|
2018-10-02 14:50:16 +03:00
|
|
|
2: andi a2, STORMASK /* At most one long to go */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-10-02 14:50:16 +03:00
|
|
|
.set noreorder
|
2005-04-17 02:20:36 +04:00
|
|
|
beqz a2, 1f
|
2020-01-22 13:58:50 +03:00
|
|
|
#ifndef CONFIG_CPU_NO_LOAD_STORE_LR
|
2018-04-17 18:40:02 +03:00
|
|
|
PTR_ADDU a0, a2 /* What's left */
|
2018-10-02 14:50:16 +03:00
|
|
|
.set reorder
|
2007-11-25 13:47:56 +03:00
|
|
|
R10KCBARRIER(0(ra))
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef __MIPSEB__
|
2014-01-03 13:23:16 +04:00
|
|
|
EX(LONG_S_R, a1, -1(a0), .Llast_fixup\@)
|
2014-11-19 11:58:10 +03:00
|
|
|
#else
|
2014-01-03 13:23:16 +04:00
|
|
|
EX(LONG_S_L, a1, -1(a0), .Llast_fixup\@)
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
2020-01-22 13:58:50 +03:00
|
|
|
#else /* CONFIG_CPU_NO_LOAD_STORE_LR */
|
2018-04-17 18:40:02 +03:00
|
|
|
PTR_SUBU t0, $0, a2
|
2018-10-02 14:50:16 +03:00
|
|
|
.set reorder
|
MIPS: memset.S: Fix byte_fixup for MIPSr6
The __clear_user function is defined to return the number of bytes that
could not be cleared. From the underlying memset / bzero implementation
this means setting register a2 to that number on return. Currently if a
page fault is triggered within the MIPSr6 version of setting of initial
unaligned bytes, the value loaded into a2 on return is meaningless.
During the MIPSr6 version of the initial unaligned bytes block, register
a2 contains the number of bytes to be set beyond the initial unaligned
bytes. The t0 register is initally set to the number of unaligned bytes
- STORSIZE, effectively a negative version of the number of unaligned
bytes. This is then incremented before each byte is saved.
The label .Lbyte_fixup\@ is jumped to on page fault. Currently the value
in a2 is incorrectly replaced by 0 - t0 + 1, effectively the number of
unaligned bytes remaining. This leads to the failures being reported by
the following test code:
static int __init test_clear_user(void)
{
int j, k;
pr_info("\n\n\nTesting clear_user\n");
for (j = 0; j < 512; j++) {
if ((k = clear_user(NULL+3, j)) != j) {
pr_err("clear_user (NULL %d) returned %d\n", j, k);
}
}
return 0;
}
late_initcall(test_clear_user);
Which reports:
[ 3.965439] Testing clear_user
[ 3.973169] clear_user (NULL 8) returned 6
[ 3.976782] clear_user (NULL 9) returned 6
[ 3.980390] clear_user (NULL 10) returned 6
[ 3.984052] clear_user (NULL 11) returned 6
[ 3.987524] clear_user (NULL 12) returned 6
Fix this by subtracting t0 from a2 (rather than $0), effectivey giving:
unset_bytes = (#bytes - (#unaligned bytes)) - (-#unaligned bytes remaining + 1) + 1
a2 = a2 - t0 + 1
This fixes the value returned from __clear user when the number of bytes
to set is > LONGSIZE and the address is invalid and unaligned.
Unfortunately, this breaks the fixup handling for unaligned bytes after
the final long, where register a2 still contains the number of bytes
remaining to be set and the t0 register is to 0 - the number of
unaligned bytes remaining.
Because t0 is now is now subtracted from a2 rather than 0, the number of
bytes unset is reported incorrectly:
static int __init test_clear_user(void)
{
char *test;
int j, k;
pr_info("\n\n\nTesting clear_user\n");
test = vmalloc(PAGE_SIZE);
for (j = 256; j < 512; j++) {
if ((k = clear_user(test + PAGE_SIZE - 254, j)) != j - 254) {
pr_err("clear_user (%px %d) returned %d\n",
test + PAGE_SIZE - 254, j, k);
}
}
return 0;
}
late_initcall(test_clear_user);
[ 3.976775] clear_user (c00000000000df02 256) returned 4
[ 3.981957] clear_user (c00000000000df02 257) returned 6
[ 3.986425] clear_user (c00000000000df02 258) returned 8
[ 3.990850] clear_user (c00000000000df02 259) returned 10
[ 3.995332] clear_user (c00000000000df02 260) returned 12
[ 3.999815] clear_user (c00000000000df02 261) returned 14
Fix this by ensuring that a2 is set to 0 during the set of final
unaligned bytes.
Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Fixes: 8c56208aff77 ("MIPS: lib: memset: Add MIPS R6 support")
Patchwork: https://patchwork.linux-mips.org/patch/19338/
Cc: James Hogan <jhogan@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org # v4.0+
2018-05-23 16:39:58 +03:00
|
|
|
move a2, zero /* No remaining longs */
|
2014-11-18 12:04:34 +03:00
|
|
|
PTR_ADDIU t0, 1
|
|
|
|
STORE_BYTE(0)
|
|
|
|
STORE_BYTE(1)
|
|
|
|
#if LONGSIZE == 4
|
|
|
|
EX(sb, a1, 2(a0), .Lbyte_fixup\@)
|
|
|
|
#else
|
|
|
|
STORE_BYTE(2)
|
|
|
|
STORE_BYTE(3)
|
|
|
|
STORE_BYTE(4)
|
|
|
|
STORE_BYTE(5)
|
|
|
|
EX(sb, a1, 6(a0), .Lbyte_fixup\@)
|
|
|
|
#endif
|
|
|
|
0:
|
2020-01-22 13:58:50 +03:00
|
|
|
#endif /* CONFIG_CPU_NO_LOAD_STORE_LR */
|
2018-10-02 14:50:16 +03:00
|
|
|
1: move a2, zero
|
|
|
|
jr ra
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.Lsmall_memset\@:
|
2018-10-02 14:50:16 +03:00
|
|
|
PTR_ADDU t1, a0, a2
|
2005-04-17 02:20:36 +04:00
|
|
|
beqz a2, 2f
|
|
|
|
|
|
|
|
1: PTR_ADDIU a0, 1 /* fill bytewise */
|
2007-11-25 13:47:56 +03:00
|
|
|
R10KCBARRIER(0(ra))
|
2018-10-02 14:50:16 +03:00
|
|
|
.set noreorder
|
2005-04-17 02:20:36 +04:00
|
|
|
bne t1, a0, 1b
|
2018-03-29 12:28:23 +03:00
|
|
|
EX(sb, a1, -1(a0), .Lsmall_fixup\@)
|
2018-10-02 14:50:16 +03:00
|
|
|
.set reorder
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-10-02 14:50:16 +03:00
|
|
|
2: move a2, zero
|
|
|
|
jr ra /* done */
|
2014-01-03 13:23:16 +04:00
|
|
|
.if __memset == 1
|
2005-04-17 02:20:36 +04:00
|
|
|
END(memset)
|
2014-01-03 13:23:16 +04:00
|
|
|
.set __memset, 0
|
|
|
|
.hidden __memset
|
|
|
|
.endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-01-22 13:58:50 +03:00
|
|
|
#ifdef CONFIG_CPU_NO_LOAD_STORE_LR
|
2014-11-18 12:04:34 +03:00
|
|
|
.Lbyte_fixup\@:
|
2018-05-23 16:39:59 +03:00
|
|
|
/*
|
|
|
|
* unset_bytes = (#bytes - (#unaligned bytes)) - (-#unaligned bytes remaining + 1) + 1
|
|
|
|
* a2 = a2 - t0 + 1
|
|
|
|
*/
|
MIPS: memset.S: Fix byte_fixup for MIPSr6
The __clear_user function is defined to return the number of bytes that
could not be cleared. From the underlying memset / bzero implementation
this means setting register a2 to that number on return. Currently if a
page fault is triggered within the MIPSr6 version of setting of initial
unaligned bytes, the value loaded into a2 on return is meaningless.
During the MIPSr6 version of the initial unaligned bytes block, register
a2 contains the number of bytes to be set beyond the initial unaligned
bytes. The t0 register is initally set to the number of unaligned bytes
- STORSIZE, effectively a negative version of the number of unaligned
bytes. This is then incremented before each byte is saved.
The label .Lbyte_fixup\@ is jumped to on page fault. Currently the value
in a2 is incorrectly replaced by 0 - t0 + 1, effectively the number of
unaligned bytes remaining. This leads to the failures being reported by
the following test code:
static int __init test_clear_user(void)
{
int j, k;
pr_info("\n\n\nTesting clear_user\n");
for (j = 0; j < 512; j++) {
if ((k = clear_user(NULL+3, j)) != j) {
pr_err("clear_user (NULL %d) returned %d\n", j, k);
}
}
return 0;
}
late_initcall(test_clear_user);
Which reports:
[ 3.965439] Testing clear_user
[ 3.973169] clear_user (NULL 8) returned 6
[ 3.976782] clear_user (NULL 9) returned 6
[ 3.980390] clear_user (NULL 10) returned 6
[ 3.984052] clear_user (NULL 11) returned 6
[ 3.987524] clear_user (NULL 12) returned 6
Fix this by subtracting t0 from a2 (rather than $0), effectivey giving:
unset_bytes = (#bytes - (#unaligned bytes)) - (-#unaligned bytes remaining + 1) + 1
a2 = a2 - t0 + 1
This fixes the value returned from __clear user when the number of bytes
to set is > LONGSIZE and the address is invalid and unaligned.
Unfortunately, this breaks the fixup handling for unaligned bytes after
the final long, where register a2 still contains the number of bytes
remaining to be set and the t0 register is to 0 - the number of
unaligned bytes remaining.
Because t0 is now is now subtracted from a2 rather than 0, the number of
bytes unset is reported incorrectly:
static int __init test_clear_user(void)
{
char *test;
int j, k;
pr_info("\n\n\nTesting clear_user\n");
test = vmalloc(PAGE_SIZE);
for (j = 256; j < 512; j++) {
if ((k = clear_user(test + PAGE_SIZE - 254, j)) != j - 254) {
pr_err("clear_user (%px %d) returned %d\n",
test + PAGE_SIZE - 254, j, k);
}
}
return 0;
}
late_initcall(test_clear_user);
[ 3.976775] clear_user (c00000000000df02 256) returned 4
[ 3.981957] clear_user (c00000000000df02 257) returned 6
[ 3.986425] clear_user (c00000000000df02 258) returned 8
[ 3.990850] clear_user (c00000000000df02 259) returned 10
[ 3.995332] clear_user (c00000000000df02 260) returned 12
[ 3.999815] clear_user (c00000000000df02 261) returned 14
Fix this by ensuring that a2 is set to 0 during the set of final
unaligned bytes.
Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Fixes: 8c56208aff77 ("MIPS: lib: memset: Add MIPS R6 support")
Patchwork: https://patchwork.linux-mips.org/patch/19338/
Cc: James Hogan <jhogan@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org # v4.0+
2018-05-23 16:39:58 +03:00
|
|
|
PTR_SUBU a2, t0
|
2018-10-02 14:50:16 +03:00
|
|
|
PTR_ADDIU a2, 1
|
2014-11-18 12:04:34 +03:00
|
|
|
jr ra
|
2020-01-22 13:58:50 +03:00
|
|
|
#endif /* CONFIG_CPU_NO_LOAD_STORE_LR */
|
2014-11-18 12:04:34 +03:00
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.Lfirst_fixup\@:
|
2018-05-23 16:39:59 +03:00
|
|
|
/* unset_bytes already in a2 */
|
2005-04-17 02:20:36 +04:00
|
|
|
jr ra
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.Lfwd_fixup\@:
|
2018-05-23 16:39:59 +03:00
|
|
|
/*
|
|
|
|
* unset_bytes = partial_start_addr + #bytes - fault_addr
|
|
|
|
* a2 = t1 + (a2 & 3f) - $28->task->BUADDR
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
PTR_L t0, TI_TASK($28)
|
|
|
|
andi a2, 0x3f
|
2010-11-10 16:48:15 +03:00
|
|
|
LONG_L t0, THREAD_BUADDR(t0)
|
2005-04-17 02:20:36 +04:00
|
|
|
LONG_ADDU a2, t1
|
2018-10-02 14:50:16 +03:00
|
|
|
LONG_SUBU a2, t0
|
2005-04-17 02:20:36 +04:00
|
|
|
jr ra
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.Lpartial_fixup\@:
|
2018-05-23 16:39:59 +03:00
|
|
|
/*
|
|
|
|
* unset_bytes = partial_end_addr + #bytes - fault_addr
|
|
|
|
* a2 = a0 + (a2 & STORMASK) - $28->task->BUADDR
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
PTR_L t0, TI_TASK($28)
|
2013-03-25 22:40:49 +04:00
|
|
|
andi a2, STORMASK
|
2010-11-10 16:48:15 +03:00
|
|
|
LONG_L t0, THREAD_BUADDR(t0)
|
MIPS: memset.S: Fix return of __clear_user from Lpartial_fixup
The __clear_user function is defined to return the number of bytes that
could not be cleared. From the underlying memset / bzero implementation
this means setting register a2 to that number on return. Currently if a
page fault is triggered within the memset_partial block, the value
loaded into a2 on return is meaningless.
The label .Lpartial_fixup\@ is jumped to on page fault. In order to work
out how many bytes failed to copy, the exception handler should find how
many bytes left in the partial block (andi a2, STORMASK), add that to
the partial block end address (a2), and subtract the faulting address to
get the remainder. Currently it incorrectly subtracts the partial block
start address (t1), which has additionally been clobbered to generate a
jump target in memset_partial. Fix this by adding the block end address
instead.
This issue was found with the following test code:
int j, k;
for (j = 0; j < 512; j++) {
if ((k = clear_user(NULL, j)) != j) {
pr_err("clear_user (NULL %d) returned %d\n", j, k);
}
}
Which now passes on Creator Ci40 (MIPS32) and Cavium Octeon II (MIPS64).
Suggested-by: James Hogan <jhogan@kernel.org>
Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/19108/
Signed-off-by: James Hogan <jhogan@kernel.org>
2018-04-17 17:52:21 +03:00
|
|
|
LONG_ADDU a2, a0
|
2018-10-02 14:50:16 +03:00
|
|
|
LONG_SUBU a2, t0
|
2005-04-17 02:20:36 +04:00
|
|
|
jr ra
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.Llast_fixup\@:
|
2018-05-23 16:39:59 +03:00
|
|
|
/* unset_bytes already in a2 */
|
2005-04-17 02:20:36 +04:00
|
|
|
jr ra
|
2014-01-03 13:23:16 +04:00
|
|
|
|
2018-03-29 12:28:23 +03:00
|
|
|
.Lsmall_fixup\@:
|
2018-05-23 16:39:59 +03:00
|
|
|
/*
|
|
|
|
* unset_bytes = end_addr - current_addr + 1
|
|
|
|
* a2 = t1 - a0 + 1
|
|
|
|
*/
|
2018-03-29 12:28:23 +03:00
|
|
|
PTR_SUBU a2, t1, a0
|
MIPS: memset: Fix CPU_DADDI_WORKAROUNDS `small_fixup' regression
Fix a commit 8a8158c85e1e ("MIPS: memset.S: EVA & fault support for
small_memset") regression and remove assembly warnings:
arch/mips/lib/memset.S: Assembler messages:
arch/mips/lib/memset.S:243: Warning: Macro instruction expanded into multiple instructions in a branch delay slot
triggering with the CPU_DADDI_WORKAROUNDS option set and this code:
PTR_SUBU a2, t1, a0
jr ra
PTR_ADDIU a2, 1
This is because with that option in place the DADDIU instruction, which
the PTR_ADDIU CPP macro expands to, becomes a GAS macro, which in turn
expands to an LI/DADDU (or actually ADDIU/DADDU) sequence:
13c: 01a4302f dsubu a2,t1,a0
140: 03e00008 jr ra
144: 24010001 li at,1
148: 00c1302d daddu a2,a2,at
...
Correct this by switching off the `noreorder' assembly mode and letting
GAS schedule this jump's delay slot, as there is nothing special about
it that would require manual scheduling. With this change in place
correct code is produced:
13c: 01a4302f dsubu a2,t1,a0
140: 24010001 li at,1
144: 03e00008 jr ra
148: 00c1302d daddu a2,a2,at
...
Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Fixes: 8a8158c85e1e ("MIPS: memset.S: EVA & fault support for small_memset")
Patchwork: https://patchwork.linux-mips.org/patch/20833/
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: stable@vger.kernel.org # 4.17+
2018-10-02 14:50:11 +03:00
|
|
|
PTR_ADDIU a2, 1
|
2018-03-29 12:28:23 +03:00
|
|
|
jr ra
|
|
|
|
|
2014-01-03 13:23:16 +04:00
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* memset(void *s, int c, size_t n)
|
|
|
|
*
|
|
|
|
* a0: start of area to clear
|
|
|
|
* a1: char to fill with
|
|
|
|
* a2: size of area to clear
|
|
|
|
*/
|
|
|
|
|
|
|
|
LEAF(memset)
|
2016-11-07 14:14:15 +03:00
|
|
|
EXPORT_SYMBOL(memset)
|
2018-10-02 14:50:16 +03:00
|
|
|
move v0, a0 /* result */
|
2014-01-03 13:23:16 +04:00
|
|
|
beqz a1, 1f
|
|
|
|
|
|
|
|
andi a1, 0xff /* spread fillword */
|
|
|
|
LONG_SLL t1, a1, 8
|
|
|
|
or a1, t1
|
|
|
|
LONG_SLL t1, a1, 16
|
|
|
|
#if LONGSIZE == 8
|
|
|
|
or a1, t1
|
|
|
|
LONG_SLL t1, a1, 32
|
|
|
|
#endif
|
|
|
|
or a1, t1
|
|
|
|
1:
|
2014-01-03 14:11:45 +04:00
|
|
|
#ifndef CONFIG_EVA
|
2014-01-03 13:23:16 +04:00
|
|
|
FEXPORT(__bzero)
|
2016-11-07 14:14:15 +03:00
|
|
|
EXPORT_SYMBOL(__bzero)
|
2015-08-05 18:41:39 +03:00
|
|
|
#else
|
|
|
|
FEXPORT(__bzero_kernel)
|
2016-11-07 14:14:15 +03:00
|
|
|
EXPORT_SYMBOL(__bzero_kernel)
|
2014-01-03 14:11:45 +04:00
|
|
|
#endif
|
2014-01-03 13:23:16 +04:00
|
|
|
__BUILD_BZERO LEGACY_MODE
|
2014-01-03 14:11:45 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_EVA
|
|
|
|
LEAF(__bzero)
|
2016-11-07 14:14:15 +03:00
|
|
|
EXPORT_SYMBOL(__bzero)
|
2014-01-03 14:11:45 +04:00
|
|
|
__BUILD_BZERO EVA_MODE
|
|
|
|
END(__bzero)
|
|
|
|
#endif
|