From patchwork Sat Sep 23 17:05:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 144042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp496947vqu; Sat, 23 Sep 2023 21:58:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsHuO7ad9eBRjRKD4spy44yGetNon2iv/4UY7kaT9KHi1pHDG0eAvZBXRkQQor9XKD7Dch X-Received: by 2002:a25:d20a:0:b0:d81:7ac8:b18e with SMTP id j10-20020a25d20a000000b00d817ac8b18emr3357229ybg.26.1695531524427; Sat, 23 Sep 2023 21:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695531524; cv=none; d=google.com; s=arc-20160816; b=YU13Fn5SR25UD05oaRpnOjiRkOB1Jkugf3kUanyeWTLFNS9c5Xhyb8uNg3A0X7R08t QO6YbvsBrkG6u+nfPuUP3czGoPqReln44Kfu0nnj/UV403GiIKOPlT9LcUqLuPKnXP+m 2EBTzlB+ZXa+ChqVDExvhn1vUIAWiGF7Hvlza2wvaaMtQ8sYPI6GFK7TEVs7HdTfU9dY ifBMcVLYsqFJuRquRQfjBEbWS2oExVyT3ResXm2R77u9xHomJWVw56j4M8x9Hxvcwmti S8dgYFGFabHOMt9W+F+oaqX8zUvxRWD0kb13ZUfPlQgWVxVK+ALmKgoE+VR9bNsurASI D0mg== 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=il3w5haBSfScQXt3dDLf9SU0J5h0ZGGXQF2FXm4L+Ew=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=N2NRgkSTQxbyl7XRGjIBeUAfnSERqMYyfpVOIcDp+tFQta0hjzcvBdEIGBgaLwVAIf xFo4ad3tmUiq46wgCpY8RbDkRM1FYuwYGLnnol6LNj/GoQo54yGeOgc/DXEJgCK5FDlu f1b8eiVO0RsB/F2ZNClDx+1NbD9QZuqMpOMTcV9Ec5F5e8d8/2oCn2T0exv9JPHmy9qE xz36VUSQosQ54yQifxMzBLLbHjxMxBnxA40BNI7LDrisvsS7E20457en21Q9aimHPaCT zIENRzXEVrpv8mewSx8ewIem48crhucJQnPWoV2CB0xzk8Yf4+Y+9Ab5KMev7xsQl8iT q9Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UWATkHGN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bx22-20020a056a02051600b00578c36d7249si7645935pgb.291.2023.09.23.21.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 21:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UWATkHGN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 383DC8373195; Sat, 23 Sep 2023 10:07:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232097AbjIWRHY (ORCPT + 30 others); Sat, 23 Sep 2023 13:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjIWRHS (ORCPT ); Sat, 23 Sep 2023 13:07:18 -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 AC4CE193 for ; Sat, 23 Sep 2023 10:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488791; 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=il3w5haBSfScQXt3dDLf9SU0J5h0ZGGXQF2FXm4L+Ew=; b=UWATkHGNEfaSVWuqcO0HwW54Eld9Fk+mtFvSK5wPKycpTXb8FFa/USZEsvysYgyMDT+b5d bzrPgdIE76k8nLDs7Wf1aX0THm0hV68eECVFUEWHolq2Z6/BupM5OHiIh43ZaWnm48CAAu BJCWfhUJukP51SH5tWTT8tioceYNiho= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-378-QsE5kBCmMOiSPEgvLSFUMA-1; Sat, 23 Sep 2023 13:06:27 -0400 X-MC-Unique: QsE5kBCmMOiSPEgvLSFUMA-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 47D56811E7B; Sat, 23 Sep 2023 17:06:27 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 222252156701; Sat, 23 Sep 2023 17:06:23 +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 5/7] vdpa: Add new vdpa_config_ops Date: Sun, 24 Sep 2023 01:05:38 +0800 Message-Id: <20230923170540.1447301-6-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=-2.1 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,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 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 (howler.vger.email [0.0.0.0]); Sat, 23 Sep 2023 10:07:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777893663606612251 X-GMAIL-MSGID: 1777893663606612251 Add new vdpa_config_ops to support iommufd Signed-off-by: Cindy Lu --- include/linux/vdpa.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 6d0f5e4e82c2..4ada5bd6f90e 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,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; }; /** @@ -282,6 +289,15 @@ struct vdpa_map_file { * @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) + * @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 */ @@ -341,6 +357,12 @@ struct vdpa_config_ops { u64 iova, u64 size); int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group, unsigned int asid); + /* 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); /* Free device resources */ void (*free)(struct vdpa_device *vdev); @@ -510,4 +532,14 @@ 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_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