Re: [RFC] cacheflush.2: Document different prototypes for different architectures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/11/20 10:09 PM, Alejandro Colomar (man-pages) wrote:
Hi Michael,

Continuing with the changes in this thread:
https://lore.kernel.org/linux-man/747d56e0-c102-ab40-add4-530a48a43a4d@xxxxxx/T/#t

I researched the architectures that have this syscall.  I found some
that clearly provide the syscall, and some that seem to have something,
but I didn't find a definition in the kernel (i.e., ARM, MicroBlaze
(glibc only)?)

arch/arm/include/uapi/asm/unistd.h:35:
#define __ARM_NR_cacheflush               (__ARM_NR_BASE+2)

arch/arm64/include/asm/unistd.h:37:
#define __ARM_NR_compat_cacheflush   (__ARM_NR_COMPAT_BASE + 2)

These syscalls are marked as private. So you should not use them from
user space.

The compilers seem not to care about these syscalls being private:

https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/lib1funcs.S#L1512
https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/clear_cache.c

Best regards

Heinrich


Research:

$ grep -rn cacheflush glibc/
glibc/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist:324:GLIBC_2.0
cacheflush F
glibc/sysdeps/unix/sysv/linux/m68k/Versions:13:    cacheflush;
glibc/sysdeps/unix/sysv/linux/m68k/arch-syscall.h:17:#define
__NR_cacheflush 123
glibc/sysdeps/unix/sysv/linux/m68k/syscalls.list:18:cacheflush	EXTRA
cacheflush	i:iiii	__cacheflush	cacheflush
glibc/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist:744:GLIBC_2.4
cacheflush F
glibc/sysdeps/unix/sysv/linux/arc/Versions:10:    cacheflush;
glibc/sysdeps/unix/sysv/linux/arc/sys/cachectl.h:1:/* cacheflush - flush
contents of instruction and/or data cache.
glibc/sysdeps/unix/sysv/linux/arc/sys/cachectl.h:30:extern int
cacheflush (void *__addr, int __nbytes, int __op) __THROW;
glibc/sysdeps/unix/sysv/linux/arc/arch-syscall.h:13:#define
__NR_cacheflush 244
glibc/sysdeps/unix/sysv/linux/arc/syscalls.list:3:cacheflush	-
cacheflush	i:pii	_flush_cache	cacheflush
glibc/sysdeps/unix/sysv/linux/arc/Makefile:10:# MIPS/Tile-style
cacheflush routine
glibc/sysdeps/unix/sysv/linux/arc/Makefile:12:sysdep_routines += cacheflush
glibc/sysdeps/unix/sysv/linux/arc/libc.abilist:574:GLIBC_2.32 cacheflush F
glibc/sysdeps/unix/sysv/linux/csky/Versions:3:    cacheflush;
glibc/sysdeps/unix/sysv/linux/csky/sys/cachectl.h:30:extern int
cacheflush (void *__addr, const int __nbytes,
glibc/sysdeps/unix/sysv/linux/csky/arch-syscall.h:10:#define
__NR_cacheflush 245
glibc/sysdeps/unix/sysv/linux/csky/syscalls.list:2:cacheflush	-
cacheflush	i:pii	_flush_cache	cacheflush
glibc/sysdeps/unix/sysv/linux/csky/Makefile:2:sysdep_routines += cacheflush
glibc/sysdeps/unix/sysv/linux/csky/libc.abilist:594:GLIBC_2.29 cacheflush F
glibc/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist:322:GLIBC_2.0
cacheflush F
glibc/sysdeps/unix/sysv/linux/mips/mips32/arch-syscall.h:19:#define
__NR_cacheflush 4147
glibc/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:322:GLIBC_2.0
cacheflush F
glibc/sysdeps/unix/sysv/linux/mips/Versions:19:    cachectl; cacheflush;
glibc/sysdeps/unix/sysv/linux/mips/sys/cachectl.h:35:extern int
cacheflush (void *__addr, const int __nbytes, const int __op) __THROW;
glibc/sysdeps/unix/sysv/linux/mips/mips64/n64/arch-syscall.h:16:#define
__NR_cacheflush 5197
glibc/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist:320:GLIBC_2.0
cacheflush F
glibc/sysdeps/unix/sysv/linux/mips/mips64/n32/arch-syscall.h:16:#define
__NR_cacheflush 6197
glibc/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist:322:GLIBC_2.0
cacheflush F
glibc/sysdeps/unix/sysv/linux/mips/syscalls.list:8:cacheflush	-
cacheflush	i:pii	_flush_cache	cacheflush
glibc/sysdeps/unix/sysv/linux/mips/Makefile:6:sysdep_routines +=
cachectl cacheflush sysmips _test_and_set
glibc/sysdeps/unix/sysv/linux/sh/arch-syscall.h:16:#define
__NR_cacheflush 123
glibc/sysdeps/unix/sysv/linux/nios2/Versions:4:    cacheflush;
glibc/sysdeps/unix/sysv/linux/nios2/sys/cachectl.h:1:/* cacheflush -
flush contents of instruction and/or data cache.
glibc/sysdeps/unix/sysv/linux/nios2/sys/cachectl.h:27:extern int
cacheflush (void *__addr, const int __nbytes, const int __op) __THROW;
glibc/sysdeps/unix/sysv/linux/nios2/arch-syscall.h:10:#define
__NR_cacheflush 244
glibc/sysdeps/unix/sysv/linux/nios2/cacheflush.c:1:/* cacheflush system
call for Nios II Linux.
glibc/sysdeps/unix/sysv/linux/nios2/cacheflush.c:27:  return
INLINE_SYSCALL (cacheflush, 3, addr, nbytes, op);
glibc/sysdeps/unix/sysv/linux/nios2/cacheflush.c:29:weak_alias
(_flush_cache, cacheflush)
glibc/sysdeps/unix/sysv/linux/nios2/Makefile:6:# MIPS-style cacheflush
routine
glibc/sysdeps/unix/sysv/linux/nios2/Makefile:8:sysdep_routines += cacheflush
glibc/sysdeps/unix/sysv/linux/nios2/libc.abilist:663:GLIBC_2.21 cacheflush F
glibc/sysdeps/unix/sysv/linux/arm/dl-machine.h:23:
INTERNAL_SYSCALL_CALL (cacheflush, (BEG), (END), 0)
glibc/sysdeps/unix/sysv/linux/arm/arch-syscall.h:17:#define
__NR_cacheflush 983042
glibc/sysdeps/unix/sysv/linux/arm/fixup-asm-unistd.h:19:#ifndef
__NR_cacheflush
glibc/sysdeps/unix/sysv/linux/arm/fixup-asm-unistd.h:20:# define
__NR_cacheflush __ARM_NR_cacheflush
glibc/sysdeps/unix/sysv/linux/microblaze/syscalls.list:3:cacheflush
EXTRA	cacheflush	i:iiii	__cacheflush	cacheflush
glibc/sysdeps/unix/sysv/linux/syscall-names.list:60:cacheflush
glibc/benchtests/strcoll-inputs/filelist#en_US.UTF-8:1417:cacheflush.c
glibc/benchtests/strcoll-inputs/filelist#en_US.UTF-8:1744:cacheflush.c
glibc/ChangeLog.old/ChangeLog.7:7489:	* sysdeps/mach/mips/cacheflush.c:
Likewise.
glibc/ChangeLog.old/ChangeLog.7:9422:	*
sysdeps/unix/sysv/linux/m68k/syscalls.list: Add cacheflush.
glibc/ChangeLog.old/ChangeLog.4:205:	* sysdeps/mach/mips/cacheflush.c:
New file.
glibc/ChangeLog.old/ChangeLog.18:40858:	*
sysdeps/unix/sysv/linux/nios2/cacheflush.c: New file.
glibc/ChangeLog.old/ChangeLog.ports-tile:700:	*
sysdeps/unix/sysv/linux/tile/cacheflush.c: New file.
grep: glibc/.git/index: binary file matches

$ grep -rn -e 'sys_cacheflush' -e 'SYSCALL_DEFINE.(cacheflush,' linux/ |
grep -v -e '/arc/' -e '/csky/' -e '/mips/' -e '/nios2/'
tools/testing/selftests/futex/functional/usr/include/linux/capability.h:251:/*
Allow flushing all cache on m68k (sys_cacheflush) */
include/uapi/linux/capability.h:253:/* Allow flushing all cache on m68k
(sys_cacheflush) */
arch/m68k/kernel/sys_m68k.c:376:/* sys_cacheflush -- flush (part of) the
processor cache.  */
arch/m68k/kernel/sys_m68k.c:378:sys_cacheflush (unsigned long addr, int
scope, int cache, unsigned long len)
arch/m68k/kernel/sys_m68k.c:531:/* sys_cacheflush -- flush (part of) the
processor cache.  */
arch/m68k/kernel/sys_m68k.c:533:sys_cacheflush (unsigned long addr, int
scope, int cache, unsigned long len)
arch/m68k/kernel/syscalls/syscall.tbl:133:123	common	cacheflush
sys_cacheflush
arch/sh/kernel/sys_sh.c:57:/* sys_cacheflush -- flush (part of) the
processor cache.  */
arch/sh/kernel/sys_sh.c:58:asmlinkage int sys_cacheflush(unsigned long
addr, unsigned long len, int op)
arch/sh/kernel/syscalls/syscall.tbl:133:123	common	cacheflush
sys_cacheflush
arch/arm/include/asm/cacheflush.h:263: * This is used for the ARM
private sys_cacheflush system call.
arch/nds32/include/uapi/asm/unistd.h:15:__SYSCALL(__NR_cacheflush,
sys_cacheflush)
arch/nds32/include/asm/syscalls.h:7:asmlinkage long
sys_cacheflush(unsigned long addr, unsigned long len, unsigned int op);
arch/nds32/kernel/sys_nds32.c:29:SYSCALL_DEFINE3(cacheflush, unsigned
int, start, unsigned int, end, int, cache)

