From patchwork Sat Sep 23 17:05:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 144021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp414891vqu; Sat, 23 Sep 2023 16:41:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbrvq+lcmlHI+6nj0nHlnh/9mz5z97wn7i2r3i1jyTPh4iwrvBR9fNs0Qji6jSXaXlz5V9 X-Received: by 2002:a9d:7654:0:b0:6c4:ce0e:29ae with SMTP id o20-20020a9d7654000000b006c4ce0e29aemr3086417otl.21.1695512498224; Sat, 23 Sep 2023 16:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695512498; cv=none; d=google.com; s=arc-20160816; b=TTJ4qFSh9xdCxkqlh0I/oP+2LzdM+Vet1KQBuUWSKTaYI41jEcsZJhYvB7Bl0NDS67 awUA/wTGit4+21M8Geu2AIAY/qvFSeKgg+pcU1oUrY3LVXTroUeLc0wLSJmRfRi1YZbj nuL3JFvCZryN9vaqcDmCq3jdDsQ3gsW+W+kH4TzIvWf7DLed04qLxZ27Hpg/o6ieapIB PlzxtKP2xZJ4y5IqQJbZ6IxfnyMmIRxZcaq+n4x20iXsMw0K3+KTFoR1oDKphiHmgczc vEX8EQt9+afPsvsTHIb8P58HtcrbWrfT8iIHIwk/YTfLT+wwoSECF0IBdzWAy5IhVbz/ 8wYw== 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:to:from :dkim-signature; bh=OSxKvZZwCgHkxa7Gx3Q9oCdQPfbiPlUKMx5CV8bK/Xw=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=yf7TqFXEDHKvvB1DWC6gTZ8sD0M6npRUw3FHk3waoSeUA2xgXPfdWsiKgEtie2hi4l xoOL9tuKkFoX+irb37iwxD/oJFVzjDLkJ8kz1b2j22dKH4BpOOtX+YkUFrW7lPDzemb8 pqFvJAjgqVGpHsFX9vzEAzWBJh+UAOjcPQU5k2ig5RNpiLSjxzuMNskml64i8+6idu09 xNl/U6ZNkmNpzC413gpbzWyu8qGLa9pB/G4PLyCDWn3L5TmEoH1pO2R2M43NqcxfBzRc jFKL7Lo7tv+qk+ZpE3URJ2djH+S/btKxLJXV1NgnstW+lYj0p0gnqBCn1CYd9XORkeFo LFpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ugx3uPtn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id y19-20020a63ce13000000b0057877ee7d78si6815268pgf.575.2023.09.23.16.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 16:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ugx3uPtn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id AB7278025E51; Sat, 23 Sep 2023 10:07:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232054AbjIWRHU (ORCPT + 30 others); Sat, 23 Sep 2023 13:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbjIWRHR (ORCPT ); Sat, 23 Sep 2023 13:07:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A0F192 for ; Sat, 23 Sep 2023 10:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OSxKvZZwCgHkxa7Gx3Q9oCdQPfbiPlUKMx5CV8bK/Xw=; b=Ugx3uPtnNO4vnms/ObL0wZ6rQiEXoCH9FMGXM0QIFqX7oNoSKcsWimRAi9resL9fdtO/dc 0XLsR6XDrnGfDa4rHKE85pLuKqEbNoAlcJeIM6XM8PGS9KTaOks3rxAgRAVf1i+ACXRf9v Qe2WYgpmTho4wiGWcIeingADkFLsweg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-186-T93U6ufYNTeOS2d86puqOg-1; Sat, 23 Sep 2023 13:06:23 -0400 X-MC-Unique: T93U6ufYNTeOS2d86puqOg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8022229AA385; Sat, 23 Sep 2023 17:06:23 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 539CC2156701; Sat, 23 Sep 2023 17:06:20 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, yi.l.liu@intel.com, jgg@nvidia.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [RFC 4/7] vdpa: change the map/unmap process to support iommufd Date: Sun, 24 Sep 2023 01:05:37 +0800 Message-Id: <20230923170540.1447301-5-lulu@redhat.com> In-Reply-To: <20230923170540.1447301-1-lulu@redhat.com> References: <20230923170540.1447301-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 10:07:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777873713330243880 X-GMAIL-MSGID: 1777873713330243880 Add the check for iommufd_ictx,If vdpa don't have the iommufd_ictx then will use the Legacy iommu domain pathway Signed-off-by: Cindy Lu --- drivers/vhost/vdpa.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 91da012084e9..8d1ad89d4671 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -981,6 +981,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, } else if (ops->set_map) { if (!v->in_batch) r = ops->set_map(vdpa, asid, iotlb); + } else if (!vdpa->iommufd_ictx) { + /* Legacy iommu domain pathway without IOMMUFD */ + r = iommu_map(v->domain, iova, pa, size, + perm_to_iommu_flags(perm)); } else { r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm)); @@ -1009,6 +1013,9 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, if (ops->set_map) { if (!v->in_batch) ops->set_map(vdpa, asid, iotlb); + } else if (!vdpa->iommufd_ictx) { + /* Legacy iommu domain pathway without IOMMUFD */ + iommu_unmap(v->domain, iova, size); } /* If we are in the middle of batch processing, delay the free * of AS until BATCH_END. @@ -1337,6 +1344,8 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v) iommu_detach_device(v->domain, dma_dev); iommu_domain_free(v->domain); } + if (vdpa->iommufd_ictx) + vdpa_iommufd_unbind(vdpa); v->domain = NULL; } @@ -1560,6 +1569,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) } atomic_set(&v->opened, 0); + atomic_set(&vdpa->iommufd_users, 0); v->minor = minor; v->vdpa = vdpa; v->nvqs = vdpa->nvqs;