From patchwork Fri Nov 3 17:16: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: 161377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1195752vqu; Fri, 3 Nov 2023 10:18:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRNKQP+TNPn6y5Yn3ElMBGQzXvSF1zef56ZO0jOizpRzeiL+mnvY4unXnwBwtzHvPAlHsA X-Received: by 2002:a17:90a:3c86:b0:27c:fb84:101a with SMTP id g6-20020a17090a3c8600b0027cfb84101amr20194205pjc.29.1699031883024; Fri, 03 Nov 2023 10:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031883; cv=none; d=google.com; s=arc-20160816; b=QNl27s9xNC9h7oZEttX6eNzW9//o8LOnquv4q/HYteaPK2+XGr5EpLWjt9rGqB0yuU prisv/8Px/RnUQOMS/ZeT7zXF3pdl6YiUTb1QjmYjzOfoEx1neB70pOxywx33NPiF8bY hDWPQjkZRC6ajsjvv4tB7pnHFEDoWkJoXc23nJhEVOXdqNw8hL1RDG0ZrIZWCKDh0jbb 8xdyN9AzLE5okP527qeRuLo9Jo1vcZWRHIN9RXLSPqpfB5indvrLxNeMyQ1zCoBdO7DQ sa33ZgP8ix8+1CasyeCEOdgQ8BB56NT8s1JASFjS7RjQJYrgIADt88f1YLFdc/bv7TSJ wMvg== 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=OZOkp7RIIlEcdzCc+o8G685sXVkqf9owoeJPzWLLPLs=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=eN0B6EESOmZp0iC3o7HyINx0UTkT7yGEiD3VgkgBkexruYHC4dAQxPmpwxAvlO/nRB zmTZQBHFxG35UuF82hFSz84z/mYA1oWDp7QvZ8Q53V7pTzLBuic4H1kv6jhcgfhKZYXY uykfgSviQWXvGiliTe0LDzXHKBSVHEmPavcmUaQNC5xPu+vtQe3UvoA7MuYRL2BuUPdL DM0eLc4U5ZpzzqOgjjN5/4gAPCNU0DPe4HiAdypR9lsURsSpuSiZr/cG/3cE/Oz/oAAj urgPg3EQNSGOgQCV710XfU751wQQH5bTfsuZdP1DS2PuBclQ0kS6gcbFF1sfmJvwu48m NUeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DXAglskq; 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 oa16-20020a17090b1bd000b002805a422743si2035333pjb.12.2023.11.03.10.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:18:03 -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=DXAglskq; 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 4D99E81BDB8D; Fri, 3 Nov 2023 10:17:55 -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 S230215AbjKCRRj (ORCPT + 35 others); Fri, 3 Nov 2023 13:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjKCRRj (ORCPT ); Fri, 3 Nov 2023 13:17:39 -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 A7F1CD48 for ; Fri, 3 Nov 2023 10:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031815; 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=OZOkp7RIIlEcdzCc+o8G685sXVkqf9owoeJPzWLLPLs=; b=DXAglskqoBjX1zAit+HiPrFFFIgik4spl9dgitQ0t1GFh/BYuLCJYEmlbtN3XOkAyFhcOv Z0KHobG2TLP4uJn1XStEOZCduueCjCfcejL1tMvNg/eavO6LA06tl5l1b6xJ1Q3NX26myw 52l83kD5zM8xotg0oiCfj4DHxaXdsCI= 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-589-s4ZotfSOOLO-hga7WjSckw-1; Fri, 03 Nov 2023 13:16:52 -0400 X-MC-Unique: s4ZotfSOOLO-hga7WjSckw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 21CC1811E88; Fri, 3 Nov 2023 17:16:52 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id F145740C6ECE; Fri, 3 Nov 2023 17:16:48 +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 1/8] vhost/iommufd: Add the functions support iommufd Date: Sat, 4 Nov 2023 01:16:34 +0800 Message-Id: <20231103171641.1703146-2-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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:17:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564055804006147 X-GMAIL-MSGID: 1781564055804006147 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 | 178 ++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 21 +++++ 2 files changed, 199 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..113dda50a9b6 --- /dev/null +++ b/drivers/vhost/iommufd.c @@ -0,0 +1,178 @@ +#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; + + return 0; +} + +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 *iommufd_ioasid) +{ + int rc; + + vhost_vdpa_lockdep_assert_held(vdpa); + + if (WARN_ON(!vdpa->iommufd_device)) + return -EINVAL; + + if (vdpa->iommufd_attached) + rc = iommufd_device_replace(vdpa->iommufd_device, + iommufd_ioasid); + else + rc = iommufd_device_attach(vdpa->iommufd_device, + iommufd_ioasid); + if (rc) + return rc; + vdpa->iommufd_attached = true; + + return 0; +} + +EXPORT_SYMBOL_GPL(vdpa_iommufd_physical_attach_ioas); +int vdpa_iommufd_physical_detach_ioas(struct vdpa_device *vdpa) +{ + vhost_vdpa_lockdep_assert_held(vdpa); + + if (WARN_ON(!vdpa->iommufd_device) || !vdpa->iommufd_attached) + return -1; + + iommufd_device_detach(vdpa->iommufd_device); + vdpa->iommufd_attached = false; + return 0; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_physical_detach_ioas); + +static void vdpa_emulated_unmap(void *data, unsigned long iova, + unsigned long length) +{ + struct vdpa_device *vdpa = data; + /* todo: need to unmap the iova-lenth in all ASID*/ + + // 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); + + struct iommufd_access *user; + + user = iommufd_access_create(ictx, &vdpa_user_ops, vdpa, out_device_id); + if (IS_ERR(user)) + return PTR_ERR(user); + vdpa->iommufd_access = user; + 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_attached = false; + vdpa->iommufd_access = NULL; + } +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_emulated_unbind); + +int vdpa_iommufd_emulated_attach_ioas(struct vdpa_device *vdpa, + u32 *iommufd_ioasid) +{ + int rc; + + struct iommufd_access *user; + + vhost_vdpa_lockdep_assert_held(vdpa); + + if (vdpa->iommufd_attached) { + rc = iommufd_access_replace(vdpa->iommufd_access, + *iommufd_ioasid); + } else { + rc = iommufd_access_attach(vdpa->iommufd_access, + *iommufd_ioasid); + } + user = vdpa->iommufd_access; + + if (rc) + return rc; + vdpa->iommufd_attached = true; + 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 (WARN_ON(!vdpa->iommufd_access) || !vdpa->iommufd_attached) + return -1; + + iommufd_access_detach(vdpa->iommufd_access); + vdpa->iommufd_attached = false; + + return 0; +} +EXPORT_SYMBOL_GPL(vdpa_iommufd_emulated_detach_ioas); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index f60d5f7bef94..179012e350f9 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -310,6 +310,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 Fri Nov 3 17:16: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: 161375 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1195696vqu; Fri, 3 Nov 2023 10:17:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnaedBZf1aolWfymnaMBs1qfJj04Xc4HCR57teEk7KRiT9+I8ue9LiRDFriU59aUKuqNWu X-Received: by 2002:a17:902:fa87:b0:1cc:3773:3d7f with SMTP id lc7-20020a170902fa8700b001cc37733d7fmr14112205plb.21.1699031877381; Fri, 03 Nov 2023 10:17:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031877; cv=none; d=google.com; s=arc-20160816; b=bdiANhIe8jvsMyhHhtA1f89hIdtIIdofqHCaodWgVO8XrQss8JGvegcHW8Tcf8UHVR Ze2KrLnglTRWwJuOZa5xWCVeESlLmLoeIy7/M6M6rcxYtcCKy+g4n0cRidTVDMokIz43 ZwSVMKjygKwqI+aIeXcxvc9OBZFq73I2aFWTscokPNihWvzZJEX7xSETEhYo6HzFtorC 6Bo3Kfh64JU7Xj79HxNzIiIar8S0PbCNJGUHTyAUOUiaM/CXsgwDspCcOrFNnPpn+/UC okrK7ixYWG2lx8aa8HI33PgqSwt27l99grScaTWj7RJ3BHsLp0H4DDZNnyxiX+9ySaes y+BQ== 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=T2BDwvqkQrafYreOuDJL/fbzR9dfSYQpbXhoeoCg4t4=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=mP74hZBif7+XUPZ8xR3vCUnCfQVuZGaDhGqtcW5aLXuBm5d8VlyBPwAPPnVA0vBMdC aPj9aZvuOKQsRKdW3w2BRooQSBcL4SKGyK/TsHsS95ELkUa1LVp7D88Xev/rh3nszJcm jV9C4+SY8rf/JQ9gDnRikUoQ+wDOC/f8C9lggdgsmbC3qUICosFJzFUpw1YNNtnPUTEC 2AZ1wr1dS2ECMCMdB9Te4qz84s2L5yKf0kCYdyr1NZacS/DZPr87i9+zPMS8AXOnbj5B dZH76GUsLaDALL7iScX40rxSh/WBrFJd2tbj10q+TJz881S/9S/vqNLfu5LIQKTpFC22 oK8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KZICXSPf; 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 z6-20020a170902d54600b001c9faf1439esi2010523plf.288.2023.11.03.10.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:17:57 -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=KZICXSPf; 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 7A9E683DBEC3; Fri, 3 Nov 2023 10:17:56 -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 S1345793AbjKCRRs (ORCPT + 35 others); Fri, 3 Nov 2023 13:17:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjKCRRo (ORCPT ); Fri, 3 Nov 2023 13:17:44 -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 652181BD for ; Fri, 3 Nov 2023 10:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031817; 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=T2BDwvqkQrafYreOuDJL/fbzR9dfSYQpbXhoeoCg4t4=; b=KZICXSPfKJFv1Pr8iADOaCuMqzcbUyxqlWevAIbjyOdwMseC5Vxqw6vuOlKPYnTWjfVviL KlOrrXHTenTngTu1okD8luEXknMV9eRBnglCPFWt+RMrCUPhE0HSxHSq79o98zDHzB0+Up SLCZsCPypcrieu0k56X3+AkjcEGoPN4= 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-605-pleYeuzlM6i_Grq8vQ4w-g-1; Fri, 03 Nov 2023 13:16:56 -0400 X-MC-Unique: pleYeuzlM6i_Grq8vQ4w-g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 D79E985A58A; Fri, 3 Nov 2023 17:16:55 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id B65AE40C6EBC; Fri, 3 Nov 2023 17:16:52 +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 2/8] Kconfig: Add the new file vhost/iommufd Date: Sat, 4 Nov 2023 01:16:35 +0800 Message-Id: <20231103171641.1703146-3-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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]); Fri, 03 Nov 2023 10:17:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564049736886858 X-GMAIL-MSGID: 1781564049736886858 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 b455d9ab6f3d..a4becfb36d77 100644 --- a/drivers/vhost/Kconfig +++ b/drivers/vhost/Kconfig @@ -72,6 +72,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 Fri Nov 3 17:16: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: 161376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1195699vqu; Fri, 3 Nov 2023 10:17:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG95ffvX0lkZJuy7Iu/CZHTqjnyvq7uFeP6SQkkWzi5gT49ZHfAsSvVJ6nviuoQJaLJH+wv X-Received: by 2002:a17:902:d2cc:b0:1cc:3ad2:13f6 with SMTP id n12-20020a170902d2cc00b001cc3ad213f6mr19773578plc.66.1699031878076; Fri, 03 Nov 2023 10:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031878; cv=none; d=google.com; s=arc-20160816; b=rcR83yLUZTik1ha+UMK88VvIrWU+4G7/QDF3Yw4OaXnnvU/+50Wr0DnTQNl1LFmbUl jtJmdPvZ1g61A97VfRlna9uB9A8GCJBSUfoT2SEnl53lpl3t1uFMyPiEj8CR9YYe8VB0 iT/w86pg/I3rTEV/x1PHkeGlYF54cJ8JxfskcUA30oIpbwgf/U764uPqYzKxZDDFdvFm l75InItUMwIfp7pbwKnqGz1tdQR3aF+xsBUmS1sMf+lCdVhEBHqt0B+wHBAt76nhn0xf 1d+qSdrSV8VHPaSLhqhV69O1SRV/Zz5OFqfax/miwbGzMXh6hvl0MZyeU4LMfT8eNKY7 oMNg== 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=JjCcpTQrJmsF+m1LiuhY/lfZrSnOFnb7RQ3HwNEy8v8=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=Q9T6RyCcSpEPJPaJXp+FlbPc7W2PdKnmiWF8zGRVEGk0HEc5EM9oEokDemeEq9Kos1 8QbLl2zasU0pohIOw1BMZBinUV7G5njMRY9XjpPb1XXzeFMYNm/qRhCQFTXdEmquGGld 0X6HMxfAn26kmaDctSp+kAogXy0SG0bwF+DkABja2McF3Jl7CIjVsrcve3AwBtEngyf/ H2VRpbkVvCiRJYKTHu62CbwZDsCqAg67WWd1IwV9Weq0F/8DQfML05Aj9qIfrBMUyFeC MN0cIgiTr10yCdCgVXIK8PQThn1yaQGbnZRG17oDs+Gncxr2ixe3v4anR4HZnqWD2eb+ Wlxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ENK+mJ1n; 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 km15-20020a17090327cf00b001c60c5bbff2si1808421plb.201.2023.11.03.10.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:17:58 -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=ENK+mJ1n; 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 3F78583DB97F; Fri, 3 Nov 2023 10:17:57 -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 S1345766AbjKCRRy (ORCPT + 35 others); Fri, 3 Nov 2023 13:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234471AbjKCRRv (ORCPT ); Fri, 3 Nov 2023 13:17:51 -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 B163CD47 for ; Fri, 3 Nov 2023 10:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031823; 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=JjCcpTQrJmsF+m1LiuhY/lfZrSnOFnb7RQ3HwNEy8v8=; b=ENK+mJ1ndLrunPqVcDm5SAIrDtynqIliDPt/gFL8pYltHCnMvtXi06MJMnLa97lWXS+JZo 8hllChZtpqayo3Fjy1FIEWXbaIjaasYohWC9fb19mG3CUEwcNTFmzWi0b1CzHPysqjfATe B0m4zOWOMDDG4hEJptS0NAEuBK18s+U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-Lrm-ZPJtNbC55VC5JqJ0OA-1; Fri, 03 Nov 2023 13:17:00 -0400 X-MC-Unique: Lrm-ZPJtNbC55VC5JqJ0OA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 99F131C29AE0; Fri, 3 Nov 2023 17:16:59 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7919440C6EBF; Fri, 3 Nov 2023 17:16:56 +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 3/8] vhost: Add 3 new uapi to support iommufd Date: Sat, 4 Nov 2023 01:16:36 +0800 Message-Id: <20231103171641.1703146-4-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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]); Fri, 03 Nov 2023 10:17:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564050189790956 X-GMAIL-MSGID: 1781564050189790956 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 | 171 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 66 ++++++++++++++ 2 files changed, 237 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 78379ffd2336..dfaddd833364 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 @@ -551,6 +563,149 @@ static long vhost_vdpa_suspend(struct vhost_vdpa *v) return ops->suspend(vdpa); } +static long vhost_vdpa_iommufd_set_device(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 ioas_id, dev_id; + struct fd f; + long r = 0; + + minsz = offsetofend(struct vhost_vdpa_set_iommufd, iommufd_ioasid); + if (copy_from_user(&set_iommufd, argp, minsz)) + return -EFAULT; + + /* Unset IOMMUFD */ + if (set_iommufd.iommufd < 0) { + 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; + return iommu_attach_device(v->domain, dma_dev); + } + + /* 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; + + r = -EINVAL; + ictx = iommufd_ctx_from_file(f.file); + if (IS_ERR(ictx)) + goto out_fdput; + + if (v->domain) { + iommu_device_unuse_default_domain(dma_dev); + iommu_detach_device(v->domain, dma_dev); + } + + ioas_id = set_iommufd.iommufd_ioasid; + r = vdpa_iommufd_bind(vdpa, ictx, &ioas_id, &dev_id); + if (r) + goto out_reattach; + + set_iommufd.out_dev_id = dev_id; + r = copy_to_user(argp + minsz, &set_iommufd.out_dev_id, + sizeof(set_iommufd.out_dev_id)) ? + -EFAULT : + 0; + if (r) + goto out_device_unbind; + + vdpa->iommufd_ictx = ictx; + +out_inc: + atomic_inc(&vdpa->iommufd_users); + + goto out_fdput; + +out_device_unbind: + + vdpa_iommufd_unbind(vdpa); +out_reattach: + iommu_device_use_default_domain(dma_dev); + iommu_attach_device(v->domain, dma_dev); + iommufd_ctx_put(ictx); +out_fdput: + fdput(f); +out: + return r; +} +int vhost_vdpa_iommufd_ioas_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) + 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 vhost_vdpa_iommufd_ioas_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); +} /* After a successful return of this ioctl the device resumes processing * virtqueue descriptors. The device becomes fully operational the same way it @@ -744,6 +899,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_iommufd_set_device(v, argp); + break; + case VDPA_DEVICE_ATTACH_IOMMUFD_AS: + r = vhost_vdpa_iommufd_ioas_attach(v, (void __user *)arg); + break; + + case VDPA_DEVICE_DETACH_IOMMUFD_AS: + r = vhost_vdpa_iommufd_ioas_detach(v, (void __user *)arg); + break; + case VHOST_VDPA_SET_CONFIG_CALL: r = vhost_vdpa_set_config_call(v, argp); break; @@ -896,6 +1063,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), GFP_KERNEL); } else { r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm), GFP_KERNEL); diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index f5c48b61ab62..07e1b2c443ca 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -219,4 +219,70 @@ */ #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) +/* vhost_vdpa_set_iommufd + * Input parameters: + * @iommufd: file descriptor from /dev/iommu; pass -1 to unset + * @iommufd_ioasid: IOAS identifier returned from ioctl(IOMMU_IOAS_ALLOC) + * Output parameters: + * @out_dev_id: device identifier + */ +struct vhost_vdpa_set_iommufd { + __s32 iommufd; + __u32 iommufd_ioasid; + __u32 out_dev_id; +}; + +#define VHOST_VDPA_SET_IOMMU_FD \ + _IOW(VHOST_VIRTIO, 0x7F, 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, 0x82, 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 Fri Nov 3 17:16: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: 161378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1196197vqu; Fri, 3 Nov 2023 10:18:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOBF17nMCS45pdp/USpJxeYvvS8hXS5IIGMeJkTUc7UV/6xBa1WyY+IgEyEyDQx9uIvnS5 X-Received: by 2002:a05:6a20:258e:b0:159:c2d0:9fc6 with SMTP id k14-20020a056a20258e00b00159c2d09fc6mr26593711pzd.8.1699031920743; Fri, 03 Nov 2023 10:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031920; cv=none; d=google.com; s=arc-20160816; b=pK+vnVH0vL/1ycKRAiAu4Ymh8O3yhRgURHJH2AgPppyOPnWoZPca2ukwRnBojwFW/o j3nuzZ+/3l/0SOoYq+Wvm658/xnKBwW6+F05tF+jxCBF44FCTemrhqhKQ6hgBfp/I52Q xEa8HdKwYC50Rn59OTX2CXY5q0BAouCX7/7+d83oI+X4J0xL8hFwI8pBdBym2/z1QEk/ Eexky9/I4X57kH+Zka9od47H2WitSDVBRJu15ieULxmCDTMTrgbl760MsIK5q556gJyU 7B87qwY7oK925vJ2HSH9M3ueUfjgpmoR7Fj3I/Z0qQzW1UpLPG8H/xSnb9rR3xTLdjeu mFNg== 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 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 u11-20020a6540cb000000b00577f67a0614si1735990pgp.879.2023.11.03.10.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:18:40 -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=LgDInuxj; 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 5AAD6823527E; Fri, 3 Nov 2023 10:18:35 -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 S1345847AbjKCRSV (ORCPT + 35 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 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 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]); Fri, 03 Nov 2023 10:18:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564095723155593 X-GMAIL-MSGID: 1781564095723155593 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 From patchwork Fri Nov 3 17:16: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: 161379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1196352vqu; Fri, 3 Nov 2023 10:18:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFh4bTqeIymyWO+e5Saahy2Lnwk6iIEds1BzYa1FX6Z7L5K36oTxspaB5i/puf3KVAn5dSr X-Received: by 2002:a05:6a20:729e:b0:181:7d6d:c0fa with SMTP id o30-20020a056a20729e00b001817d6dc0famr7058410pzk.49.1699031933994; Fri, 03 Nov 2023 10:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031933; cv=none; d=google.com; s=arc-20160816; b=kGXSuE6G4iJjnCJ97QJNOZQJWRtPQ4BLbJhv8K2kDqqCS4mxKdBWHpk2y6lqo06LMB 8yLyu3bRsBBEs+erJSiXz4lV5T5BDifIekNGNJZqOjsE3qvgIeNZ/UrWeP9U5EMqzMYu 5n9I1NHUU8WxxH6kl7ltglM/Z4n5EQBg42rEe3yEUBxBOzcXAG/EzVO5JwpEloTtnivs k42PnmetQpvegqVmUMUHtU8LLf61wfUu2Ay5usjqkNPW8HMl51tz6vAlxKok7vhPsefg 1YlU4U+RAwn5/QcD4MV9YdPNz482+41Er4UYAHXEh2xVXjBe0sKwaJSpXW+/y6mzyPXY 4qWg== 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=qZcijrBkenJpJgKIh5nn77fb44ksEJ9Uwp/HPtluVaY=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=oeqerJJZ4icYPufTXI3lFQ3hKU/nO/aCQhLOG+TWWaoVAK515KsxDKphbt5QWdqdpJ vthkBSDD8MNrqIug8k1BFRiwY6tjItAzfrc5mrhGDPhORbAD6QwbBQIrfofYj4KnuDy7 L+v6knLwxxY77jMTe5IIEPKr1wogAKic+mAXA4CEGNDQyUm2GZK4o/DX4tsPvoh78o2K g+p5k6Qm+ZRbX+OP9gF0TpHORFBjwO6THplOMKhUk6pBNOxOzPaY9x5w0ocPojqPbktc /xWfuBWF/9mmm7x0pEFO1AKJKtINdE2CTZCg3076rWsGP5Y1kCRWbTSTd1h3BKUCTrDB LTCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FLhpaRJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id q1-20020a170902dac100b001bf0b29d935si1985250plx.34.2023.11.03.10.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:18:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FLhpaRJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 20552832F666; Fri, 3 Nov 2023 10:18:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377382AbjKCRS0 (ORCPT + 35 others); Fri, 3 Nov 2023 13:18:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377249AbjKCRSX (ORCPT ); Fri, 3 Nov 2023 13:18:23 -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 05517D48 for ; Fri, 3 Nov 2023 10:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031859; 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=qZcijrBkenJpJgKIh5nn77fb44ksEJ9Uwp/HPtluVaY=; b=FLhpaRJ43evcLk4oVC0416wghzrtz+4oiTFODPMtRG8iQfwyB7zPuQfxnyy6KYi+SSeWyI zbSz3P9jRVj1Iv5pMknBHfBdWwkudzpl1DDdNJW3zanzRTbPmCCLsgdrXVFORxp1v1Rl1P 4fuvJo33hpdky5V1MDBmAnLphGI+uhI= 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-396-WVF19FtuOU6EB2xsKppuQQ-1; Fri, 03 Nov 2023 13:17:34 -0400 X-MC-Unique: WVF19FtuOU6EB2xsKppuQQ-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 B31B6101389C; Fri, 3 Nov 2023 17:17:28 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A0CFC15983; Fri, 3 Nov 2023 17:17:25 +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 5/8] vdpa_sim :Add support for iommufd Date: Sat, 4 Nov 2023 01:16:38 +0800 Message-Id: <20231103171641.1703146-6-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 03 Nov 2023 10:18:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564109367901146 X-GMAIL-MSGID: 1781564109367901146 Add new vdpa_config_ops function 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 76d41058add9..9400ec32ec41 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -762,6 +762,10 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .bind_mm = vdpasim_bind_mm, .unbind_mm = vdpasim_unbind_mm, .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 = { @@ -799,6 +803,10 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .bind_mm = vdpasim_bind_mm, .unbind_mm = vdpasim_unbind_mm, .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 Fri Nov 3 17:16: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: 161380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1196583vqu; Fri, 3 Nov 2023 10:19:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnjiOdAg67XIc14DzETpcpxgOmWXY9xITz+kaGcv/NsfA2B9md0VEwDHX+V8KAkM2lbPXD X-Received: by 2002:a4a:eace:0:b0:586:b79f:b0ee with SMTP id s14-20020a4aeace000000b00586b79fb0eemr22221704ooh.5.1699031951350; Fri, 03 Nov 2023 10:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031951; cv=none; d=google.com; s=arc-20160816; b=VWMzDxvNUFQr+HIotJAFpbJ54IW4lJSHmcgI44NEx3lCsQ4WRghV59uN3Mfxn/mjAi Rl1OER6WX910/Pc0rVZoBcwWVpNGBiEZuCZ/CczUcFA6JDVUU273k3LFLAGupNqV7FTr WLnqOA+tb3SNj5VO9ZT1m1dMpDjCyY7H0CkqKt3EAS0Ea75WlXV+zIrFM02aNpds7z0Y 5fylsIS9B1AnDqdleeIoswX8vbUun810X/F+8f4UTPe2/PN/j18zvKB+Wzs9JVqdD1v8 7xDXtoUGX7gTIlkFOrWo7lAZBBN3AxULezj8FTU/GQn8jKJwZtRTu/gcgNXe0G/wle4H jeEw== 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=GpK/Y1O55XislOg5N5jgXt0h6vbPef/n6csAVM8Xygs=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=t+qkn10wmemYY4tA4felyBWGxuqAFVM6xRtFs9/Zo0+BV0H+nMAu459leH9qUgwJ46 /Xe0iac4J1wreBOKjoPRHAArKrht7ZoD+Qd+HX8fdeur1zHmg+TxWqy13F4kIdI+FyQH ys1NR7RsXJeAnxyv4EzPj1okMnHrJM3AzhbWvZhoJiFZFZyNesyy0/ricVysKQOtDgJ/ nqvGbcnZBpok7gnq2LmQjEfGHk3G590lyUc22k/C+d4Za5ssarA04Cc6bn6+Z04JcKKy ckrkLNUXz6RWUsvdXGmTGsYO4yjOL+c2yVsljht9jNs8RTuGImCEEKE8CNagEGiBx6C/ GKtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WW9A36V0; 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 u186-20020a6385c3000000b00578a56baebesi1713097pgd.674.2023.11.03.10.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:19:11 -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=WW9A36V0; 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 B5AFB8232B2B; Fri, 3 Nov 2023 10:19:08 -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 S1377621AbjKCRSi (ORCPT + 35 others); Fri, 3 Nov 2023 13:18:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234418AbjKCRSg (ORCPT ); Fri, 3 Nov 2023 13:18:36 -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 6E821D59 for ; Fri, 3 Nov 2023 10:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031863; 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=GpK/Y1O55XislOg5N5jgXt0h6vbPef/n6csAVM8Xygs=; b=WW9A36V0M78YifZLp9JBpTkKsQDrxnlkCKOLmT0jEwNLcXhltvXPwOBi1ImKk/5xN1R36A ZY66fjG57TFhb5YyXerufluLtBPUfNDt1uVdzri9auPhUL+r4Q09avfn4O/c483R3zROGe Ymgk68YZjrhVH0WhNyTactvLsm6cqFI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-44JTi4YMOiuZp0J0ge-3XA-1; Fri, 03 Nov 2023 13:17:37 -0400 X-MC-Unique: 44JTi4YMOiuZp0J0ge-3XA-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 775B33826D52; Fri, 3 Nov 2023 17:17:32 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54708C15983; Fri, 3 Nov 2023 17:17:29 +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 6/8] vdpa: change the map/unmap process to support iommufd Date: Sat, 4 Nov 2023 01:16:39 +0800 Message-Id: <20231103171641.1703146-7-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 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 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]); Fri, 03 Nov 2023 10:19:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564127083306187 X-GMAIL-MSGID: 1781564127083306187 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 | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index dfaddd833364..0e2dba59e1ce 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -1067,9 +1067,6 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, /* Legacy iommu domain pathway without IOMMUFD */ r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm), GFP_KERNEL); - } else { - r = iommu_map(v->domain, iova, pa, size, - perm_to_iommu_flags(perm), GFP_KERNEL); } if (r) { vhost_iotlb_del_range(iotlb, iova, iova + size - 1); @@ -1095,8 +1092,10 @@ 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); } - } static int vhost_vdpa_va_map(struct vhost_vdpa *v, @@ -1149,7 +1148,36 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v, return ret; } +#if 0 +int vhost_pin_pages(struct vdpa_device *device, dma_addr_t iova, int npage, + int prot, struct page **pages) +{ + if (!pages || !npage) + return -EINVAL; + //if (!device->config->dma_unmap) + //return -EINVAL; + + if (0) { //device->iommufd_access) { + int ret; + + if (iova > ULONG_MAX) + return -EINVAL; + ret = iommufd_access_pin_pages( + device->iommufd_access, iova, npage * PAGE_SIZE, pages, + (prot & IOMMU_WRITE) ? IOMMUFD_ACCESS_RW_WRITE : 0); + if (ret) { + + return ret; + } + + return npage; + } else { + return pin_user_pages(iova, npage, prot, pages); + } + return -EINVAL; +} +#endif static int vhost_vdpa_pa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, u64 iova, u64 size, u64 uaddr, u32 perm) @@ -1418,9 +1446,13 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v) struct device *dma_dev = vdpa_get_dma_dev(vdpa); if (v->domain) { - iommu_detach_device(v->domain, dma_dev); + if (!vdpa->iommufd_ictx) { + iommu_detach_device(v->domain, dma_dev); + } iommu_domain_free(v->domain); } + if (vdpa->iommufd_ictx) + vdpa_iommufd_unbind(vdpa); v->domain = NULL; } @@ -1645,6 +1677,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 Fri Nov 3 17:16: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: 161381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1196646vqu; Fri, 3 Nov 2023 10:19:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGU6odx2IYvm1Br7V1mPIP0oZjOTNsT4yRrjRYGHM41l1OY6ScMfgm0x0NzfmD3Fvj5XrI7 X-Received: by 2002:a05:6a20:8f07:b0:181:6f00:2f73 with SMTP id b7-20020a056a208f0700b001816f002f73mr8769434pzk.3.1699031956501; Fri, 03 Nov 2023 10:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031956; cv=none; d=google.com; s=arc-20160816; b=xkINlxX43IPg9fAm6g4Kjzvt8l/MqMJGQxgemaRKgQzBNqEEUn5fUKyzVP7ewHjSyi DZGNB/+f9ie0sBtV8gfPaTtcUFU2ZL/C/WqPPD/5F5nT/wSFJC2fN792KUE2coWk5Z5C DyxjQkPDOcPqOk4y7JENgEHJe2I2qogSMPPO7mJSkICVOVO9sMsg5HAM0qOPPQyebWoH +0vNN9Jo/OwpcTQFAFsicWHgIuMCpxgDPzyXdN/4zBYbdmnbjZPr82PDV9QNr7QsRwdD OmYeoi8nSpta7+mX925qbJFwEmFYACtRTWmmnxPNPPJdQIaLrc89sAQGfxxj4YlZkSq0 XEBA== 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=ZVS2kk0D6Tt1PgwcrwV42T54QxmIjT+wF7r94StjHU4=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=uK1zaIvdMX2CYxfzo65Cf3u78O3zT9h3UGCq8cB7Q/fVYIVHJsq4NUx4xuC0IIh6zR 8PvBZIKZDb0qEYNZ0+rAe1GC1l8E0NYbgm7qezZOqnkEA9b5Ra2ETmNcnT4iamK7K4rq hQXJoAxDMKrrWf0RPVSRIbBm7LKhDikyQWLri1onDy5EJvq9A4ZF0m0utMkfUuJsbAhY jGutP7gYedVwOpxRrxyb7ZrJ3L2HW/m1kvY/YP7WEFlXflFB5ggUoaWkju9JnKILaIFm Dxsol861m5dpobOq+0OHwRsO09z5du/jSUkcbQh3Axmot050IHwHCGMVswsdEQDEtetx jXQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HYpS2zJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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. [23.128.96.38]) by mx.google.com with ESMTPS id cp5-20020a056a00348500b006be322191desi1864429pfb.112.2023.11.03.10.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:19:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HYpS2zJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 3452681BDB9C; Fri, 3 Nov 2023 10:19:14 -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 S1377719AbjKCRSk (ORCPT + 35 others); Fri, 3 Nov 2023 13:18:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234408AbjKCRSg (ORCPT ); Fri, 3 Nov 2023 13:18:36 -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 147BA1BD for ; Fri, 3 Nov 2023 10:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031862; 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=ZVS2kk0D6Tt1PgwcrwV42T54QxmIjT+wF7r94StjHU4=; b=HYpS2zJgWieuA97Fnr0ELmzm+Tb4O+/uvGMRB46qYiZ958QhhXCsaaFxGKuTu3U93yDyDb S5HO4YsvvAtnYh0NOzYv89DLrf4uFyV29eALnFpvAWxvZePNyoKtUMesYhnqOyMHbbfktC V0XcLO4nZcfeIyZLzIqqGk5ougg1NXk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-lM2HJKEnOZCxb--cVZ2jKw-1; Fri, 03 Nov 2023 13:17:40 -0400 X-MC-Unique: lM2HJKEnOZCxb--cVZ2jKw-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 3EFB8282478F; Fri, 3 Nov 2023 17:17:36 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A404C1290F; Fri, 3 Nov 2023 17:17:32 +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 7/8] vp_vdpa::Add support for iommufd Date: Sat, 4 Nov 2023 01:16:40 +0800 Message-Id: <20231103171641.1703146-8-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 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:19:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564132998224777 X-GMAIL-MSGID: 1781564132998224777 Add new vdpa_config_ops function to support iommufd Signed-off-by: Cindy Lu --- drivers/vdpa/virtio_pci/vp_vdpa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c index 281287fae89f..dd2c372d36a6 100644 --- a/drivers/vdpa/virtio_pci/vp_vdpa.c +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c @@ -460,6 +460,10 @@ static const struct vdpa_config_ops vp_vdpa_ops = { .set_config = vp_vdpa_set_config, .set_config_cb = vp_vdpa_set_config_cb, .get_vq_irq = vp_vdpa_get_vq_irq, + .bind_iommufd = vdpa_iommufd_physical_bind, + .unbind_iommufd = vdpa_iommufd_physical_unbind, + .attach_ioas = vdpa_iommufd_physical_attach_ioas, + .detach_ioas = vdpa_iommufd_physical_detach_ioas, }; static void vp_vdpa_free_irq_vectors(void *data) From patchwork Fri Nov 3 17:16:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 161382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1196690vqu; Fri, 3 Nov 2023 10:19:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxBbDi7nizCXCCHL+J7GBUk16lOPK+SHd2iaR4k6o9S8r/tvEYi6eFRgbyTasppFzaR/0e X-Received: by 2002:a17:90a:31c6:b0:27d:2601:bc92 with SMTP id j6-20020a17090a31c600b0027d2601bc92mr4363776pjf.11.1699031960751; Fri, 03 Nov 2023 10:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699031960; cv=none; d=google.com; s=arc-20160816; b=u918ZtMZWCt5cpE+hTWjN7Phi85N1rg+07Ikj4e5ntDtP9WQnZF6I38RFln0C3A3B3 gpVPWZthPYyRyxwGACdmIwQjSLY16ytq7tZhntiBCq/ar4QUoPDHZDCJzCZQRSa9vM2c 3upRr10UFo+9POEkI9aA3Yr7GriFTBJK6dlJAcfW/NKe7KFD0mlFa/ANEbepCj44evWj 1+zFX9MgUligWoJPvKUWyJ7eRHwqlFLAW0YzCboj6iUifv4xOiAt4dWWUg2bViNdRsVQ BHvKhUNGvVfBrXumKEOE5ugtoKWKXlx+CR7gwVo3KdkSBULtvUwDK3Pk57Qi6vDaCr1y 7RRg== 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=aCTB8Gg9xttEfEVtECz9fqwzez2GQHqNSW6hXp3Vsbk=; fh=xiBZnYthZkU72K3VlivZH8ewgfrUkWRaBxXhAGtxMAw=; b=zTNNiWtudFTrLTM4zhlXzlgz+kxVxp12Y+2yzi9zZ7V2HapRH9kR42QM6cmAzSN4RZ ILp85ixfBf/ysnu/klobHWoacakIFMlwTarc1MOOqdzNCIgXnoMryCccAatzAK+ZSnA1 8GbYFyD/78786bNTO4uB1vLQupFJoO+d1rNMtWNIhqtYZawj2lJOTtA4Sl59PRT0etBt 54fZbiNytaDUCSV2kwUtzOA+tZFO4wC4l7F2yxzx3iJkvYLAyjiD+eJ1JoAkSuXssyRp /tjtaBAvsX6ivnL05D8wv+HJqiD54Dy5OZbUln2SSnn8UqrqkSrEDNIzYcbl3jxdnz1I b5uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CncPKdss; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x2-20020a170902e04200b001c724f997ffsi1810849plx.131.2023.11.03.10.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CncPKdss; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id BBBD6832F661; Fri, 3 Nov 2023 10:19:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbjKCRTB (ORCPT + 35 others); Fri, 3 Nov 2023 13:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230202AbjKCRS7 (ORCPT ); Fri, 3 Nov 2023 13:18:59 -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 17BF810C4 for ; Fri, 3 Nov 2023 10:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699031885; 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=aCTB8Gg9xttEfEVtECz9fqwzez2GQHqNSW6hXp3Vsbk=; b=CncPKdsswMVl/lCkDzCSPz8NMM0ddK5mJGhnm6h4Ifs22e2h5RJCxw2EIu3CVAYrcaWIbC YZmIhr+aZYjuOZPeQjvz5Nyt74dqlugLRp+l2FHdAem9zxhynEnHqY0GbnmOhSOIXu9/XT qEhsJkkRjrD1U134h9n0HlGbj1z0w+o= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-HmhpnDUUNMKaWArsODPEXQ-1; Fri, 03 Nov 2023 13:18:02 -0400 X-MC-Unique: HmhpnDUUNMKaWArsODPEXQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 902D33C16DDC; Fri, 3 Nov 2023 17:18:01 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63D381121309; Fri, 3 Nov 2023 17:17:58 +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 8/8] iommu: expose the function iommu_device_use_default_domain Date: Sat, 4 Nov 2023 01:16:41 +0800 Message-Id: <20231103171641.1703146-9-lulu@redhat.com> In-Reply-To: <20231103171641.1703146-1-lulu@redhat.com> References: <20231103171641.1703146-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 03 Nov 2023 10:19:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781564137522250886 X-GMAIL-MSGID: 1781564137522250886 Expose the function iommu_device_use_default_domain() and iommu_device_unuse_default_domain(), While vdpa bind the iommufd device and detach the iommu device, vdpa need to call the function iommu_device_unuse_default_domain() to release the owner Signed-off-by: Cindy Lu --- drivers/iommu/iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 3bfc56df4f78..987cbf8c9a87 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3164,6 +3164,7 @@ int iommu_device_use_default_domain(struct device *dev) return ret; } +EXPORT_SYMBOL_GPL(iommu_device_use_default_domain); /** * iommu_device_unuse_default_domain() - Device driver stops handling device @@ -3187,6 +3188,7 @@ void iommu_device_unuse_default_domain(struct device *dev) mutex_unlock(&group->mutex); iommu_group_put(group); } +EXPORT_SYMBOL_GPL(iommu_device_unuse_default_domain); static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) {