Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp636429rdf; Fri, 3 Nov 2023 10:18:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4vWP0pc1J42ovxFTn+mz2BXk7tO86QAEjpKyQzBspRNTaPg/Pfx1U+MSoaTD+D27yGkK5 X-Received: by 2002:a05:6358:7e4a:b0:169:9586:9195 with SMTP id p10-20020a0563587e4a00b0016995869195mr9415890rwm.31.1699031923503; Fri, 03 Nov 2023 10:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031923; cv=none; d=google.com; s=arc-20160816; b=EEMq67JpaZVNSxZuoktG2+dJXU3ebHk42Gz9BQhm3nTXdEBS4q2D7LYPza4xeAsOLd rZdNazzdnhnwn4VUwmhvFDkKZW2DbQAfCZDto2lxSZ/SwAKSHS4l0EQ3zSsVaP4VOJVX WJuVkyyZ/2qyu13MGZq4Ss+pMiD6z+tnd5WISxR7s8i/GLOmEwTyMdlS9jAoOGEJnJcg QiqEMTnhZaihyKfwdbWl0nBnS+aSUH9tPX/cTTiNisbrkI790+DY61ymmMZjeFCN0dQs aFAzTBQxN7stf8DwSRlRnbC2oNrpP9YWqR1Y/+oHWdJhd56wZLXUQY3ypBsaF2CscYb1 LpMA== 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=xuqvr5RWRiWU1vecaSpLFCcLTpJ+4Yg7zkI2ypzhUqw=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=RImuPxIzGW4lBkp4T51XR2HqATrlFNDnb/wVsLlnXPicj/5crgXScbBgztZvG/OkKu EbJtAh80UNjDdq3fpmJYrW8T0BMZTakleR3eyfrUYPB6crQc+ckqp2IsAO0AQYv942RB x3sSlhym/RGahxm6wt4Kzl5R8e68c5vWTDkR4UUqRW8mlP2784Z2QsWCuBebYhl6SDGP eAlZDZRfFqt3U7vxVtJwPRBPCv+eFjdH5zJXlWp4C1KnxDD2WEkJcZHnrbm+tI5Prsb3 qiGI2+K+m57Z8nT89ZQYlyWKi3RotYMbz9SXXRmF3L4Qsvg6P8kRjkzZyA3QHO68PBkm 7aKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LgDInuxj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 74-20020a63004d000000b005b90af19430si1786455pga.595.2023.11.03.10.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:18:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LgDInuxj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id A06A38039ECA; Fri, 3 Nov 2023 10:18:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234490AbjKCRSV (ORCPT + 99 others); Fri, 3 Nov 2023 13:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234418AbjKCRST (ORCPT ); Fri, 3 Nov 2023 13:18:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DC29D4C for ; Fri, 3 Nov 2023 10:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031852; 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=xuqvr5RWRiWU1vecaSpLFCcLTpJ+4Yg7zkI2ypzhUqw=; b=LgDInuxjPlVIe8Dcj2bevueBD8tDWgdcM04qFir7d3zsXAl8Bow+IafEqWOLNLtw+NdjQI ODFXOKYsk78viujuiKOTX0UQqr+/ersBDtLpSpOmYvPyvKvLdygrY6cHZRE/FTy9Z/JLHN ZpgtsrDSqwKjVPrMlpwlJ62sYIYtVn8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-19-9U5j9LuUPY-QMBSo0Y4PAQ-1; Fri, 03 Nov 2023 13:17:25 -0400 X-MC-Unique: 9U5j9LuUPY-QMBSo0Y4PAQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7CE285D536; Fri, 3 Nov 2023 17:17:24 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id C264EC1290F; Fri, 3 Nov 2023 17:17:21 +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 v1 4/8] vdpa: Add new vdpa_config_ops to support iommufd Date: Sat, 4 Nov 2023 01:16:37 +0800 Message-Id: <20231103171641.1703146-5-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 03 Nov 2023 10:18:37 -0700 (PDT) Add 4 new vdpa_config_ops function to support iommufd Signed-off-by: Cindy Lu --- include/linux/vdpa.h | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 0e652026b776..233d80f9d910 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,12 @@ struct vdpa_device { struct vdpa_mgmt_dev *mdev; unsigned int ngroups; unsigned int nas; + struct iommufd_access *iommufd_access; + struct iommufd_device *iommufd_device; + struct iommufd_ctx *iommufd_ictx; + unsigned long *vq_bitmap; + atomic_t iommufd_users; + bool iommufd_attached; }; /** @@ -332,6 +339,17 @@ struct vdpa_map_file { * @vdev: vdpa device * @free: Free resources that belongs to vDPA (optional) * @vdev: vdpa device + * @bind_iommufd: use vdpa_iommufd_physical_bind for an IOMMU + * backed device. + * otherwise use vdpa_iommufd_emulated_bind + * @unbind_iommufd: use vdpa_iommufd_physical_unbind for an IOMMU + * backed device. + * otherwise, use vdpa_iommufd_emulated_unbind + * @attach_ioas: use vdpa_iommufd_physical_attach_ioas for an + * IOMMU backed device. + * @detach_ioas: Opposite of attach_ioas + * @free: Free resources that belongs to vDPA (optional) + * @vdev: vdpa device */ struct vdpa_config_ops { /* Virtqueue ops */ @@ -402,6 +420,13 @@ struct vdpa_config_ops { /* Free device resources */ void (*free)(struct vdpa_device *vdev); + /* IOMMUFD ops */ + int (*bind_iommufd)(struct vdpa_device *vdev, struct iommufd_ctx *ictx, + u32 *out_device_id); + void (*unbind_iommufd)(struct vdpa_device *vdev); + int (*attach_ioas)(struct vdpa_device *vdev, u32 *pt_id); + int (*detach_ioas)(struct vdpa_device *vdev); + }; struct vdpa_device *__vdpa_alloc_device(struct device *parent, @@ -570,4 +595,15 @@ struct vdpa_mgmt_dev { int vdpa_mgmtdev_register(struct vdpa_mgmt_dev *mdev); void vdpa_mgmtdev_unregister(struct vdpa_mgmt_dev *mdev); -#endif /* _LINUX_VDPA_H */ +int vdpa_iommufd_physical_bind(struct vdpa_device *vdpa, + struct iommufd_ctx *ictx, u32 *out_device_id); +void vdpa_iommufd_physical_unbind(struct vdpa_device *vdpa); +int vdpa_iommufd_physical_attach_ioas(struct vdpa_device *vdpa, u32 *pt_id); +int vdpa_iommufd_physical_detach_ioas(struct vdpa_device *vdpa); +int vdpa_iommufd_emulated_bind(struct vdpa_device *vdpa, + struct iommufd_ctx *ictx, u32 *out_device_id); +void vdpa_iommufd_emulated_unbind(struct vdpa_device *vdpa); +int vdpa_iommufd_emulated_attach_ioas(struct vdpa_device *vdpa, u32 *pt_id); +int vdpa_iommufd_emulated_detach_ioas(struct vdpa_device *vdpa); + +#endif -- 2.34.3