Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2187731ybm; Thu, 23 May 2019 12:48:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl75a8d4Yi0+t4etyqoSHaKweCggJz3E0OrX0nTIBz1XSx5S6D4Zi5XWFAhK36IwpgzJon X-Received: by 2002:a65:4144:: with SMTP id x4mr41777160pgp.282.1558640926656; Thu, 23 May 2019 12:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640926; cv=none; d=google.com; s=arc-20160816; b=qCMeFp3fstegsN6a69ITF+/mqBlaJT9d0+cqJRBs94wu88oR+LUZhGknNX5lWW2GIY /xopEvrenuOnJtqgCGUtvo3mjhKOQkXaB8HsYIlA66PQCRDR+4RfrV+z2Ao9K6YSfFh2 YDTVRkC2gAuylGwPa12nnRfZ90e+Ej+0Uwocel5jTdSIhF6RyY8oa98LVsBNrQ8IRztx clw5IJ+5BBgIus20kqwQPGHWKa/lnf2OKnPRcuiNhJCiCkdAC4OxIuNUdZghFd02No9Y KtJK8YAMVSzs262mQwn1qKJX6sD5BfT7xwSU6iAmGeO2k/zy6Dooweo3QowO+xI2oyyv kD6g== 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=fL9f5LEnzUe/bRPs5qJt5srNAjWHh7zUey3dOoK2rtk=; b=zbmX0Rg3Hc/7NBvvu2lTyKTLJBvQo/BTMm7nSRIkBaHPJtvk1fPXfQHUkwSGaDd3yh ky4KWqasRHI6s1ysAL/y6isKlOAEoh4HFDiWahBKamMU34GdoC3IVL+xzfselVF4q0ZW ut+C6TjeiTUt94CKtm2PIK6SrE8IXcl2eRX+PAVrb120a588EvLMUI+PKRL4wthrlQof H+iETgjF8130AbkznfvmELDREY60WrWrmXzK1ca8Rc8chp2m3gFWpyZn85JJa65d4zzd zJe8PAl8jojjakg9gVVYfSOJFLL1ilf30as9TprM9SjB1puxGg9sKb3xKviFfsI+7mc3 LsTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GsAqwifS; 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 p16si595418plo.310.2019.05.23.12.48.31; Thu, 23 May 2019 12:48:46 -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=GsAqwifS; 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 S2388683AbfEWTOK (ORCPT + 99 others); Thu, 23 May 2019 15:14:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:48082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388678AbfEWTOH (ORCPT ); Thu, 23 May 2019 15:14:07 -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 5275A217D9; Thu, 23 May 2019 19:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638846; bh=Re8T2yTHXK5XAfnVq2GhyXnFobK1U4GrBjodwoG3V1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GsAqwifSIJAPc5rAw+7Skji10ACv3hllz6uenmSmtMqHFBp+rPS/f0wEZ2EaipxYS cMBFQt22nxIfHywe0ETUZgPCv4+1er+KNV4ZpfvMkpAUa/z06LjvpVI8bkXHWy/WmF KZP8gFo26uQoSjq9HM/Nkdit1f2khRtcYvVjXcqU= 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.14 75/77] bpf: add map_lookup_elem_sys_only for lookups from syscall side Date: Thu, 23 May 2019 21:06:33 +0200 Message-Id: <20190523181730.307329542@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@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 @@ -28,6 +28,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 @@ -493,7 +493,10 @@ static int map_lookup_elem(union bpf_att err = bpf_fd_htab_map_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();