mirror of
				git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
				synced 2025-11-01 09:13:37 +00:00 
			
		
		
		
	Clang reports a warning on the __tlbi(aside1is, 0) macro expansion since
the value size does not match the register size specified in the inline
asm. Construct the ASID value using the __TLBI_VADDR() macro.
Fixes: 222fc0c850 ("arm64: compat: Workaround Neoverse-N1 #1542419 for compat user-space")
Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Cc: James Morse <james.morse@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
		
	
			
		
			
				
	
	
		
			120 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0-only
 | 
						|
/*
 | 
						|
 * Based on arch/arm/kernel/sys_arm.c
 | 
						|
 *
 | 
						|
 * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
 | 
						|
 * Copyright (C) 1995, 1996 Russell King.
 | 
						|
 * Copyright (C) 2012 ARM Ltd.
 | 
						|
 */
 | 
						|
 | 
						|
#include <linux/compat.h>
 | 
						|
#include <linux/cpufeature.h>
 | 
						|
#include <linux/personality.h>
 | 
						|
#include <linux/sched.h>
 | 
						|
#include <linux/sched/signal.h>
 | 
						|
#include <linux/slab.h>
 | 
						|
#include <linux/syscalls.h>
 | 
						|
#include <linux/uaccess.h>
 | 
						|
 | 
						|
#include <asm/cacheflush.h>
 | 
						|
#include <asm/system_misc.h>
 | 
						|
#include <asm/tlbflush.h>
 | 
						|
#include <asm/unistd.h>
 | 
						|
 | 
						|
static long
 | 
						|
__do_compat_cache_op(unsigned long start, unsigned long end)
 | 
						|
{
 | 
						|
	long ret;
 | 
						|
 | 
						|
	do {
 | 
						|
		unsigned long chunk = min(PAGE_SIZE, end - start);
 | 
						|
 | 
						|
		if (fatal_signal_pending(current))
 | 
						|
			return 0;
 | 
						|
 | 
						|
		if (cpus_have_const_cap(ARM64_WORKAROUND_1542419)) {
 | 
						|
			/*
 | 
						|
			 * The workaround requires an inner-shareable tlbi.
 | 
						|
			 * We pick the reserved-ASID to minimise the impact.
 | 
						|
			 */
 | 
						|
			__tlbi(aside1is, __TLBI_VADDR(0, 0));
 | 
						|
			dsb(ish);
 | 
						|
		}
 | 
						|
 | 
						|
		ret = __flush_cache_user_range(start, start + chunk);
 | 
						|
		if (ret)
 | 
						|
			return ret;
 | 
						|
 | 
						|
		cond_resched();
 | 
						|
		start += chunk;
 | 
						|
	} while (start < end);
 | 
						|
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
static inline long
 | 
						|
do_compat_cache_op(unsigned long start, unsigned long end, int flags)
 | 
						|
{
 | 
						|
	if (end < start || flags)
 | 
						|
		return -EINVAL;
 | 
						|
 | 
						|
	if (!access_ok((const void __user *)start, end - start))
 | 
						|
		return -EFAULT;
 | 
						|
 | 
						|
	return __do_compat_cache_op(start, end);
 | 
						|
}
 | 
						|
/*
 | 
						|
 * Handle all unrecognised system calls.
 | 
						|
 */
 | 
						|
long compat_arm_syscall(struct pt_regs *regs, int scno)
 | 
						|
{
 | 
						|
	void __user *addr;
 | 
						|
 | 
						|
	switch (scno) {
 | 
						|
	/*
 | 
						|
	 * Flush a region from virtual address 'r0' to virtual address 'r1'
 | 
						|
	 * _exclusive_.  There is no alignment requirement on either address;
 | 
						|
	 * user space does not need to know the hardware cache layout.
 | 
						|
	 *
 | 
						|
	 * r2 contains flags.  It should ALWAYS be passed as ZERO until it
 | 
						|
	 * is defined to be something else.  For now we ignore it, but may
 | 
						|
	 * the fires of hell burn in your belly if you break this rule. ;)
 | 
						|
	 *
 | 
						|
	 * (at a later date, we may want to allow this call to not flush
 | 
						|
	 * various aspects of the cache.  Passing '0' will guarantee that
 | 
						|
	 * everything necessary gets flushed to maintain consistency in
 | 
						|
	 * the specified region).
 | 
						|
	 */
 | 
						|
	case __ARM_NR_compat_cacheflush:
 | 
						|
		return do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
 | 
						|
 | 
						|
	case __ARM_NR_compat_set_tls:
 | 
						|
		current->thread.uw.tp_value = regs->regs[0];
 | 
						|
 | 
						|
		/*
 | 
						|
		 * Protect against register corruption from context switch.
 | 
						|
		 * See comment in tls_thread_flush.
 | 
						|
		 */
 | 
						|
		barrier();
 | 
						|
		write_sysreg(regs->regs[0], tpidrro_el0);
 | 
						|
		return 0;
 | 
						|
 | 
						|
	default:
 | 
						|
		/*
 | 
						|
		 * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
 | 
						|
		 * if not implemented, rather than raising SIGILL. This
 | 
						|
		 * way the calling program can gracefully determine whether
 | 
						|
		 * a feature is supported.
 | 
						|
		 */
 | 
						|
		if (scno < __ARM_NR_COMPAT_END)
 | 
						|
			return -ENOSYS;
 | 
						|
		break;
 | 
						|
	}
 | 
						|
 | 
						|
	addr  = (void __user *)instruction_pointer(regs) -
 | 
						|
		(compat_thumb_mode(regs) ? 2 : 4);
 | 
						|
 | 
						|
	arm64_notify_die("Oops - bad compat syscall(2)", regs,
 | 
						|
			 SIGILL, ILL_ILLTRP, addr, scno);
 | 
						|
	return 0;
 | 
						|
}
 |