Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp807929rdb; Fri, 26 Jan 2024 11:13:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtEGU1fcSoEmcLIAygit0cXjlb0UJGD/KDUUZqG5df/bImxb8kkBEP6uOifjt9bLTaBtRN X-Received: by 2002:a17:90a:c084:b0:294:b5a2:bc86 with SMTP id o4-20020a17090ac08400b00294b5a2bc86mr323660pjs.65.1706296407573; Fri, 26 Jan 2024 11:13:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706296407; cv=pass; d=google.com; s=arc-20160816; b=BjfCqygB6F0sBQr8ZELYpBEzz6ibZZIOyA0M5PGa75A/RgP0pa4w1IsAyui8qoOO6N iNccWYDuVEn8HypCpkjxvr0NrAD+TVAYBNeVjlpMtxpI/IUA//qJL3QxEktHzbtxFyE1 aymXDjN+kFj2Ot3cD6b0DYZR9Des4nQ41H+tJiupuULDAv76JoYA2W2+QgmUSgeUzkCM 9tlhX8+5j94sKrLAWY2FL3byGzdAF3/SBLdYhob40dvpwDllU7CeeLJ9TIOE/QL0FvNO XeYaA16WY0xlyxezZrZ4RmOhFk8/swxxC6/Wa0eowJTEiYEn6YbazZggXu5y1Q3IzaMm w39A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=PYK+TiD5HMpRkIpXovifKI0o2etTJ+uAa13zaxsGlus=; fh=53FFPsZDJQrlOZBT9Or4gR6Gx6ZGGQJtoCPEatgY4/Q=; b=GewghiIrN7j3TBttc9YSg54z63KZXe1wLpENieR1sWuDBFxWpklkitleKsVelp9HKD 1X26k5UX9Qg2MHc4v0bar7Ai0lfIrDHTA6ym6gIBOSyhQQ0DdaR42lp0BPL9y7RoiP/c z2XeGleHqp12cbROQcf5CroY04lPS6eyzLpu7HgxmZqcfi+t8HsEfMlcOlm1heDyrV9s XTdpUIAkThri6aSEimXC0Zrrobn8iKBQkK3ZXCUfC72vAKh2XDubuMTSffGu5yvTzXeQ 9ZDvH6JZIAEWN2TqnteU8D0wUSEvsRkGbbTsv64z0jLhUrW+bHk3B17VB4wP0KPAJzu7 PqBQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-40547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x4-20020a17090ad68400b002905aac028dsi3530152pju.185.2024.01.26.11.13.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 11:13:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-40547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 47035B23C22 for ; Fri, 26 Jan 2024 19:13:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 535D5224DE; Fri, 26 Jan 2024 19:13:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C6BC22325; Fri, 26 Jan 2024 19:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706296392; cv=none; b=AQCYRQzQU4sJrIH/B1SnAo8io1hgbbzHCtKh+f/MCSLFpX2dC/b/N2/LM08xVn9/NSFZhh9Dgc+M8FCSRfGREYBk48W4+SJsBZZh8Ctf820juCcNIUMR2/iZdigNh9Hk4mhvGchknOQaLTJeDDaODWA9Gc7DMqyk//AyFje+Wag= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706296392; c=relaxed/simple; bh=07owUgy6Vz2p9oaXMtBIEvYNVRrPWXi1zFehd3AVO/o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EiEdYQ0BmVHD/SN2cYHgGFzvBf73S2o3C7s1hH4V2W4KSC+sLvPkXP/VQ7xVW6abfBb8w8DTGF3HGqTLW3gojyi5v7MRepdRHJoUSa+0Dwd4M0L922HtHIhbP5WoC7dqPTkit8d+CwXoarPJcvnVHVzDFrrpbmW5TrERkE/JrUc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 12E381FB; Fri, 26 Jan 2024 11:13:54 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D43B3F73F; Fri, 26 Jan 2024 11:13:07 -0800 (PST) Message-ID: <1c62d388-a600-40d8-b386-15841cb1af95@arm.com> Date: Fri, 26 Jan 2024 19:13:05 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 2/7] dma: avoid expensive redundant calls for sync operations Content-Language: en-GB To: =?UTF-8?B?UGV0ciBUZXNhxZnDrWs=?= Cc: Alexander Lobakin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christoph Hellwig , Marek Szyprowski , Joerg Roedel , Will Deacon , Greg Kroah-Hartman , "Rafael J. Wysocki" , Magnus Karlsson , Maciej Fijalkowski , Alexander Duyck , bpf@vger.kernel.org, netdev@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20240126135456.704351-1-aleksander.lobakin@intel.com> <20240126135456.704351-3-aleksander.lobakin@intel.com> <0f6f550c-3eee-46dc-8c42-baceaa237610@arm.com> <7ff3cf5d-b3ff-4b52-9031-30a1cb71c0c9@intel.com> <0cf72c00-21d9-4f1a-be14-80336da5dff4@arm.com> <20240126194819.147cb4e2@meshulam.tesarici.cz> From: Robin Murphy In-Reply-To: <20240126194819.147cb4e2@meshulam.tesarici.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 26/01/2024 6:48 pm, Petr Tesařík wrote: > On Fri, 26 Jan 2024 17:21:24 +0000 > Robin Murphy wrote: > >> On 26/01/2024 4:45 pm, Alexander Lobakin wrote: >>> From: Robin Murphy >>> Date: Fri, 26 Jan 2024 15:48:54 +0000 >>> >>>> On 26/01/2024 1:54 pm, Alexander Lobakin wrote: >>>>> From: Eric Dumazet >>>>> >>>>> Quite often, NIC devices do not need dma_sync operations on x86_64 >>>>> at least. >>>>> Indeed, when dev_is_dma_coherent(dev) is true and >>>>> dev_use_swiotlb(dev) is false, iommu_dma_sync_single_for_cpu() >>>>> and friends do nothing. >>>>> >>>>> However, indirectly calling them when CONFIG_RETPOLINE=y consumes about >>>>> 10% of cycles on a cpu receiving packets from softirq at ~100Gbit rate. >>>>> Even if/when CONFIG_RETPOLINE is not set, there is a cost of about 3%. >>>>> >>>>> Add dev->skip_dma_sync boolean which is set during the device >>>>> initialization depending on the setup: dev_is_dma_coherent() for direct >>>>> DMA, !(sync_single_for_device || sync_single_for_cpu) or positive result >>>>> from the new callback, dma_map_ops::can_skip_sync for non-NULL DMA ops. >>>>> Then later, if/when swiotlb is used for the first time, the flag >>>>> is turned off, from swiotlb_tbl_map_single(). >>>> >>>> I think you could probably just promote the dma_uses_io_tlb flag from >>>> SWIOTLB_DYNAMIC to a general SWIOTLB thing to serve this purpose now. >>> >>> Nice catch! >>> >>>> >>>> Similarly I don't think a new op is necessary now that we have >>>> dma_map_ops.flags. A simple static flag to indicate that sync may be> skipped under the same conditions as implied for dma-direct - i.e. >>>> dev_is_dma_coherent(dev) && !dev->dma_use_io_tlb - seems like it ought >>>> to suffice. >>> >>> In my initial implementation, I used a new dma_map_ops flag, but then I >>> realized different DMA ops may require or not require syncing under >>> different conditions, not only dev_is_dma_coherent(). >>> Or am I wrong and they would always be the same? >> >> I think it's safe to assume that, as with P2P support, this will only >> matter for dma-direct and iommu-dma for the foreseeable future, and >> those do currently share the same conditions as above. Thus we may as >> well keep things simple for now, and if anything ever does have cause to >> change, it can be the future's problem to keep this mechanism working as >> intended. > > Can we have a comment that states this assumption along with the flag? > Because when it breaks, it will keep someone cursing for days why DMA > sometimes fails on their device before they find out it's not synced. > And then wondering why the code makes such silly assumptions... Indeed, apologies if it wasn't totally clear, but I really was implying a literal "may skip sync if coherent and not using SWIOTLB (which matches dma-direct)" flag, documented as such, and not trying to dress it up as anything more generic. I just can't suggest a suitably concise name for that of the top of my head... :) Thanks, Robin.