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); From patchwork Thu Aug 15 12:13:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 171436 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2106840ily; Thu, 15 Aug 2019 05:14:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAbH87TxxyZYPeIQXVprNHgnNqPKMcoueRRLkHgF1FNFUCq9NNowTf0s+4Gx3PRuvOd3/d X-Received: by 2002:a17:902:b591:: with SMTP id a17mr4125767pls.189.1565871277035; Thu, 15 Aug 2019 05:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565871277; cv=none; d=google.com; s=arc-20160816; b=hZ6Odkcmzrt0eGqO63QW9dk13cUmocW06PWFijrdvzET5fY0vmYpWx/jJBZVb6/HbO NLVDhy8vDmQDudJ6trZB3Ib+kBqSwLBkkuTD393kyrQjdZrhrj5rA6RsTmHok+mvHQaW 7Fu/4xwIRiN5yd3K93zCDx0oHjrq734cLWX1ddqysYQHtZk0S3hJfj/szIXAmY+1Uz6Z dIQAs9/sVUK0fowXo6/ZwZgRwJIez3JvkO4tpEXHZ6WGjfm5Wb59ESDG0fXejMao4lSE 4Xd3bkGUqSm5GIIZMHSYFVKfNFlUVaHz9yperMyAuIAQt99FVJfrz3/HYDfKToSUXS1+ oQVQ== 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=aIVfXCW1+kiXSGueAdzDW1yyefj6NecEzYan4H+pqQc=; b=MeHVuTPEjH+aqCbf38BgBpxGm+5VqThVG/nJN5lbAM7l1tMlYnJsH3cTDVO+xuKPKN 8NnF/OOdt0nxInGGf+PWP2ss4lEXnxGAL8Sj96j31A6l/aF0moP6IrBI9xQkaFY/lDeF V1LXtEHTHQ3GaAZt4asAwkQC4NK++Yrx0oN+WmuDIH/mB+BIHdxetu3W8ToOun0uBABE cM1przc32pAv4Nud/u6x/Pjefs7rD5R3xrJ5umTv+PkxxZMueGMB8iQL4CiOmvhDUzyC AOji/sYArhc8a/YHi3Js7jK2flCgSnqSmFmTlRqdEfV+gs7LqtJGKwUaxgrthNmA8xBf dhMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IWRo0YgI; 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.36; Thu, 15 Aug 2019 05:14:37 -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=IWRo0YgI; 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 S1731774AbfHOMOg (ORCPT + 8 others); Thu, 15 Aug 2019 08:14:36 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:36781 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731777AbfHOMOc (ORCPT ); Thu, 15 Aug 2019 08:14:32 -0400 Received: by mail-lf1-f67.google.com with SMTP id j17so1510142lfp.3 for ; Thu, 15 Aug 2019 05:14:30 -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=aIVfXCW1+kiXSGueAdzDW1yyefj6NecEzYan4H+pqQc=; b=IWRo0YgIC5PrnJ7KHBk5p2MKI1bMnA25MrpR3+u6sXtARJMClbHlRjCEeBl8LlYmw+ CuA31luU5HMV8WIcc8wNZzm3INx7zoxVpNydrj/gZHlq3e6d7oTsqmtP/NkFCyrMsRvF 36oQVwiV3yUfI0TdJSpqkg73xRcBNxJBbyaqRQE+Xe/z1xejqHw1z1j67k8meNUe1BVU Mb7yn4eVM87G0tC/eNq9T/gJtQiOquVYAIS0t5nmxbHTyZkgyvRm0tyaatmWjeeghO1g 3Ab7WzGzwRqzwZ5zQS5gisf5Nnj7vvq543McaqHLPDAo0FNTP+icYMYi/mj7t2rAzo1k ybsw== 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=aIVfXCW1+kiXSGueAdzDW1yyefj6NecEzYan4H+pqQc=; b=oHjMpmTHN9hOCIc3rQ4hiMSvD62+BJ+lPi/lkwpTOg0Lf4TO5ZYIQI3wqDRm99Nep6 GU7DYGj30UvNzkfFb/t22IIZk1AjkXWAvmY/TvBzvsIEAh+hFSQdAykuI0QN33Bg10Dc 8VRWmLkFX0raJvYwn5MI4aIfgKY1fwgrlAGTAYoAI5b3Xt72PCoPxhcfVgor+G/3GGuk PMio6vcrSzfIE0z0rTJxSHxvosu/O3yTbhPatIFPCkjIcTYtnJph6Nmc3ZIz+Y3Nhhcn d0OrPo6WrREUR5CA5vtgQ4FkD4lyBkojyAITM7EOOZHhZnDhKut8M3YE5iBElpVUiau2 lRoQ== X-Gm-Message-State: APjAAAXIQwAppC/jhaAPBWfJW2a7tUxJs40B7TGh3ynSQcc2zVGtMjV9 PI7RR3Zw26flOlLh/Yx8E8ui7g== X-Received: by 2002:ac2:599b:: with SMTP id w27mr2300688lfn.75.1565871270040; Thu, 15 Aug 2019 05:14:30 -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.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 15 Aug 2019 05:14:29 -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 3/3] samples: bpf: syscal_nrs: use mmap2 if defined Date: Thu, 15 Aug 2019 15:13:56 +0300 Message-Id: <20190815121356.8848-4-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 arm32 xdp sockets mmap2 is preferred, so use it if it's defined. Declaration of __NR_mmap can be skipped and it breaks build. Signed-off-by: Ivan Khoronzhuk --- samples/bpf/syscall_nrs.c | 6 ++++++ samples/bpf/tracex5_kern.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) -- 2.17.1 diff --git a/samples/bpf/syscall_nrs.c b/samples/bpf/syscall_nrs.c index 516e255cbe8f..88f940052450 100644 --- a/samples/bpf/syscall_nrs.c +++ b/samples/bpf/syscall_nrs.c @@ -9,5 +9,11 @@ void syscall_defines(void) COMMENT("Linux system call numbers."); SYSNR(__NR_write); SYSNR(__NR_read); +#ifdef __NR_mmap2 + SYSNR(__NR_mmap2); +#endif +#ifdef __NR_mmap SYSNR(__NR_mmap); +#endif + } diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c index f57f4e1ea1ec..35cb0eed3be5 100644 --- a/samples/bpf/tracex5_kern.c +++ b/samples/bpf/tracex5_kern.c @@ -68,12 +68,25 @@ PROG(SYS__NR_read)(struct pt_regs *ctx) return 0; } +#ifdef __NR_mmap2 +PROG(SYS__NR_mmap2)(struct pt_regs *ctx) +{ + char fmt[] = "mmap2\n"; + + bpf_trace_printk(fmt, sizeof(fmt)); + return 0; +} +#endif + +#ifdef __NR_mmap PROG(SYS__NR_mmap)(struct pt_regs *ctx) { char fmt[] = "mmap\n"; + bpf_trace_printk(fmt, sizeof(fmt)); return 0; } +#endif char _license[] SEC("license") = "GPL"; u32 _version SEC("version") = LINUX_VERSION_CODE;