From patchwork Fri Feb 1 00:19:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Fijalkowski X-Patchwork-Id: 1034540 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=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GL5wrp/S"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43rHnJ2RPpz9sMl for ; Fri, 1 Feb 2019 11:20:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728885AbfBAAUf (ORCPT ); Thu, 31 Jan 2019 19:20:35 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46389 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728468AbfBAAUU (ORCPT ); Thu, 31 Jan 2019 19:20:20 -0500 Received: by mail-lf1-f65.google.com with SMTP id f5so3707829lfc.13 for ; Thu, 31 Jan 2019 16:20:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IdFDd7FlwtxfWeyfo8vy1Mb3DPIEiT2KinMeWYppe6g=; b=GL5wrp/SMOeSI3uA0JV7UcE+Fvvg7KzLdugX9bH4UIB8XvG73xcj9rBUJhCUFHhI4F GWnrGbbmiEJ6zz4nu/e1IJJT3gh0XiGA1YzHLbuUIOuoYOTT0W3L4yMD6KnC4/y9TlNz OazT8wbfiNiB9LR8LULYlSUbiiL9nHhTsZsOn5gPrhC66wgc8/ODP4kM25DUYWR9fZoi 9OVgMOZk6FkNURwDtivZ+x5+DgeovZdRueO7Z9QDSDovmuaE6TM83cLnBwzoN6wTxu9+ Vjm3GVuvJIG3PDgyxe0+yLsE1TG1RQR+VQ5X+MuCVpoG1snRlJy7GaoFUZ7WGQ+1/fij FEPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IdFDd7FlwtxfWeyfo8vy1Mb3DPIEiT2KinMeWYppe6g=; b=nI52wwTu+AuJ55NyMkVQ+hZfRm5G4dFfliaLHgSIHbHTMXhJ3xXPcoPFjeyr4dJZE8 SL3478AFIF3LSl4CpJqO6jY3DAmSTANjW5a/9RzssrC0vvN/PW7tb5diF3nRaMsAYv/I sLv+6C2QwAk47aV2lkIQaQqxVLrduZ7t9c0DJld9hbanKsMOj962BIMbnP1tJgWDQ2oQ qfP1vzMHHs7s5YSu8HyCtU2F7wkVtlJYx1912p0HM/YGokc564aWFiBuvzBIfEnC/u4D xqmakk6+BwHRdWaPHa0sXvSNUJvhWMg+uYcGi13ZHnserpyy1y7kmM9dBiGQkaVscDtI s80Q== X-Gm-Message-State: AJcUukfIZcN2sXnt8GPmMU5JXmFZqudhhEF7yOHiYE7klNOs45cOvCu3 SQ0CAzz3fPzfkUy8gUOHUxNQK2m0dss= X-Google-Smtp-Source: ALg8bN4J2d4kXQEqjM+2n29KTf/3FGotK98oK17GIjQ+zm6GluJ7CBzk81v2X1PidWkKqYl4asCOmA== X-Received: by 2002:a19:8c1b:: with SMTP id o27mr27915936lfd.90.1548980418714; Thu, 31 Jan 2019 16:20:18 -0800 (PST) Received: from localhost.localdomain (host-185-93-94-63.ip-point.pl. [185.93.94.63]) by smtp.gmail.com with ESMTPSA id j18-v6sm1005495ljc.52.2019.01.31.16.20.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Jan 2019 16:20:18 -0800 (PST) From: Maciej Fijalkowski X-Google-Original-From: Maciej Fijalkowski To: daniel@iogearbox.net, ast@kernel.org Cc: netdev@vger.kernel.org, jakub.kicinski@netronome.com, brouer@redhat.com, john.fastabend@gmail.com Subject: [PATCH bpf-next v5 4/8] samples/bpf: Extend RLIMIT_MEMLOCK for xdp_{sample_pkts, router_ipv4} Date: Fri, 1 Feb 2019 01:19:50 +0100 Message-Id: <20190201001954.4130-5-maciej.fijalkowski@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20190201001954.4130-1-maciej.fijalkowski@intel.com> References: <20190201001954.4130-1-maciej.fijalkowski@intel.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is a common problem with xdp samples that happens when user wants to run a particular sample and some bpf program is already loaded. The default 64kb RLIMIT_MEMLOCK resource limit will cause a following error (assuming that xdp sample that is failing was converted to libbpf usage): libbpf: Error in bpf_object__probe_name():Operation not permitted(1). Couldn't load basic 'r0 = 0' BPF program. libbpf: failed to load object './xdp_sample_pkts_kern.o' Fix it in xdp_sample_pkts and xdp_router_ipv4 by setting RLIMIT_MEMLOCK to RLIM_INFINITY. Signed-off-by: Maciej Fijalkowski Reviewed-by: Jakub Kicinski Acked-by: Jesper Dangaard Brouer Acked-by: John Fastabend --- samples/bpf/xdp_router_ipv4_user.c | 7 +++++++ samples/bpf/xdp_sample_pkts_user.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/samples/bpf/xdp_router_ipv4_user.c b/samples/bpf/xdp_router_ipv4_user.c index cea2306f5ab7..c63c6beec7d6 100644 --- a/samples/bpf/xdp_router_ipv4_user.c +++ b/samples/bpf/xdp_router_ipv4_user.c @@ -25,6 +25,7 @@ #include #include "bpf_util.h" #include "bpf/libbpf.h" +#include int sock, sock_arp, flags = 0; static int total_ifindex; @@ -609,6 +610,7 @@ static int monitor_route(void) int main(int ac, char **argv) { + struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; struct bpf_prog_load_attr prog_load_attr = { .prog_type = BPF_PROG_TYPE_XDP, }; @@ -635,6 +637,11 @@ int main(int ac, char **argv) ifname_list = (argv + 1); } + if (setrlimit(RLIMIT_MEMLOCK, &r)) { + perror("setrlimit(RLIMIT_MEMLOCK)"); + return 1; + } + if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) return 1; diff --git a/samples/bpf/xdp_sample_pkts_user.c b/samples/bpf/xdp_sample_pkts_user.c index 8dd87c1eb560..5f5828ee0761 100644 --- a/samples/bpf/xdp_sample_pkts_user.c +++ b/samples/bpf/xdp_sample_pkts_user.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "perf-sys.h" #include "trace_helpers.h" @@ -99,6 +100,7 @@ static void sig_handler(int signo) int main(int argc, char **argv) { + struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; struct bpf_prog_load_attr prog_load_attr = { .prog_type = BPF_PROG_TYPE_XDP, }; @@ -114,6 +116,11 @@ int main(int argc, char **argv) return 1; } + if (setrlimit(RLIMIT_MEMLOCK, &r)) { + perror("setrlimit(RLIMIT_MEMLOCK)"); + return 1; + } + numcpus = get_nprocs(); if (numcpus > MAX_CPUS) numcpus = MAX_CPUS;