Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2183278ybm; Thu, 23 May 2019 12:44:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyM0aqTMhtlh0rvq4b1a9cAl5CgGVCJZquznI2y/PZas8XrLMwiKT7AJ2Lj97qd6nOjlmzv X-Received: by 2002:a62:5f42:: with SMTP id t63mr64435771pfb.83.1558640645926; Thu, 23 May 2019 12:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640645; cv=none; d=google.com; s=arc-20160816; b=SS1O8flGrdn/JjapSH9ca/AzoOLsRpV+95mhxUU9hNWUTjvgi2lPjwCbms9HIpAmNT GNXDprUGc9l/gApcvhAX1rU8gGN93DwOuxF5yb8XuMBn22FaosXuZuymOZ5Orh00GAfR OBNTscMvoCzR39j/t9tgd+poG3c7mfpH0rwWiEaPTzYXnW5cnu6egJyTJ4kx7L6oLmvn G7VCcvLw01zNg9iPG4kXbNu9Idu/qTOaFDvGZMNVgYRS4Sl96V+pzk3cYAYSxDCW/f6p dHJvlGRMKpQB+9fPmmp5xzfeBP9150Upd9w4qS4BuZ7nc9xiUqXpA7rl8AgqOuj7+9JZ iDVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fOB/ERrpCxmIVk5prH15UoHcZeH3+0ZhPbAJe8DhTPc=; b=0N/vISVzFr5Fe6eNO6JKEGWdbm8UktPxW+CiP5W+SbwBHdB2/AQepi6OewYOuvkQkr 4kYt1E0uFeYKxycnQ7aaySq5tlqNqhKzNP1wqLrZfJBdVdiB31SDkxztEEL2nhuW72Rw 7YnyK68qGy+Az9Z6ktdR0pQtGCSpqu5mhDtiK7WToPOsl3fp4RITPeZEO4B9r8QIj7B5 l99UVQsOYRKp86RQFlxiZUHo1Jjvsy5+5fOZJx1crmxYkDs+IIxoZYzi9EPDa1GR9W5N ll5dZQFE2SC5Gw+1VemsmG/awdXynKJVSGdRN66GTHRCSHWQ45/3KOhpL4KbHNPTbu1D mxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="hKS3OM/h"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si537988pgh.331.2019.05.23.12.43.50; Thu, 23 May 2019 12:44:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="hKS3OM/h"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390493AbfEWTmE (ORCPT + 99 others); Thu, 23 May 2019 15:42:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:55644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388839AbfEWTTd (ORCPT ); Thu, 23 May 2019 15:19:33 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E335120863; Thu, 23 May 2019 19:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639172; bh=NxlkgndduMBlQUHyFdbZ5HLM7/ESUJYyK8ZlwqGaSh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hKS3OM/hQWMGcC2MwF0JNW4YaAx8Zvpr30vjEzOI2RzkuzNL/inoOVbJH1MZr0ypg Zr/9bQn9NCvQCfdfvqp/7UmjdiFcejavT33Qiiy0zVsLw0gRZX/28Ey0Ww0HPy3Vhl qdRCjVUoTq+MHf5EhobkQpT0UiauoKl6UL5NIk0k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Martin KaFai Lau , Alexei Starovoitov Subject: [PATCH 4.19 113/114] bpf: add map_lookup_elem_sys_only for lookups from syscall side Date: Thu, 23 May 2019 21:06:52 +0200 Message-Id: <20190523181740.896392740@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181731.372074275@linuxfoundation.org> References: <20190523181731.372074275@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Borkmann commit c6110222c6f49ea68169f353565eb865488a8619 upstream. Add a callback map_lookup_elem_sys_only() that map implementations could use over map_lookup_elem() from system call side in case the map implementation needs to handle the latter differently than from the BPF data path. If map_lookup_elem_sys_only() is set, this will be preferred pick for map lookups out of user space. This hook is used in a follow-up fix for LRU map, but once development window opens, we can convert other map types from map_lookup_elem() (here, the one called upon BPF_MAP_LOOKUP_ELEM cmd is meant) over to use the callback to simplify and clean up the latter. Signed-off-by: Daniel Borkmann Acked-by: Martin KaFai Lau Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- include/linux/bpf.h | 1 + kernel/bpf/syscall.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -34,6 +34,7 @@ struct bpf_map_ops { void (*map_free)(struct bpf_map *map); int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key); void (*map_release_uref)(struct bpf_map *map); + void *(*map_lookup_elem_sys_only)(struct bpf_map *map, void *key); /* funcs callable from userspace and from eBPF programs */ void *(*map_lookup_elem)(struct bpf_map *map, void *key); --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -721,7 +721,10 @@ static int map_lookup_elem(union bpf_att err = bpf_fd_reuseport_array_lookup_elem(map, key, value); } else { rcu_read_lock(); - ptr = map->ops->map_lookup_elem(map, key); + if (map->ops->map_lookup_elem_sys_only) + ptr = map->ops->map_lookup_elem_sys_only(map, key); + else + ptr = map->ops->map_lookup_elem(map, key); if (ptr) memcpy(value, ptr, value_size); rcu_read_unlock();