From patchwork Thu May 11 14:38:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 92673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4432570vqo; Thu, 11 May 2023 07:49:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4D+/IGZ/6L+vzM8oruuDGo6E3LBFGeFVAZZTbMBw6H7DZL4BwyEfM1JKOvfpYO0kT2Gjan X-Received: by 2002:a05:6a20:244b:b0:100:a9e3:17d4 with SMTP id t11-20020a056a20244b00b00100a9e317d4mr16720690pzc.0.1683816559216; Thu, 11 May 2023 07:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683816559; cv=none; d=google.com; s=arc-20160816; b=WN37Ivlz24A7uN/Nd9QPn2AOeFjIvF0OIOx44lwi0PQqZmgFFhI+3awKXmiSVRQ1jl LxWM7KL2RsTpT3tScoYTWbzpB2nCc+eWq8KadhwhvAOPr0XeVLfLcvfUa2SIXTXKAlLY g9heWFnJzED/YIokAYMSVtzXfvA2BWqER9NjAEMZvoYbAz7tEpQlvMfTqT84Qi1akDTE ulJm8OkihXqq55WT+Gkhq3X7mUBpdALIh1/vQ7DHeSjSELK4RMCGWyUqgH1GpuQAfnf8 /NvHF4R1HpJtUrVOHJ1tNTnYKZgFbuQImJHdKN1YEVH2Y+TuGpy3BYUoXGxV5y4OFzmg Uk2A== 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=q8E4cDEhhSVLcv0LSCwH5BbGOQLSh/RH0HVSlYbKW6Y=; b=f1SyIYrz789+yaRjkMWDVVxgSgsJGG/cDRH8+FXxaqDeKdXmCq8YS/zF0mr3bgyUDx mbfwPEtV1azbH6qr4C7Lw+ey5flrb/7EDRczzGsF0XQRQCIepC9jgcYJxlv+iaXnTLlB I2SAatOGZ/cFl+tW6PsURoVSNBPmwwwCjPNxuGjk0PMVoorHF14MzhAw5s4vjosJCTCA tA+mcP2XE3fOOZs+cgA3tu6aVJH949AWF/XvoxsWDlQ5dfKhC05YmUhGRh1Rr2iEsQco Cs2B3+GjFYyVXciYLUHZvT//i2VGwOGHavwRWCJtwHUlYY2qo0NlqTZvf/3hZvR9/rOh 92yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CTZEYr00; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k8-20020a637b48000000b0050300a5cf3csi6965950pgn.469.2023.05.11.07.49.05; Thu, 11 May 2023 07:49:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CTZEYr00; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238204AbjEKOnk (ORCPT + 99 others); Thu, 11 May 2023 10:43:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238575AbjEKOmb (ORCPT ); Thu, 11 May 2023 10:42:31 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C8E2124A4; Thu, 11 May 2023 07:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683815931; x=1715351931; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ke4Q2tfTPA1F8lkmM3qM3tQXa//6Jv+EtDRXACRgOKk=; b=CTZEYr00d3JJ1FzJh8Zs3tzAA5yUhl3XN6/a2tEjk1gjfISzDCw9LChP gpcjNNo+3GcQ4omZvLZjFxxhmpzpHEXLiF5PCKRS95tNQcPh+iORDeZh2 m80jAMtv1W+n6gkwMpoeT17FJZ9BNIM5nYc+NUihkYsqE6UYNz2b17UMA boZjnTtzsNZz3gV9p0M0jMFBYvXny/I6jUQzrxrxvAOB0xQRDECmeqcDO bmjmb7FmYU1CIdDjkkvAwHru1yoMjd5Y3LFf3o88YWaJH51D1bWyFsg8V yXw1z8XlyAosEpHCmBwzie0iTjiSJUiq2rz1O2Y/AVaBonoPMG2hU2otT g==; X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="339812903" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="339812903" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 07:38:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="730382619" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="730382619" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga008.jf.intel.com with ESMTP; 11 May 2023 07:38:49 -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 Subject: [PATCH v2 05/11] iommufd/hw_pagetable: Do not populate user-managed hw_pagetables Date: Thu, 11 May 2023 07:38:38 -0700 Message-Id: <20230511143844.22693-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511143844.22693-1-yi.l.liu@intel.com> References: <20230511143844.22693-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765609632503834335?= X-GMAIL-MSGID: =?utf-8?q?1765609632503834335?= From: Nicolin Chen A user-managed hw_pagetable does not need to get populated, since it is managed by a guest OS. Move the iopt_table_add_domain and list_add_tail calls into a helper, where the hwpt pointer will be redirected to its hwpt->parent if it's available. Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/iommufd/hw_pagetable.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index ec9b140939ce..73d7d9d07726 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -58,6 +58,24 @@ int iommufd_hw_pagetable_enforce_cc(struct iommufd_hw_pagetable *hwpt) return 0; } +static int iommufd_hw_pagetable_link_ioas(struct iommufd_hw_pagetable *hwpt) +{ + int rc; + + /* + * Only a parent hwpt needs to be linked to the IOAS. And a hwpt->parent + * must be linked to the IOAS already, when it's being allocated. + */ + if (hwpt->parent) + return 0; + + rc = iopt_table_add_domain(&hwpt->ioas->iopt, hwpt->domain); + if (rc) + return rc; + list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); + return 0; +} + /** * iommufd_hw_pagetable_alloc() - Get an iommu_domain for a device * @ictx: iommufd context @@ -151,10 +169,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, goto out_abort; } - rc = iopt_table_add_domain(&hwpt->ioas->iopt, hwpt->domain); + rc = iommufd_hw_pagetable_link_ioas(hwpt); if (rc) goto out_detach; - list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); return hwpt; out_detach: