From mboxrd@z Thu Jan 1 00:00:00 1970 From: Prashant Bhole Subject: [RFC v2 bpf-next 1/5] bpf: error handling when map_lookup_elem isn't supported Date: Tue, 2 Oct 2018 14:35:15 +0900 Message-ID: <20181002053519.8000-2-bhole_prashant_q7@lab.ntt.co.jp> References: <20181002053519.8000-1-bhole_prashant_q7@lab.ntt.co.jp> Cc: Prashant Bhole , Jakub Kicinski , "David S . Miller" , Quentin Monnet , netdev@vger.kernel.org To: Alexei Starovoitov , Daniel Borkmann Return-path: Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:52781 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbeJBMSA (ORCPT ); Tue, 2 Oct 2018 08:18:00 -0400 In-Reply-To: <20181002053519.8000-1-bhole_prashant_q7@lab.ntt.co.jp> Sender: netdev-owner@vger.kernel.org List-ID: The error value returned by map_lookup_elem doesn't differentiate whether lookup was failed because of invalid key or lookup is not supported. Lets add handling for -EOPNOTSUPP return value of map_lookup_elem() method of map, with expectation from map's implementation that it should return -EOPNOTSUPP if lookup is not supported. The errno for bpf syscall for BPF_MAP_LOOKUP_ELEM command will be set to EOPNOTSUPP if map lookup is not supported. Signed-off-by: Prashant Bhole --- kernel/bpf/syscall.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 5742df21598c..4f416234251f 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -719,10 +719,15 @@ static int map_lookup_elem(union bpf_attr *attr) } else { rcu_read_lock(); ptr = map->ops->map_lookup_elem(map, key); - if (ptr) + if (IS_ERR(ptr)) { + err = PTR_ERR(ptr); + } else if (!ptr) { + err = -ENOENT; + } else { + err = 0; memcpy(value, ptr, value_size); + } rcu_read_unlock(); - err = ptr ? 0 : -ENOENT; } if (err) -- 2.17.1