Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp710749pxb; Wed, 20 Jan 2021 19:32:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0jB1+czBCfKoEXbhMwZQJwgMlqDN9SpqdDS1g7hVSI29JN5raiyCyj4csl0Ezoiv4VvxX X-Received: by 2002:a17:906:3f8d:: with SMTP id b13mr7712680ejj.464.1611199945445; Wed, 20 Jan 2021 19:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611199945; cv=none; d=google.com; s=arc-20160816; b=qH7XbPDu+7g4rYnJxMy2hUNhBn5+b/SDLKqEqsDg/0ManPoXCXGC9iisqGFXvlh/Hk wb3DVlmNjCKH/Ku4ARcHmrak3YO79PYy25bFnn+AeWqfWvs+KyLX3Ys1T07t5PWYykK3 gh1a7FAtWd397RyBs2eWqgidNJLw5IfCHfIDXap7Sj54Sb3zwTIGrbpyAhUjKNhxtUPs W/JzuYJvQ/XY/YXTvCpunhtKUlvoGdCaKjbBlZ84kBppgah2uw4cuQ+v5vo2/3oUhIcu S1yfd281qyuZmvGk6xnWrWoqla/rYlJhzOtTEEIyscppy2/fALzye4hv66f4QkfzwD7g AeAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=V/1TBQ4VEUa7FhVQPwUQv4FuTUqjT4Wc8GDOh/qjJlw=; b=t4JluyaDPU+o5aJRzttsUTNkPaJImzuuqDOQS7TOS/p8TfCGQJc5X3VANUb0473z7u 0K6ek9FUidV/q5HSeDJGniEZijm+TrR0W0ryG27VkCDNWDeF4JtDqMZLr+ynx5BoBoHM p7rkuRH0IIFudhQ2fU04bCAOoCVKpuzmLv9mC+PWhDAOgalJexqRjk7fdzWpmg8efu3K YXUK05lifxD3IwFJ++SrCIyWmzIcfAbZhAM93C6olu9QblGbAKx+aM46AGNdw9oqVPyV mC0a7eJs5UTNZrAJyttnSDTfrxEDGNu0WHLKJ0ua9GBQ/unYR4VfHQRGYUP/lptZuzOh 1wlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmvEQDVt; 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 de13si893764edb.279.2021.01.20.19.32.02; Wed, 20 Jan 2021 19:32:25 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmvEQDVt; 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 S2404661AbhATXzs (ORCPT + 99 others); Wed, 20 Jan 2021 18:55:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:54556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733269AbhATVcT (ORCPT ); Wed, 20 Jan 2021 16:32:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 59FD52368A; Wed, 20 Jan 2021 21:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611178292; bh=9CXXn3DwKkTTYhGUSuO/SI53HoPSF8zgyeHYS4YvRdY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZmvEQDVtsexRf8n+ZOC1JbuBQnuBhbV+r3jD4kU3Q1tMAid8yX+yqYfJEbOdcXgMA rj/QXs5sTJEgKtheY4gImRh4zCXvn8N2ChQdofm3pHRivCgOB+sxuai3yKlikVUe8k 0BmRxe14MAaAn1jeMSxzxdQbEaIjPFqRcdtyHRGAO007v7GUojsrvuJx0vbYiLCW4y CE8T7v8FgFjOOFzn6XDR1a3R7a15VGz6LfvNskEJWJ+wrvKK3PCEo/X4rrgHOkc5EU 75qDn57wy4vXYALFVoUbkz6Mt+vLxPPKyyUcaTDi5ZRLHNNoPHr3mcqRXma66ALKFJ ALtCNmZmqRqOg== Received: by mail-ed1-f49.google.com with SMTP id d22so76419edy.1; Wed, 20 Jan 2021 13:31:32 -0800 (PST) X-Gm-Message-State: AOAM532/KVUKVt254MTD6P8nSQDMd2LjTVg/rD0zc+DIZF+ZlLMvwNBt vB7ykdKkCU5Pwo1LmWdSaHIzxhd9Xi0AhQ6/oQ== X-Received: by 2002:a05:6402:1751:: with SMTP id v17mr8944895edx.289.1611178290171; Wed, 20 Jan 2021 13:31:30 -0800 (PST) MIME-Version: 1.0 References: <20210106034124.30560-1-tientzu@chromium.org> <20210106034124.30560-6-tientzu@chromium.org> <20210120165348.GA220770@robh.at.kernel.org> <313f8052-a591-75de-c4c2-ee9ea8f02e7f@arm.com> In-Reply-To: <313f8052-a591-75de-c4c2-ee9ea8f02e7f@arm.com> From: Rob Herring Date: Wed, 20 Jan 2021 15:31:17 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v3 5/6] dt-bindings: of: Add restricted DMA pool To: Robin Murphy Cc: Claire Chang , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Christoph Hellwig , Marek Szyprowski , Grant Likely , Heinrich Schuchardt , Thierry Reding , Ingo Molnar , Thiago Jung Bauermann , Peter Zijlstra , Greg Kroah-Hartman , Saravana Kannan , "Wysocki, Rafael J" , Heikki Krogerus , Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , linuxppc-dev , Linux IOMMU , xen-devel@lists.xenproject.org, Tomasz Figa , Nicolas Boichat Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 11:30 AM Robin Murphy wrote: > > On 2021-01-20 16:53, Rob Herring wrote: > > On Wed, Jan 06, 2021 at 11:41:23AM +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 device tree. > > > > If this goes into DT, I think we should be able to use dma-ranges for > > this purpose instead. Normally, 'dma-ranges' is for physical bus > > restrictions, but there's no reason it can't be used for policy or to > > express restrictions the firmware has enabled. > > There would still need to be some way to tell SWIOTLB to pick up the > corresponding chunk of memory and to prevent the kernel from using it > for anything else, though. Don't we already have that problem if dma-ranges had a very small range? We just get lucky because the restriction is generally much more RAM than needed. In any case, wouldn't finding all the dma-ranges do this? We're already walking the tree to find the max DMA address now. > >> Signed-off-by: Claire Chang > >> --- > >> .../reserved-memory/reserved-memory.txt | 24 +++++++++++++++++++ > >> 1 file changed, 24 insertions(+) > >> > >> diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > >> index e8d3096d922c..44975e2a1fd2 100644 > >> --- a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > >> +++ b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > >> @@ -51,6 +51,20 @@ 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 restrict > >> + the DMA to a predefined memory region. > >> - vendor specific string in the form ,[-] > >> no-map (optional) - empty property > >> - Indicates the operating system must not create a virtual mapping > >> @@ -120,6 +134,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>; > >> + }; > >> }; > >> > >> /* ... */ > >> @@ -138,4 +157,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>; > > > > PCI hosts often have inbound window configurations that limit the > > address range and translate PCI to bus addresses. Those windows happen > > to be configured by dma-ranges. In any case, wouldn't you want to put > > the configuration in the PCI host node? Is there a usecase of > > restricting one PCIe device and not another? > > The general design seems to accommodate devices having their own pools > such that they can't even snoop on each others' transient DMA data. If > the interconnect had a way of wiring up, say, PCI RIDs to AMBA NSAIDs, > then in principle you could certainly apply that to PCI endpoints too > (presumably you'd also disallow them from peer-to-peer transactions at > the PCI level too). At least for PCI, I think we can handle this. We have the BDF in the 3rd address cell in dma-ranges. The Openfirmware spec says those are 0 in the case of ranges. It doesn't talk about dma-ranges though. But I think we could extend it to allow for BDF. Though typically with PCIe every device is behind its own bridge and each bridge node can have a dma-ranges. Rob