Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp325001rdh; Sat, 23 Sep 2023 12:04:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGds4PvVQmmU5yWKJKXS9fSwQNJv+QEaJfzCCXN4tuSehxRPibSZd8v8h7lV5r/y5muoa4U X-Received: by 2002:a54:448d:0:b0:3a7:30cb:c092 with SMTP id v13-20020a54448d000000b003a730cbc092mr3438327oiv.48.1695495840724; Sat, 23 Sep 2023 12:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695495840; cv=none; d=google.com; s=arc-20160816; b=IZmVbzlnUr3Ru8MyuHepFuv0IyC4HtCFpR2nmjnCl+eVy37QlAgx3UYw1tUnunbz56 jcAN7dLlZ+8fb1GD/7dTd0gCw60QqrMM+hNtWKvBFZ0aKZ7BykOazCa0VmZfDZK/yqtK i0cpSRA0s8DNY61zHqOr9Ay3WV5b/3qA5i+4o9C8SsLfgEdIzBepyF2Ka8D1+A9VNCJP DFHz5VOlAbYlPezCEx7NrTlLqewA8cW0uJLLBejDrV6HD2GkqZIaJFEuez2lSe7bj6Tz 6RhFAdo7qRpZs8KJbozVd+SEEGe80h7qP2wokpz6duw9suMZiZiiwamQiCHlVE2j5bXf B6GQ== 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:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id q18-20020a170902dad200b001bf741231f7si1900257plx.570.2023.09.23.12.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 12:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; 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:1 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 morse.vger.email (Postfix) with ESMTP id F3047832A04C; Sat, 23 Sep 2023 10:07:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232084AbjIWRHU (ORCPT + 99 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Sat, 23 Sep 2023 10:07:20 -0700 (PDT) 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; -- 2.34.3