From patchwork Thu Aug 15 12:13:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 171435 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2106801ily; Thu, 15 Aug 2019 05:14:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLKCosQavGcJAzOdmnY0+bm6j1vnZ8AVjq1k61Twosuv+WBUTthARvksRNtv6smx3FwMlk X-Received: by 2002:a63:3009:: with SMTP id w9mr3433158pgw.260.1565871275044; Thu, 15 Aug 2019 05:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565871275; cv=none; d=google.com; s=arc-20160816; b=x8aypkeWqpUTFkLHR9e0otwhpMIwycHvwz0fDB5yVyLi6Zd+yr6FPyROi/AEVLubJe E4XWEayA95ZGtA+KKYkaBnK6BQNlmcbTXd5C0BjM0dIvUmfGpS2juXaFUHaJMsLPF7ie stflca+KARmbxnDtX49j6xnR3mSQmXNTmHNgWZZjkF50rspF39xgaC9SxSDbgioqsLF8 ZTAfQs62FXwXq4AcUDZI8f/alfy7nL+HgdBWZGhHb909yWo4lZAPnSIeCUbOwloCEqEF Vr3Ptz5mY1gab9DmFogGOCqc8JKCoroodtDQWFVIeQSdLrz4oengahE3pGmGj/i61678 7gnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=33puqWwMZjyd4TYEQvWXwTMbXdpLyUiQZumxgi8mks8=; b=i+Oft8ClaefdVPYIsfjR/s2OzA5YhDRuwzVJ+nz4+LBk/z2ae0oVdn8aEIIOxLH2Vw 8UqffIYj6hjohMD3ZYxQeWPstZ5/HpUNbWDcg9zAm6XWNLMvQiSH3cDQy/cqH/NcJxks SgKWxfoFQRYV62b/np9NO4rpTDEIXvuysCIXt7DOBCmgT3E2wIRsH7m+ZOf+Yz63Ixsm xoHbeVkipbjek4HurWfRlaGs79DT1POafYpOyPzbZ3Z5CvaBmWkezbAYP8SCIvo71p7J nZMPwfFxnIgz2Ov2gxNsDd7YfaI/VdYC9o7L8KklAHi62L7nY9gxnYEFvc9KklQaJMhw 09wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pe3tFCbO; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n14si1990139pfq.108.2019.08.15.05.14.34; Thu, 15 Aug 2019 05:14:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pe3tFCbO; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731753AbfHOMOd (ORCPT + 8 others); Thu, 15 Aug 2019 08:14:33 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35303 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731771AbfHOMOa (ORCPT ); Thu, 15 Aug 2019 08:14:30 -0400 Received: by mail-lj1-f194.google.com with SMTP id l14so2059167lje.2 for ; Thu, 15 Aug 2019 05:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=33puqWwMZjyd4TYEQvWXwTMbXdpLyUiQZumxgi8mks8=; b=pe3tFCbO2RnIoNE/LB44dZjDO8vQ7HB0YywwEaUvwc5hJvVjxuiE04bAv94cX33+Sb NgfDL1T8IKqF3c1g4406lT/qYceHkQd/qshFBjOdaqP0ZHzyj22HHZu/JeWW/rtMix7c m39QlnkRsMxEe5HcgnuAWA4njyQHElgbOlKYwH25btDHvOouEnZJsGaTKpnzVGBf8/yN R0Ph7iMRYy/FpaLft34m9NQOPCOF8oqq82MwG1boLLjuhRBGiOLFaxNaUfXg5jdJyQe2 fmIudYQsUC1xRYY1XirqkuFbwtTbggb9/i+QGg04jjfUgpk5DfFV73t8cz/EwME7GcTN iuXA== 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=33puqWwMZjyd4TYEQvWXwTMbXdpLyUiQZumxgi8mks8=; b=YlXRSSKE30sTON96yS0jk9iubYWuc7wwob+mR6R/Fuu+A/REXTcwW7T66+/YYiuOXE O1VXIv9z6A+/mp935ClDOfc/NiyjTeYvvaW2jgfy7MWvz9jkt+bBaAFQKDjix9yO/TIJ Jur7iSvPcWVJ3U861qJRweMBgBDrqDgvWLAGw1RXcdxAdTB5u/f7z6gRiHoNvfCFoDsG OM+klC41Hq5AFydX7KivpIMt+qHa5E5Uzj1c8PPL/jS5sv2BIYTpOBo/9ft4b+bNd5MM MiWAbhELe5UHJRRj1pw25tq7/HvZKb7No/c/ZzZeFAo21sbckLxz1YwBPEomHB0qYZNt 8CaQ== X-Gm-Message-State: APjAAAXv/RRVDQDwlhK2uMnvHq9TPnNtvBOzI/J6uh0+ZyJjLAcJBylC fz84E20C+9lInp/iPrjglX5Slw== X-Received: by 2002:a2e:81c3:: with SMTP id s3mr2567234ljg.70.1565871268718; Thu, 15 Aug 2019 05:14:28 -0700 (PDT) Received: from localhost.localdomain (168-200-94-178.pool.ukrtel.net. [178.94.200.168]) by smtp.gmail.com with ESMTPSA id q25sm462060ljg.30.2019.08.15.05.14.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 15 Aug 2019 05:14:28 -0700 (PDT) From: Ivan Khoronzhuk To: magnus.karlsson@intel.com, bjorn.topel@intel.com Cc: davem@davemloft.net, hawk@kernel.org, john.fastabend@gmail.com, jakub.kicinski@netronome.com, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org, xdp-newbies@vger.kernel.org, linux-kernel@vger.kernel.org, jlemon@flugsvamp.com, yhs@fb.com, andrii.nakryiko@gmail.com, Ivan Khoronzhuk Subject: [PATCH bpf-next v2 2/3] xdp: xdp_umem: replace kmap on vmap for umem map Date: Thu, 15 Aug 2019 15:13:55 +0300 Message-Id: <20190815121356.8848-3-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190815121356.8848-1-ivan.khoronzhuk@linaro.org> References: <20190815121356.8848-1-ivan.khoronzhuk@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For 64-bit there is no reason to use vmap/vunmap, so use page_address as it was initially. For 32 bits, in some apps, like in samples xdpsock_user.c when number of pgs in use is quite big, the kmap memory can be not enough, despite on this, kmap looks like is deprecated in such cases as it can block and should be used rather for dynamic mm. Signed-off-by: Ivan Khoronzhuk --- net/xdp/xdp_umem.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) -- 2.17.1 Acked-by: Jonathan Lemon diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index a0607969f8c0..d740c4f8810c 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "xdp_umem.h" #include "xsk_queue.h" @@ -170,7 +170,30 @@ static void xdp_umem_unmap_pages(struct xdp_umem *umem) unsigned int i; for (i = 0; i < umem->npgs; i++) - kunmap(umem->pgs[i]); + if (PageHighMem(umem->pgs[i])) + vunmap(umem->pages[i].addr); +} + +static int xdp_umem_map_pages(struct xdp_umem *umem) +{ + unsigned int i; + void *addr; + + for (i = 0; i < umem->npgs; i++) { + if (PageHighMem(umem->pgs[i])) + addr = vmap(&umem->pgs[i], 1, VM_MAP, PAGE_KERNEL); + else + addr = page_address(umem->pgs[i]); + + if (!addr) { + xdp_umem_unmap_pages(umem); + return -ENOMEM; + } + + umem->pages[i].addr = addr; + } + + return 0; } static void xdp_umem_unpin_pages(struct xdp_umem *umem) @@ -312,7 +335,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) u32 chunk_size = mr->chunk_size, headroom = mr->headroom; unsigned int chunks, chunks_per_page; u64 addr = mr->addr, size = mr->len; - int size_chk, err, i; + int size_chk, err; if (chunk_size < XDP_UMEM_MIN_CHUNK_SIZE || chunk_size > PAGE_SIZE) { /* Strictly speaking we could support this, if: @@ -378,10 +401,11 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) goto out_account; } - for (i = 0; i < umem->npgs; i++) - umem->pages[i].addr = kmap(umem->pgs[i]); + err = xdp_umem_map_pages(umem); + if (!err) + return 0; - return 0; + kfree(umem->pages); out_account: xdp_umem_unaccount_pages(umem);