Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3709370imu; Mon, 28 Jan 2019 09:24:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN7i3OZkh5HWo0S2idgoO+HxS52sEtqHHhfVI7ioohs3dOqVXjhCO4GQ3ETQSAUSgRu8yR0s X-Received: by 2002:a65:4b82:: with SMTP id t2mr20620826pgq.189.1548696288387; Mon, 28 Jan 2019 09:24:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696288; cv=none; d=google.com; s=arc-20160816; b=kprHnO1RxgDS4I/AewZdBApjV+WTEWtCIMX0zock2eDpzqAJo+/2HOeHTlgX4yiKjb XI6bWx5YS2zX44eKnG3bJoGLNj0oUgh1jL9vT7SekzR7QVSFgmIajUSr/w7VmoOAlERz BKrHpBhl3h1UZliKwLGFj2Agrkq3DTN6BY7ZEtmoo1VeFgvSRYWnQ+0Q/PfTs9X7hB3e OY1zDjoPM4ukFAvu1ChePn8XfQylLhXxL/bKjVdQVPEzXHXqqi1sRb6GdxWm25NgYzBC OlATMwUlRIi8w8ES85DpQvzqk4l71j22vgXOJNzCiWGA0Df5Xk8reMbgDcNtabA97VAo FlWg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5s3OZKq3nA3grGy4UONHO9cKQ5p66pDeBAPkEKp0MlU=; b=pgHJvR2vsuLhGXWB2Vi7G7TRMGqHk5o9qtK7aE2jqLEbS6hs1vDty9jnCQuqshxSaX 25RCWG6YTwl1oJMfZhTMzyW8zFl1a9mkDnA04avbBlwLmoI9iaNy6bKDVBWwbyPuXwpd jqqArj0SzQKkKt/lUDKD2sXQ2gQh9gv08+XEF3Qg8izZDRnDTdVKvuEdL4su2Zw1SeOF tg5M3UpRrNmeNDEdhulwrSR/aeay9jYgf8UHlFEsOprRlODRnRVJVa3ZhCIqpJ5IFpfz kvL77XAoLhOXiudZ0vC0v7QOtqvrL42SQ/80qGXLUDm5nLnys+URbMJvPSdpoFo+eIij O+3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l+we9Exo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l36si34026098plb.433.2019.01.28.09.24.33; Mon, 28 Jan 2019 09:24:48 -0800 (PST) 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=l+we9Exo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731081AbfA1QBl (ORCPT + 99 others); Mon, 28 Jan 2019 11:01:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:46896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731064AbfA1QBj (ORCPT ); Mon, 28 Jan 2019 11:01:39 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B58EE2175B; Mon, 28 Jan 2019 16:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691299; bh=04JFyb4oLAhGZ2NFy3SOSeScfuCQpZn7/Bxw8pJ+GVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l+we9ExoP9Q+vapx4zt//iOiMI8UCGNv4WpCuLcMjh29GWV63UhFE8GTfioqRQXV2 WTcg1uGoLX7R8klp0cy3a2GE1jdVpMpAkQQ9eEW1nQtRXZ4HMIlFPClrVYXJaznvIh Ru7qGhtYbRWse98W/ToRTamcRrxKR0mGng3MOgrc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stanislav Fomichev , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 050/258] bpf: libbpf: retry map creation without the name Date: Mon, 28 Jan 2019 10:55:56 -0500 Message-Id: <20190128155924.51521-50-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Fomichev [ Upstream commit 23499442c319412aa8e54e7a939e2eb531bdd77d ] Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name for maps. Pre v4.14 kernels don't know about map names and return an error about unexpected non-zero data. Retry sys_bpf without a map name to cover older kernels. v2 changes: * check for errno == EINVAL as suggested by Daniel Borkmann Signed-off-by: Stanislav Fomichev Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- tools/lib/bpf/bpf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 60aa4ca8b2c5..7a0014794bff 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -77,6 +77,7 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) { __u32 name_len = create_attr->name ? strlen(create_attr->name) : 0; union bpf_attr attr; + int ret; memset(&attr, '\0', sizeof(attr)); @@ -94,7 +95,15 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) attr.map_ifindex = create_attr->map_ifindex; attr.inner_map_fd = create_attr->inner_map_fd; - return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); + ret = sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); + if (ret < 0 && errno == EINVAL && create_attr->name) { + /* Retry the same syscall, but without the name. + * Pre v4.14 kernels don't support map names. + */ + memset(attr.map_name, 0, sizeof(attr.map_name)); + return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); + } + return ret; } int bpf_create_map_node(enum bpf_map_type map_type, const char *name, -- 2.19.1