Skip to content

Commit a2d25a5

Browse files
murzinvwildea01
authored andcommitted
arm64: compat: align cacheflush syscall with arch/arm
Update handling of cacheflush syscall with changes made in arch/arm counterpart: - return error to userspace when flushing syscall fails - split user cache-flushing into interruptible chunks - don't bother rounding to nearest vma Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com> [will: changed internal return value from -EINTR to 0 to match arch/arm/] Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent a1ae65b commit a2d25a5

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

‎arch/arm64/include/asm/cacheflush.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extern void flush_cache_all(void);
7373
extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
7474
extern void flush_icache_range(unsigned long start, unsigned long end);
7575
extern void __flush_dcache_area(void *addr, size_t len);
76-
extern void __flush_cache_user_range(unsigned long start, unsigned long end);
76+
extern long __flush_cache_user_range(unsigned long start, unsigned long end);
7777

7878
static inline void flush_cache_mm(struct mm_struct *mm)
7979
{

‎arch/arm64/kernel/sys_compat.c‎

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,39 @@
2828
#include <asm/cacheflush.h>
2929
#include <asm/unistd.h>
3030

31-
static inline void
32-
do_compat_cache_op(unsigned long start, unsigned long end, int flags)
31+
static long
32+
__do_compat_cache_op(unsigned long start, unsigned long end)
3333
{
34-
struct mm_struct *mm = current->active_mm;
35-
struct vm_area_struct *vma;
34+
long ret;
3635

37-
if (end < start || flags)
38-
return;
36+
do {
37+
unsigned long chunk = min(PAGE_SIZE, end - start);
3938

40-
down_read(&mm->mmap_sem);
41-
vma = find_vma(mm, start);
42-
if (vma && vma->vm_start < end) {
43-
if (start < vma->vm_start)
44-
start = vma->vm_start;
45-
if (end > vma->vm_end)
46-
end = vma->vm_end;
47-
up_read(&mm->mmap_sem);
48-
__flush_cache_user_range(start & PAGE_MASK, PAGE_ALIGN(end));
49-
return;
50-
}
51-
up_read(&mm->mmap_sem);
39+
if (fatal_signal_pending(current))
40+
return 0;
41+
42+
ret = __flush_cache_user_range(start, start + chunk);
43+
if (ret)
44+
return ret;
45+
46+
cond_resched();
47+
start += chunk;
48+
} while (start < end);
49+
50+
return 0;
5251
}
5352

53+
static inline long
54+
do_compat_cache_op(unsigned long start, unsigned long end, int flags)
55+
{
56+
if (end < start || flags)
57+
return -EINVAL;
58+
59+
if (!access_ok(VERIFY_READ, start, end - start))
60+
return -EFAULT;
61+
62+
return __do_compat_cache_op(start, end);
63+
}
5464
/*
5565
* Handle all unrecognised system calls.
5666
*/
@@ -74,8 +84,7 @@ long compat_arm_syscall(struct pt_regs *regs)
7484
* the specified region).
7585
*/
7686
case __ARM_NR_compat_cacheflush:
77-
do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
78-
return 0;
87+
return do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
7988

8089
case __ARM_NR_compat_set_tls:
8190
current->thread.tp_value = regs->regs[0];

‎arch/arm64/mm/cache.S‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20+
#include <linux/errno.h>
2021
#include <linux/linkage.h>
2122
#include <linux/init.h>
2223
#include <asm/assembler.h>
@@ -140,9 +141,12 @@ USER(9f, ic ivau, x4 ) // invalidate I line PoU
140141
add x4, x4, x2
141142
cmp x4, x1
142143
b.lo 1b
143-
9: // ignore any faulting cache operation
144144
dsb ish
145145
isb
146+
mov x0, #0
147+
ret
148+
9:
149+
mov x0, #-EFAULT
146150
ret
147151
ENDPROC(flush_icache_range)
148152
ENDPROC(__flush_cache_user_range)

0 commit comments

Comments
 (0)