Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2172912ybm; Thu, 23 May 2019 12:33:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwkdu67iJXzTFD/veLnZNriNaZ8GV8sFvqqwGcbHLJ1lHRzO0BdHLyg6OXpni0IKQP5zwv X-Received: by 2002:a63:2c4a:: with SMTP id s71mr83094408pgs.343.1558640001064; Thu, 23 May 2019 12:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640001; cv=none; d=google.com; s=arc-20160816; b=Yvnxyi7APy+y2n/G5JXi2lF4TX1kcIHEMBVvRTV2A4YPJZFsU9QoOux7A/N/X7GbeV R3L8d/MAHIcDe95BkjBwSC02CdcXHstUsKLszIjBRmbZD9vHyOVYvu+5/OSnvZvnQlBj MHHejeopO3c+9qUQnPzk6Ni61IeySUF+sVser29BJhR/bSEl+8UnE8h1PSCJ1kRoo0gY 6KWVAOEU7IIsY6U7WdZQEHrMdiLMwmAc5K5vY/6Mhd3cqwIZF2BHm1+M4L+BbYm3cUML IfJgBli5ku6M/EihcIAn+LJLZTxZiSaarUT41/s8J5WdHV6w+CV7ZAwZ5eKCaQdg5wfN KvYg== 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=9wwCXcvFNbKewg7+NBAIlz+OfqeI71cU1qeC97/gSyM=; b=LNrKktXDazRfDQAIEWVzDVhabZIf6uKTtavZcC2wnxolD5twIzmP96/HJjLBqBwubA TMTeKtpL583hZrm9vQ1CrXqqaec2dakDZp59BTacHclcX0wUKHDoAYbY83CnPNUdGy4n CsurRiuX9sDhXzL4h33XzFPa0TGbfgxF3PFvCfstL/pkuPtx2VGs4/ykKT+EHWoNDtAM 18YX0qp6YTL+xvQhovzVe4yT+FwE8gv4aouwYpQfRj8M/s2jz1zKCbFnTOTmkunCw4bg ujna9yF2fEsmhag605yitJih+a+uObjWI/P+V1L3bCkfrtptiTxhjlPoV2YEjDth9VGD 9vjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rkr3arT1; 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 q125si317178pfq.163.2019.05.23.12.33.04; Thu, 23 May 2019 12:33:21 -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=rkr3arT1; 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 S2403833AbfEWTbU (ORCPT + 99 others); Thu, 23 May 2019 15:31:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403811AbfEWTbR (ORCPT ); Thu, 23 May 2019 15:31:17 -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 ABC13206BA; Thu, 23 May 2019 19:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639877; bh=4LSiMGims+OsxiTMkToI2njYq4F0Tah+eeKCZeVa3Nk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rkr3arT1rIlXELxa8M93Xr4rRoOSbTbxTLEw47ahYwsyJgtvqR8I9H7tGa7GCpcPc YprXKkGf6TOTxgDil808uWUt1lpyV0YlVO4aQcHi7VqUKcfqNurf9JyvIpu+4TmiH6 LEvEMI761C90MY2TMwisVOcp4aFbKpRMFzG/2mTc= 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 5.1 117/122] bpf: add map_lookup_elem_sys_only for lookups from syscall side Date: Thu, 23 May 2019 21:07:19 +0200 Message-Id: <20190523181721.047758128@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@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 @@ -36,6 +36,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 @@ -773,7 +773,10 @@ static int map_lookup_elem(union bpf_att err = map->ops->map_peek_elem(map, 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 (IS_ERR(ptr)) { err = PTR_ERR(ptr); } else if (!ptr) {