Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch/tile: support <asm/cachectl.h> header for cacheflush() syscall

We already had a syscall that did some dcache flushing, but it was
not used in practice. Make it MIPS compatible instead so it can
do both the DCACHE and ICACHE actions. We have code that wants to
be able to use the ICACHE flush mode from userspace so this change
enables that.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>

+55 -8
+1
arch/tile/include/asm/Kbuild
··· 2 2 3 3 header-y += ../arch/ 4 4 5 + header-y += cachectl.h 5 6 header-y += ucontext.h 6 7 header-y += hardwall.h 7 8
+42
arch/tile/include/asm/cachectl.h
··· 1 + /* 2 + * Copyright 2011 Tilera Corporation. All Rights Reserved. 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License 6 + * as published by the Free Software Foundation, version 2. 7 + * 8 + * This program is distributed in the hope that it will be useful, but 9 + * WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 11 + * NON INFRINGEMENT. See the GNU General Public License for 12 + * more details. 13 + */ 14 + 15 + #ifndef _ASM_TILE_CACHECTL_H 16 + #define _ASM_TILE_CACHECTL_H 17 + 18 + /* 19 + * Options for cacheflush system call. 20 + * 21 + * The ICACHE flush is performed on all cores currently running the 22 + * current process's address space. The intent is for user 23 + * applications to be able to modify code, invoke the system call, 24 + * then allow arbitrary other threads in the same address space to see 25 + * the newly-modified code. Passing a length of CHIP_L1I_CACHE_SIZE() 26 + * or more invalidates the entire icache on all cores in the address 27 + * spaces. (Note: currently this option invalidates the entire icache 28 + * regardless of the requested address and length, but we may choose 29 + * to honor the arguments at some point.) 30 + * 31 + * Flush and invalidation of memory can normally be performed with the 32 + * __insn_flush(), __insn_inv(), and __insn_finv() instructions from 33 + * userspace. The DCACHE option to the system call allows userspace 34 + * to flush the entire L1+L2 data cache from the core. In this case, 35 + * the address and length arguments are not used. The DCACHE flush is 36 + * restricted to the current core, not all cores in the address space. 37 + */ 38 + #define ICACHE (1<<0) /* invalidate L1 instruction cache */ 39 + #define DCACHE (1<<1) /* flush and invalidate data cache */ 40 + #define BCACHE (ICACHE|DCACHE) /* flush both caches */ 41 + 42 + #endif /* _ASM_TILE_CACHECTL_H */
-3
arch/tile/include/asm/compat.h
··· 242 242 long compat_sys_sched_rr_get_interval(compat_pid_t pid, 243 243 struct compat_timespec __user *interval); 244 244 245 - /* Tilera Linux syscalls that don't have "compat" versions. */ 246 - #define compat_sys_flush_cache sys_flush_cache 247 - 248 245 /* These are the intvec_64.S trampolines. */ 249 246 long _compat_sys_execve(const char __user *path, 250 247 const compat_uptr_t __user *argv,
+2 -1
arch/tile/include/asm/syscalls.h
··· 43 43 u32 len, int advice); 44 44 int sys32_fadvise64_64(int fd, u32 offset_lo, u32 offset_hi, 45 45 u32 len_lo, u32 len_hi, int advice); 46 - long sys_flush_cache(void); 46 + long sys_cacheflush(unsigned long addr, unsigned long len, 47 + unsigned long flags); 47 48 #ifndef __tilegx__ /* No mmap() in the 32-bit kernel. */ 48 49 #define sys_mmap sys_mmap 49 50 #endif
+2 -2
arch/tile/include/asm/unistd.h
··· 24 24 #include <asm-generic/unistd.h> 25 25 26 26 /* Additional Tilera-specific syscalls. */ 27 - #define __NR_flush_cache (__NR_arch_specific_syscall + 1) 28 - __SYSCALL(__NR_flush_cache, sys_flush_cache) 27 + #define __NR_cacheflush (__NR_arch_specific_syscall + 1) 28 + __SYSCALL(__NR_cacheflush, sys_cacheflush) 29 29 30 30 #ifndef __tilegx__ 31 31 /* "Fast" syscalls provide atomic support for 32-bit chips. */
+8 -2
arch/tile/kernel/sys.c
··· 32 32 #include <asm/syscalls.h> 33 33 #include <asm/pgtable.h> 34 34 #include <asm/homecache.h> 35 + #include <asm/cachectl.h> 35 36 #include <arch/chip.h> 36 37 37 - SYSCALL_DEFINE0(flush_cache) 38 + SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len, 39 + unsigned long, flags) 38 40 { 39 - homecache_evict(cpumask_of(smp_processor_id())); 41 + if (flags & DCACHE) 42 + homecache_evict(cpumask_of(smp_processor_id())); 43 + if (flags & ICACHE) 44 + flush_remote(0, HV_FLUSH_EVICT_L1I, mm_cpumask(current->mm), 45 + 0, 0, 0, NULL, NULL, 0); 40 46 return 0; 41 47 } 42 48