Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7298190ybl; Wed, 15 Jan 2020 19:54:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwTqtQqhL0VVlj7jyn6rO1isuPNaznLjvZxNTLrCPJ38mVq/BD3z4gEpHg4w7SEMGLrL4xX X-Received: by 2002:a9d:6ac1:: with SMTP id m1mr468494otq.101.1579146855487; Wed, 15 Jan 2020 19:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579146855; cv=none; d=google.com; s=arc-20160816; b=S+9Du2qEAOiBbEywMJxTCeSOxK8YC5IFyF2HQZsUFKmdPy3VuM9gVzzNe8rYoKvj7D XOCXU8GON2Q9wWKLz2fkD3j6sG1xjPPI3e+oksK40+fBNtStl1Obt4zPACe0bc43jbp/ paBZn86JbGqf1Wtq1aT1qkeE+JYbyzU30GiyZNnVc5gFYLnrsJtG+aV5lWD1UMLZElX3 OKehPuzXqbiKwZShNhYKK4Go5Mf7gcA67izobtPXa4wTBoM97ez/P4LO4jCngASUMFos +6V76FdxNZLhZOO+RKY/Ka43IfiYn0D2tb7KCNmvZ9lEMq2yXrZ4QLMDKVXVIdjzJmfC MyCw== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=QYDIddpraf1y7iH1YrZ3bXVk4InOC/gXpwyEqB+s6Kg=; b=lsoC977lgReTWeBZ65e45ydSxKap2b2OScWjRPjb9+PeIFfNui8mRwFvJVx9va/0tC sTHAtttKhE8Y/vvdYB9uCqTDM4CoEA6/6XtMrjodK2spqLUv4N4SzK0STRbNglhparIs eHI5LDki7BqzkdJy/5QuJ9eYqHRjtRa9cQRcaHybop1Hm8jfBQxxnwYJbaB482kDVzvq QY3Rsz+ODzl74v8gsnioJUrQZyjDZvjCZOznl4tNa2YP0vwG4tLOtvcEZ5mm9FlF50dE SCkk7pjbnULAQzmyQJ5OGwOuXNeD09NO5yO/4JxKu0aQsCJ8a2XnVmifrO/iqaHWJhw6 HMaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IO231mF6; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4si10826996oiy.97.2020.01.15.19.54.03; Wed, 15 Jan 2020 19:54:15 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=IO231mF6; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729782AbgAPDAI (ORCPT + 99 others); Wed, 15 Jan 2020 22:00:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31480 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729130AbgAPDAI (ORCPT ); Wed, 15 Jan 2020 22:00:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579143606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QYDIddpraf1y7iH1YrZ3bXVk4InOC/gXpwyEqB+s6Kg=; b=IO231mF6hW35fStU+BMazWebu3yMedee2DQz/xpNv3+NRLQ6G4jVA9+l0nlHKAxWnQGHA5 hM/KzC7QLcKBZUhy+dkbHDLEzQPh76h/G8OTj6wjJ/50O4fQk7AKljNbDr/a5n+yWWS7op Z0CyAv6qRXGwe/ms4ejhjb2gHDD4YCA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-VmuSj52CP52FZ32jsTdlSA-1; Wed, 15 Jan 2020 22:00:05 -0500 X-MC-Unique: VmuSj52CP52FZ32jsTdlSA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66E9F107ACC7; Thu, 16 Jan 2020 03:00:03 +0000 (UTC) Received: from x1.home (ovpn-116-28.phx2.redhat.com [10.3.116.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 452F088898; Thu, 16 Jan 2020 03:00:00 +0000 (UTC) Date: Wed, 15 Jan 2020 19:59:59 -0700 From: Alex Williamson To: Mika =?UTF-8?B?UGVudHRpbMOk?= Cc: Yan Zhao , "zhenyuw@linux.intel.com" , "intel-gvt-dev@lists.freedesktop.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "pbonzini@redhat.com" , "kevin.tian@intel.com" , "peterx@redhat.com" Subject: Re: [PATCH v2 1/2] vfio: introduce vfio_dma_rw to read/write a range of IOVAs Message-ID: <20200115195959.28f33078@x1.home> In-Reply-To: <80cf3888-2e51-3fd7-a064-213e7ded188e@nextfour.com> References: <20200115034132.2753-1-yan.y.zhao@intel.com> <20200115035303.12362-1-yan.y.zhao@intel.com> <20200115130638.6926dd08@w520.home> <80cf3888-2e51-3fd7-a064-213e7ded188e@nextfour.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 16 Jan 2020 02:30:52 +0000 Mika Penttil=C3=A4 wrote: > On 15.1.2020 22.06, Alex Williamson wrote: > > On Tue, 14 Jan 2020 22:53:03 -0500 > > Yan Zhao wrote: > > =20 > >> vfio_dma_rw will read/write a range of user space memory pointed to by > >> IOVA into/from a kernel buffer without pinning the user space memory. > >> > >> TODO: mark the IOVAs to user space memory dirty if they are written in > >> vfio_dma_rw(). > >> > >> Cc: Kevin Tian > >> Signed-off-by: Yan Zhao > >> --- > >> drivers/vfio/vfio.c | 45 +++++++++++++++++++ > >> drivers/vfio/vfio_iommu_type1.c | 76 +++++++++++++++++++++++++++++++= ++ > >> include/linux/vfio.h | 5 +++ > >> 3 files changed, 126 insertions(+) > >> > >> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > >> index c8482624ca34..8bd52bc841cf 100644 > >> --- a/drivers/vfio/vfio.c > >> +++ b/drivers/vfio/vfio.c > >> @@ -1961,6 +1961,51 @@ int vfio_unpin_pages(struct device *dev, unsign= ed long *user_pfn, int npage) > >> } > >> EXPORT_SYMBOL(vfio_unpin_pages); > >> =20 > >> +/* > >> + * Read/Write a range of IOVAs pointing to user space memory into/fro= m a kernel > >> + * buffer without pinning the user space memory > >> + * @dev [in] : device > >> + * @iova [in] : base IOVA of a user space buffer > >> + * @data [in] : pointer to kernel buffer > >> + * @len [in] : kernel buffer length > >> + * @write : indicate read or write > >> + * Return error code on failure or 0 on success. > >> + */ > >> +int vfio_dma_rw(struct device *dev, dma_addr_t iova, void *data, > >> + size_t len, bool write) > >> +{ > >> + struct vfio_container *container; > >> + struct vfio_group *group; > >> + struct vfio_iommu_driver *driver; > >> + int ret =3D 0; =20 >=20 > Do you know the iova given to vfio_dma_rw() is indeed a gpa and not iova= =20 > from a iommu mapping? So isn't it you actually assume all the guest is=20 > pinned, > like from device assignment? >=20 > Or who and how is the vfio mapping added before the vfio_dma_rw() ? vfio only knows about IOVAs, not GPAs. It's possible that IOVAs are identity mapped to the GPA space, but a VM with a vIOMMU would quickly break any such assumption. Pinning is also not required. This access is via the CPU, not the I/O device, so we don't require the memory to be pinning and it potentially won't be for a non-IOMMU backed mediated device. The intention here is that via the mediation of an mdev device, a vendor driver would already know IOVA ranges for the device to access via the guest driver programming of the device. Thanks, Alex