Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp1243650lqo; Thu, 9 May 2024 08:28:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXb9huY4bfGz3rbHYylPJqdRccFOTUANza6EkVz3+DYHzk31HLp5P4NCTNP8Hy/FSobOkuWlnT2SQ5f/vkoNLURMHiPPlX4XUrLbXZxsQ== X-Google-Smtp-Source: AGHT+IFlq9bMV+XoGQl01XWHYznLqK1h2nRLlkHNMbP4RV9S8nR0EVnrW2Ytto52OWbErUZt/51M X-Received: by 2002:a17:903:1108:b0:1eb:fe3:3436 with SMTP id d9443c01a7336-1eeb078f3aamr66252845ad.52.1715268493857; Thu, 09 May 2024 08:28:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715268493; cv=pass; d=google.com; s=arc-20160816; b=xxnGbianaPsj4xsfqQZ4uxQPWTtRLQQC0ltFkPrJ5tIHqyVMTPKxzO1wlsKn+/4wd5 1W4x/JvgCi/5AsgAPosqu6ky4FQ8+pHGclr2/aHB862PvansjJhZKgZQJAeKiHznfwCh gcT4bj8DZ0xVzmlOwqYAARV+gCQjmCIDOAYZVQQE1Hll668nr9U5a7jzg0ZExreejAGR 4PmkACqwe1lP8A1ot1upumx/GWqcXyAWCyemgQN2VZuhMX/Ld19x/x2Yhu62zdTwtpyv jrL5ERCylu86G/DS9JHF+VSrwqQWJ0uNWkNaMATVcEDMDuR2UrJn7LGDt+ZtWw1rBkdm xU3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:content-transfer-encoding:in-reply-to:from :content-language:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature:dkim-filter; bh=iKzan+AtH1MLoCj0BGLCQVFuAFEDByvOY6m2IAn5u1E=; fh=USyERmskA8ZRzkI4TT3kxK4e4aQUKXQdIgOawUMZmtQ=; b=t02MK3iYmCW1VwSdXG8/b3W631vH33QI70KswCo4dTRm086q3Fn1X7W+OmtsOkmLLS CbslTu8QAVpr5Si4bWVUR4QUncRX8kqn1vG7hjm/ZElMWzy57wRXlIl+SN9qAHwgvfxl Uj98YapEtyPYkvyyB1kBXKR6s5jnnKR2ISylu9JLxtSApxttrJWkS4onhSGrG753qWLf c1kpkw+EZr7t27XhZaXPr1Xx0VE5eTVwT/JrG2kjWESlvPp8Qy1GXOc9smCV6HsQ9kes BM/nXzra5xFwxFEf2B67mrvsHFEJ5NLqWfLhV5rvl9NX3g2F4dekfPp+nqORgQLBYd06 XOTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=b8QfaBGy; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-174632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c037543si15349795ad.341.2024.05.09.08.28.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 08:28:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=b8QfaBGy; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-174632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.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 BE8D0B20DE6 for ; Thu, 9 May 2024 15:28:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BB5A16F832; Thu, 9 May 2024 15:27:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="b8QfaBGy" Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (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 4B25E16F27C for ; Thu, 9 May 2024 15:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715268458; cv=none; b=aUL6zTAc1XjH5KJwWreIdqc4RIlnIZQ96PwFjGajT/eUB4Qlj1QOvi+aRTs9I/cQPEvE+VQBg/2F5BezF8FdCKNWj1KD70hxYmcL1sUMlVftajBPhWv5+TEZa+ImekimyUcu34idEnmtZSu0ZCxyfZDOi33RywqHrW7rxNpBBas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715268458; c=relaxed/simple; bh=D+gVTItRtfglcVRMVjWLYiTUP3h7feBGYvgzlXWh3Qs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:From:In-Reply-To: Content-Type:References; b=ETmFp+SoBsOFb14OdwMJq39HXxJEGDjrAj7TSautbbRsG6dnKuLL3j6hd3Oegiwnli820VzdscLmr4TUx+Imj6TQOLvmd+VWZ5ObwRQjmU2Csk3VZbZGlya/FKnmP6Z40LVrLoePnkbG9o0c5SfOO573vkM5jfBfjh4EeeYNYAY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=b8QfaBGy; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240509152733euoutp021786765a590a40145aa8311051aa0c73~N25IIhQeB1310813108euoutp02M for ; Thu, 9 May 2024 15:27:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240509152733euoutp021786765a590a40145aa8311051aa0c73~N25IIhQeB1310813108euoutp02M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715268453; bh=iKzan+AtH1MLoCj0BGLCQVFuAFEDByvOY6m2IAn5u1E=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=b8QfaBGyodS0ZrDbPtPVb6Z8aQXNK8nRVGyTx8DYfWp1V6XDjVV6NOnZ50bq51ZLB Tvj25fhF/bEO+63/SAL6bTNTwpk8gKXJie9D5t0F1qH4DM9bgwXbIYUNEbwHnTawOy poKtORPufvrAK7wcExjJBJ0RRzVAsM6P6/H2ZYao= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240509152733eucas1p21b928a4d596f3cc47a1ffbb0d0b0a66a~N25H6UKAt0901309013eucas1p2K; Thu, 9 May 2024 15:27:33 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 15.C9.09620.46BEC366; Thu, 9 May 2024 16:27:32 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240509152732eucas1p1b71b1a26a0ad22e4b312fc67d31ce565~N25HdLGmP1519015190eucas1p11; Thu, 9 May 2024 15:27:32 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240509152732eusmtrp21f58eaa0be099ccb174a9941fecd3be0~N25HchPCn3217432174eusmtrp2p; Thu, 9 May 2024 15:27:32 +0000 (GMT) X-AuditID: cbfec7f5-d31ff70000002594-4b-663ceb64d8ec Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F5.9E.09010.46BEC366; Thu, 9 May 2024 16:27:32 +0100 (BST) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240509152731eusmtip1743dcfe9fff0115332f0217b51336b15~N25GgQt502500825008eusmtip1x; Thu, 9 May 2024 15:27:31 +0000 (GMT) Message-ID: <34f29631-af45-462a-a168-e9f4bb4451cf@samsung.com> Date: Thu, 9 May 2024 17:27:31 +0200 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] dma: fix DMA sync for drivers not calling dma_set_mask*() To: Alexander Lobakin , Christoph Hellwig Cc: Eric Dumazet , Jakub Kicinski , Steven Price , 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 Content-Language: en-US From: Marek Szyprowski In-Reply-To: <20240509144616.938519-1-aleksander.lobakin@intel.com> Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPKsWRmVeSWpSXmKPExsWy7djPc7opr23SDB5vtbG4+Hkhq8XnI8fZ LJ4ee8RusXL1USaLX18sLDpnb2C3uLCtj9Xi8q45bBYrDp1gtzi2QMxixu2lzBZzv0xltjj4 4QmrReOR92wWLXdMHfg9nhycx+SxZt4aRo8Fm0o9Fu95yeSxaVUnm8eLzTMZPXbfbGDz+LxJ LoAjissmJTUnsyy1SN8ugStj1fbrzAXrdCpWbXjM2sB4VbmLkZNDQsBE4sbX8yxdjFwcQgIr GCUez5rDBuF8YZTYsncrK0iVkMBnRol1fR4wHSemn4XqWM4osWLvHlYI5yOjxO4JN9m7GDk4 eAXsJL7vAmtgEVCR2LXjCyOIzSsgKHFy5hMWEFtUQF7i/q0Z7CC2sECAxORf98CWiQiESTw6 2gNWzyywn1ni/XMtCFtc4taT+UwgNpuAoUTX2y42EJtTwFliTutKJogaeYntb+cwQxy6nlNi +m8WCNtFYtKz3UwQtrDEq+Nb2CFsGYn/O0FmcgHZ7YwSC37fh3ImMEo0PL/FCFFlLXHn3C82 kMeYBTQl1u/Shwg7Svy4dIMJJCwhwCdx460gxA18EpO2TWeGCPNKdLQJQVSrScw6vg5u7cEL l5gnMCrNQgqVWUi+nIXkm1kIexcwsqxiFE8tLc5NTy02zkst1ytOzC0uzUvXS87P3cQITHOn /x3/uoNxxauPeocYmTgYDzFKcDArifBW1VinCfGmJFZWpRblxxeV5qQWH2KU5mBREudVTZFP FRJITyxJzU5NLUgtgskycXBKNTDpzjL8s9wzN3ZtaHJTui+Pqcfsc/Gd8/Zvf3RPMpZDu+Fx waKLi4w/x8pmieYuXJV85aU5n4Of8BnFO590VbnFUtUu1TkFaAucPHbgoLKsi8yR08VCHTt9 N13SbV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z7 9jOKEvtE9PmWSl5tvjjhjxvXm6DX11gyLcOsZjzaNGeOK/O7ot3PFogonDkgtI5ZcDk33zaL S2tvNJd12143bWnSk/vmIdTLVlGmc6s28LNr9urtK476tk6Re1KlVLXH7mZM+yWLV2rfd7Sx uHEe1l/yXj1jlp/x+S8Tj2WF+RZuWWxYaMK8ukqWZZmit/wN5fr53Fe/GLU5rv35xL/Hovuk TUrB84j0Yq57ZbJRnUli77dv3vNn7qrmkJTNEg7/5t37GB/+5t3t1cwfOu34P/1Kr3l3+PWG pHvZ6l8W5oR+De9ondytx+Q9W4mlOCPRUIu5qDgRACyAurJ3AwAA X-CMS-MailID: 20240509152732eucas1p1b71b1a26a0ad22e4b312fc67d31ce565 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20240509144704eucas1p2fe6bfb07a9b39f548e7db0f24e47eb0a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240509144704eucas1p2fe6bfb07a9b39f548e7db0f24e47eb0a References: <20240509144616.938519-1-aleksander.lobakin@intel.com> On 09.05.2024 16:46, Alexander Lobakin wrote: > There are several reports that the DMA sync shortcut broke non-coherent > devices. > dev->dma_need_sync is false after the &device allocation and if a driver > didn't call dma_set_mask*(), it will still be false even if the device > is not DMA-coherent and thus needs synchronizing. Due to historical > reasons, there's still a lot of drivers not calling it. > Invert the boolean, so that the sync will be performed by default and > the shortcut will be enabled only when calling dma_set_mask*(). > > Reported-by: Marek Szyprowski > Closes: https://lore.kernel.org/lkml/46160534-5003-4809-a408-6b3a3f4921e9@samsung.com > Reported-by: Steven Price > Closes: https://lore.kernel.org/lkml/010686f5-3049-46a1-8230-7752a1b433ff@arm.com > Fixes: 32ba8b823252 ("dma: avoid redundant calls for sync operations") > Signed-off-by: Alexander Lobakin Tested-by: Marek Szyprowski > --- > include/linux/device.h | 4 ++-- > include/linux/dma-map-ops.h | 4 ++-- > include/linux/dma-mapping.h | 2 +- > kernel/dma/mapping.c | 10 +++++----- > kernel/dma/swiotlb.c | 2 +- > 5 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/include/linux/device.h b/include/linux/device.h > index ed95b829f05b..d4b50accff26 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -691,7 +691,7 @@ struct device_physical_location { > * and optionall (if the coherent mask is large enough) also > * for dma allocations. This flag is managed by the dma ops > * instance from ->dma_supported. > - * @dma_need_sync: The device needs performing DMA sync operations. > + * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. > * > * At the lowest level, every device in a Linux system is represented by an > * instance of struct device. The device structure contains the information > @@ -805,7 +805,7 @@ struct device { > bool dma_ops_bypass : 1; > #endif > #ifdef CONFIG_DMA_NEED_SYNC > - bool dma_need_sync:1; > + bool dma_skip_sync:1; > #endif > }; > > diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h > index 4893cb89cb52..5217b922d29f 100644 > --- a/include/linux/dma-map-ops.h > +++ b/include/linux/dma-map-ops.h > @@ -280,8 +280,8 @@ static inline void dma_reset_need_sync(struct device *dev) > { > #ifdef CONFIG_DMA_NEED_SYNC > /* Reset it only once so that the function can be called on hotpath */ > - if (unlikely(!dev->dma_need_sync)) > - dev->dma_need_sync = true; > + if (unlikely(dev->dma_skip_sync)) > + dev->dma_skip_sync = false; > #endif > } > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > index eb4e15893b6c..f693aafe221f 100644 > --- a/include/linux/dma-mapping.h > +++ b/include/linux/dma-mapping.h > @@ -295,7 +295,7 @@ bool __dma_need_sync(struct device *dev, dma_addr_t dma_addr); > static inline bool dma_dev_need_sync(const struct device *dev) > { > /* Always call DMA sync operations when debugging is enabled */ > - return dev->dma_need_sync || IS_ENABLED(CONFIG_DMA_API_DEBUG); > + return !dev->dma_skip_sync || IS_ENABLED(CONFIG_DMA_API_DEBUG); > } > > static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, > diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c > index 3524bc92c37f..3f77c3f8d16d 100644 > --- a/kernel/dma/mapping.c > +++ b/kernel/dma/mapping.c > @@ -392,7 +392,7 @@ bool __dma_need_sync(struct device *dev, dma_addr_t dma_addr) > > if (dma_map_direct(dev, ops)) > /* > - * dma_need_sync could've been reset on first SWIOTLB buffer > + * dma_skip_sync could've been reset on first SWIOTLB buffer > * mapping, but @dma_addr is not necessary an SWIOTLB buffer. > * In this case, fall back to more granular check. > */ > @@ -407,20 +407,20 @@ static void dma_setup_need_sync(struct device *dev) > > if (dma_map_direct(dev, ops) || (ops->flags & DMA_F_CAN_SKIP_SYNC)) > /* > - * dma_need_sync will be reset to %true on first SWIOTLB buffer > + * dma_skip_sync will be reset to %false on first SWIOTLB buffer > * mapping, if any. During the device initialization, it's > * enough to check only for the DMA coherence. > */ > - dev->dma_need_sync = !dev_is_dma_coherent(dev); > + dev->dma_skip_sync = dev_is_dma_coherent(dev); > else if (!ops->sync_single_for_device && !ops->sync_single_for_cpu && > !ops->sync_sg_for_device && !ops->sync_sg_for_cpu) > /* > * Synchronization is not possible when none of DMA sync ops > * is set. > */ > - dev->dma_need_sync = false; > + dev->dma_skip_sync = true; > else > - dev->dma_need_sync = true; > + dev->dma_skip_sync = false; > } > #else /* !CONFIG_DMA_NEED_SYNC */ > static inline void dma_setup_need_sync(struct device *dev) { } > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index ae3e593eaadb..068134697cf1 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -1409,7 +1409,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, > } > > /* > - * If dma_need_sync wasn't set, reset it on first SWIOTLB buffer > + * If dma_skip_sync was set, reset it on first SWIOTLB buffer > * mapping to always sync SWIOTLB buffers. > */ > dma_reset_need_sync(dev); Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland