Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5235973pxj; Wed, 26 May 2021 06:08:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqbn/7FI+5McmkUs4CGEslMTfFwnCXLZDOAWNT7A4Ccugfp1wCW+9Dlh/3CkN3qZ6K2k3Q X-Received: by 2002:a5d:4a51:: with SMTP id v17mr2201930wrs.393.1622034535299; Wed, 26 May 2021 06:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622034535; cv=none; d=google.com; s=arc-20160816; b=UEtRY2YWBvWghnM8xwH0QQr1xzWiezOYAo39QmdQAEx36/YBD00fDPr1WqXql6Fts1 AK7wEK1oy+BZ/42WyEgzgoMP9pPjjaeaAMKf4rHupSiWI4Td+AQydvbcxQF5vqyeeAQk 5LUI94nTu2Lw/ayModZWQCzNUxhvce9JnvAyOzQ1K8gyQ5u34l6+qyu2rMOxViEFwfnx wMLUVUPHk/2fYgq67f8Nk+HWGl7kZHCkiRMZKRTGBYZZ3x/3whHruzdYbirdNJsjngJ9 jaOFeKSNthOR4Iy1i0Szi5KpHk7XeN6IxEleRUQWy1f2Kadr+2sB4IVBYh/vVhW6ghNj HtOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=gMzyAnYPmerz+a+7zbSX+5AFHEYsBrVPgrRvWgMltQ8=; b=PUbgpaHStZOqbl1XpaBP0xPe+sHXszg3zmVb1yt7zo5s1m30Bca7euoasut7gxPP6d GAUDEbLQnCbkk6naDic2qiyX2lY5YW6vXgrNutT4/sP+vmgLpLtF5Q/9DjEoSMjZKtYy ssXvh7kFnrj0I1o+8ic1qPGsQgjJhbnpP0gGjs3tsTbunrHGGEPjxuizr0zpZKaUOt39 ZJXWuJ4qqnkPFNckkMl9QrtJAHYZ632NRKv+6PkV0TOqWvNYb+v0b/eBIsyYzUGxVcTx 6n4xbdkVCaOFEu0UNXvhKXkjyyekjeirvB2SWx6ZE1u22LXiTmALosObVymuz9s2LOGi 8ryw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dD4raOXl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h9si17838365ejc.653.2021.05.26.06.08.32; Wed, 26 May 2021 06:08:55 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dD4raOXl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234250AbhEZMPG (ORCPT + 99 others); Wed, 26 May 2021 08:15:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:50730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233784AbhEZMPF (ORCPT ); Wed, 26 May 2021 08:15:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7DB6A613D6; Wed, 26 May 2021 12:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622031214; bh=6cgAAAry3KXjHYICFlfgug7HP7MtfiezqAbh5vyjbAk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dD4raOXl4m/1dmUYxCXd+9Zhh/XbrtQC52Qny8ZwVBaqmrNGpiCc5ZIU1b4WjGm8H uJa3jIZybN6M6kTMpAfuccsLT4/wRQbg2MVSjmE1yL01mC3lcM16NVvL5naGjFRQ57 RUc8/qmG6+LKY4mt6jNuAHGXfU60PflHdIRn81RXVX/L8quJSpzl4wYs9fdYRMYSyz TDHUTCxqGOaTMeMxI6d2iUlniRYHOiu06+32s75wchffQ8s3cbbJwvz7Jm6fWP5KI+ RznUS6G8WImqfu6sIHm02R4cmQSm1/c2dk4BLfXSL89hrwovsmQduosVw5UITnC7eb z+DGv0xJWhG6g== Date: Wed, 26 May 2021 13:13:23 +0100 From: Will Deacon To: Claire Chang Cc: Rob Herring , mpe@ellerman.id.au, Joerg Roedel , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski , benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , "Rafael J . Wysocki" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , tfiga@chromium.org, bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Subject: Re: [PATCH v7 14/15] dt-bindings: of: Add restricted DMA pool Message-ID: <20210526121322.GA19313@willie-the-truck> References: <20210518064215.2856977-1-tientzu@chromium.org> <20210518064215.2856977-15-tientzu@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210518064215.2856977-15-tientzu@chromium.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Claire, On Tue, May 18, 2021 at 02:42:14PM +0800, Claire Chang wrote: > Introduce the new compatible string, restricted-dma-pool, for restricted > DMA. One can specify the address and length of the restricted DMA memory > region by restricted-dma-pool in the reserved-memory node. > > Signed-off-by: Claire Chang > --- > .../reserved-memory/reserved-memory.txt | 27 +++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > index e8d3096d922c..284aea659015 100644 > --- a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > +++ b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > @@ -51,6 +51,23 @@ compatible (optional) - standard definition > used as a shared pool of DMA buffers for a set of devices. It can > be used by an operating system to instantiate the necessary pool > management subsystem if necessary. > + - restricted-dma-pool: This indicates a region of memory meant to be > + used as a pool of restricted DMA buffers for a set of devices. The > + memory region would be the only region accessible to those devices. > + When using this, the no-map and reusable properties must not be set, > + so the operating system can create a virtual mapping that will be used > + for synchronization. The main purpose for restricted DMA is to > + mitigate the lack of DMA access control on systems without an IOMMU, > + which could result in the DMA accessing the system memory at > + unexpected times and/or unexpected addresses, possibly leading to data > + leakage or corruption. The feature on its own provides a basic level > + of protection against the DMA overwriting buffer contents at > + unexpected times. However, to protect against general data leakage and > + system memory corruption, the system needs to provide way to lock down > + the memory access, e.g., MPU. Note that since coherent allocation > + needs remapping, one must set up another device coherent pool by > + shared-dma-pool and use dma_alloc_from_dev_coherent instead for atomic > + coherent allocation. > - vendor specific string in the form ,[-] > no-map (optional) - empty property > - Indicates the operating system must not create a virtual mapping > @@ -120,6 +137,11 @@ one for multimedia processing (named multimedia-memory@77000000, 64MiB). > compatible = "acme,multimedia-memory"; > reg = <0x77000000 0x4000000>; > }; > + > + restricted_dma_mem_reserved: restricted_dma_mem_reserved { > + compatible = "restricted-dma-pool"; > + reg = <0x50000000 0x400000>; > + }; nit: You need to update the old text that states "This example defines 3 contiguous regions ...". > }; > > /* ... */ > @@ -138,4 +160,9 @@ one for multimedia processing (named multimedia-memory@77000000, 64MiB). > memory-region = <&multimedia_reserved>; > /* ... */ > }; > + > + pcie_device: pcie_device@0,0 { > + memory-region = <&restricted_dma_mem_reserved>; > + /* ... */ > + }; I still don't understand how this works for individual PCIe devices -- how is dev->of_node set to point at the node you have above? I tried adding the memory-region to the host controller instead, and then I see it crop up in dmesg: | pci-host-generic 40000000.pci: assigned reserved memory node restricted_dma_mem_reserved but none of the actual PCI devices end up with 'dma_io_tlb_mem' set, and so the restricted DMA area is not used. In fact, swiotlb isn't used at all. What am I missing to make this work with PCIe devices? Thanks, Will