From patchwork Fri Feb 1 21:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Fijalkowski X-Patchwork-Id: 1035214 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="KTefH86s"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43rrLl32P8z9sBZ for ; Sat, 2 Feb 2019 08:47:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726677AbfBAVr6 (ORCPT ); Fri, 1 Feb 2019 16:47:58 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33025 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726652AbfBAVr4 (ORCPT ); Fri, 1 Feb 2019 16:47:56 -0500 Received: by mail-lj1-f194.google.com with SMTP id v1-v6so7099143ljd.0 for ; Fri, 01 Feb 2019 13:47:55 -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=KTefH86six5kFyiH506GsH3Oi1CQ+f6Nlll2carlxiCw8v7CPlE08/Nm2b5W40ioUX 0YHWKPDOGWknBuKpQiCzIMEULnYQMzLC3+ym9lw6Ng3wwU3C1gNT5DtsF4cj1QcY3yL7 f50xsC4l2yiwWbnMVJUivseEwEClynZ4a+Gdxhk2f+rrr3lyOGJLM+3nIpZDL5tEgwHf TkH/qxWmS50ZC4sXGbsXW+ahm7lO+4g2u2DR2VN7k8qlqoUsvWb6mEMEVlgja4+7QsRf JWSImhZR7tsQ9ks26y6mjdWlXNJF0RHiUglgimbH7MeXiYSpHW6cjif7OPlcMAHZMqIJ o3bg== 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=YFhb3Aq9IYX3gy1d0Z3wix3iNK6sZxBXN5p3BCyZGOqGCu6eiqQGLJOJvEmGBgHbaJ NHRy/fmEmuVGmBkEWinjgGJS89Y/RmngX+YocDsENbFJkdUhHPgHJUKWFOLmsiBvVNx9 K8VrunDEXXMZhwS/w1QeeT/IYYsKor7hwGNfjBNIEJjw2tXGTW1wBaTwD9HKB3BKbkok yix/JCpYREzdYLD57o40JXQf+NsugUNvKKjMENw4jREmC5wuV6Gd9MKv6QAe670P1b4l 2b+arVV2nn7VhuNSP/cFM4vmilFd9TYtpXDxftvkf7HCGOMHNAiIwS4XkqFiqT0aJZXi T/eQ== X-Gm-Message-State: AHQUAubBPNrgbuypcyzaBXFxbQeqzL9r5isRzs6rVgkULM5+TJqWnA/C icG607CpJs1t26vuWvixgGM= X-Google-Smtp-Source: AHgI3Ia2OKB5pG71AhG3G/fxEUSXm4kAt6ounQ7B8CRn+c44Fp76leH6IG45dJoFlSsnWAuwWeQbZA== X-Received: by 2002:a2e:8546:: with SMTP id u6-v6mr18323016ljj.95.1549057674547; Fri, 01 Feb 2019 13:47:54 -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 d24-v6sm1456213ljg.2.2019.02.01.13.47.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 13:47:53 -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 v6 4/8] samples/bpf: Extend RLIMIT_MEMLOCK for xdp_{sample_pkts, router_ipv4} Date: Fri, 1 Feb 2019 22:42:26 +0100 Message-Id: <20190201214230.1441-5-maciej.fijalkowski@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20190201214230.1441-1-maciej.fijalkowski@intel.com> References: <20190201214230.1441-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;