Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2961125lqt; Tue, 23 Apr 2024 06:59:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXvsLk4HAirQphCiSbKk+nIA5CVbLc6gsD+3VOk1o4aBEsD1JB4F/vEv6gQFW54DciL3u6T2fUK+6DaZJElOeGaltjeEmKCzIQ0hiR1MQ== X-Google-Smtp-Source: AGHT+IGOyuwQzRFWVsFqkfDbWl+V5e/jfz6kR+CmTynMF5dmAg1NsyWZO8Pqu3hPoVZNsCBBNkzL X-Received: by 2002:a17:90b:3783:b0:2ae:fdfc:312b with SMTP id mz3-20020a17090b378300b002aefdfc312bmr430048pjb.49.1713880745116; Tue, 23 Apr 2024 06:59:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713880745; cv=pass; d=google.com; s=arc-20160816; b=t2ABbecVTuM1YrWa6vPN8qDxI75VgBu5bSGPVyA4Z9Fm1vsZjTTv2X3hZpGyks2SDp lJSyd3RpliAUs7obVPKknbIerEO8HPewSaWIERt+M+BR30hE8u9wwXBgf3Q1SXJ5p+KA E/2MCzZPo2gQgE9Ixf792Jvt8jt1pefBMYkyaNBOVDq4liCxXA4gPYJNYm5badedfL/h Nlvs54gsStMZypooPJJKXzHE4URkpZ9e5R3tywjDmRVAmD4X3BXub1FYrU7acSP/IVWp UNILyK4+YqTU05noSMTTaxoAF6qkI2dXShEwy/wL/Q+sjlQ5OAhUhmUHIquczXMSRVUs WKtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=RLulHWT5zpCb2L5FFkT68BceSnJCiWpcsLqB3PL5DUk=; fh=XQR/2xX0Fo1qiXvWXbqY2WT0J3RtRMz5arolgjVK/GU=; b=J4ENPtQO0yH1VF5nt/smE9GT7wGS/lM8mGPXuiwBYpovlA1PrIh3c43ichtGSR5Bdx et5XbYVZ8Fl4BIk6EMWTODzGbVhujDJmOa4Q6KtUftAovY9TlpeJ3L9hyIvRII+nQwxp XKh+v0vTGx6hvFCDmGDJnHGAxPmLHKIUa5xu7VDCfHm9zrlXK9NBaDxGPu6qzY6oZT// jIoh76W0QDrjOioz1zORC1l1+yZiRzjWL+AUvAFC6k0b0EJ0RxfO1C2O4Fcu7kwdoLwm /2/KZ8FNKkG387XoemGCg00zdofNWZqEPUmWluHDOaUlg9QFl3wF536mSw4Vtig/xmzl HI7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dfi2uLq2; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-155318-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155318-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id np9-20020a17090b4c4900b002ae941beeecsi1642941pjb.1.2024.04.23.06.59.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155318-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dfi2uLq2; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-155318-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155318-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B64E4285A36 for ; Tue, 23 Apr 2024 13:59:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFD25137770; Tue, 23 Apr 2024 13:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dfi2uLq2" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30CD3136E16; Tue, 23 Apr 2024 13:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713880731; cv=none; b=T7kcZ2rrHcoy72jT+RMrFag/0PqnM32B8o6RToVSMuM/DqQ8M3HTIN1vSXI8ECULuVSlyWQda+WdDXU1h9dGp2bcaF5pf1TURrN9uN8E/aPiIUPzeFbG8gCJre4H3in6N6MMijA6Zc3pgCjTg4fOA6cipz/wa+KbpCzUkFFPlZs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713880731; c=relaxed/simple; bh=PM4hKVCgLViTlEhxGEmFa37oVZWQvC3vlHhtyjhGMvA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tNfQVUvjfHoAgWfsa0evPQ8cZp5uhp6te+75nKM8QYusyU8kNrGA8Dr1VyVmDi7j0wrCVvKZXxqOB6eFtushca3gUREnZqCqUkZVMEpx0yba89pzIDxHvTyjSOy4iT/qHBvLhoMphbGN/hrMepZ+58QpiK49Pee5L0sg95RpTe4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dfi2uLq2; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713880730; x=1745416730; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PM4hKVCgLViTlEhxGEmFa37oVZWQvC3vlHhtyjhGMvA=; b=dfi2uLq288Zmbcqgo/fAuud0TuOT1tc4CNcWBAR5MsldW0QYQl7fiQFH hnah70cS4YJk1bfvl1vkcSi6j9a86k300A1geJKPdh+4yybJ6AvdoUg2c e82dRfe/eP6IHp9iCVgnaNi9C2rgV2ARZAF1413DOldlCi6qzpqqnfp9j gth8BTF+ffI65M5kN9+8Mvwsc0AnUN8dF4kP4hL7EebLtcCYcI79aa37F sRg5Pm5fW8n6fUcQEUgpurREssyhiwsl2qu526zM1Cis5as0aiEYpxUVc 3bsLwWbrahfYRs4mHjQZQ5CS8mADQrq4ysHRWfvXubofv5dg+7sI3PTY0 w==; X-CSE-ConnectionGUID: 4iQ6PcLLSTyEciMdK/uoZw== X-CSE-MsgGUID: 6NVhk/ogTdK/Od/1CGbhGQ== X-IronPort-AV: E=McAfee;i="6600,9927,11053"; a="26921426" X-IronPort-AV: E=Sophos;i="6.07,222,1708416000"; d="scan'208";a="26921426" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2024 06:58:49 -0700 X-CSE-ConnectionGUID: If+xOyfqRgibg6Xjd3xxdg== X-CSE-MsgGUID: Rz+XMKpcS8KsUB23qWigbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,222,1708416000"; d="scan'208";a="24431745" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa008.fm.intel.com with ESMTP; 23 Apr 2024 06:58:45 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Joerg Roedel , Will Deacon , "Rafael J. Wysocki" , Magnus Karlsson , nex.sw.ncis.osdt.itp.upstreaming@intel.com, bpf@vger.kernel.org, netdev@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 0/7] dma: skip calling no-op sync ops when possible Date: Tue, 23 Apr 2024 15:58:25 +0200 Message-ID: <20240423135832.2271696-1-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The series grew from Eric's idea and patch at [0]. The idea of using the shortcut for direct DMA as well belongs to Chris. When an architecture doesn't need DMA synchronization and the buffer is not an SWIOTLB buffer, most of times the kernel and the drivers end up calling DMA sync operations for nothing. Even when DMA is direct, this involves a good non-inline call ladder and eats a bunch of CPU time. With IOMMU, this results in calling indirect calls on hotpath just to check what is already known and return. XSk is been using a custom shortcut for that for quite some time. I recently wanted to introduce a similar one for Page Pool. Let's combine all this into one generic shortcut, which would cover all DMA sync ops and all types of DMA (direct, IOMMU, ...). * #1 adds stub inlines to be able to compile DMA sync ops out when not needed. * #2 adds generic shortcut and enables it for direct DMA. * #3 adds ability to skip DMA syncs behind an IOMMU. * #4-5 are just cleanups for Page Pool to avoid merge conflicts in future. * #6 checks for the shortcut as early as possible in the Page Pool code to make sure no cycles wasted. * #7 replaces XSk's shortcut with the generic one. On 100G NIC, the result is +3-5% for direct DMA and +10-11% for IOMMU. As a bonus, XSk core now allows batched buffer allocations for IOMMU setups. If the shortcut is not available on some system, there should be no visible performance regressions. [0] https://lore.kernel.org/netdev/20221115182841.2640176-1-edumazet@google.com Alexander Lobakin (7): dma: compile-out DMA sync op calls when not used dma: avoid redundant calls for sync operations iommu/dma: avoid expensive indirect calls for sync operations page_pool: make sure frag API fields don't span between cachelines page_pool: don't use driver-set flags field directly page_pool: check for DMA sync shortcut earlier xsk: use generic DMA sync shortcut instead of a custom one kernel/dma/Kconfig | 5 + include/net/page_pool/types.h | 25 ++++- include/linux/device.h | 4 + include/linux/dma-map-ops.h | 12 ++ include/linux/dma-mapping.h | 105 +++++++++++++----- include/net/xdp_sock_drv.h | 7 +- include/net/xsk_buff_pool.h | 14 +-- drivers/iommu/dma-iommu.c | 3 +- drivers/net/ethernet/engleder/tsnep_main.c | 2 +- .../net/ethernet/freescale/dpaa2/dpaa2-xsk.c | 2 +- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 2 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 2 +- drivers/net/ethernet/intel/igc/igc_main.c | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 2 +- .../ethernet/mellanox/mlx5/core/en/xsk/rx.c | 4 +- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 2 +- drivers/net/ethernet/netronome/nfp/nfd3/xsk.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- kernel/dma/mapping.c | 69 +++++++++--- kernel/dma/swiotlb.c | 6 + net/core/page_pool.c | 76 ++++++++----- net/xdp/xsk_buff_pool.c | 28 +---- 22 files changed, 243 insertions(+), 133 deletions(-) --- From v3[1]: * #1: * don't prefix DMA sync ops with '__', just define them as empty inlines when !DMA_NEED_SYNC (Chris, Robin); * always select DMA_NEED_SYNC when DMA_API_DEBUG (^); * #2: * don't use BIT(), keep the style consistent (^); * check for dma_map_ops::sync_sg_*() in dma_setup_need_sync() (^); * don't reset the flag in swiotlb_alloc() as it's not streaming API (^); * instead of 'dma_skip_sync', name the flag 'dma_need_sync' and inverse the logic (^); * setup the shortcut in dma_set_mask() (assuming every driver using DMA must call it on probe) (^); * combine dma_direct() and (ops->flags & CAN_SKIP_SYNC) checks (Robin); * #3: - pick Acked-by (Robin). From v2[2]: * #1: * use two tabs for indenting multi-line function prototypes (Chris); * #2: * make shortcut clearing function generic and move it out of the SWIOTLB code (Chris); * remove dma_set_skip_sync(): use direct assignment during the initial setup, not used anywhere else (Chris); * commitmsg: remove "NIC" and the workaround paragraph (Chris). From v1[3]: * #1: * use static inlines instead of macros (Chris); * move CONFIG_DMA_NEED_SYNC check into dma_skip_sync() (Robin); * #2: * use a new dma_map_ops flag instead of new callback, assume the same conditions as for direct DMA are enough (Petr, Robin); * add more code comments to make sure the whole idea and path are clear (Petr, Robin, Chris); * #2, #3: correct the Git tags and the authorship a bit. Not addressed in v2: * #1: * dma_sync_*range_*() are still wrapped, as some subsystems may want to call the underscored versions directly (e.g. Page Pool); * #2: * the new dev->dma_skip_sync bit is still preferred over checking for READ_ONCE(dev->dma_uses_io_tlb) + dev_is_dma_coherent() on hotpath as a faster solution. [1] https://lore.kernel.org/netdev/20240214162201.4168778-1-aleksander.lobakin@intel.com [2] https://lore.kernel.org/netdev/20240205110426.764393-1-aleksander.lobakin@intel.com [3] https://lore.kernel.org/netdev/20240126135456.704351-1-aleksander.lobakin@intel.com -- 2.44.0