Rendered page (NOTES only):

[
NOTES
    Architecture-specific variants
        Glibc  provides a wrapper for this system call, with the pro‐
        totype shown in SYNOPSIS, for  the  following  architectures:
        ARC, CSKY, MIPS, and NIOS2. // lowercase?

        On  some other architectures, Linux provides this system call
        with different arguments:

        M68K:

            int cacheflush(unsigned long addr, int scope, int cache,
                           unsigned long len);

        SH:

            int cacheflush(unsigned long addr, unsigned long len, int op);

        NDS32:

            int cacheflush(unsigned int start, unsigned int end, int cache);

        // ARM??

    GCC alternative
        Unless you need the finer grained control  that  this  system
        call  provides,  you  probably  want  to use the GCC built-in
        function __builtin___clear_cache(), which provides a portable
        interface  across  platforms  supported by GCC and compatible
        compilers:

            void __builtin___clear_cache(void *begin, void *end);

        On platforms that don't require  instruction  cache  flushes,
        __builtin___clear_cache() has no effect.

        Note:  On  some  GCC-compatible compilers, such as clang, the
        prototype for this function uses char * instead of void * for
        the parameters.

]

'GCC alternative' is the name I gave to the NOTES from the other thread,
which aren't yet merged (I'll send the patches after the weekend, probably).

Subsections based on:
fadvise64(2)

Can you review this?

Thanks,

Alex






[Index of Archives]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux