mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	bpf: Allows per-cpu maps and map-in-map in sleepable programs
Since sleepable programs are now executing under migrate_disable the per-cpu maps are safe to use. The map-in-map were ok to use in sleepable from the time sleepable progs were introduced. Note that non-preallocated maps are still not safe, since there is no rcu_read_lock yet in sleepable programs and dynamically allocated map elements are relying on rcu protection. The sleepable programs have rcu_read_lock_trace instead. That limitation will be addresses in the future. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: KP Singh <kpsingh@kernel.org> Link: https://lore.kernel.org/bpf/20210210033634.62081-9-alexei.starovoitov@gmail.com
This commit is contained in:
		
							parent
							
								
									dcf33b6f4d
								
							
						
					
					
						commit
						638e4b825d
					
				
					 2 changed files with 8 additions and 3 deletions
				
			
		| 
						 | 
					@ -1148,7 +1148,7 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
 | 
				
			||||||
		/* unknown flags */
 | 
							/* unknown flags */
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	WARN_ON_ONCE(!rcu_read_lock_held());
 | 
						WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	key_size = map->key_size;
 | 
						key_size = map->key_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1202,7 +1202,7 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
 | 
				
			||||||
		/* unknown flags */
 | 
							/* unknown flags */
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	WARN_ON_ONCE(!rcu_read_lock_held());
 | 
						WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	key_size = map->key_size;
 | 
						key_size = map->key_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10384,9 +10384,14 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env,
 | 
				
			||||||
		case BPF_MAP_TYPE_HASH:
 | 
							case BPF_MAP_TYPE_HASH:
 | 
				
			||||||
		case BPF_MAP_TYPE_LRU_HASH:
 | 
							case BPF_MAP_TYPE_LRU_HASH:
 | 
				
			||||||
		case BPF_MAP_TYPE_ARRAY:
 | 
							case BPF_MAP_TYPE_ARRAY:
 | 
				
			||||||
 | 
							case BPF_MAP_TYPE_PERCPU_HASH:
 | 
				
			||||||
 | 
							case BPF_MAP_TYPE_PERCPU_ARRAY:
 | 
				
			||||||
 | 
							case BPF_MAP_TYPE_LRU_PERCPU_HASH:
 | 
				
			||||||
 | 
							case BPF_MAP_TYPE_ARRAY_OF_MAPS:
 | 
				
			||||||
 | 
							case BPF_MAP_TYPE_HASH_OF_MAPS:
 | 
				
			||||||
			if (!is_preallocated_map(map)) {
 | 
								if (!is_preallocated_map(map)) {
 | 
				
			||||||
				verbose(env,
 | 
									verbose(env,
 | 
				
			||||||
					"Sleepable programs can only use preallocated hash maps\n");
 | 
										"Sleepable programs can only use preallocated maps\n");
 | 
				
			||||||
				return -EINVAL;
 | 
									return -EINVAL;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue