Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp630454pxf; Wed, 10 Mar 2021 13:44:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwz/5Ch/r5Phhmqm6ZD62P5Dne9yzejxWb7gxaSQ6OZz3ljdne0deScuPCc0z+UvFHlVjxq X-Received: by 2002:a17:906:bfcc:: with SMTP id us12mr3297ejb.266.1615412663459; Wed, 10 Mar 2021 13:44:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615412663; cv=none; d=google.com; s=arc-20160816; b=hY2pdX+6ldtId/OEqekWriKa3Zej2jd+jy0dBHxOnW5WwnO56meVRSc/FjSYw5HXIA 3/BrZxYr58yUP++XZ0VrE8oZHz3S/wo3kJW4KB4Ti7sMBSt3yIpsqcMYedQEZX4twuLt B45i/SNlri00fJlkH8991hZEffrzYRdl4Dgqg/1XY6QooPSLwo3JKhsZ2rcXbE66MmLC 0WgNxFnEBNG9TK9X9IQNWcpsVjr5OJa0YcPj2TfpRCEwKEf1SPjZWg4mynXnW4JvLAUt fxs7BQYBkhRKX/ZASjUCceRN+etZto7OuH7aHfGDIaZWnor5nd8IVVDqep7uLUNaGYmZ Vrrw== 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=FNh9bGZM4U0TXffjXSwIwHM7mdvj/B67Bh3pYuXLGfo=; b=uDOynHcygE1/Ui2urb8ElB5as+dhnm6WSzj3ll+zfKa3oPbBixMF+pyYdNqxRXuWpk pVyf5ktWeKWBf+KGBrAxOI8x8LnXRPt0Y+h2SWXm0sM7q+BVHwY3+tIBpBQhbHof+cBm 9XF92HaJmKTE2YHnh2mHAikGAIETKX6yN91pw5whOb32w/NCvBj7P8FGZIweom8GsseS 4GVUgJdiBiodvtEFmy4AlNXCWlVKvacSwDJi330rt2+bIecI90Qr07kQydZrcjSITY5o P906HO4t1OX2p3vpvbxCRTODEXHtpoNcWLrckl+EOmgemM8jhQ/1VoPkxh8PMcnfft+j 04jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eDXX9I0r; 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 i8si394579edy.129.2021.03.10.13.43.59; Wed, 10 Mar 2021 13:44:23 -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=eDXX9I0r; 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 S231636AbhCJVlO (ORCPT + 99 others); Wed, 10 Mar 2021 16:41:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:42890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231778AbhCJVky (ORCPT ); Wed, 10 Mar 2021 16:40:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 731E764FE8; Wed, 10 Mar 2021 21:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615412454; bh=lljbEm8y6jNcxvIMoB+J261BTyFdid0U0j/1mSpgrns=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eDXX9I0rBca4D2age7wm+DtVv6geacxhoDXnt5SysKVhym9aYBoOULiDV+ts4rOLP jxqSr5B0vX0/o/NShM/j+kwlnb4hGRATSr0mEhy2fTgb4b/f9TFkN0sucrguP/wUnN VpsdkpA2+bkS7oY10zU2zq+j59iH8lNhIYLI61shYJGWLghrHuyig30tcjLo3fTgbB 3DEVFLncbcg+C2B9HtVOo3SUvsmkNa+xgZXWZi3ZI5a2G3Gno+oUiLdB0wFYwj7D9V li5Sma9VH3O9evfauK7N3UwWSXURG5BK+1LBH0BYK5Vbx589vAqinspwZjQAwTmkXH mjJKT2LCYnF3Q== Received: by mail-qk1-f179.google.com with SMTP id m186so1917402qke.12; Wed, 10 Mar 2021 13:40:54 -0800 (PST) X-Gm-Message-State: AOAM532bmvbOE5P49KZOS0cD2KWJvsod2ISvDBzPVJPC80auwWE+hToR AA4UccCh9R29pvbb73fNZY1LaaCoz6jH/BN8fQ== X-Received: by 2002:a05:620a:1001:: with SMTP id z1mr4659415qkj.364.1615412453005; Wed, 10 Mar 2021 13:40:53 -0800 (PST) MIME-Version: 1.0 References: <20210209062131.2300005-1-tientzu@chromium.org> <20210209062131.2300005-14-tientzu@chromium.org> <20210310160747.GA29834@willie-the-truck> In-Reply-To: <20210310160747.GA29834@willie-the-truck> From: Rob Herring Date: Wed, 10 Mar 2021 14:40:41 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 13/14] dt-bindings: of: Add restricted DMA pool To: Will Deacon Cc: Claire Chang , Michael Ellerman , Joerg Roedel , Frank Rowand , Konrad Rzeszutek Wilk , Boris Ostrovsky , Juergen Gross , Christoph Hellwig , Marek Szyprowski , Benjamin Herrenschmidt , Paul Mackerras , "list@263.net:IOMMU DRIVERS" , Stefano Stabellini , Robin Murphy , Grant Likely , Heinrich Schuchardt , Thierry Reding , Ingo Molnar , Thiago Jung Bauermann , Peter Zijlstra , Greg KH , Saravana Kannan , "Rafael J . Wysocki" , Heikki Krogerus , Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev , xen-devel , Nicolas Boichat , Jim Quinlan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 10, 2021 at 9:08 AM Will Deacon wrote: > > Hi Claire, > > On Tue, Feb 09, 2021 at 02:21:30PM +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 | 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..fc9a12c2f679 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 lock down > > + the memory access, e.g., MPU. > > As far as I can tell, these pools work with both static allocations (which > seem to match your use-case where firmware has preconfigured the DMA ranges) > but also with dynamic allocations where a 'size' property is present instead > of the 'reg' property and the kernel is responsible for allocating the > reservation during boot. Am I right and, if so, is that deliberate? I believe so. I'm not keen on having size only reservations in DT. Yes, we allowed that already, but that's back from the days of needing large CMA carveouts to be reserved early in boot. I've read that the kernel is much better now at contiguous allocations, so do we really need this in DT anymore? > I ask because I think that would potentially be useful to us for the > Protected KVM work, where we need to bounce virtio memory accesses via > guest-determined windows because the guest memory is generally inaccessible > to the host. We've been hacking this using a combination of "swiotlb=force" > and set_memory_{decrypted,encrypted}() but it would be much better to > leverage the stuff you have here. > > Also: > > > + > > + 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>; > > + /* ... */ > > + }; > > I find this example a bit weird, as I didn't think we usually had DT nodes > for PCI devices; rather they are discovered as a result of probing config > space. Is the idea that you have one reserved memory region attached to the > RC and all the PCI devices below that share the region, or is there a need > for a mapping mechanism? We can have DT nodes for PCI. AIUI, IBM power systems always do. For FDT, it's only if there are extra non-discoverable resources. It's particularly fun when it's resources which need to be enabled for the PCI device to be discovered. That seems to be a growing problem as PCI becomes more common on embedded systems. Rob