Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1280506lqh; Mon, 6 May 2024 02:50:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWcv8IFGqoH94RnVZl7GATI7RTJ39ItlVAMy6KWkVsmztnbfdlO1aczbOFNDSoaqdcZ7ZfCkL+36w6cEAh4upMth/kRJUBa5oFikmb+KA== X-Google-Smtp-Source: AGHT+IFKiarzdoC+eMGqIBoFGK1jWLfqf3ahwqjgK2+XlacC4P6+nuTmnLX5NWmA6xvYqKclLwFe X-Received: by 2002:a05:6a20:4393:b0:1ae:3f36:28cf with SMTP id i19-20020a056a20439300b001ae3f3628cfmr9985634pzl.56.1714989013024; Mon, 06 May 2024 02:50:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714989013; cv=pass; d=google.com; s=arc-20160816; b=o72UrVh1Y1LR8A2+0xV7PsYptAN7PR8g8ROocW0dxY5VBZnvWLAcCGG5fHDh7IY3OQ RJFqy+jQlobUERSNoa0CVCqskl0Z+i+fX4TUiNDr5r5F7xS9wn1bd0f0ba/MEYjNJojF wEB9Q7nBZHHk89nFytc6W2hkxALQJnDVKRJ1TSWnxqpWj7M4+1Y3uIRzE9LiuN8tz+qO bmyKtZKeC0pTdP1RnRY2ZUHi6RHdUT4sgm+HlXid2Fa86Hk5WA4JgIRKWV7r2h4+7YFg BJnk1Bg/kKPDcZJigxepk7mblwYm/PmBXfLkO90E2R7keGHxIwYzyBG8Crx7q5lh4Ba/ neqA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wH/mIgLWz4I8aUEiCUmSrIrY1DjXcQD2QORseDQo+/g=; fh=XQR/2xX0Fo1qiXvWXbqY2WT0J3RtRMz5arolgjVK/GU=; b=mClk53uCs+Ibb6RkFB++FYrBbM3RA8TyqR146khSkv5RQnQuOInL2nHVgjYdhcK0jm QAC31ZUwuazF5U/A9l1DPqgcKLnYwHCUIadreHTDTDsShAoBw4jrs3YJJqZbs1M4jtHX 3QpXrgpEihSkaQAoKgfZK5EhvK+OBbPBsblFU/MpxF3qdHBTVj+Y+k8kST+LCMv6hLTJ gohJc8DrEF1PNQYQhCqxVVxdjbYqtK7i1iwFaKi+v+14HUBbYt2MGTi9Xh0gjqjmswaY pA2iexvm4Ub2LvJ3zZaCCxG6SncZw/B1fjVVoKTwIL5UMW2qWtbE3vvnb10uGvG7bAx3 ql1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="XsDQnh/o"; 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-169602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169602-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 t3-20020a170902e84300b001eb1663c808si8019019plg.544.2024.05.06.02.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 02:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169602-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="XsDQnh/o"; 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-169602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169602-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 8DBCC28287E for ; Mon, 6 May 2024 09:49:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A05771428E6; Mon, 6 May 2024 09:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XsDQnh/o" 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 232E5142915; Mon, 6 May 2024 09:49:21 +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=1714988964; cv=none; b=Qc93LXsV1zhgDMdyg3GOkpl6c7tASEszzxPPj3DKF9OTBv+TSQY+rkRbOdAQon4k0IMNJbxJrqfEd5SPxJ/BNd4mfT+l7B0J6TgaTn1N/HI72501lV1OGCgJeNgsJ4+hh/NKiXWViUHir7mekH14u5vX2Dqn0tqmWVjY2UWKKxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714988964; c=relaxed/simple; bh=yweqzDe5hTKxj6yfc0j/PwOzUMo+FV4q54VN1Y3+NCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FTrEYdJ83mZ2+AIDDcv6iXbEYAX9QJCxj6wpxpzAvEfOFCs2ugMdT4JzsxBTZ5YMPHkPIrGpjqLSEpCrk593/xv2LOrO7BOFF2jbJfhWaeo0/GVuIRD5GMWpvLTI6aI+lS3VcgcT3qWFmDe6g5+JY1To9s97bNAnHBsHW6WjgH0= 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=XsDQnh/o; 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=1714988961; x=1746524961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yweqzDe5hTKxj6yfc0j/PwOzUMo+FV4q54VN1Y3+NCs=; b=XsDQnh/o1JwPTQ1Q1hEA4lB+Vtkf9vZN80fw3T+6+GYnov4pAjSNoaGz N/4PrWw0dFVvMluKiQOEKiPHs9zxoy5xnlkJZtZ8d8JWWiUmSFkT9yCbj R/gZCQEgnAYgwERBxRYTsBJNwSogfj0paRTBcCKCtrfWt8/EYXMJ7G8m1 0OEB5+B9lMRFVMDYTeFlXfxvsmMWBRfZCf9eI2mhyIyDhfY0k66aiDwC1 H5ebukdc19ntHfnGhNuo7bP33YNw29mTVORPvU1uOl7jUQKs+Jy9i3ZGu vipylcL7+Ppt6NcyP0F8N3vsfLO7tpPPARvFQFcU6CGlShvL/tqBKyD2q Q==; X-CSE-ConnectionGUID: 9+1lZ4KpSKafr8MadYmiEA== X-CSE-MsgGUID: wY+kxy0JT+OUO2frUWRfoA== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="28200950" X-IronPort-AV: E=Sophos;i="6.07,258,1708416000"; d="scan'208";a="28200950" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 02:49:21 -0700 X-CSE-ConnectionGUID: clcfe+2YTUitkRIobQ9qUA== X-CSE-MsgGUID: fuy5GYqqRw6cyeqMSiyijQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,258,1708416000"; d="scan'208";a="58995710" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa002.jf.intel.com with ESMTP; 06 May 2024 02:49:17 -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 v5 1/7] dma: compile-out DMA sync op calls when not used Date: Mon, 6 May 2024 11:48:49 +0200 Message-ID: <20240506094855.12944-2-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240506094855.12944-1-aleksander.lobakin@intel.com> References: <20240506094855.12944-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some platforms do have DMA, but DMA there is always direct and coherent. Currently, even on such platforms DMA sync operations are compiled and called. Add a new hidden Kconfig symbol, DMA_NEED_SYNC, and set it only when either sync operations are needed or there is DMA ops or swiotlb or DMA debug is enabled. Compile global dma_sync_*() and dma_need_sync() only when it's set, otherwise provide empty inline stubs. The change allows for future optimizations of DMA sync calls depending on runtime conditions. Signed-off-by: Alexander Lobakin --- kernel/dma/Kconfig | 5 +++ include/linux/dma-mapping.h | 62 ++++++++++++++++++++----------------- kernel/dma/mapping.c | 22 +++++++------ 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index d62f5957f36b..c06e56be0ca1 100644 --- a/kernel/dma/Kconfig +++ b/kernel/dma/Kconfig @@ -107,6 +107,11 @@ config DMA_BOUNCE_UNALIGNED_KMALLOC bool depends on SWIOTLB +config DMA_NEED_SYNC + def_bool ARCH_HAS_SYNC_DMA_FOR_DEVICE || ARCH_HAS_SYNC_DMA_FOR_CPU || \ + ARCH_HAS_SYNC_DMA_FOR_CPU_ALL || DMA_API_DEBUG || DMA_OPS || \ + SWIOTLB + config DMA_RESTRICTED_POOL bool "DMA Restricted Pool" depends on OF && OF_RESERVED_MEM && SWIOTLB diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 4a658de44ee9..a569b56b25e2 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -117,14 +117,6 @@ dma_addr_t dma_map_resource(struct device *dev, phys_addr_t phys_addr, size_t size, enum dma_data_direction dir, unsigned long attrs); void dma_unmap_resource(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir, unsigned long attrs); -void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size, - enum dma_data_direction dir); -void dma_sync_single_for_device(struct device *dev, dma_addr_t addr, - size_t size, enum dma_data_direction dir); -void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, - int nelems, enum dma_data_direction dir); -void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, - int nelems, enum dma_data_direction dir); void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs); void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, @@ -147,7 +139,6 @@ u64 dma_get_required_mask(struct device *dev); bool dma_addressing_limited(struct device *dev); size_t dma_max_mapping_size(struct device *dev); size_t dma_opt_mapping_size(struct device *dev); -bool dma_need_sync(struct device *dev, dma_addr_t dma_addr); unsigned long dma_get_merge_boundary(struct device *dev); struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size, enum dma_data_direction dir, gfp_t gfp, unsigned long attrs); @@ -195,22 +186,6 @@ static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { } -static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, - size_t size, enum dma_data_direction dir) -{ -} -static inline void dma_sync_single_for_device(struct device *dev, - dma_addr_t addr, size_t size, enum dma_data_direction dir) -{ -} -static inline void dma_sync_sg_for_cpu(struct device *dev, - struct scatterlist *sg, int nelems, enum dma_data_direction dir) -{ -} -static inline void dma_sync_sg_for_device(struct device *dev, - struct scatterlist *sg, int nelems, enum dma_data_direction dir) -{ -} static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) { return -ENOMEM; @@ -277,10 +252,6 @@ static inline size_t dma_opt_mapping_size(struct device *dev) { return 0; } -static inline bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) -{ - return false; -} static inline unsigned long dma_get_merge_boundary(struct device *dev) { return 0; @@ -310,6 +281,39 @@ static inline int dma_mmap_noncontiguous(struct device *dev, } #endif /* CONFIG_HAS_DMA */ +#if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC) +void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size, + enum dma_data_direction dir); +void dma_sync_single_for_device(struct device *dev, dma_addr_t addr, + size_t size, enum dma_data_direction dir); +void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, + int nelems, enum dma_data_direction dir); +void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, + int nelems, enum dma_data_direction dir); +bool dma_need_sync(struct device *dev, dma_addr_t dma_addr); +#else /* !CONFIG_HAS_DMA || !CONFIG_DMA_NEED_SYNC */ +static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, + size_t size, enum dma_data_direction dir) +{ +} +static inline void dma_sync_single_for_device(struct device *dev, + dma_addr_t addr, size_t size, enum dma_data_direction dir) +{ +} +static inline void dma_sync_sg_for_cpu(struct device *dev, + struct scatterlist *sg, int nelems, enum dma_data_direction dir) +{ +} +static inline void dma_sync_sg_for_device(struct device *dev, + struct scatterlist *sg, int nelems, enum dma_data_direction dir) +{ +} +static inline bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) +{ + return false; +} +#endif /* !CONFIG_HAS_DMA || !CONFIG_DMA_NEED_SYNC */ + struct page *dma_alloc_pages(struct device *dev, size_t size, dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp); void dma_free_pages(struct device *dev, size_t size, struct page *page, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 58db8fd70471..c78b78e95a26 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -329,6 +329,7 @@ void dma_unmap_resource(struct device *dev, dma_addr_t addr, size_t size, } EXPORT_SYMBOL(dma_unmap_resource); +#ifdef CONFIG_DMA_NEED_SYNC void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir) { @@ -385,6 +386,17 @@ void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, } EXPORT_SYMBOL(dma_sync_sg_for_device); +bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + if (dma_map_direct(dev, ops)) + return dma_direct_need_sync(dev, dma_addr); + return ops->sync_single_for_cpu || ops->sync_single_for_device; +} +EXPORT_SYMBOL_GPL(dma_need_sync); +#endif /* CONFIG_DMA_NEED_SYNC */ + /* * The whole dma_get_sgtable() idea is fundamentally unsafe - it seems * that the intention is to allow exporting memory allocated via the @@ -841,16 +853,6 @@ size_t dma_opt_mapping_size(struct device *dev) } EXPORT_SYMBOL_GPL(dma_opt_mapping_size); -bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) -{ - const struct dma_map_ops *ops = get_dma_ops(dev); - - if (dma_map_direct(dev, ops)) - return dma_direct_need_sync(dev, dma_addr); - return ops->sync_single_for_cpu || ops->sync_single_for_device; -} -EXPORT_SYMBOL_GPL(dma_need_sync); - unsigned long dma_get_merge_boundary(struct device *dev) { const struct dma_map_ops *ops = get_dma_ops(dev); -- 2.45.0