Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3389652ybi; Mon, 10 Jun 2019 09:24:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTjrtoF2tPPzqJ6kjI5u4I75DN2nX4NfKqpK0Dt5Dsud5Vd7Brv2HPunyONYPYGpcGY3Vx X-Received: by 2002:a63:2ec6:: with SMTP id u189mr16245211pgu.44.1560183882798; Mon, 10 Jun 2019 09:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560183882; cv=none; d=google.com; s=arc-20160816; b=Pkj/3ICwCPH/Ndc214KwxUzzfp9IIJouhmRDNzp+S49aOrSKoP4Da6XgOQBplxDXu5 o/c9Uor8m11o0YTEHCUsCgVYNKAIkTAQE99FTgoPaOL+VBeyvfMx1p3t3nxPoV7A7P0K pZpjL3M4vrt1I8ZsaNdPMZZldEsfmNGdODg8iFLzQt1GjIE4IgUE/01ccw/7FDsaKPqR WW9rTcBHwRdXqQLNgkhL1Iv1fNrvpilAnd5oqOqpfHExKPNrQOdNPX6zsK5JZZt6DH7s Ncj2B+w/dvNr21vS43aGlSHKE1zmNVAMVdIlT1aN/K4wl1jhOV31jgElcw8q0MCD7TQx yeFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hwAMwagac6Yi0afPfWltWIF0pd2yRFxuWvj33N/Nr+0=; b=Nvjy2QlQPUNccUS4C7L4+BYi1b28jscJVXbWLqHZuhhSJKyqC8x9FtiuYa3Yuc8YPt kCStxv6LxuLXjdXIuERHpY4J1tRbjfRnzXrtd2pDprxwKaRu+K83ccfSkUOdxbG3O+SP t799YsaFKR4TsQrXeALXrDZp9itxM4dNRcYVYOFTH8fY1nFELG3id0QmY4CFsFDbDaOR 0n1tKQHU3rEyizxTdKHT2Yz/aYtk7CyQWhXQAC4P0bpNgcfoByz/WSQldY3Zv5rKTvZG NbfoezUr+fjTdLpsU6nXGpRIFPMcEcQfGyBrCuMHIlb+ozePA0PsoGj6xs2Zf3rlFtqZ TYIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="4gJaN/ei"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8si10206064pgc.464.2019.06.10.09.24.28; Mon, 10 Jun 2019 09:24:42 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="4gJaN/ei"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391243AbfFJPmy (ORCPT + 99 others); Mon, 10 Jun 2019 11:42:54 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:35292 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390454AbfFJPmx (ORCPT ); Mon, 10 Jun 2019 11:42:53 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5AFdYQh181982; Mon, 10 Jun 2019 15:41:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=hwAMwagac6Yi0afPfWltWIF0pd2yRFxuWvj33N/Nr+0=; b=4gJaN/eiXIY+aw+Q6HR4ak8yWFhBOv3LOxXnlrJFHtAXJwuhBrSTOB56BPNaAI26NVbw VH/aaPrnJZXx+Ra6Qgm3tkQzYm3V9tFHKsxVMrKwkxnw0Sqmsyl0ZyQ2dI+yg1yaxV42 ti+kNw5mGuWn2NgwHEGdDRTodebgb1ei22MVzAOTudlgNA8fnKYBufikKvK1StfBnRWG KLRNBLE7QdHY93P9MDwlX1UmTlnxS3JSbRSXUCwoxZ3hXkr7xQYB1ZS/+9Ebno3RHV/i fllnLHowwewnxfc+LBEVR0XbAc8xvehTEQAAf2pWvwpsZqpncQ0qOOFqhw2Rj+gLL0nN Kw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 2t02hefv9c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2019 15:41:28 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5AFfEdN079190; Mon, 10 Jun 2019 15:41:27 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2t024tw7ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2019 15:41:27 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5AFfIXg006946; Mon, 10 Jun 2019 15:41:19 GMT Received: from char.us.oracle.com (/10.152.32.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 10 Jun 2019 08:41:18 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 80A556A00FC; Mon, 10 Jun 2019 11:42:41 -0400 (EDT) Date: Mon, 10 Jun 2019 11:42:41 -0400 From: Konrad Rzeszutek Wilk To: Lu Baolu Cc: 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 Message-ID: <20190610154241.GS28796@char.us.oracle.com> References: <20190603011620.31999-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190603011620.31999-1-baolu.lu@linux.intel.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9284 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=551 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906100107 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9284 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=601 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906100107 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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? Thank you for making this awesome cover letter btw!