Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2165432ybl; Thu, 15 Aug 2019 07:33:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6iBGksCFC607vxJle+wE7Oi5VH8Gr4oayi4WbP5Kk5UOePLH9o0yjNI47gQBCZGcCyYv0 X-Received: by 2002:a17:902:e6:: with SMTP id a93mr4549206pla.175.1565879601950; Thu, 15 Aug 2019 07:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565879601; cv=none; d=google.com; s=arc-20160816; b=ZCykuM3lBpCotWsPOGuL8Zrdorsc6j8C1wR4Qq7siqJVosYOvopnH1ogzI+Ntqcb9k ZB1/87VUHddEtHSXp3bA6meQjVMWNK29unGuWs1dtKBYbEGbD2aADTErjjTcEsYAXBUF p7n58Mx8k8PTLHwIqRCS5+0DBT3gO6YaPC5BZohxzKfRh+fROnBBWTav0aIAFVUYEKg6 84BySGd97TqhVQ0flxoLdwvRQdpFS1WcszTRdIMEWRTVUU098fuHqu0jHAUvGzGP8Zl4 RIgsGeZ3gDhph1HnLPgeSG2Huz5j1KEbWW+dnqpN/4Qz5mX5ifV/KYZ7Ka78B67CC0Xz c3gg== 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=nbAoXKKvFwvjmuXVmXBhNZtEwMZ4tqM0ffzKFS4m6F8mV21upsPOIZ4SC1PKgjQN/y 6bWAU4LfP2fW687LHkt2lGr9N+KeOIEYB4V9+p6HA91EkhdTQ+p7be/ONLpu47ZWYMCi P9qzUiknSxoNuK7tzj+1gP4E7w3OwVLkRgCquBuen6h0izpOSJ9s75TjgyooAp4SgG5u noVQRqhuyfVZ5eCPkUeLZ2qMwcgJWrm+zuMBvqnF1UG+5FKkiccGG8dXbtY3oWKaJwk/ Q8Auyjh6/6JUArgx6xFsOq9JgjuvormM4Y608wWOQhy8arifa46c6w/FZziKWTBXeN/j xeIQ== 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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 f20si2155868pfn.166.2019.08.15.07.33.06; Thu, 15 Aug 2019 07:33:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1731812AbfHOMOe (ORCPT + 99 others); Thu, 15 Aug 2019 08:14:34 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46523 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731774AbfHOMOb (ORCPT ); Thu, 15 Aug 2019 08:14:31 -0400 Received: by mail-lj1-f193.google.com with SMTP id f9so2002991ljc.13 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=FrroZS/PBJO9gP7YvxIwo/p9UjDVIX8gUT0s/H9tIXHht/yD3gurKuJVZp0InoMf/m KZqmHeQwrtxU/Ik0Kxr2xW77lv4VqMQfyMxhdqi3NKrgpEI/ivtEKMoniyqrfuvLcf/h VgXYgdnUOUlBPEPQp4dnkvvbR8p7eElfCZS2cjk168ASeB1HQiC5Gjnm00DQESOp2wRk skQyUFlbVViAaRX5rYdcAT4RLT2esZSEtnRhHEfq/Ppmn5m9uLQ9EdGOXKFmpPIz2N3x a7cvwsHVWJgw8pfftR9XgiIFyKPwfDopXeVJY9Is5aZ1OmKkOf6Mpfk5dQjoQfprZHPD eWlg== X-Gm-Message-State: APjAAAUIxCYmjNW9xrqPR75BNId8i6SmqykOYZedVVZIeINYp9BRqYKO ZQYVRV+B0GPhEhDyOrBYB5eDTA== 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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); -- 2.17.1