Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp228916pxb; Wed, 20 Jan 2021 05:46:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyntSMgRc//nLgp+suNZpd+SfcGaHxy3yShsMwRrHiuQihSNoJicOW9A74At809j1mq4i9V X-Received: by 2002:a17:906:1741:: with SMTP id d1mr6441950eje.182.1611150408859; Wed, 20 Jan 2021 05:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611150408; cv=none; d=google.com; s=arc-20160816; b=TpfoRsyxKqy2doNDu2X97VJHoZ2lh2WTWFrw+WAyiYOJBO+VjG3LYoyihnK+rg0Sif BrvJOfbgVA8S03xiXgdyWktwvBR84TH3By7xOMMfyC3Xi/If74a74jQ+AVnuqpil6JGk EDmDcr5R0zd78xuW0f0uFIXM1DEbgVdHDJXM66GmGs3Xovbhl0c/vepY2hSuAigAR+Rh o9VyplSjs7qmexq0RbXwZcgNBoKyGrlnN7oxzxIQMkX01rdnOAG8C4xjqrjE0q27bHKf 7/jV8vP4g84k1L6lqjrYSGkWuHWoDVb5UrUf4MZdaRBYSRZTdr67eZ0TPi2PCq5GjQMj 1ryQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=TRsUOKokreRB/xHYh1+6adxX4iJRCQEWubijbKvKlfA=; b=i39VwuxUCzXteObF5NTIr5dMX0DjzP3w5Mn/N3FJjsgGXcmhrWppec3uPuudrUnJki USLc0fLs9s10Q2lRIjE2/JYMyVZOx+HRvLcSIsCm3ClAQ6FcVxBJDY98zJ4G+Msjb2OV QAauREwZWyMYErZxL5SD7tqdlv2bLvPrVC+q84QkH4oWBgLWtLzE5b4vcuebkH8cOb/H W/0Ee2qMRcgn6SDvUorxSDo6DIqTPoOOczqW/NThr457VZOmaEWm9cF9rW20TwjOEHS8 zDkyn8g5tDVXo1VyjIPyc5eMsxwjMVtNE6XoD/wlhnzOfaZoYB7j58ppDqQRE98/jA4b 7sSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si505816ejm.462.2021.01.20.05.46.24; Wed, 20 Jan 2021 05:46:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2389117AbhATNML (ORCPT + 99 others); Wed, 20 Jan 2021 08:12:11 -0500 Received: from foss.arm.com ([217.140.110.172]:59796 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387715AbhATMad (ORCPT ); Wed, 20 Jan 2021 07:30:33 -0500 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 B9747D6E; Wed, 20 Jan 2021 04:29:47 -0800 (PST) Received: from [10.57.39.58] (unknown [10.57.39.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3030F3F66E; Wed, 20 Jan 2021 04:29:46 -0800 (PST) Subject: Re: [RFC PATCH V2 2/2] iommu: add Unisoc iommu basic driver To: Chunyan Zhang Cc: DTML , Linux Kernel Mailing List , Chunyan Zhang , Sheng Xu , iommu@lists.linux-foundation.org, Rob Herring , Kevin Tang , Baolin Wang , Orson Zhai References: <20210108113851.354947-1-zhang.lyra@gmail.com> <20210108113851.354947-3-zhang.lyra@gmail.com> <47f73502-15fe-5d65-6fc9-22eb078d7797@arm.com> From: Robin Murphy Message-ID: <3a2561fc-65a6-4c68-fdb7-a5b670706f43@arm.com> Date: Wed, 20 Jan 2021 12:29:44 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-20 11:40, Chunyan Zhang wrote: [...] >>> + pgt_base_iova = dom->pgt_va + >>> + ((iova - mdata->iova_start) >> SPRD_IOMMU_PAGE_SHIFT); >>> + >>> + spin_lock_irqsave(&dom->pgtlock, flags); >>> + for (i = 0; i < page_num; i++) { >>> + pgt_base_iova[i] = pabase >> SPRD_IOMMU_PAGE_SHIFT; >> >> Out of curiosity, is the pagetable walker cache-coherent, or is this >> currently managing to work by pure chance and natural cache churn? > > ->iotlb_sync_map() was implemented in this driver, I guess that has > done what you say here? No, sync_map only ensures that the previous (invalid) PTE isn't held in the IOMMU's TLB. If pgt_va is a regular page allocation then you're writing the new PTE to normal kernel memory, with nothing to guarantee that write goes any further than the CPU's L1 cache. Thus either the IOMMU has capable of snooping the CPU caches in order to see the updated PTE value (rather than refetching the stale value from DRAM), or you're just incredibly lucky that by the time the IOMMU *does* go to fetch the PTE for that address, that updated cache line has already been evicted out to DRAM naturally. This is not an issue if you use the proper DMA allocator, since that will ensure you get a non-cacheable buffer if you need one. Robin.