From patchwork Thu Jan 17 01:01:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Fijalkowski X-Patchwork-Id: 1026362 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="unk0GC4h"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43g5QB6PcDz9sD9 for ; Thu, 17 Jan 2019 12:02:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727410AbfAQBCJ (ORCPT ); Wed, 16 Jan 2019 20:02:09 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:39633 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727306AbfAQBCI (ORCPT ); Wed, 16 Jan 2019 20:02:08 -0500 Received: by mail-lf1-f66.google.com with SMTP id n18so6443583lfh.6 for ; Wed, 16 Jan 2019 17:02:07 -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=Lrfa+WMB3a5ZAdgxiBeW/96MxdHxwgYMhQux9k0HMw4=; b=unk0GC4hmM6a31V33XaKjsdfm9vZgp1iDfRqKEcdQNySYbr8VGJ53k7TEXSZImenzl JURmeZ5t9vErmBtOZ7WbT9kg1xc+rRqaYIOTBPwiLgBSvLeCTPeyFYhKrr35TOac48EP YW4zjKhEziG/seQbo2/cZophzWKwi5Vh1OS0Rj9s4A895sxl6zDs0fl7zlOMPU9CrX0v WJevIEYxei2om6FJDQZnFoTNJDSO5of5e7ZhDafSNR1RLLBfi1+qxNURfkisGOlH+usy wVbacoCTQl6Ag6l0h349i71dtQ0YHIUqvHe4C2wiIfxDvjTZDapi6dIitCgnFQnPVRBB Mw3Q== 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=Lrfa+WMB3a5ZAdgxiBeW/96MxdHxwgYMhQux9k0HMw4=; b=ILrTNDWpX9TjvhkAUxmYTvaVM0qHpUu2+QtMiMHEE647IZ9zezIW6vWVE+Bd0ZwOzF tb6n2hEunYIyHuqxMx1qKQ0FNjjYW2phpIwhT+9y4i6mYt7CzGpqPKR1TkTykGmCTdu6 8DWIzpWXAyRHI/k/G2YpGWYpBq195rwOEPBPXKDDTJ7WvOYz+WssLg+KVMczuLnhrmjM Dst3H+YHB1SfuLsEeNJWY8cSKjkN+C1JrcNCe7rfDNxCpUEZqngKTBvX4xHYMjbpNdWn wY1DFkjM36DWVInDfF5V/xjxN0ie++ZPDhlSoDxK5bTbrvB1RiF7t5NjTgLDrn9moo+d Zlbg== X-Gm-Message-State: AJcUukfxBb/6KQTU7FJQzxsNMAT99ICaVySfH954Ftw4Lr6khbY0Ommh WlRT1zm9GUwLjW8RZPeUsh1VqoUQ X-Google-Smtp-Source: ALg8bN4FL0DgE15f+JSLdLkZEfWBBZXgfqaDkbrP9deDTMbcZizfOXPqne6fWVLunAzlsXbaIjOzsw== X-Received: by 2002:a19:4bc9:: with SMTP id y192mr8751073lfa.49.1547686926525; Wed, 16 Jan 2019 17:02:06 -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 l17sm4341lfk.40.2019.01.16.17.02.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Jan 2019 17:02:05 -0800 (PST) From: Maciej Fijalkowski To: daniel@iogearbox.net, ast@kernel.org Cc: netdev@vger.kernel.org, jakub.kicinski@netronome.com, brouer@redhat.com Subject: [PATCH bpf-next 3/6] samples: bpf: Extend RLIMIT_MEMLOCK for xdp_{sample_pkts, router_ipv4} Date: Thu, 17 Jan 2019 02:01:12 +0100 Message-Id: <20190117010115.18234-4-maciejromanfijalkowski@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20190117010115.18234-1-maciejromanfijalkowski@gmail.com> References: <20190117010115.18234-1-maciejromanfijalkowski@gmail.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 --- 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;