Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2650772imj; Mon, 11 Feb 2019 06:29:03 -0800 (PST) X-Google-Smtp-Source: AHgI3IaXcFv4AmDMO3u8lcHuQZV4d8aJ9sEu1tDZTCQDYB/VY0yfoInsOFdKElAT7gIKRiht0uwg X-Received: by 2002:aa7:8759:: with SMTP id g25mr28065963pfo.248.1549895343736; Mon, 11 Feb 2019 06:29:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895343; cv=none; d=google.com; s=arc-20160816; b=jGxKo0KP3fSHqAR+8KvLg9tQ51S+h5FDdPbZt2U2pGPzMnzdOGyYQ6V+DB6obfyrmu Qofc1+H4BmCcI/FzxpjFZ22K1H7FfpZ20ucwO0Pfh6s0Q4QqeZ4VWxaHrYPDNC7327uM DlfhcWc+rG14cYoxKjlmsTovctYinDhLyrakp//jEKafzBwtd6LHCXQ7fNoZz6+6rEgm BSkzD9Xdh6UfM2gR4r6MbWbX+V403jB2M/fHbK/7vQLwJbCv7Y/9elSq1AP+j2h1HU2e 7G95g/PF9myrUeLx4V7F3pe3a1bPCVthJhW9EHjlIRowYY8QcQ5S4rPCn7Yc7djSom6E F8bQ== 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=zFqG3IjzWw3e36WkRuxSCbgwbw8T3T+rdf4pB5Bcmw0=; b=yqgdK714QkpwTDcvL3UY1epgdjKizelg0bd6d3Sd3+GZ13Z+YiaZ+CUvremvTFpeMm FGA6DUe6FHWmMtfCgLRdHVAf+bSV1mA3Z1vGBhgaPiij5eNW14+XiNgBNkYpGCvsZtOl sPkJsR1lu2W04P2ONYTYQsTVsr/gPftj5OgsEe41/ASFjtwjYGG81OSoMhi4B0mz44FE hgDjS5rn5VrKGxLZllfnc0LPaK5xSf3y7jplQTPD8sZZ0KghO6ZLE25W2WYERWsGjB8Q i8PAjoqBSirsf1++TiQdah15Y7CjM3CI1LjBczUFYnNqohBZZGwkaMikrKb4eLQiOcK6 AZ7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x5kaWWAh; 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 c1si9895493plr.55.2019.02.11.06.28.47; Mon, 11 Feb 2019 06:29:03 -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=x5kaWWAh; 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 S1729210AbfBKOYb (ORCPT + 99 others); Mon, 11 Feb 2019 09:24:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:57744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729201AbfBKOYa (ORCPT ); Mon, 11 Feb 2019 09:24:30 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 4326A20821; Mon, 11 Feb 2019 14:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895069; bh=QVA1vZRMxU56s2OSJtL/LlaOuDeiCH1S7spM/sMeGO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x5kaWWAhon7vXxcoECnT8nHgmeGLe2lm3lQ6bAdjDLGjmvOK9AmrCUixGSRFnpDcC z7Az4ebCsLYhVEdSwrjK30QK7Wm0yynBSKBlu2pqy9IZYa9/MmF6wbFylAailomhD2 1lFTxjgqITGdEHM46bO7qtLRQydmjQj5djKXD/40= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stanislav Fomichev , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.20 051/352] bpf: libbpf: retry map creation without the name Date: Mon, 11 Feb 2019 15:14:38 +0100 Message-Id: <20190211141849.476010499@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 03f9bcc4ef50..961e1b9fc592 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -69,6 +69,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)); @@ -86,7 +87,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