From patchwork Tue May 15 19:06:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 913873 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=fail (p=none dis=none) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40ln9r5mnQz9s01 for ; Wed, 16 May 2018 05:06:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752470AbeEOTGy (ORCPT ); Tue, 15 May 2018 15:06:54 -0400 Received: from mga09.intel.com ([134.134.136.24]:36358 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752351AbeEOTGw (ORCPT ); Tue, 15 May 2018 15:06:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 May 2018 12:06:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,404,1520924400"; d="scan'208";a="51095703" Received: from twgeistx-mobl2.ger.corp.intel.com (HELO btopel-mobl1.ger.corp.intel.com) ([10.249.39.165]) by orsmga003.jf.intel.com with ESMTP; 15 May 2018 12:06:46 -0700 From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: bjorn.topel@gmail.com, magnus.karlsson@gmail.com, magnus.karlsson@intel.com, alexander.h.duyck@intel.com, alexander.duyck@gmail.com, john.fastabend@gmail.com, ast@fb.com, brouer@redhat.com, willemdebruijn.kernel@gmail.com, daniel@iogearbox.net, mst@redhat.com, netdev@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , michael.lundkvist@ericsson.com, jesse.brandeburg@intel.com, anjali.singhai@intel.com, qi.z.zhang@intel.com, intel-wired-lan@lists.osuosl.org Subject: [RFC PATCH bpf-next 03/12] xsk: introduce xdp_umem_frame Date: Tue, 15 May 2018 21:06:06 +0200 Message-Id: <20180515190615.23099-4-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180515190615.23099-1-bjorn.topel@gmail.com> References: <20180515190615.23099-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Björn Töpel The xdp_umem_frame holds the address for a frame. Trade memory for faster lookup. Later, we'll add DMA address here as well. Signed-off-by: Björn Töpel --- include/net/xdp_sock.h | 8 +++++--- net/xdp/xdp_umem.c | 29 +++++++++++++++++++++++++---- net/xdp/xdp_umem.h | 9 +-------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index c959aa43fb01..09068c4f068e 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -29,16 +29,18 @@ struct xdp_umem_props { u32 nframes; }; +struct xdp_umem_frame { + void *addr; +}; + struct xdp_umem { struct xsk_queue *fq; struct xsk_queue *cq; + struct xdp_umem_frame *frames; struct page **pgs; struct xdp_umem_props props; u32 npgs; u32 frame_headroom; - u32 nfpp_mask; - u32 nfpplog2; - u32 frame_size_log2; struct user_struct *user; struct pid *pid; unsigned long address; diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index 7cc162799744..b426cbe3151a 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -92,6 +92,9 @@ static void xdp_umem_release(struct xdp_umem *umem) umem->pgs = NULL; } + kfree(umem->frames); + umem->frames = NULL; + xdp_umem_unaccount_pages(umem); out: kfree(umem); @@ -181,7 +184,8 @@ int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) { u32 frame_size = mr->frame_size, frame_headroom = mr->frame_headroom; u64 addr = mr->addr, size = mr->len; - unsigned int nframes, nfpp; + u32 nfpplog2, frame_size_log2; + unsigned int nframes, nfpp, i; int size_chk, err; if (!umem) @@ -234,9 +238,6 @@ int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) umem->pgs = NULL; umem->user = NULL; - umem->frame_size_log2 = ilog2(frame_size); - umem->nfpp_mask = nfpp - 1; - umem->nfpplog2 = ilog2(nfpp); atomic_set(&umem->users, 1); err = xdp_umem_account_pages(umem); @@ -246,6 +247,26 @@ int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) err = xdp_umem_pin_pages(umem); if (err) goto out_account; + + umem->frames = kcalloc(nframes, sizeof(*umem->frames), GFP_KERNEL); + if (!umem->frames) { + err = -ENOMEM; + goto out_account; + } + + frame_size_log2 = ilog2(frame_size); + nfpplog2 = ilog2(nfpp); + for (i = 0; i < nframes; i++) { + u64 pg, off; + char *data; + + pg = i >> nfpplog2; + off = (i & (nfpp - 1)) << frame_size_log2; + + data = page_address(umem->pgs[pg]); + umem->frames[i].addr = data + off; + } + return 0; out_account: diff --git a/net/xdp/xdp_umem.h b/net/xdp/xdp_umem.h index 32ad59b7322f..0a969384af93 100644 --- a/net/xdp/xdp_umem.h +++ b/net/xdp/xdp_umem.h @@ -19,14 +19,7 @@ static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx) { - u64 pg, off; - char *data; - - pg = idx >> umem->nfpplog2; - off = (idx & umem->nfpp_mask) << umem->frame_size_log2; - - data = page_address(umem->pgs[pg]); - return data + off; + return umem->frames[idx].addr; } static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem,