From patchwork Mon Oct 9 08:51:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 149879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1730629vqo; Mon, 9 Oct 2023 01:52:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxfMpsvJKGUDr4mu4RzDDzK9N/hlWtyVBibh6RmujpjivHWM0E00B4Jvsmx+Q4ijj/thux X-Received: by 2002:a05:6870:b294:b0:1b0:43b6:e13b with SMTP id c20-20020a056870b29400b001b043b6e13bmr17691395oao.54.1696841539931; Mon, 09 Oct 2023 01:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696841539; cv=none; d=google.com; s=arc-20160816; b=Ffkv/s9QMmFcqMAeMI1dC9Mg4wU9WmDeImajDFXM/0lQih3+2+TaGkSxn7uNwqcPEa kd7QAU22r1iSGCHVM2LWIaHW6kmc3pUfQa12NfdukGG/C9KneVzPOeiIfl+g+Rb4HZMO v4RTWrjpK44uV0FKYfjM++Q4T9gadJIhC3OqxLKRYLuB4OpHmAxIbBAiWsHgaEh3BSYO UGE0yAWgSURHzqGdqFHVCokkWeUm4b64S8G2Rgzr/Y3wKL+tcHIab0bElR3FXZiiaDGd Ln43MPy0Q+C/0Rg8X8o6w7IuhqIMINgI8Cn+3RtBoV6rimvmcluCC3D2FDN4xxnEoGln baBw== 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:cc:to:from :dkim-signature; bh=r5OLSp6aon4Z7sTwjp70I2jiqGVe7o7ZFvKyAip93B8=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=VR4yBL/GuYfHZGpToUqn+Wn+eXwJy0NqZNFB9KrR5jvW0V9TUn/HwXIzNTFdZivNNE haLFjAr1QQZ+1mdd5Wo4FN+jDT+7LqJFAHS9zbVvZgOPwN+gTs59qMnLyuvvTNmm/QLf azLrDlm90OHk1m8fkGfakdBybNy20d0Bqwzv9Nf6B0Z+1lO8Ek6efAY+qUi/YiJ5AyZJ CdNEFwLmcEk/MO51tcGQ5huTobvSGZ4a/S4W3VVbml20O8JsfUQmPbrpos+PJstdFP1p Ezu+V6n6uDauJHk7Ko6shViLK6ozacImLnAfVhBQrM9kwKuCm51gdeNEeBr3kPvXaJcb XSyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X06F2lsQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id d5-20020a056a00244500b0068fce0c7193si7077124pfj.282.2023.10.09.01.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:52:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X06F2lsQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8A1AC809E228; Mon, 9 Oct 2023 01:52:15 -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 S1345631AbjJIIwE (ORCPT + 18 others); Mon, 9 Oct 2023 04:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345587AbjJIIvg (ORCPT ); Mon, 9 Oct 2023 04:51:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F235410F; Mon, 9 Oct 2023 01:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696841495; x=1728377495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5oSl+8ABY4vMSX9OU2YlTePC4xhTypHD8FVbeS8l5Dc=; b=X06F2lsQCmdC4Ka44hq+k5KesMR3Q+SUElVwwZRwKpivOAa121mKChHK qHSByYnis09eXYObQRt5s/2+RmU71ed/7SQWqGFwxCSOzNs3aKqx373tv QZPk2TSkQ19ChGQb9ASCh/5PspfMAQH3VQxLWH7e/IVYUBNy0UvH5hwi+ 4XDulU3/JeENyI7CxLOCoJPyYgsJp9a90wVKFNJrdv1Vns5q3jaAWpCV5 5DiSpqnm65gPIK6aJMf00ggiHPyLUWXS6ILm50V+KuaYHwJRUXdwx9gso TSGYqsQQidwF8vRD8q1O9u5wiZH96ro4oRAs6Yn7l/vsGPBYytGf9cwyo w==; X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="364390811" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="364390811" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 01:51:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="818781686" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="818781686" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 09 Oct 2023 01:51:33 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [RFC 4/7] iommufd: Support attach/replace for SIOV virtual device {dev, pasid} Date: Mon, 9 Oct 2023 01:51:20 -0700 Message-Id: <20231009085123.463179-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231009085123.463179-1-yi.l.liu@intel.com> References: <20231009085123.463179-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 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]); Mon, 09 Oct 2023 01:52:15 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779267314596994155 X-GMAIL-MSGID: 1779267314596994155 From: Kevin Tian SIOV devices allows driver to tag different PASIDs for the virtual devices within it. Such driver should call iommufd_device_bind_pasid() to connect the pasid of the device to iommufd, and then driver is able to attach the virtual device to IOAS/HWPT with the iommufd_device_attach() API. Unlike physical devices, for SIOV virtual devices, iommufd_device_attach() eventually uses the idev->default_pasid when the virtual device is attached to an IOAS/HWPT. Also, there is no need to do immediate_attach per iommu domain allocation in the attach/replace path if any iommu domain allocation happens since the attach/replace is eventually pasid attach/replace. Signed-off-by: Kevin Tian Signed-off-by: Yi Liu --- drivers/iommu/iommufd/device.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 35c1419ee96b..4882e3106b2e 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -841,7 +841,11 @@ int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id) .pasid = IOMMU_PASID_INVALID }; - rc = iommufd_device_change_pt(idev, pt_id, &data); + if (idev->igroup) + rc = iommufd_device_change_pt(idev, pt_id, &data); + else + /* SIOV device follows generic pasid attach flow */ + rc = iommufd_device_pasid_attach(idev, idev->default_pasid, pt_id); if (rc) return rc; @@ -876,7 +880,12 @@ int iommufd_device_replace(struct iommufd_device *idev, u32 *pt_id) .pasid = IOMMU_PASID_INVALID }; - return iommufd_device_change_pt(idev, pt_id, &data); + if (idev->igroup) { + return iommufd_device_change_pt(idev, pt_id, &data); + } else { + /* SIOV device follows generic pasid replace flow */ + return iommufd_device_pasid_replace(idev, idev->default_pasid, pt_id); + } } EXPORT_SYMBOL_NS_GPL(iommufd_device_replace, IOMMUFD); @@ -891,8 +900,12 @@ void iommufd_device_detach(struct iommufd_device *idev) { struct iommufd_hw_pagetable *hwpt; - hwpt = iommufd_hw_pagetable_detach(idev); - iommufd_hw_pagetable_put(idev->ictx, hwpt); + if (idev->igroup) { + hwpt = iommufd_hw_pagetable_detach(idev); + iommufd_hw_pagetable_put(idev->ictx, hwpt); + } else { + iommufd_device_pasid_detach(idev, idev->default_pasid); + } refcount_dec(&idev->obj.users); } EXPORT_SYMBOL_NS_GPL(iommufd_device_detach, IOMMUFD);