Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5349344ybi; Wed, 12 Jun 2019 00:42:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6yHD2zjPe9yECEGzmLIsGnTR83FhF128Qps3RqicVGWyjbDr1639gYVvc8ugVnY2kAude X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr80414904plb.221.1560325369883; Wed, 12 Jun 2019 00:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560325369; cv=none; d=google.com; s=arc-20160816; b=e1k7oWqi1kHUhypiur5FR1vvnE99k3yGNzkzDhGMAySlB5PFC/CjlMU6FijXq5NEem CeID9/X7FiSVbTaNQ8TxneqyvoNYTdBqqrK4EFuDzlc7Vayc/Z0NH87pjgmgFtiUGOFW nZl9E5QH0xzSe4uemRSEEWLH9vIAWpM1ICBNSxOhruSoRb8wrbZg0HWDKm61ZWtAqsIj pnITTYejiLyr/f+QpQIdpM1RR7LHivrnVnmEcAuBmEuk9o2UV1TKfyEsvd6VE9DPzLmQ gOZQNY26tLIoy+hf/NcR+W1ElhT7Ms5sziGNtvbJZNIOZZtWCghjSR35cdN4E6l75xSI jFow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:cc; bh=nxRZSBrsGtgmORMcmtTb5/xKQT6gfTzjHAEq2Xl95R4=; b=vGi2uiwdppXUaJxSfJaOEx+vytkXhvoP1NX9JVLg3UzJGGpOSLSESmWP/yZzV1alXt udks0/sGzChtAvjO9jGi59CTxueNfj1rqgoidcDx3mzkv/zfGVSxn8KwqjoGM/kRpTXU OYoZJ1tBjUmRViq2mI4Ll3n3R2/3X1yKmlUtYPYcghoY8iw2K2SMyeihAxNqGqi5MjC3 B86ugKlLquOqKNV/axTpuC7EAjrMutJxsBiBcqkAXZ+yImCKFVHFCxwzSXfrRVjJwbbo inwuoOQPVhYPkiHE04yt2zdYUGagoEsmTvr+t/4spqM9O95kjMCdMzdkdnhtA6ypta1Y aMGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si15509193pfa.240.2019.06.12.00.42.30; Wed, 12 Jun 2019 00:42:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408506AbfFLDHW (ORCPT + 99 others); Tue, 11 Jun 2019 23:07:22 -0400 Received: from mga07.intel.com ([134.134.136.100]:29083 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404957AbfFLDHW (ORCPT ); Tue, 11 Jun 2019 23:07:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 20:07:21 -0700 X-ExtLoop1: 1 Received: from allen-box.sh.intel.com (HELO [10.239.159.136]) ([10.239.159.136]) by orsmga004.jf.intel.com with ESMTP; 11 Jun 2019 20:07:15 -0700 Cc: baolu.lu@linux.intel.com, David Woodhouse , Joerg Roedel , Bjorn Helgaas , Christoph Hellwig , ashok.raj@intel.com, jacob.jun.pan@intel.com, alan.cox@intel.com, kevin.tian@intel.com, mika.westerberg@linux.intel.com, Ingo Molnar , Greg Kroah-Hartman , pengfei.xu@intel.com, Marek Szyprowski , Robin Murphy , Jonathan Corbet , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Steven Rostedt , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 0/9] iommu: Bounce page for untrusted devices To: Konrad Rzeszutek Wilk References: <20190603011620.31999-1-baolu.lu@linux.intel.com> <20190610154241.GS28796@char.us.oracle.com> From: Lu Baolu Message-ID: Date: Wed, 12 Jun 2019 11:00:06 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190610154241.GS28796@char.us.oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 6/10/19 11:42 PM, Konrad Rzeszutek Wilk wrote: > On Mon, Jun 03, 2019 at 09:16:11AM +0800, Lu Baolu wrote: >> The Thunderbolt vulnerabilities are public and have a nice >> name as Thunderclap [1] [3] nowadays. This patch series aims >> to mitigate those concerns. >> >> An external PCI device is a PCI peripheral device connected >> to the system through an external bus, such as Thunderbolt. >> What makes it different is that it can't be trusted to the >> same degree as the devices build into the system. Generally, >> a trusted PCIe device will DMA into the designated buffers >> and not overrun or otherwise write outside the specified >> bounds. But it's different for an external device. >> >> The minimum IOMMU mapping granularity is one page (4k), so >> for DMA transfers smaller than that a malicious PCIe device >> can access the whole page of memory even if it does not >> belong to the driver in question. This opens a possibility >> for DMA attack. For more information about DMA attacks >> imposed by an untrusted PCI/PCIe device, please refer to [2]. >> >> This implements bounce buffer for the untrusted external >> devices. The transfers should be limited in isolated pages >> so the IOMMU window does not cover memory outside of what >> the driver expects. Previously (v3 and before), we proposed >> an optimisation to only copy the head and tail of the buffer >> if it spans multiple pages, and directly map the ones in the >> middle. Figure 1 gives a big picture about this solution. >> >> swiotlb System >> IOVA bounce page Memory >> .---------. .---------. .---------. >> | | | | | | >> | | | | | | >> buffer_start .---------. .---------. .---------. >> | |----->| |*******>| | >> | | | | swiotlb| | >> | | | | mapping| | >> IOMMU Page '---------' '---------' '---------' >> Boundary | | | | >> | | | | >> | | | | >> | |------------------------>| | >> | | IOMMU mapping | | >> | | | | >> IOMMU Page .---------. .---------. >> Boundary | | | | >> | | | | >> | |------------------------>| | >> | | IOMMU mapping | | >> | | | | >> | | | | >> IOMMU Page .---------. .---------. .---------. >> Boundary | | | | | | >> | | | | | | >> | |----->| |*******>| | >> buffer_end '---------' '---------' swiotlb'---------' >> | | | | mapping| | >> | | | | | | >> '---------' '---------' '---------' >> Figure 1: A big view of iommu bounce page >> >> As Robin Murphy pointed out, this ties us to using strict mode for >> TLB maintenance, which may not be an overall win depending on the >> balance between invalidation bandwidth vs. memcpy bandwidth. If we >> use standard SWIOTLB logic to always copy the whole thing, we should >> be able to release the bounce pages via the flush queue to allow >> 'safe' lazy unmaps. So since v4 we start to use the standard swiotlb >> logic. >> >> swiotlb System >> IOVA bounce page Memory >> buffer_start .---------. .---------. .---------. >> | | | | | | >> | | | | | | >> | | | | .---------.physical >> | |----->| | ------>| |_start >> | |iommu | | swiotlb| | >> | | map | | map | | >> IOMMU Page .---------. .---------. '---------' > > The prior picture had 'buffer_start' at an offset in the page. I am > assuming you meant that here in as well? In prior picture, since we only use bounce buffer for head and tail partial-page buffers, so we need to return buffer_start at the same offset as the physical buffer. Here, we use a whole swiotlb bounce buffer, hence we should use the same offset as the bounce buffer (a.k.a. offset = 0). > > Meaning it starts at the same offset as 'physical_start' in the right > side box? > >> Boundary | | | | | | >> | | | | | | >> | |----->| | | | >> | |iommu | | | | >> | | map | | | | >> | | | | | | >> IOMMU Page .---------. .---------. .---------. >> Boundary | | | | | | >> | |----->| | | | >> | |iommu | | | | >> | | map | | | | >> | | | | | | >> IOMMU Page | | | | | | >> Boundary .---------. .---------. .---------. >> | | | |------->| | >> buffer_end '---------' '---------' swiotlb| | >> | |----->| | map | | >> | |iommu | | | | >> | | map | | '---------' physical >> | | | | | | _end >> '---------' '---------' '---------' >> Figure 2: A big view of simplified iommu bounce page >> >> The implementation of bounce buffers for untrusted devices >> will cause a little performance overhead, but we didn't see >> any user experience problems. The users could use the kernel > > What kind of devices did you test it with? Most test work was done by Xu Pengfei (cc'ed). He has run the code on real platforms with various thunderbolt peripherals (usb, disk, network, etc.). > > Thank you for making this awesome cover letter btw! > You are welcome. Best regards, Baolu