mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	bpf: Add kernel test functions for fentry testing
Add few kernel functions with various number of arguments, their types and sizes for BPF trampoline testing to cover different calling conventions. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20191114185720.1641606-9-ast@kernel.org
This commit is contained in:
		
							parent
							
								
									e41074d39d
								
							
						
					
					
						commit
						faeb2dce08
					
				
					 1 changed files with 41 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -105,6 +105,40 @@ static int bpf_test_finish(const union bpf_attr *kattr,
 | 
			
		|||
	return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Integer types of various sizes and pointer combinations cover variety of
 | 
			
		||||
 * architecture dependent calling conventions. 7+ can be supported in the
 | 
			
		||||
 * future.
 | 
			
		||||
 */
 | 
			
		||||
int noinline bpf_fentry_test1(int a)
 | 
			
		||||
{
 | 
			
		||||
	return a + 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int noinline bpf_fentry_test2(int a, u64 b)
 | 
			
		||||
{
 | 
			
		||||
	return a + b;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int noinline bpf_fentry_test3(char a, int b, u64 c)
 | 
			
		||||
{
 | 
			
		||||
	return a + b + c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int noinline bpf_fentry_test4(void *a, char b, int c, u64 d)
 | 
			
		||||
{
 | 
			
		||||
	return (long)a + b + c + d;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int noinline bpf_fentry_test5(u64 a, void *b, short c, int d, u64 e)
 | 
			
		||||
{
 | 
			
		||||
	return a + (long)b + c + d + e;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
 | 
			
		||||
{
 | 
			
		||||
	return a + (long)b + c + d + (long)e + f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
 | 
			
		||||
			   u32 headroom, u32 tailroom)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -122,6 +156,13 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
 | 
			
		|||
		kfree(data);
 | 
			
		||||
		return ERR_PTR(-EFAULT);
 | 
			
		||||
	}
 | 
			
		||||
	if (bpf_fentry_test1(1) != 2 ||
 | 
			
		||||
	    bpf_fentry_test2(2, 3) != 5 ||
 | 
			
		||||
	    bpf_fentry_test3(4, 5, 6) != 15 ||
 | 
			
		||||
	    bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
 | 
			
		||||
	    bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
 | 
			
		||||
	    bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111)
 | 
			
		||||
		return ERR_PTR(-EFAULT);
 | 
			
		||||
	return data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue