From patchwork Fri Oct 18 04:19:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 61458 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AFB461BF27; Fri, 18 Oct 2019 06:20:01 +0200 (CEST) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by dpdk.org (Postfix) with ESMTP id 1EF19B62 for ; Fri, 18 Oct 2019 06:20:00 +0200 (CEST) Received: by mail-pf1-f177.google.com with SMTP id y22so3027406pfr.3 for ; Thu, 17 Oct 2019 21:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=GqULp09w03Ek7k7VtFlaeaXLOyfWXyfLCtovhmrGlEo=; b=uwe78rO8B657lM9222nudJcaPBdTpxi91iO253sqiHgy+EluHAq42MQH+ZsLRJz/tL l60Yf617gsnK1l17avj7Y3neCcSjy+cD1RIslBLO0Qu3r1eRJCdvOXJMOOPHDjHQqASP JhIE5i2m5Y4afGp+zZhh67wa2Spwcc67hpQhGVgjTT8mZb4E5Zm4JFM1FMRsRKamJBIw GJC4goiKAfcXGx4untNMtLZE/DiyeXqnqfYCxRZbE4gKA6zF/60rv0OATomOgd/fkDXB 236JiV88gbeVD1kq68Q9VE2rouE7YQz2E8OqbUC3dsCp3VdkaYGhwZuUu+ySodR+w3xw rYcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=GqULp09w03Ek7k7VtFlaeaXLOyfWXyfLCtovhmrGlEo=; b=KcTAz06CUJfUgo3TU2/cLd9VBlPYn+48Qrd7I6KmA04+h8wrQKBypLoWvYKEU3DHfC ZRuno25IaA6uGRIWpUKFbt1yYFaVIKiPZkS+yQ0zayBHNWP1Ke6BxugsnuOaGcxDmKGa hS2pyIyxJqd/oU9/UDFcjOXJuhlhPCdAJOj9mUOweqxy/flDPbkYin1Ku4GXgba18i8z aQognetOg6eNUMDxKD6wd6nsTh2pxltjTbk3zNhzAP7jIumJmzsFxc43bB7z75mI+lrI KvuIm2BfAELJGhQJ7TKWIWPgCFAlg83Yk8FzbK2woMTXKsGAqCo5kui+zUlVF66FZeYr i6Ag== X-Gm-Message-State: APjAAAW19ZDZ0SShEf3JhfEfZBD3qxkg5JU0GYGhDyR03nYUcXhUWgZZ jGZ3NieA4kgWGmW/iFh5BpAfdnu2u+lSsQ== X-Google-Smtp-Source: APXvYqywsxhGBGIJqMBg0CEYw6232jYZ57BlbtpxUAPG57dzZiTOMyMTyDatOF6+63k5eTGdOxNc/g== X-Received: by 2002:a63:e1f:: with SMTP id d31mr7797215pgl.379.1571372399074; Thu, 17 Oct 2019 21:19:59 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id d5sm6325902pfa.180.2019.10.17.21.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 21:19:58 -0700 (PDT) Date: Thu, 17 Oct 2019 21:19:52 -0700 From: Stephen Hemminger To: "Ananyev, Konstantin" Cc: dev@dpdk.org Message-ID: <20191017211952.6ebf0312@hermes.lan> MIME-Version: 1.0 Subject: [dpdk-dev] ebpf issues with secondary process. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Trying to use the existing BPF code in BPF for packet filter is possible. But one road block is that capture wants to allow a secondary process to insert a packet filter. The current code in bpf_load() won't work for that. The BPF program needs to be in shared area to allow secondary process to work. Why does the code use mmap() as an allocator instead of rte_malloc? Something like the diff below (untested). JIT would have the same problem but you would have issues with the mprotect stuff with huge pages. I also noticed that bpf code is not using rte_memcpy and it has unnecessary casts to void *. diff --git a/lib/librte_bpf/bpf.c b/lib/librte_bpf/bpf.c index 7e1879ffa5b5..d6995bbf0ba9 100644 --- a/lib/librte_bpf/bpf.c +++ b/lib/librte_bpf/bpf.c @@ -22,7 +22,7 @@ rte_bpf_destroy(struct rte_bpf *bpf) if (bpf != NULL) { if (bpf->jit.func != NULL) munmap(bpf->jit.func, bpf->jit.sz); - munmap(bpf, bpf->sz); + rte_free(bpf); } } diff --git a/lib/librte_bpf/bpf_load.c b/lib/librte_bpf/bpf_load.c index 2a3b901d74c3..9a8e438a8963 100644 --- a/lib/librte_bpf/bpf_load.c +++ b/lib/librte_bpf/bpf_load.c @@ -32,9 +32,8 @@ bpf_load(const struct rte_bpf_prm *prm) bsz = sizeof(bpf[0]); sz = insz + xsz + bsz; - buf = mmap(NULL, sz, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (buf == MAP_FAILED) + buf = rte_malloc("bpf", sz, 0); + if (buf == NULL) return NULL; bpf = (void *)buf;