From patchwork Sat Sep 23 17:05:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 144014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp406149vqu; Sat, 23 Sep 2023 16:11:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHk6qUqTwOjbPvlhbuex+jpUU0H5BZQPFqfBqQMIZzM3odV+gBK4gDtmYbwPrf7RslD7ee X-Received: by 2002:a05:6358:720:b0:143:9075:6d9c with SMTP id e32-20020a056358072000b0014390756d9cmr3457863rwj.5.1695510669315; Sat, 23 Sep 2023 16:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695510669; cv=none; d=google.com; s=arc-20160816; b=rimQ+gilpjRcFZQw1rBSD477r2z1csar+hxjfVSHslyKqfsvzL3w2mYOfoYgQSbbFm UguyKt9IkyugcUbMgjZ/JJTsqjF6l8eSsgMyg6fx2qk5NNxrpHOS47cZoAz+fLdA0rMJ szy+OYe4o7obJoD4g+69o7NKxBxsetWFY6aMdE+dliLeLSy405iZjlHJo0VtH+ShaaXD NmS+olhz9RXwMAA3awtu/uvVwZp/KyuIiRbifvjHsP+C7uIPyEYPsg2iaG2/91yRUWlc vs1LoR/+J1dSQEec1mo/hMwxW/lDBy1q2GVZkucEIjXTIJcAooyRCPimPFd7OFaShyZ8 tfTQ== 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=gZXSGgSLa3AyMB+//ooPSLru9tn8EO08jVq0CDYH8UM=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=BDBHLpJZa4JrwExGKfp9XyQOlXYETjcCv56KTXZzds2pvkvpE/36z+9OPvw6bK4In+ 9z4gVYKuF0rBs2HyuNX04DgOaY7OwLSQ/yOGJXzb65Vp4x+PoAR2cDTxblEHhqUuQsNX aPrTsMphC3twI14PDSsCPsMvskkDDQfJK6ORgBhEOUuHybBPROJbcC05wV2bYvSxjZqT dEdTX0hZfi9dhz1n7ZgKLUoMI4rdIDahJkpflFx8hucOUwq7snsG2H9yPdsr0avwzBtT BYppUY5Azxd0MSbCL4P+CMHeqIWvfXMTaVd1pLn4Qq6WupbcX9+tDcHYzxIwbuRvgf3N 2h/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CCgtTiKs; 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 36-20020a631564000000b00578bd92e502si6732713pgv.558.2023.09.23.16.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 16:11:09 -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=CCgtTiKs; 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 B2FC68043057; Sat, 23 Sep 2023 10:06:44 -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 S232041AbjIWRGm (ORCPT + 30 others); Sat, 23 Sep 2023 13:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbjIWRGl (ORCPT ); Sat, 23 Sep 2023 13:06:41 -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 774EC100 for ; Sat, 23 Sep 2023 10:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gZXSGgSLa3AyMB+//ooPSLru9tn8EO08jVq0CDYH8UM=; b=CCgtTiKsbOHUy5U5h3h+KRCUB1LtA91Eh7j6CjOMRDfZHGdKRoWjymPMYNCHO+hd6zQ7Gp F8IUaOZ5pbB1XdAs6AkOc4PMdjPNqbA49PA4DEShkXsNzv43O0UCFVzzeqE/K9xH1PBWLr aCpMjCONFGdHpHnAFIxd2WHBoOU+S4M= 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-455-K5M1yv96PjmVB0IHcgvaqA-1; Sat, 23 Sep 2023 13:05:51 -0400 X-MC-Unique: K5M1yv96PjmVB0IHcgvaqA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 9BBCF800045; Sat, 23 Sep 2023 17:05:50 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 754B32026D4B; Sat, 23 Sep 2023 17:05:47 +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 1/7] vhost/iommufd: Add the functions support iommufd Date: Sun, 24 Sep 2023 01:05:34 +0800 Message-Id: <20230923170540.1447301-2-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.4 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-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]); Sat, 23 Sep 2023 10:06:44 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777871795444015824 X-GMAIL-MSGID: 1777871795444015824 Add a new file vhost/iommufd.c to support the function of iommufd, This file contains iommufd function of emulated device and the physical device.  Signed-off-by: Cindy Lu --- drivers/vhost/iommufd.c | 151 ++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 21 ++++++ 2 files changed, 172 insertions(+) create mode 100644 drivers/vhost/iommufd.c diff --git a/drivers/vhost/iommufd.c b/drivers/vhost/iommufd.c new file mode 100644 index 000000000000..080858f76fd5 --- /dev/null +++ b/drivers/vhost/iommufd.c @@ -0,0 +1,151 @@ +#include +#include + +#include "vhost.h" + +MODULE_IMPORT_NS(IOMMUFD); + +int vdpa_iommufd_bind(struct vdpa_device *vdpa, struct iommufd_ctx *ictx, + u32 *ioas_id, u32 *device_id) +{ + int ret; + + vhost_vdpa_lockdep_assert_held(vdpa); + + /* + * If the driver doesn't provide this op then it means the device does + * not do DMA at all. So nothing to do. + */ + if (!vdpa->config->bind_iommufd) + return 0; + + ret = vdpa->config->bind_iommufd(vdpa, ictx, device_id); + if (ret) + return ret; + + ret = vdpa->config->attach_ioas(vdpa, ioas_id); + if (ret) + goto err_unbind; + vdpa->iommufd_attached = true; + + return 0; + +err_unbind: + if (vdpa->config->unbind_iommufd) + vdpa->config->unbind_iommufd(vdpa); + return ret; +} + +void vdpa_iommufd_unbind(struct vdpa_device *vdpa) +{ + vhost_vdpa_lockdep_assert_held(vdpa); + + if (vdpa->config->unbind_iommufd) + vdpa->config->unbind_iommufd(vdpa); +} + +int vdpa_iommufd_physical_bind(struct vdpa_device *vdpa, + struct iommufd_ctx *ictx, u32 *out_device_id) +{ + struct device *dma_dev = vdpa_get_dma_dev(vdpa); + struct iommufd_device *idev; + + idev = iommufd_device_bind(ictx, dma_dev, out_device_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + vdpa->iommufd_device = idev; + return 0; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_physical_bind); + +void vdpa_iommufd_physical_unbind(struct vdpa_device *vdpa) +{ + vhost_vdpa_lockdep_assert_held(vdpa); + + if (vdpa->iommufd_attached) { + iommufd_device_detach(vdpa->iommufd_device); + vdpa->iommufd_attached = false; + } + iommufd_device_unbind(vdpa->iommufd_device); + vdpa->iommufd_device = NULL; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_physical_unbind); + +int vdpa_iommufd_physical_attach_ioas(struct vdpa_device *vdpa, u32 *pt_id) +{ + unsigned int flags = 0; + + return iommufd_device_attach(vdpa->iommufd_device, pt_id); +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_physical_attach_ioas); + +static void vdpa_emulated_unmap(void *data, unsigned long iova, + unsigned long length) +{ + struct vdpa_device *vdpa = data; + + vdpa->config->dma_unmap(vdpa, 0, iova, length); +} + +static const struct iommufd_access_ops vdpa_user_ops = { + .needs_pin_pages = 1, + .unmap = vdpa_emulated_unmap, +}; + +int vdpa_iommufd_emulated_bind(struct vdpa_device *vdpa, + struct iommufd_ctx *ictx, u32 *out_device_id) +{ + vhost_vdpa_lockdep_assert_held(vdpa); + + vdpa->iommufd_ictx = ictx; + iommufd_ctx_get(ictx); + struct iommufd_device *idev; + + idev = iommufd_device_bind(ictx, vdpa->dma_dev, out_device_id); + + if (IS_ERR(idev)) + return PTR_ERR(idev); + vdpa->iommufd_device = idev; + return 0; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_emulated_bind); + +void vdpa_iommufd_emulated_unbind(struct vdpa_device *vdpa) +{ + vhost_vdpa_lockdep_assert_held(vdpa); + + if (vdpa->iommufd_access) { + iommufd_access_destroy(vdpa->iommufd_access); + vdpa->iommufd_access = NULL; + } + iommufd_ctx_put(vdpa->iommufd_ictx); + vdpa->iommufd_ictx = NULL; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_emulated_unbind); + +int vdpa_iommufd_emulated_attach_ioas(struct vdpa_device *vdpa, u32 *pt_id) +{ + struct iommufd_access *user; + + vhost_vdpa_lockdep_assert_held(vdpa); + + user = iommufd_access_create(vdpa->iommufd_ictx, *pt_id, &vdpa_user_ops, + vdpa); + if (IS_ERR(user)) + return PTR_ERR(user); + vdpa->iommufd_access = user; + return 0; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_emulated_attach_ioas); +int vdpa_iommufd_emulated_detach_ioas(struct vdpa_device *vdpa) +{ + vhost_vdpa_lockdep_assert_held(vdpa); + + if (!vdpa->iommufd_ictx || !vdpa->iommufd_access) + return -1; + + iommufd_access_destroy(vdpa->iommufd_access); + vdpa->iommufd_access = NULL; + return 0; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_emulated_detach_ioas); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 790b296271f1..c470a5596d9c 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -291,6 +291,27 @@ static inline bool vhost_is_little_endian(struct vhost_virtqueue *vq) } #endif +struct iommufd_ctx; +struct vdpa_device; +void vhost_vdpa_lockdep_assert_held(struct vdpa_device *vdpa); + +#if IS_ENABLED(CONFIG_IOMMUFD) +int vdpa_iommufd_bind(struct vdpa_device *vdpa, struct iommufd_ctx *ictx, + u32 *ioas_id, u32 *device_id); +void vdpa_iommufd_unbind(struct vdpa_device *vdpa); +#else +static inline int vdpa_iommufd_bind(struct vdpa_device *vdpa, + struct iommufd_ctx *ictx, u32 *ioas_id, + u32 *device_id) +{ + return -EOPNOTSUPP; +} + +static inline void vdpa_iommufd_unbind(struct vdpa_device *vdpa) +{ +} +#endif + /* Memory accessors */ static inline u16 vhost16_to_cpu(struct vhost_virtqueue *vq, __virtio16 val) { From patchwork Sat Sep 23 17:05:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 143974 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp312883vqu; Sat, 23 Sep 2023 11:13:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQ09cwEWOTppHPYxkE0PjGiQJlqNcTtCqQIMjaVvhNBxpKP2SdUS+azyCsCg86th89FkOS X-Received: by 2002:aca:1119:0:b0:3a1:d1d9:d59c with SMTP id 25-20020aca1119000000b003a1d1d9d59cmr3675110oir.33.1695492801585; Sat, 23 Sep 2023 11:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695492801; cv=none; d=google.com; s=arc-20160816; b=WsF2dd40hfrqtrFkIeNFMrR0tB3TpyLgTs7AHMcR04wic79mQ2Oy3zgMzcMZvcGiNc +F4XZiAQ6cHcHgvVILwLCJB50aunQ13ZlpIqb20AVCDkDPfanF9wNEQSJcxT/7pTc3z6 NEpZAMflzXS2bH/jKILvnR6aJTLAJxQA3eLQT4rG9VcW9r0lriG3hzGsSCmrj2f97laD 3Y0ogN3x+SxWjk2boGoLT+fgECdBxebv8UQE0cju4tEZLtJWbMqfD4rZLAT/6o1kZIYA 4ovt9W+R+IMnSEyDq9mTTjkiYD7Wrt+xI0rUA6FTSv/EZ+gvGIXM98xuRzTi98KNK/dL OYeg== 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=7UcKrjqyQxxSyECaK74/D93KIs/IAtnu5JgrP6RvkC4=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=frEyZQlJrYjSv0pYrsdNXNBfIpnW7oCQty2pbaGEx0ItSIyXz9yrfo1Gf5P9rDRbWO zFsQLcbyYccSAJ4Pe4QgcWxRDjHL6J9mD6EhDn/uFjY5Y+tclwALfFWKQ7txWyy4wtd8 FMwNqNC6NKaC4RByg+xG0Dg3nXarAfwmFtTIRnryeFJoVuirtbT0DsF0F8EgVjXNpG96 +3FCnJeacTifGk8xlWBiwQ5sZj16uMfR0Z8kCxRtp6iQXxn8UcqRjk0QHuOyRKHYVCyU WTAVE8hoHgtfdHGZQ9QYrs/dYEf24G5L/3EfCgrZnp63L5a/2SPk5PwjbWHEadax6XL5 VS/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dRbj4lw8; 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 x128-20020a636386000000b0056969e398fcsi6354497pgb.862.2023.09.23.11.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 11:13:21 -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=dRbj4lw8; 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 986CD802FD10; Sat, 23 Sep 2023 10:06:51 -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 S232066AbjIWRGu (ORCPT + 30 others); Sat, 23 Sep 2023 13:06:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232073AbjIWRGr (ORCPT ); Sat, 23 Sep 2023 13:06:47 -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 667FD11B for ; Sat, 23 Sep 2023 10:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488756; 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=7UcKrjqyQxxSyECaK74/D93KIs/IAtnu5JgrP6RvkC4=; b=dRbj4lw8gkxcZtNFc+S0kqdjQJfdXx0rp7Ioxo/lsO49tiWi7PoH4/gEAYYe6UlA5Zis3o JbFxNqlUPxLYpgJ+veImZPuSotrFwV1ck60RW5kRdSlgcXnu8dxcFbw+VbTkPXw0yh7GHX FZkFZ4SbaX2jMZZUSy1vDMLvKHA7Huw= 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-609-toftKyUmOkqGbn7mW2VNZw-1; Sat, 23 Sep 2023 13:05:55 -0400 X-MC-Unique: toftKyUmOkqGbn7mW2VNZw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 62F22185A790; Sat, 23 Sep 2023 17:05:54 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C91F2026D4B; Sat, 23 Sep 2023 17:05:50 +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 2/7] Kconfig: Add the new file vhost/iommufd Date: Sun, 24 Sep 2023 01:05:35 +0800 Message-Id: <20230923170540.1447301-3-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.4 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_H4,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 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 10:06:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777853059870982489 X-GMAIL-MSGID: 1777853059870982489 Change the makefile and Kconfig, to add the new file vhost/iommufd.c Signed-off-by: Cindy Lu --- drivers/vhost/Kconfig | 1 + drivers/vhost/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig index 587fbae06182..c54cea6c03f0 100644 --- a/drivers/vhost/Kconfig +++ b/drivers/vhost/Kconfig @@ -67,6 +67,7 @@ config VHOST_VDPA select VHOST select IRQ_BYPASS_MANAGER depends on VDPA + depends on IOMMUFD || !IOMMUFD help This kernel module can be loaded in host kernel to accelerate guest virtio devices with the vDPA-based backends. diff --git a/drivers/vhost/Makefile b/drivers/vhost/Makefile index f3e1897cce85..cda7f6b7f8da 100644 --- a/drivers/vhost/Makefile +++ b/drivers/vhost/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_VHOST_RING) += vringh.o obj-$(CONFIG_VHOST_VDPA) += vhost_vdpa.o vhost_vdpa-y := vdpa.o +vhost_vdpa-$(CONFIG_IOMMUFD) += iommufd.o obj-$(CONFIG_VHOST) += vhost.o From patchwork Sat Sep 23 17:05:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 143993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp354008vqu; Sat, 23 Sep 2023 13:16:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9JyvZi58L8ytll+ekfz0DfrX821JR/3XhZstapAJRg/7FBUKuZshxWQdakGvTj+4wR0Eo X-Received: by 2002:a05:6a20:2589:b0:153:56b1:8417 with SMTP id k9-20020a056a20258900b0015356b18417mr3773026pzd.21.1695500218014; Sat, 23 Sep 2023 13:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695500217; cv=none; d=google.com; s=arc-20160816; b=bgDJuEouKzBBNq6Wm6gp0xJ68TjrK/pMIhSU1YAWQoM3jcspi3gPJR5U4isP+x2/7p Z1OWi1ZiYsO25juKFH3p2UnELpQ1QAOf0Zqfrpftwkw4yD+6qqNavoBliILjJAi1+edd PXYOz4alKdseB/5s9bg6mNyv6KqAWD8GVHRhoo7oh+ebbXrQfdL1N1T6NN/PRconFvsj Sx0pFxnYR6RCSPREgOj6F+f6dJMqPoHRJz40SNPtnGe4l6WM7UHN8PleM5ps3a8Picj1 b1HsNBu4hMFm6hUfByG2O/Sz4KGbkMXZXyo8MfegvQzgnEMIqDQu7HXIYXC8IDeuMd/Y x0uA== 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=Hdq7599fHShALDoHh3mBOkTQ5ptt25at1kAS6tkS55Q=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=MbekOUvGZDUC3ujdG2e7MxfQe5ebyg0jpkHQg71RyqxjzRaor8Ls/XrdRExgg4QmUA Ur6zzSkb0EXrzzltCzueyF7PfchQGNl/HNIJptyY+AzjwuyFfWJOnJlWMlMhwhZzmQ5R uYQBE3f0vr+PIS2eJ7SKm3jSkpdVxX7JpqYtR76uXM2PwOKa5g3VPhsFPL2rhNvAoCbe z7NpyGDUaYsRfejXjR6pRg+Mr4NytPJ5qqhVV5O5bCOrniCDavi63sMrsyuHsC2uu7SE EAPGEGjjLCy06GO1/4npEnNJ2LcREZlvPfRpQP4GbndZVTwLd4WFNzXamMLdyYyYrRc5 D/Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JvbogTR4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id v17-20020a62c311000000b0068fb9c0bb07si6346261pfg.13.2023.09.23.13.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 13:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JvbogTR4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 5E0E5820AA80; Sat, 23 Sep 2023 10:07:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbjIWRG6 (ORCPT + 30 others); Sat, 23 Sep 2023 13:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232097AbjIWRGz (ORCPT ); Sat, 23 Sep 2023 13:06:55 -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 282C2196 for ; Sat, 23 Sep 2023 10:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488763; 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=Hdq7599fHShALDoHh3mBOkTQ5ptt25at1kAS6tkS55Q=; b=JvbogTR4vOOEmsuv7ThHmhsRT3C0D7K4yUJ7AZZCvb4DA0uHCDer57qbnWbLkGjghxklzy JrMkaVAxS9dLsmIO0PFGQZV1zE/8sinVloey2iPgRO6ZQlyI+amULIO6SiIRKSVDfR7T5i 4rNAaJI5exfbH/G/WX8qvhQuGCsgPEo= 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-139-vtlIZNBLPJ6ZbV8PT1oUxw-1; Sat, 23 Sep 2023 13:05:58 -0400 X-MC-Unique: vtlIZNBLPJ6ZbV8PT1oUxw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 2AD1F1C05133; Sat, 23 Sep 2023 17:05:58 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 045652026D4B; Sat, 23 Sep 2023 17:05:54 +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 3/7] vhost: Add 3 new uapi to support iommufd Date: Sun, 24 Sep 2023 01:05:36 +0800 Message-Id: <20230923170540.1447301-4-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.4 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sat, 23 Sep 2023 10:07:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777860836775309556 X-GMAIL-MSGID: 1777860836775309556 VHOST_VDPA_SET_IOMMU_FD: bind the device to iommufd device VDPA_DEVICE_ATTACH_IOMMUFD_AS: Attach a vdpa device to an iommufd address space specified by IOAS id. VDPA_DEVICE_DETACH_IOMMUFD_AS: Detach a vdpa device from the iommufd address space Signed-off-by: Cindy Lu --- drivers/vhost/vdpa.c | 191 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 71 ++++++++++++++ 2 files changed, 262 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index ec32f785dfde..91da012084e9 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,8 @@ #include "vhost.h" +MODULE_IMPORT_NS(IOMMUFD); + enum { VHOST_VDPA_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2) | @@ -69,6 +72,15 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, u64 start, u64 last, u32 asid); +void vhost_vdpa_lockdep_assert_held(struct vdpa_device *vdpa) +{ + struct vhost_vdpa *v = vdpa_get_drvdata(vdpa); + + if (WARN_ON(!v)) + return; + lockdep_assert_held(&v->vdev.mutex); +} + static inline u32 iotlb_to_asid(struct vhost_iotlb *iotlb) { struct vhost_vdpa_as *as = container_of(iotlb, struct @@ -497,6 +509,173 @@ static long vhost_vdpa_suspend(struct vhost_vdpa *v) return ops->suspend(vdpa); } +static long vhost_vdpa_tmp_set_iommufd(struct vhost_vdpa *v, void __user *argp) +{ + struct device *dma_dev = vdpa_get_dma_dev(v->vdpa); + struct vhost_vdpa_set_iommufd set_iommufd; + struct vdpa_device *vdpa = v->vdpa; + struct iommufd_ctx *ictx; + unsigned long minsz; + u32 pt_id, dev_id; + struct fd f; + long r = 0; + int idx; + + minsz = offsetofend(struct vhost_vdpa_set_iommufd, ioas_id); + if (copy_from_user(&set_iommufd, argp, minsz)) + return -EFAULT; + + if (set_iommufd.group_id >= v->nvqs) + return -ENOBUFS; + + idx = array_index_nospec(set_iommufd.group_id, v->nvqs); + + /* Unset IOMMUFD */ + if (set_iommufd.iommufd < 0) { + if (!test_bit(idx, vdpa->vq_bitmap)) + return -EINVAL; + + if (!vdpa->iommufd_ictx || !vdpa->iommufd_device) + return -EINVAL; + if (atomic_read(&vdpa->iommufd_users)) { + atomic_dec(&vdpa->iommufd_users); + return 0; + } + vdpa_iommufd_unbind(v->vdpa); + vdpa->iommufd_device = NULL; + vdpa->iommufd_ictx = NULL; + clear_bit(idx, vdpa->vq_bitmap); + return iommu_attach_device(v->domain, dma_dev); + } + /* First opened virtqueue of this vdpa device */ + + if (!vdpa->vq_bitmap) { + vdpa->vq_bitmap = bitmap_alloc(v->nvqs, GFP_KERNEL); + } + ///if (test_bit(idx, vdpa->vq_bitmap)) + //return -EBUSY; + + /* For same device but different groups, ++refcount only */ + if (vdpa->iommufd_device) + goto out_inc; + + r = -EBADF; + f = fdget(set_iommufd.iommufd); + if (!f.file) + goto out_bitmap_free; + + r = -EINVAL; + ictx = iommufd_ctx_from_file(f.file); + if (IS_ERR(ictx)) + goto out_fdput; + + if (v->domain) + iommu_detach_device(v->domain, dma_dev); + +#if 0 + iommu_group_add_device(iommu_group_alloc(), &vdpa->dev); +#endif + pt_id = set_iommufd.ioas_id; + r = vdpa_iommufd_bind(vdpa, ictx, &pt_id, &dev_id); + if (r) + goto out_reattach; + + set_iommufd.out_dev_id = dev_id; + set_iommufd.out_hwpt_id = pt_id; + r = copy_to_user(argp + minsz, &set_iommufd.out_dev_id, + sizeof(set_iommufd.out_dev_id) + + sizeof(set_iommufd.out_hwpt_id)) ? + -EFAULT : + 0; + if (r) + goto out_device_unbind; + printk(KERN_ERR "[%s] %d called %p\n", __func__, __LINE__, + vdpa->iommufd_ictx); + + vdpa->iommufd_ictx = ictx; + +out_inc: + atomic_inc(&vdpa->iommufd_users); + set_bit(idx, vdpa->vq_bitmap); + + goto out_fdput; + +out_device_unbind: + + vdpa_iommufd_unbind(vdpa); +out_reattach: + + iommu_attach_device(v->domain, dma_dev); + iommufd_ctx_put(ictx); +out_fdput: + fdput(f); +out_bitmap_free: + bitmap_free(vdpa->vq_bitmap); + return r; +} +int vdpa_ioctl_device_attach(struct vhost_vdpa *v, void __user *arg) +{ + struct vdpa_device_attach_iommufd_as attach; + unsigned long minsz; + int ret; + + minsz = offsetofend(struct vdpa_device_attach_iommufd_as, ioas_id); + + if (copy_from_user(&attach, (void __user *)arg, minsz)) + return -EFAULT; + + if (attach.argsz < minsz || attach.flags || + attach.ioas_id == IOMMUFD_INVALID_ID) + return -EINVAL; + + if (!v->vdpa->config->bind_iommufd) + return -ENODEV; + + if (!v->vdpa->iommufd_ictx) { + ret = -EINVAL; + return ret; + } + + ret = v->vdpa->config->attach_ioas(v->vdpa, &attach.ioas_id); + + if (ret) + return ret; + + ret = copy_to_user( + (void __user *)arg + + offsetofend(struct vdpa_device_attach_iommufd_as, + flags), + &attach.ioas_id, sizeof(attach.ioas_id)) ? + -EFAULT : + 0; + + if (ret) + return ret; + + return 0; +} + +int vdpa_ioctl_device_detach(struct vhost_vdpa *v, void __user *arg) +{ + struct vdpa_device_detach_iommufd_as detach; + unsigned long minsz; + + minsz = offsetofend(struct vdpa_device_detach_iommufd_as, flags); + + if (copy_from_user(&detach, (void __user *)arg, minsz)) + return -EFAULT; + + if (detach.argsz < minsz || detach.flags) + return -EINVAL; + + if (!v->vdpa->config->bind_iommufd) + return -ENODEV; + + if (v->vdpa->iommufd_ictx) { + return -EINVAL; + } + return v->vdpa->config->detach_ioas(v->vdpa); +} static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) @@ -655,6 +834,18 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, case VHOST_SET_LOG_FD: r = -ENOIOCTLCMD; break; + case VHOST_VDPA_SET_IOMMU_FD: + + r = vhost_vdpa_tmp_set_iommufd(v, argp); + break; + case VDPA_DEVICE_ATTACH_IOMMUFD_AS: + r = vdpa_ioctl_device_attach(v, (void __user *)arg); + break; + + case VDPA_DEVICE_DETACH_IOMMUFD_AS: + r = vdpa_ioctl_device_detach(v, (void __user *)arg); + break; + case VHOST_VDPA_SET_CONFIG_CALL: r = vhost_vdpa_set_config_call(v, argp); break; diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index f9f115a7c75b..cdda0c1860d8 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -45,6 +45,7 @@ #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) /* Specify an eventfd file descriptor to signal on log write. */ #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) +/* Specify an iommufd file descriptor for IO address translation */ /* Ring setup. */ /* Set number of descriptors in ring. This parameter can not @@ -180,4 +181,74 @@ */ #define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D) +/* vhost vdpa set iommufd + * Input parameters: + * @iommufd: file descriptor from /dev/iommu; pass -1 to unset + * @group_id: identifier of the group that a virtqueue belongs to + * @ioas_id: IOAS identifier returned from ioctl(IOMMU_IOAS_ALLOC) + * Output parameters: + * @out_dev_id: device identifier + * @out_hwpt_id: hardware IO pagetable identifier + */ +struct vhost_vdpa_set_iommufd { + __s32 iommufd; + __u32 group_id; + __u32 ioas_id; + __u32 out_dev_id; + __u32 out_hwpt_id; +}; + +#define VHOST_VDPA_SET_IOMMU_FD \ + _IOW(VHOST_VIRTIO, 0x7e, struct vhost_vdpa_set_iommufd) + +/* + * VDPA_DEVICE_ATTACH_IOMMUFD_AS - + * _IOW(VHOST_VIRTIO, 0x7f, struct vdpa_device_attach_iommufd_as) + * + * Attach a vdpa device to an iommufd address space specified by IOAS + * id. + * + * Available only after a device has been bound to iommufd via + * VHOST_VDPA_SET_IOMMU_FD + * + * Undo by VDPA_DEVICE_DETACH_IOMMUFD_AS or device fd close. + * + * @argsz: user filled size of this data. + * @flags: must be 0. + * @ioas_id: Input the target id which can represent an ioas + * allocated via iommufd subsystem. + * + * Return: 0 on success, -errno on failure. + */ +struct vdpa_device_attach_iommufd_as { + __u32 argsz; + __u32 flags; + __u32 ioas_id; +}; + +#define VDPA_DEVICE_ATTACH_IOMMUFD_AS \ + _IOW(VHOST_VIRTIO, 0x7f, struct vdpa_device_attach_iommufd_as) + +/* + * VDPA_DEVICE_DETACH_IOMMUFD_AS + * + * Detach a vdpa device from the iommufd address space it has been + * attached to. After it, device should be in a blocking DMA state. + * + * Available only after a device has been bound to iommufd via + * VHOST_VDPA_SET_IOMMU_FD + * + * @argsz: user filled size of this data. + * @flags: must be 0. + * + * Return: 0 on success, -errno on failure. + */ +struct vdpa_device_detach_iommufd_as { + __u32 argsz; + __u32 flags; +}; + +#define VDPA_DEVICE_DETACH_IOMMUFD_AS \ + _IOW(VHOST_VIRTIO, 0x83, struct vdpa_device_detach_iommufd_as) + #endif 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; 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 From patchwork Sat Sep 23 17:05:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 143984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp332978vqu; Sat, 23 Sep 2023 12:11:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGh2GVwbfsN1r7+VVFurT2U3UxbGRC9Gyu+K5/ZTkZlaYg1ybsa21ZEzZr1s1ZiasW6yJvT X-Received: by 2002:a17:902:dac8:b0:1c5:746f:efb1 with SMTP id q8-20020a170902dac800b001c5746fefb1mr3949630plx.8.1695496281480; Sat, 23 Sep 2023 12:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695496281; cv=none; d=google.com; s=arc-20160816; b=Wk8xQBvymKu3/jxeeBBr+UvIIub6PVyBQbMqq1BqIY2015YdV14PHz3JPkP6i90nWC AuyaSczJzps/Gmck/6O6qNO+4CXzfkzACRAB/gInEK9q2ETNaZiSsRFCDu5wW4M0VRSh S8VefFVPTD3MsECpt5xYmkspRRxLCD5+hg0fvOUOPFDwlkm6o4LgAB6uotYfxc7ywv3q bC/+VIB13XPr6O5h1A1ATie+XIpJUWddXHbqwGUszI3OOYwo4WLUDIa9TFHb3vNlBL49 iPfzcBIQXuJnUg1ZHmylkfoZxif5QWE/L147qvxWiVM3wOxAvyPbMrDpRczzGMJaC1wC JWvg== 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=5JLc/gcAH7DqQQF3pLiWnqXoje3Kz4Ompug0RZFEuno=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=pK/hDsoOxWqyMMkE0NPxUZK4YI8YTu31v+/nnm1Orvo57+ghGpkLyPCwhGBQT2Q3XF Z7Wo771j3CA04Vp916eXwP8P0pwJhkkm1KSWE5gXP5709MI2WoZ8XG9siDRX0V8+2LpE 2yhxVtq8hAML1WVbMD/ZIqAmJhWuoUYD0t6dpUDFHnbPHGA2CFJeQMEBlfTO3gnTXvnV zfg9vAjCpdgwaUw1RJtkyBYPUC49i8RyYnpJ0zJI2lgTFqvFgsnsqMJdf3fF4tNXY0wS orJ5NfJUD3H/DeYqnUoY1RdTYVmXPhpeG+sjVEV3VKnpnGVBZPMrzWzodUGCa8EojR0X YYaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gqNQ7XU5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id d14-20020a170902cece00b001bc674914b0si7293936plg.472.2023.09.23.12.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 12:11:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gqNQ7XU5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 0CFDF801B73C; Sat, 23 Sep 2023 10:07:38 -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 S232072AbjIWRHe (ORCPT + 30 others); Sat, 23 Sep 2023 13:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjIWRH3 (ORCPT ); Sat, 23 Sep 2023 13:07:29 -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 77C3E194 for ; Sat, 23 Sep 2023 10:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488794; 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=5JLc/gcAH7DqQQF3pLiWnqXoje3Kz4Ompug0RZFEuno=; b=gqNQ7XU52rlFNyl3JZVL8fqeRWFGaCgSrvBn9le9iIT5mt+aAkIGIkHHys3D6BozjYfOci RZE9HXDx+HyoxUh3l6/OZRQDsuAq2gnOypZ0S1NpPsbIivBiZ2uW+ELUMx7QI33nAXPtUb EhlUq0QCCEtAp54+jFMAB7dR0xgWZv8= 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-20-r5i6n1P3PIacCZt-mrDfdQ-1; Sat, 23 Sep 2023 13:06:31 -0400 X-MC-Unique: r5i6n1P3PIacCZt-mrDfdQ-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 0EFE13C025B6; Sat, 23 Sep 2023 17:06:31 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD11E2156701; Sat, 23 Sep 2023 17:06:27 +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 6/7] vdpa_sim :Add support for iommufd Date: Sun, 24 Sep 2023 01:05:39 +0800 Message-Id: <20230923170540.1447301-7-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:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777856708763587534 X-GMAIL-MSGID: 1777856708763587534 Add new vdpa_config_ops to support iommufd Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index cb88891b44a8..55e6f45bb274 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -727,6 +727,10 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .dma_map = vdpasim_dma_map, .dma_unmap = vdpasim_dma_unmap, .free = vdpasim_free, + .bind_iommufd = vdpa_iommufd_emulated_bind, + .unbind_iommufd = vdpa_iommufd_emulated_unbind, + .attach_ioas = vdpa_iommufd_emulated_attach_ioas, + .detach_ioas = vdpa_iommufd_emulated_detach_ioas, }; static const struct vdpa_config_ops vdpasim_batch_config_ops = { @@ -759,6 +763,10 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .set_group_asid = vdpasim_set_group_asid, .set_map = vdpasim_set_map, .free = vdpasim_free, + .bind_iommufd = vdpa_iommufd_emulated_bind, + .unbind_iommufd = vdpa_iommufd_emulated_unbind, + .attach_ioas = vdpa_iommufd_emulated_attach_ioas, + .detach_ioas = vdpa_iommufd_emulated_detach_ioas, }; MODULE_VERSION(DRV_VERSION); From patchwork Sat Sep 23 17:05:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 144041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp495275vqu; Sat, 23 Sep 2023 21:51:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPYIG4UXM8iqy1gdxLSF2rYzwDcCNEZxcLORrlVVfHfT6hZAMinQvzZzqTErr3vW2nZZ4d X-Received: by 2002:a05:6a20:5492:b0:133:8784:15f7 with SMTP id i18-20020a056a20549200b00133878415f7mr9343095pzk.14.1695531069805; Sat, 23 Sep 2023 21:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695531069; cv=none; d=google.com; s=arc-20160816; b=cof80fUl47fu1bkL2gUq59SJdZtlyBz2VYiQtYAhjs98fFfpsJ4sMxJLDE0I8Uz3p8 O5zRh53x5o6gC97IDGdLc973nT0xQUd/PGxDX9+A4d+nZFO9soYmm3ap1KgXZtKR8JKW ki+BIOGWc2uh8goY4gyiP1UvQnXDWA00NI9A1vFysgOiiY7kWLGSCF8aAXB1cUnO/1Wm 0b1K9GcOZupl1ArJWM8Q/sFlDqml6URQZGPR0SsTEpkdhCIEdERahEyWU369w08f4FW0 kiX/LBJih0fhCxU8gMW6TMlZXzdhhBIi64U+MKdrL549udLuIDn8doLRgYGXHcXPTDWc refg== 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=0foaQUJDnKYeTXBZ0CfBrMz9PTwxeVPI+eHRfhl6x0E=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=z+tcgTsMztSGh9o2VKjn+xfe4FlnzFVo/2T+i/tiu/jI8UaqwegnUZqU2Out9nRzWj oGxVvPEYWFjn5dxVYnBoirCyVXIlWElJ46qPS1jSvxhjPq+vip/lWpk4e4BJNP2HD955 e1+cwZ6eiSgSPTadfc52s5hLZRCTuOgOl2EFrXLWlcDwRQNsVv9UZ6NRahDSEmIzxQwf ab52FyVGC6MX24P6q7YZlvxg2jABllD/G10GOrPrwXF/z9HbXDx8IcUinaiTJyi/HodO DPVNoJSE8TB53dyATtlk+LsXIOhS1fzAl2olDb8OxPpceNhnUsoA4lixJLIKixTeh0dx V6ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dGUVrAL5; 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 x33-20020a634861000000b0057047d68837si7273036pgk.869.2023.09.23.21.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 21:51:09 -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=dGUVrAL5; 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 C8A9F801B73D; Sat, 23 Sep 2023 10:07:39 -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 S231991AbjIWRHh (ORCPT + 30 others); Sat, 23 Sep 2023 13:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232136AbjIWRH3 (ORCPT ); Sat, 23 Sep 2023 13:07:29 -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 1D2C01A6 for ; Sat, 23 Sep 2023 10:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695488798; 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=0foaQUJDnKYeTXBZ0CfBrMz9PTwxeVPI+eHRfhl6x0E=; b=dGUVrAL5d4NpzoT6GUVK0GkW69itdIgNIqfaCJYB7OGBC/f2oS9QoIfJcDqybwYmidtcym 7Btp33n+sYI7KXekR2QR+MU0M5OrA+yexkoaaXCVs9rqnM+cTIht/lY2iqKt9ARW+bJfIH SSLie/RqvvfXcdhDqAKkMDwkxgaaUh4= 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-561-0ElBDspMNB2imCymtZ9AEQ-1; Sat, 23 Sep 2023 13:06:35 -0400 X-MC-Unique: 0ElBDspMNB2imCymtZ9AEQ-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 CB3111C05135; Sat, 23 Sep 2023 17:06:34 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id A474F2156701; Sat, 23 Sep 2023 17:06:31 +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 7/7] iommufd: Skip the CACHE_COHERENCY and iommu group check Date: Sun, 24 Sep 2023 01:05:40 +0800 Message-Id: <20230923170540.1447301-8-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_H4,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:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777893187116716558 X-GMAIL-MSGID: 1777893187116716558 This is just the work arround for vdpa, I Will fix these problems in the next version. Skip these 2 checks: 1.IOMMU_CAP_CACHE_COHERENCY check 2.iommu_group_get check Signed-off-by: Cindy Lu --- drivers/iommu/iommufd/device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index f7cb353fd9c7..0224d751f503 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -71,8 +71,8 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, * to restore cache coherency. */ if (!device_iommu_capable(dev, IOMMU_CAP_CACHE_COHERENCY)) - return ERR_PTR(-EINVAL); - + //return ERR_PTR(-EINVAL); +#if 0 group = iommu_group_get(dev); if (!group) return ERR_PTR(-ENODEV); @@ -80,7 +80,7 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, rc = iommu_device_claim_dma_owner(dev, ictx); if (rc) goto out_group_put; - +#endif idev = iommufd_object_alloc(ictx, idev, IOMMUFD_OBJ_DEVICE); if (IS_ERR(idev)) { rc = PTR_ERR(idev);