From patchwork Thu Jan 24 21:47:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Fijalkowski X-Patchwork-Id: 1030698 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="i7JfpuJ1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43lwkW5dqSz9s55 for ; Fri, 25 Jan 2019 08:48:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728148AbfAXVsC (ORCPT ); Thu, 24 Jan 2019 16:48:02 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:33116 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728094AbfAXVsB (ORCPT ); Thu, 24 Jan 2019 16:48:01 -0500 Received: by mail-lf1-f67.google.com with SMTP id i26so5490531lfc.0 for ; Thu, 24 Jan 2019 13:47:59 -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=wX5pwMPNYGbgINWvvApWq9o21OMGSlcwcP8XyY14aw4=; b=i7JfpuJ1p2rQN04hm2fcpdKEKY0SVdccdMsJturOdnjdawoSEPzFA6WbQdcOCgbwZG iBZEffBBlVtwyIRiDCqrPfyJw2Bm10O5RZnBoJ7tYKw5Vy2C62iCReo22Jx1FI3xzTUk HE6OIOBarZftieDT3SoSY55BH3hrGEjjWTFeGTA7w+OWUub9M+zq877orRxTOyQ7vk85 OWRWStab1uUtlbmyR4Ky1cfFZVCD90oP/SHdF3i8jP5wIuwibSeNgIYRHoxNOKcO3Yup l9q+Nju+2vGzq8r/uiIK7qe0TN8n7tjtybi5z9dy+dEdGcDvTdV/QNn0B9sFSMSQRV2Y pHfA== 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=wX5pwMPNYGbgINWvvApWq9o21OMGSlcwcP8XyY14aw4=; b=Ern6D41dC5EOdTxayR/MQfENbCffUqraPiIcJFwUTgzVnB3QarG1q5595HNMfnwSlX cFQsdKSmSTcG5GUSihh/xNh9OOmzWjRbd3KFvwfQdsLPjzpQcovmKmoutV86J2JC+2hq ZEsvqsJ/IBJqgu6BCMQxH/2Bcr4TuozQBCfEifstpCODJbQmT9s6hI5EVoaA3q3hjYI/ BThAE3kNU6xyAr/AlShrEwkOydUt/M39eYsIv0XdsOIBI9qqMBWruyzKE1RLMkcJkQgo QMo9GNDPSmgpgqn8T7PjkBAYqpBXHoygzOi5fu+KVyOYT2R3OYgB3c3RQZcjMrQHKr8J lVRA== X-Gm-Message-State: AJcUukeCf7dNNzv2ZRn3Yq1F8eAqQkyQEoOx96OB9uGQVcxDf6Kv5wXB HRB/kIFjflnr9muMXSD8vqs= X-Google-Smtp-Source: ALg8bN4Od8vGvJ1broQQGEmjOzK8ATeRMw9GLDv71gyugcAUyX4We00PrnJgx3xgcNkWNsYAPpRvXw== X-Received: by 2002:a19:6514:: with SMTP id z20mr6684605lfb.31.1548366478915; Thu, 24 Jan 2019 13:47:58 -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 w4sm1136285lfk.83.2019.01.24.13.47.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Jan 2019 13:47:58 -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 v3 4/7] samples/bpf: Extend RLIMIT_MEMLOCK for xdp_{sample_pkts, router_ipv4} Date: Thu, 24 Jan 2019 22:47:44 +0100 Message-Id: <20190124214747.6986-5-maciejromanfijalkowski@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20190124214747.6986-1-maciejromanfijalkowski@gmail.com> References: <20190124214747.6986-1-maciejromanfijalkowski@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Maciej Fijalkowski 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 --- 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;