From patchwork Wed Apr 22 08:30:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: maowenan X-Patchwork-Id: 1274844 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 496YVt6pwHz9sSK for ; Wed, 22 Apr 2020 18:28:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726499AbgDVI2u (ORCPT ); Wed, 22 Apr 2020 04:28:50 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57570 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726466AbgDVI2t (ORCPT ); Wed, 22 Apr 2020 04:28:49 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0CC4F9E052D804296E37; Wed, 22 Apr 2020 16:28:46 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Wed, 22 Apr 2020 16:28:40 +0800 From: Mao Wenan To: , , , , , , , CC: , , , Subject: [PATCH bpf-next 1/2] bpf: Change error code when ops is NULL Date: Wed, 22 Apr 2020 16:30:09 +0800 Message-ID: <20200422083010.28000-2-maowenan@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422083010.28000-1-maowenan@huawei.com> References: <20200422083010.28000-1-maowenan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is one error printed when use type BPF_MAP_TYPE_SOCKMAP to create map: libbpf: failed to create map (name: 'sock_map'): Invalid argument(-22) This is because CONFIG_BPF_STREAM_PARSER is not set, and bpf_map_types[type] return invalid ops. It is not clear to show the cause of config missing with return code -EINVAL, so add pr_warn() and change error code to describe the reason. Signed-off-by: Mao Wenan Reported-by: kbuild test robot Reported-by: kbuild test robot Reported-by: kbuild test robot --- kernel/bpf/syscall.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index d85f37239540..f67bc063bf75 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -112,9 +112,11 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) return ERR_PTR(-EINVAL); type = array_index_nospec(type, ARRAY_SIZE(bpf_map_types)); ops = bpf_map_types[type]; - if (!ops) - return ERR_PTR(-EINVAL); - + if (!ops) { + pr_warn("map type %d not supported or + kernel config not opened\n", type); + return ERR_PTR(-EOPNOTSUPP); + } if (ops->map_alloc_check) { err = ops->map_alloc_check(attr); if (err) From patchwork Wed Apr 22 08:30:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: maowenan X-Patchwork-Id: 1274845 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 496YVy17gGz9sSg for ; Wed, 22 Apr 2020 18:28:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726534AbgDVI2z (ORCPT ); Wed, 22 Apr 2020 04:28:55 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57568 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726396AbgDVI2t (ORCPT ); Wed, 22 Apr 2020 04:28:49 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 05290F7D3C5C81FB0C00; Wed, 22 Apr 2020 16:28:46 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Wed, 22 Apr 2020 16:28:41 +0800 From: Mao Wenan To: , , , , , , , CC: , , , Subject: [PATCH bpf-next 2/2] libbpf: Return err if bpf_object__load failed Date: Wed, 22 Apr 2020 16:30:10 +0800 Message-ID: <20200422083010.28000-3-maowenan@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422083010.28000-1-maowenan@huawei.com> References: <20200422083010.28000-1-maowenan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org bpf_object__load() has various return code, when it failed to load object, it must return err instead of return -EINVAL. Signed-off-by: Mao Wenan Acked-by: Andrii Nakryiko --- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 8f480e29a6b0..8e1dc6980fac 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -7006,7 +7006,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, err = bpf_object__load(obj); if (err) { bpf_object__close(obj); - return -EINVAL; + return err; } *pobj = obj;