Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp197144pxb; Thu, 14 Apr 2022 19:57:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwalI42vw+DMziiwspx27UGEAlTdOEDs5h/Z3Sq8XVg2E6N72rfYarKj7rGIuF0JOmSjDIJ X-Received: by 2002:a05:6a00:124f:b0:4fb:2608:78de with SMTP id u15-20020a056a00124f00b004fb260878demr6731379pfi.27.1649991449436; Thu, 14 Apr 2022 19:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649991449; cv=none; d=google.com; s=arc-20160816; b=k2dKcRawkF4KscmSm2GhP8FN7Aph7QN7WIdVgXTbLIvTczeh8pn4LUDTfJs4YNnoZo 8lQeuL6NJ8Osr3wj2uuiV1H/1uoC5/V1PZfD04KIYG+vAnfCMBHmDiEJWaLwkiK+nHOe ki4pg3A+U19Qp5hR4tGo3Zcwcz++jvm3GUD1lL24JMR0HKEtOlkMpo1qeY4mve/9/JvH MDE159vxievzXrJBIy0bC+ebdjaZaiNcMw4tyac8rEuyVuxcQ9XresGSQc4IKUiLdaCE UGLWGzXn/J8Sk/Qb+xJFcpJGZPFTMkSvpJW6cLlIXNOykeWxPr4ZN1PcHd83b3nZ5Hfv tWAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=h8GC+d+rw06BBegzr+MHGZt8YKZfLes3RDo5FIDnzmg=; b=s5XhqhHC4Ozl4gav9mAfCEsoUtdA3Vz1v9FHxKTKmCO+DRSVyRpFPD8deoZbwq/dJB sq2Y5eg51YGHGudMdZr3GRex3wRRNtAM0CRVynNHRb1+rZ9xJQQrNvlT/mxIPk9qzMUC +ZKJAqL15CrxweOOhFn5NMOBT+iY71/H793bevWGJa03N/bdogg2wIQTJVYVMA2MwfTe jhDE9aD3NexEPE/HZkAoy1QybizbFVNUNJktxrZi0WPqhwFNItWH53hTR1OSxEdJ4adT r3bFx4esA3xIPMKHd1oRp2+umNByKWEroSdhhvoLRZWzBN/YR35Hqev43vF7NrvVLeDz mciw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a17090341c900b001586f9a109fsi285907ple.0.2022.04.14.19.57.15; Thu, 14 Apr 2022 19:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235716AbiDMNNZ (ORCPT + 99 others); Wed, 13 Apr 2022 09:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233614AbiDMNNX (ORCPT ); Wed, 13 Apr 2022 09:13:23 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6E7A3981F for ; Wed, 13 Apr 2022 06:11:02 -0700 (PDT) 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 6446A12FC; Wed, 13 Apr 2022 06:11:02 -0700 (PDT) Received: from [10.57.41.19] (unknown [10.57.41.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 23AB13F73B; Wed, 13 Apr 2022 06:11:01 -0700 (PDT) Message-ID: <4a993382-6a29-a0f4-4600-90ab60ad982a@arm.com> Date: Wed, 13 Apr 2022 14:10:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] dma-direct: avoid redundant memory sync for swiotlb Content-Language: en-GB To: Christoph Hellwig , Chao Gao Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, m.szyprowski@samsung.com, Wang Zhaoyang1 , Gao Liang , Kevin Tian References: <20220412113805.3210-1-chao.gao@intel.com> <20220413010157.GA10502@gao-cwp> <20220413045958.GA31209@lst.de> From: Robin Murphy In-Reply-To: <20220413045958.GA31209@lst.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-04-13 05:59, Christoph Hellwig wrote: > On Wed, Apr 13, 2022 at 09:02:02AM +0800, Chao Gao wrote: >> dma_direct_sync_single_for_cpu() also calls arch_sync_dma_for_cpu_all() >> and arch_dma_mark_clean() in some cases. if SWIOTLB does sync internally, >> should these two functions be called by SWIOTLB? >> >> Personally, it might be better if swiotlb can just focus on bounce buffer >> alloc/free. Adding more DMA coherence logic into swiotlb will make it >> a little complicated. >> >> How about an open-coded version of dma_direct_sync_single_for_cpu >> in dma_direct_unmap_page with swiotlb_sync_single_for_cpu replaced by >> swiotlb_tbl_unmap_single? > > I don't think the swiotlb and non-coherent case ever fully worked. > Before the merge of swiotlb into dma-direct they obviously were > mutally exclusive, and even now all the cache maintainance is done > on the physical address of the original data, not the swiotlb buffer. Are you sure? AFAICS swiotlb_map() does the right thing, and dma_direct_{sync,unmap} are working off the DMA address, which is that of the bounce slot when SWIOTLB is involved (not least, how would the is_swiotlb_buffer() checks work otherwise?) > If we want to fix that properly all the arch dma calls will need to > move into swiotlb, but that is a much bigger patch. > > So for now I'd be happy with the one liner presented here, but > eventually the whole area could use an overhaul. Sure, whoever gets round to tackling DMA_ATTR_NO_SNOOP first will need to go through all the cache maintenance hooks anyway, so happy to kick the can down the road until then. Thanks, Robin.