Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp9786pxk; Wed, 23 Sep 2020 20:24:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxC3p6zT9UIjtyZgRUK5BRfz432NTiqIT0G9rVLMn+a8TO4vevb+8hjenjKp7+wXWm53uV X-Received: by 2002:a17:907:377:: with SMTP id rs23mr2631412ejb.415.1600917888433; Wed, 23 Sep 2020 20:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600917888; cv=none; d=google.com; s=arc-20160816; b=ZrnhWHMpG8o7trDUbtUv3IrMyqFwC3zhyxMx+CJ0ksFa6wxEwKMlVSebq4hwdzifzx AcbqglXCuTbgkLN6kNJwVtNEGktzENHBl5YAqWBm7IrxURUzl0AQmOGMa+AAXzHd7X9R 3FtQ3EGRskGegMhWc/SDVk5bHBdZZjonSIoeRahZYRdj+Ke/KZc9SBIbmoQWqyr/GPhz s6Lp0DWrQgagyONucbsRB6NJdDbuQE0943/iywSgGd2RSC5bD8OxaxwTe3yYEaTT21Ex hrB5CP3YxVAVIUaw56cKI9eOsgGA05vGoCRwWwAetuGHPRmyDx9rPouL/BBzLh+HibZY Xcew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IQQgZh+gmoXmevwc83LrqfZS2uZOmcneMxMvJmUeEy4=; b=WuULIzsj/DsqsyR1abm9N7+1P++cGqHkvHHAY9OLVIOObGDd3eZgLNGoz5to+yVFac UetB/Lc6wYNaowY72oQYrPYEBgSiBeU/VZOZ8EXoswGkBkFJGfvNUMSs4cjkHJPSOLZ3 JxHunee/vNvhSmnxekByzPha1VaQ1Ul1ZExjPAqvIRE5huL3QagQUqfLE2fRa/7jowCh oGdnrSkoRUaP7erPQf7z2vRPdBEmsvktpwhIRB7EQFO4NhWJY4fbNY3/trZ7T5vBxwAV StjZFQi6Rtq9mR5sPNkbOz/urml5bHW9VV7w2C48f2G5CGWF3TDzVEL0Mj7wURJ4WsRW g7GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cohONExj; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si1214114edq.603.2020.09.23.20.24.24; Wed, 23 Sep 2020 20:24:48 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=cohONExj; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726803AbgIXDWn (ORCPT + 99 others); Wed, 23 Sep 2020 23:22:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37911 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726787AbgIXDWn (ORCPT ); Wed, 23 Sep 2020 23:22:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600917761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IQQgZh+gmoXmevwc83LrqfZS2uZOmcneMxMvJmUeEy4=; b=cohONExjuHywBpXkHxe1Tby/RugOck4Hw+HYOSRXaqZ5MMithrOkqMH5ak9MuPxILIOqgr ZNRqKa6WwS2rhhEwG26/I5YVyBLhFmeagncMG52EFMCGEec9br85lZemZ+rhXy3ogWOubX f1qN/BrZQ/7xhbWxQ3Mi62CuCaLj2Pg= 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-571-AmEEzgldPdWN3B4wDLZIfg-1; Wed, 23 Sep 2020 23:22:36 -0400 X-MC-Unique: AmEEzgldPdWN3B4wDLZIfg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C804807352; Thu, 24 Sep 2020 03:22:35 +0000 (UTC) Received: from jason-ThinkPad-X1-Carbon-6th.redhat.com (ovpn-13-193.pek2.redhat.com [10.72.13.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77B6355768; Thu, 24 Sep 2020 03:22:29 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: lulu@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rob.miller@broadcom.com, lingshan.zhu@intel.com, eperezma@redhat.com, hanand@xilinx.com, mhabets@solarflare.com, eli@mellanox.com, amorenoz@redhat.com, maxime.coquelin@redhat.com, stefanha@redhat.com, sgarzare@redhat.com Subject: [RFC PATCH 05/24] vhost-vdpa: passing iotlb to IOMMU mapping helpers Date: Thu, 24 Sep 2020 11:21:06 +0800 Message-Id: <20200924032125.18619-6-jasowang@redhat.com> In-Reply-To: <20200924032125.18619-1-jasowang@redhat.com> References: <20200924032125.18619-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To prepare for the ASID support for vhost-vdpa, try to pass IOTLB object to dma helpers. Signed-off-by: Jason Wang --- drivers/vhost/vdpa.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 9c641274b9f3..74bef1c15a70 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -489,10 +489,11 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, return r; } -static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, u64 start, u64 last) +static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 start, u64 last) { struct vhost_dev *dev = &v->vdev; - struct vhost_iotlb *iotlb = dev->iotlb; struct vhost_iotlb_map *map; struct page *page; unsigned long pfn, pinned; @@ -514,8 +515,9 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, u64 start, u64 last) static void vhost_vdpa_iotlb_free(struct vhost_vdpa *v) { struct vhost_dev *dev = &v->vdev; + struct vhost_iotlb *iotlb = dev->iotlb; - vhost_vdpa_iotlb_unmap(v, 0ULL, 0ULL - 1); + vhost_vdpa_iotlb_unmap(v, iotlb, 0ULL, 0ULL - 1); kfree(dev->iotlb); dev->iotlb = NULL; } @@ -542,15 +544,14 @@ static int perm_to_iommu_flags(u32 perm) return flags | IOMMU_CACHE; } -static int vhost_vdpa_map(struct vhost_vdpa *v, +static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, u64 iova, u64 size, u64 pa, u32 perm) { - struct vhost_dev *dev = &v->vdev; struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; int r = 0; - r = vhost_iotlb_add_range(dev->iotlb, iova, iova + size - 1, + r = vhost_iotlb_add_range(iotlb, iova, iova + size - 1, pa, perm); if (r) return r; @@ -559,7 +560,7 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, r = ops->dma_map(vdpa, iova, size, pa, perm); } else if (ops->set_map) { if (!v->in_batch) - r = ops->set_map(vdpa, dev->iotlb); + r = ops->set_map(vdpa, iotlb); } else { r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm)); @@ -568,29 +569,30 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, return r; } -static void vhost_vdpa_unmap(struct vhost_vdpa *v, u64 iova, u64 size) +static void vhost_vdpa_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 iova, u64 size) { - struct vhost_dev *dev = &v->vdev; struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; - vhost_vdpa_iotlb_unmap(v, iova, iova + size - 1); + vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1); if (ops->dma_map) { ops->dma_unmap(vdpa, iova, size); } else if (ops->set_map) { if (!v->in_batch) - ops->set_map(vdpa, dev->iotlb); + ops->set_map(vdpa, iotlb); } else { iommu_unmap(v->domain, iova, size); } } static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, struct vhost_iotlb_msg *msg) { struct vhost_dev *dev = &v->vdev; - struct vhost_iotlb *iotlb = dev->iotlb; struct page **page_list; unsigned long list_size = PAGE_SIZE / sizeof(struct page *); unsigned int gup_flags = FOLL_LONGTERM; @@ -644,7 +646,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, if (last_pfn && (this_pfn != last_pfn + 1)) { /* Pin a contiguous chunk of memory */ csize = (last_pfn - map_pfn + 1) << PAGE_SHIFT; - if (vhost_vdpa_map(v, iova, csize, + if (vhost_vdpa_map(v, iotlb, iova, csize, map_pfn << PAGE_SHIFT, msg->perm)) goto out; @@ -660,11 +662,12 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, } /* Pin the rest chunk */ - ret = vhost_vdpa_map(v, iova, (last_pfn - map_pfn + 1) << PAGE_SHIFT, + ret = vhost_vdpa_map(v, iotlb, iova, + (last_pfn - map_pfn + 1) << PAGE_SHIFT, map_pfn << PAGE_SHIFT, msg->perm); out: if (ret) { - vhost_vdpa_unmap(v, msg->iova, msg->size); + vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); atomic64_sub(npages, &dev->mm->pinned_vm); } mmap_read_unlock(dev->mm); @@ -678,6 +681,7 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + struct vhost_iotlb *iotlb = dev->iotlb; int r = 0; r = vhost_dev_check_owner(dev); @@ -686,17 +690,17 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, switch (msg->type) { case VHOST_IOTLB_UPDATE: - r = vhost_vdpa_process_iotlb_update(v, msg); + r = vhost_vdpa_process_iotlb_update(v, iotlb, msg); break; case VHOST_IOTLB_INVALIDATE: - vhost_vdpa_unmap(v, msg->iova, msg->size); + vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); break; case VHOST_IOTLB_BATCH_BEGIN: v->in_batch = true; break; case VHOST_IOTLB_BATCH_END: if (v->in_batch && ops->set_map) - ops->set_map(vdpa, dev->iotlb); + ops->set_map(vdpa, iotlb); v->in_batch = false; break; default: -- 2.20.1