Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1427485lqp; Mon, 15 Apr 2024 06:27:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVh2EnWD5TcEotU7SpBlWEisD3JnFoMWE8xV4Rs1PcSBJ6FF0Vn0KMWKFHqEox/dVGga2v1Lyabc9vVeP3A7F7jpaydVqJPh1M20cT4vA== X-Google-Smtp-Source: AGHT+IGUZ6cmMSvaKnu8jbry56UXlu+hnKagPtYmZE69wfnQBxcN8h3VFoyHJawrk/MgSX8QSJ43 X-Received: by 2002:a05:620a:6213:b0:78e:c3f3:d8f9 with SMTP id ou19-20020a05620a621300b0078ec3f3d8f9mr8560536qkn.49.1713187628843; Mon, 15 Apr 2024 06:27:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713187628; cv=pass; d=google.com; s=arc-20160816; b=mdrElfjGDrZb0pi8+oZ9jnPWb3auDLaBfWbtFniQw0KKUgQPR2mjLrTQV1VYZTKgEp iN7ByEyHXnkBaykPEJwBeSCowylQisEvvjZm4cmvzqib9pYuXJVDxJ7lv2O+Kb0PVzRK iR0Ng8d/F11vqEgPP8dVdKVhE0knK1RrDGT/PDENBRGEu6ZrdcyrAzSKHv10fEVjIATA klCUpARSFpmWeQSuKgqTHJ0n0dRPp5cUcgoTmZdxAKVCwnb6IQtLq1D7TF+TWMbjhSdk koYk9OE+HpEM+xZm7JjDcugSIyP/KwYH1h8pSrP8dhPbt3xr+pmdWwKgeQu2eNoickBW SRYw== 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 :subject:cc:to:from:date:dkim-signature; bh=H7qkdyb/Y4bVUiPoNIOX6jPwjCN1aPjIKdG4tz+fkTw=; fh=RWlKL0lc97XGcnOASTB2gfHeiuyAf7jWmD59Zl7PkFo=; b=aoPljy/ra56e5p9UOG3LaY6ZsJ0J3IWtflwRsvxHxLgLdNqyFpTUvlIDjGvFGSIPId ErhB5FJ0evhzZfhGB7Z573T2c6LtSmozOElvRcOa3J7Og+EzC9ZiULAx3Vp+eyFZ4v9r xdrzXG48EaN2s/xBW3HHsn67SaMVCjPhn4jK179Lua1BU8KJIgvQc2Zc0D0Uw8GYkYpR y6ociHiquVL+vHu+gsG/D7vPIg8zpnnHX5hqoJ1ddQ0bjPlNPb2K5xAcqEhFdaEzPak4 7vCOzwn1NLNe0Keq7r57zWSUoW9E/W0JlBzJRWdkv1D6MC6O6Ej03NqhV/gDFZQQ9j4d D7wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=09GybjZJ; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-145236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k4-20020ae9f104000000b0078d61f28b0fsi9895182qkg.399.2024.04.15.06.27.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:27:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=09GybjZJ; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-145236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9087E1C211D6 for ; Mon, 15 Apr 2024 13:27:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C64E373189; Mon, 15 Apr 2024 13:19:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="09GybjZJ" Received: from bee.tesarici.cz (bee.tesarici.cz [37.205.15.56]) (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 47B6B5D74E for ; Mon, 15 Apr 2024 13:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=37.205.15.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187174; cv=none; b=HTkaf4A+y8OAIuWICKUSScoJSgDhX4oASV0250NaGzS+0v6XCffTr+Su3FgxkEtSibDz2p65H30Dpf3HGpREdzPwL+TNaWZ8U0IOB/fhOEIPZxTVcwGnWZLjhL2wfQlYX2yiVEakCgUlUv9nPRskw9j2nqdA5aejk5HRBg8wjno= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187174; c=relaxed/simple; bh=V3w3lxBxdx1g2rbfU49MScfZLmbOgUTm9NFTMUes6po=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CrilCuh7SiM1c45rtBYWKbtZpRbZdbCEb5y1KJQX7GYcwdcGKnJzUVC7UA4YVAgAtjvY+6h5z7li/0VOfjHgmJvRx0S4Ag4ifUMrU4y2M4EN/co0AE1GMF93ecT0PkQ1ebeb+4HEZLQR/UX8162jXxjQtYJFVJaWBnmcEzhL6gI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tesarici.cz; spf=pass smtp.mailfrom=tesarici.cz; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b=09GybjZJ; arc=none smtp.client-ip=37.205.15.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tesarici.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tesarici.cz Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 171AF1BEEE3; Mon, 15 Apr 2024 15:19:29 +0200 (CEST) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=quarantine dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tesarici.cz; s=mail; t=1713187170; bh=H7qkdyb/Y4bVUiPoNIOX6jPwjCN1aPjIKdG4tz+fkTw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=09GybjZJ1pkgrpv8t2KOl3uKTKKOq3Mydc0g3n0IOtyEHDRPP38j3ntH7mdKsnlAO 6Hqcizz8+UeFHftXQg4reiQDgXnI3Lo5tTfhPMDjy2DPgjpME3XCggOTCFtRPmfU83 5xWyfvjSKaNrWlhcEBxmEc51bHRiOeWnoiySR7p+DA8hU9ksIvEokmv5ep0UBNkE1q XvETXhkz88EpVJGcOFb5FwfLqXpnwF5ofgJYpSaAeXve2JZFyP04cGW/pC/uxbLIuy 6bMCzD0Dy/wm5IaVr5qHmb86wUL3hZVhs5KYU5uRTnTuHi301uT2VJjFYmHdcqH//1 sIs0YspVlj5xg== Date: Mon, 15 Apr 2024 15:19:27 +0200 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Michael Kelley Cc: "mhkelley58@gmail.com" , "robin.murphy@arm.com" , "joro@8bytes.org" , "will@kernel.org" , "jgross@suse.com" , "sstabellini@kernel.org" , "oleksandr_tyshchenko@epam.com" , "hch@lst.de" , "m.szyprowski@samsung.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "xen-devel@lists.xenproject.org" , "roberto.sassu@huaweicloud.com" Subject: Re: [PATCH 1/2] swiotlb: Remove alloc_size argument to swiotlb_tbl_map_single() Message-ID: <20240415151927.0145f742@meshulam.tesarici.cz> In-Reply-To: References: <20240408041142.665563-1-mhklinux@outlook.com> <20240415134624.22092bb0@meshulam.tesarici.cz> <20240415145023.78e7ce97@meshulam.tesarici.cz> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-suse-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 15 Apr 2024 13:03:30 +0000 Michael Kelley wrote: > From: Petr Tesa=C5=99=C3=ADk Sent: Monday, April 15, 2= 024 5:50 AM > >=20 > > On Mon, 15 Apr 2024 12:23:22 +0000 > > Michael Kelley wrote: > > =20 > > > From: Petr Tesa=C5=99=C3=ADk Sent: Monday, April 1= 5, 2024 4:46 AM =20 > > > > > > > > Hi Michael, > > > > > > > > sorry for taking so long to answer. Yes, there was no agreement on = the > > > > removal of the "dir" parameter, but I'm not sure it's because of > > > > symmetry with swiotlb_sync_*(), because the topic was not really > > > > discussed. > > > > > > > > The discussion was about the KUnit test suite and whether direction= is > > > > a property of the bounce buffer or of each sync operation. Since DM= A API > > > > defines associates each DMA buffer with a direction, the direction > > > > parameter passed to swiotlb_sync_*() should match what was passed to > > > > swiotlb_tbl_map_single(), because that's how it is used by the gene= ric > > > > DMA code. In other words, if the parameter is kept, it should be ke= pt > > > > to match dma_map_*(). > > > > > > > > However, there is also symmetry with swiotlb_tbl_unmap_single(). Th= is > > > > function does use the parameter for the final sync. I believe there > > > > should be a matching initial sync in swiotlb_tbl_map_single(). In > > > > short, the buffer sync for DMA non-coherent devices should be moved= from > > > > swiotlb_map() to swiotlb_tbl_map_single(). If this sync is not need= ed, > > > > then the caller can (and should) include DMA_ATTR_SKIP_CPU_SYNC in > > > > the flags parameter. > > > > > > > > To sum it up: > > > > > > > > * Do *NOT* remove the "dir" parameter. > > > > * Let me send a patch which moves the initial buffer sync. > > > > =20 > > > > > > I'm not seeing the need to move the initial buffer sync. All > > > callers of swiotlb_tbl_map_single() already have a subsequent > > > check for a non-coherent device, and a call to > > > arch_sync_dma_for_device(). And the Xen code has some > > > special handling that probably shouldn't go in > > > swiotlb_tbl_map_single(). Or am I missing something? =20 > >=20 > > Oh, sure, there's nothing broken ATM. It's merely a cleanup. The API is > > asymmetric and thus confusing. You get a final sync by default if you > > call swiotlb_tbl_unmap_single(), =20 >=20 > I don't see that final sync in swiotlb_tbl_unmap_single(). It calls > swiotlb_bounce() to copy the data, but it doesn't deal with > non-coherent devices or call arch_sync_dma_for_cpu(). Ouch. You're right! The buffer gets only bounced but not synced if device DMA is non-coherent. So, how is this supposed to work? Now I'm looking at the code in dma_direct_map_page(), and it calls arch_sync_dma_for_device() explicitly, _except_ when using SWIOTLB. So, maybe I should instead review all callers of swiotlb_map(), make sure that they handle non-coherent devices, and then remove the sync from swiotlb_map()? I mean, the current situation seems somewhat disorganized to me. Petr T