From patchwork Mon Jul 24 11:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 124835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1726147vqg; Mon, 24 Jul 2023 04:17:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGNeLfF4PaYKWTBrra7U1zf2+DHZu2Ha9Hw/ktZhvbnkQpghbwyls/i7eqUVdUMWkDsWjGY X-Received: by 2002:a17:90a:e650:b0:267:f1e1:5a51 with SMTP id ep16-20020a17090ae65000b00267f1e15a51mr3382028pjb.35.1690197447287; Mon, 24 Jul 2023 04:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690197447; cv=none; d=google.com; s=arc-20160816; b=yiec+ttq7dXWO3FFMW9/gRyFzawCkrkAm356h9drTwbLAXz/voXQ9OUUn/PM1pXvRt CxzfANP00I629c5O8iodM2654h9OzKcm7S8wZnJYELvYZWdfF1wvkrJg9j3WaUjoNMGv el7gAJS6I3vXd4KAPkUQv+7jaxPrQ2L2eJ2tBqLdJyK73JCLH6dnLOsNJRRZ5PKTX1FY acPIwZfNYYj6MafrGjf2EwFsrMK0F8lEL5NGObxeT+TbCgZZ9bWqucyRKfXKxNtiDc08 sWEGd68nZBzOKOYiEgtQAJ7FkXCe8rVjvgUnuitb2ZtWkfR3HirWXA5B3mL/fX3k03Wl go1A== 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=pAY0iXm5oUSja5dcUyz1xLXXrnv9wkB5uArqdJgoy+E=; fh=25kVo4cotgMzE250R6E3K5ES7E7C2JawiavlW0h5mKU=; b=rcx/JvopkoDtDBBWBLuFXKAuSmOEwgEpncDUXba3xI2VobvZR3ppY72SA/iuxD8f6V TQ9QfDZJ1BxukCAeCzs1eKj91zc9sDUo9x6TKam4NUH5u4GWHLrzniasDppFZVmB8Yg6 M3zGcGcXUeDNhNiuQrh+FUtYVycd8u8vHNSdS2rz75MxfTgOMhxvvoU6YiZDmOAmkU4S Rd1lEWRakybj1NkmoDbFUkdCD7X/SPUx1agQmCLTiVMPGYYxd67gN5YZIJteofjhNf7E pZ11eP4N7yTq2H9EoF7MXZ6Useo/W0/EHygty/uxwuCbUaKulknZyHTu7CWY4rBnvu9V lfbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eLI1z2pP; 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 n4-20020a17090a5a8400b0025bdfe1bc66si11351751pji.165.2023.07.24.04.17.13; Mon, 24 Jul 2023 04:17:27 -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=eLI1z2pP; 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 S231807AbjGXLEa (ORCPT + 99 others); Mon, 24 Jul 2023 07:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233385AbjGXLEZ (ORCPT ); Mon, 24 Jul 2023 07:04:25 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB9A81B3; Mon, 24 Jul 2023 04:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690196656; x=1721732656; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n7hWgi3n+9uv44qqUfgpCeLTeQHcAqVitGGJSoCyeqw=; b=eLI1z2pPDzHmZJjBw5mrnUNjsiKCYoXh9S9f31CeY4PhtRCzKT+yumBL ZyLe3tPuSz3E6Jd31RjOJZ+ZCd3tsNnYEvKr27LXN4CbUrb/CMF2ZLnw2 N3bUOeNj2FLMSaVW4MZt2+oGkNhBfK0Gf9OC+xqE4t2xJjgB0Z2SpbDmN 7l+qTO50WWn/r5KBYJvO+ItnAhkGjaYMh988bQOKVIGgKA9/hyYSySr9P WrrzxBjQxsWj864bbcmpAnNFplEMEyjYjLvHXkPp9iXIXY0506OawQgIL LUH9MPPHNfaIBxQDWzg9/s6A8k440rFmTVSo01TCkOB/wEy3oPvYh/fOi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="347013278" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="347013278" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 04:04:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="815775792" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="815775792" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jul 2023 04:04:15 -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 v3 05/17] iommufd/hw_pagetable: Do not populate user-managed hw_pagetables Date: Mon, 24 Jul 2023 04:03:54 -0700 Message-Id: <20230724110406.107212-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724110406.107212-1-yi.l.liu@intel.com> References: <20230724110406.107212-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, SPF_HELO_PASS,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: INBOX X-GMAIL-THRID: 1772300478780404075 X-GMAIL-MSGID: 1772300478780404075 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 Reviewed-by: Kevin Tian --- 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 28122a49b529..c7301cf0e85a 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 @@ -160,10 +178,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: