Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp487411pxu; Thu, 7 Jan 2021 09:53:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvLpZb/RQiyx6LAqIWDAJpeRATSyyE8Y30UkiuDeRIqZm1npGf1H8kBhOag8EknkuvDzsR X-Received: by 2002:a17:906:c2ca:: with SMTP id ch10mr7141059ejb.157.1610041989119; Thu, 07 Jan 2021 09:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610041989; cv=none; d=google.com; s=arc-20160816; b=qVCp+9wIg+hFtFohafgwcwfnHR04kQnzPKaMjFk9o5U4ahuQX/JpMh3Etl1D/m3lkJ QPXbNZxbYwbA+lj1zBmIMwXLYD2uKevGUIrOYJcSP8ADvtWVFHAukU/wvrrZoqRIXYhE ToUALAfQz/RopVgxrTIOP6baq88maND2uK3Fd9qgL4qZd57umES6SrVp8SqaZ9UFQpDc j+8r9bx1nBv85oh+ESY2lDcLy6DU6xfvRNQ9gTchvKaLvwh/kGSWWixNtpTv39uF2gh8 4harEvYgY6zV+HzgDiXro24LvFejbIlDoT226o7BC5952CIJkGmxgy7RPrVRM8E+VllP DUkg== 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=6Eoqk68P1Bcb0VR3W1zmVx5ceWjyA10pZm4KhVQJdAs=; b=z8Ejd95e86vuE/ZBsY1Auabd7P3ggC5pG2F3EAOkxQHpjHhCVBT1B3VElDGunkIlLF Je0+9jNBNAm1XlInMIlaP9mvqX1R2fNL7dTxmLCS6vefIcz8YO97hryTovzLaGU2Zhl4 IdHeA/hRgdU0tJIBJhQcUw4gN3Xyy4/5q06dCk2OSHTwpf1Sgr0iKk2QHLF08MjRQQIu VLWYheZhfwoUYEG405tqzat+23K6LYzsaESBqJfkH/3ZhLJH5WqsaRDEg0ykMSExSwW0 awRurHiniWZrlPhsC2kTXTx7ext1S1/lGHqlAxSJaxx5Yu4dG4wihy3BkAFa83hejLto 0C+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GM+iTlQ3; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z21si2542124ejj.256.2021.01.07.09.52.45; Thu, 07 Jan 2021 09:53:09 -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=@chromium.org header.s=google header.b=GM+iTlQ3; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728826AbhAGRuJ (ORCPT + 99 others); Thu, 7 Jan 2021 12:50:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726319AbhAGRuI (ORCPT ); Thu, 7 Jan 2021 12:50:08 -0500 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2EBC0612F6 for ; Thu, 7 Jan 2021 09:48:42 -0800 (PST) Received: by mail-io1-xd32.google.com with SMTP id d9so6970353iob.6 for ; Thu, 07 Jan 2021 09:48:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6Eoqk68P1Bcb0VR3W1zmVx5ceWjyA10pZm4KhVQJdAs=; b=GM+iTlQ3BQkvH1ob8TdUxcmAsi46pi2mtWELHUgZFyyPO+EndHkxYi6Efkg3O18Tku edQt8UB0Llti6Epm5pi7gQD7Rvjj2XwfVndg2ehauNbNVLy3PAXR8NhD8ppHMDSgrEjB eTe/tAn9d2RFhHsPSUNMdpOJeoKvJtOqJ4IiU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6Eoqk68P1Bcb0VR3W1zmVx5ceWjyA10pZm4KhVQJdAs=; b=MQWRXZwGCPol6KXUW3EQ7NoiJcc6RnXe81xsK6ApPTY9X+kATuFdhT7jFBSRZj2VUC IYyMdoZAWJAFk4J/Hlpi8yGnPHDoFgQB1FGGRgpFUfTyDLOUEtoQTdjNEmpNnED6rfA7 BVClFiqM/4e3pjnQS5Q1xDuBG0DTyHbvK3h/A4ZkkG0/SB2kihGy6N58hqrgN68iWHrG jghs9DQkz2bfOg1Mm+KVxJ+ECR4IwoHeYdNUUxQuWd3+5c2WCyFY1urq9hHXk4gBNDqQ M4pj4jmLcjN03T2uhjphXi6xaYT0wqjKJx1MMYsk4tJSK2osF/rKZucc8sOB5m9vCkM9 2XyA== X-Gm-Message-State: AOAM532o6V2YrjR0Bm05H+NIulF5Yr36sG/4BqO/xDa2GQ9KW63FA5th qaCeWUf1AXk0KDn92U/3xyu0oZqglaZ/N+tA X-Received: by 2002:a02:8791:: with SMTP id t17mr9010493jai.28.1610041721575; Thu, 07 Jan 2021 09:48:41 -0800 (PST) Received: from mail-il1-f172.google.com (mail-il1-f172.google.com. [209.85.166.172]) by smtp.gmail.com with ESMTPSA id h16sm4866906ile.6.2021.01.07.09.48.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Jan 2021 09:48:41 -0800 (PST) Received: by mail-il1-f172.google.com with SMTP id e7so7548489ile.7 for ; Thu, 07 Jan 2021 09:48:41 -0800 (PST) X-Received: by 2002:a92:d592:: with SMTP id a18mr8620iln.64.1610041335740; Thu, 07 Jan 2021 09:42:15 -0800 (PST) MIME-Version: 1.0 References: <20210106034124.30560-1-tientzu@chromium.org> In-Reply-To: From: Claire Chang Date: Fri, 8 Jan 2021 01:42:04 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v3 0/6] Restricted DMA To: Florian Fainelli Cc: Rob Herring , mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , will@kernel.org, Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, Christoph Hellwig , Marek Szyprowski , 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@intel.com, heikki.krogerus@linux.intel.com, Andy Shevchenko , rdunlap@infradead.org, dan.j.williams@intel.com, Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , xen-devel@lists.xenproject.org, Tomasz Figa , Nicolas Boichat , Jim Quinlan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 7, 2021 at 2:48 AM Florian Fainelli wrote: > > Hi, > > First of all let me say that I am glad that someone is working on a > upstream solution for this issue, would appreciate if you could CC and > Jim Quinlan on subsequent submissions. Sure! > > On 1/5/21 7:41 PM, Claire Chang wrote: > > This series implements mitigations for 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. > > > > For example, we plan to use the PCI-e bus for Wi-Fi and that PCI-e bus is > > not behind an IOMMU. As PCI-e, by design, gives the device full access to > > system memory, a vulnerability in the Wi-Fi firmware could easily escalate > > to a full system exploit (remote wifi exploits: [1a], [1b] that shows a > > full chain of exploits; [2], [3]). > > > > To mitigate the security concerns, we introduce restricted DMA. Restricted > > DMA utilizes the existing swiotlb to bounce streaming DMA in and out of a > > specially allocated region and does memory allocation from the same region. > > 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 a way to restrict the DMA to a predefined memory region (this is > > usually done at firmware level, e.g. in ATF on some ARM platforms). > > Can you explain how ATF gets involved and to what extent it does help, > besides enforcing a secure region from the ARM CPU's perpsective? Does > the PCIe root complex not have an IOMMU but can somehow be denied access > to a region that is marked NS=0 in the ARM CPU's MMU? If so, that is > still some sort of basic protection that the HW enforces, right? We need the ATF support for memory MPU (memory protection unit). Restricted DMA (with reserved-memory in dts) makes sure the predefined memory region is for PCIe DMA only, but we still need MPU to locks down PCIe access to that specific regions. > > On Broadcom STB SoCs we have had something similar for a while however > and while we don't have an IOMMU for the PCIe bridge, we do have a a > basic protection mechanism whereby we can configure a region in DRAM to > be PCIe read/write and CPU read/write which then gets used as the PCIe > inbound region for the PCIe EP. By default the PCIe bridge is not > allowed access to DRAM so we must call into a security agent to allow > the PCIe bridge to access the designated DRAM region. > > We have done this using a private CMA area region assigned via Device > Tree, assigned with a and requiring the PCIe EP driver to use > dma_alloc_from_contiguous() in order to allocate from this device > private CMA area. The only drawback with that approach is that it > requires knowing how much memory you need up front for buffers and DMA > descriptors that the PCIe EP will need to process. The problem is that > it requires driver modifications and that does not scale over the number > of PCIe EP drivers, some we absolutely do not control, but there is no > need to bounce buffer. Your approach scales better across PCIe EP > drivers however it does require bounce buffering which could be a > performance hit. Only the streaming DMA (map/unmap) needs bounce buffering. I also added alloc/free support in this series (https://lore.kernel.org/patchwork/patch/1360995/), so dma_direct_alloc() will try to allocate memory from the predefined memory region. As for the performance hit, it should be similar to the default swiotlb. Here are my experiment results. Both SoCs lack IOMMU for PCIe. PCIe wifi vht80 throughput - MTK SoC tcp_tx tcp_rx udp_tx udp_rx w/o Restricted DMA 244.1 134.66 312.56 350.79 w/ Restricted DMA 246.95 136.59 363.21 351.99 Rockchip SoC tcp_tx tcp_rx udp_tx udp_rx w/o Restricted DMA 237.87 133.86 288.28 361.88 w/ Restricted DMA 256.01 130.95 292.28 353.19 The CPU usage doesn't increase too much either. Although I didn't measure the CPU usage very precisely, it's ~3% with a single big core (Cortex-A72) and ~5% with a single small core (Cortex-A53). Thanks! > > Thanks! > -- > Florian