Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp611771rdb; Tue, 19 Sep 2023 05:32:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqVXbdrsBs/n73tbwsGmF0p05unc2KCKaaj4b6aCL8CU2u+YD7vG3TPui8VmHkuHL/yI3c X-Received: by 2002:a17:903:41c5:b0:1be:f45c:bc38 with SMTP id u5-20020a17090341c500b001bef45cbc38mr15173274ple.2.1695126756657; Tue, 19 Sep 2023 05:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695126756; cv=none; d=google.com; s=arc-20160816; b=OoewyUqB8K4an5cCsIMngjKICMbZ4e9vln8Ah9K1kiUz1F8xZ/eHfUVNYZ1Ptf0OOS wsaZdqPrE8nIUnGFS8EM4xihFknlDWcW/3Qm/2iEabZEs/f88rGWqlm1vCpzel3ReW4g qa2aCPcaPBZQdg/3hrIbCZ3XaOa7y2xtv2KcjaBFJqh0gYNsk5M6cExA+C02XlZVTbM7 GX48cUPGRy6j5LKfJt42EQLz5M3SZNfNMkB2TEkBFeyXLNQaJb/93tdx6cnANjcUJ1qb GkJ4lBaituMbYuGafORBbJkEHyRyp9kPxhBdI39ZWO+zodQwbFI+wLD+X9rx5qdB2QRG 9kmg== 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=5k8vQcR9Y700jDibsL6fBlemuEInlV0ExgbA4ifN46M=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=mmvqRE3FRXDJl+iVqgEHb0i6t8nAJLu9duyozE6nch3oxjQ7VofEGfLZryYuP7IY8R M6CHxn5xcxq3cWEuz87BJqbIHy/gkTJCVfSfD4LYYR7DJerQjQSAke2rUGYWfpnDNAD6 dpPizPNCdQjtzQ20trLz3UmNqYFbT09IsEbcDzCNLO3l7S0csM1SrkNABEh0CL8HbaWv zsevv4jmxePC8TpIdY/Aa+YEDp1VzkXIv0BquALkBZiDF16QWyttW/xYiOTSvUD0k6kQ l1pEiPrvBzGjr0yzPwYghTlQUgt8w2s9aNeBg9s47cu/WNGI6AyqeUuuh8xp+F9R/nbA 7r6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cEJ5ZlqR; 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=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id i12-20020a170902c94c00b001bdb799f0fcsi9920117pla.609.2023.09.19.05.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 05:32:36 -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=@intel.com header.s=Intel header.b=cEJ5ZlqR; 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=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1488D8096A48; Tue, 19 Sep 2023 02:26:16 -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 S231334AbjISJ0N (ORCPT + 99 others); Tue, 19 Sep 2023 05:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbjISJ0J (ORCPT ); Tue, 19 Sep 2023 05:26:09 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7325612E; Tue, 19 Sep 2023 02:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695115559; x=1726651559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2u453SswpKakc0NOsEhGqMN9HDyZwW3XZ2U2N48J7YQ=; b=cEJ5ZlqRGQodnm+BbID6byANhSAcQS0D/pdTLSCsmafieJX3UnXg/Lh1 3/Awx24gTmqkRMF1nSsvUUKM0v7r75Ev/Wbz0DrTYIDUVmPmR5vPFgX/i 9AST63r2Kk6jz7/VWCDR9lH0r01wjAqjLLfKdwveMNcTUdb2j20YtMj9t IGqP1Epkys4WmqWgBme9FekHltzrLoaeCa1I2RXYVNjZ5tqLuOJCgN8/W 3JPL8tNXiLntg1+JLmJOUKdYcq/h/S2oPdTIVQ/DTeSi8rQxgbu4A3nZ8 iYrxhtb8BulAT9NpxXW0cuYeKKY8RR8HmMBVBiQ9AfU3G+ptrFn0tMp3I A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446368918" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="446368918" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 02:25:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="722804768" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="722804768" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 19 Sep 2023 02:25:26 -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: [PATCH 2/6] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Date: Tue, 19 Sep 2023 02:25:19 -0700 Message-Id: <20230919092523.39286-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919092523.39286-1-yi.l.liu@intel.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 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 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]); Tue, 19 Sep 2023 02:26:16 -0700 (PDT) This makes IOMMUFD to use iommu_domain_alloc_user() for iommu_domain creation as IOMMUFD needs to support iommu_domain allocation with parameters from userspace in nested support. If the iommu driver doesn't provide domain_alloc_user callback then IOMMUFD falls back to use iommu_domain_alloc(). Suggested-by: Jason Gunthorpe Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/iommufd/hw_pagetable.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index cf2c1504e20d..48874f896521 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -5,6 +5,7 @@ #include #include +#include "../iommu-priv.h" #include "iommufd_private.h" void iommufd_hw_pagetable_destroy(struct iommufd_object *obj) @@ -74,6 +75,7 @@ struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, struct iommufd_device *idev, bool immediate_attach) { + const struct iommu_ops *ops = dev_iommu_ops(idev->dev); struct iommufd_hw_pagetable *hwpt; int rc; @@ -88,10 +90,19 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, refcount_inc(&ioas->obj.users); hwpt->ioas = ioas; - hwpt->domain = iommu_domain_alloc(idev->dev->bus); - if (!hwpt->domain) { - rc = -ENOMEM; - goto out_abort; + if (ops->domain_alloc_user) { + hwpt->domain = ops->domain_alloc_user(idev->dev, 0); + if (IS_ERR(hwpt->domain)) { + rc = PTR_ERR(hwpt->domain); + hwpt->domain = NULL; + goto out_abort; + } + } else { + hwpt->domain = iommu_domain_alloc(idev->dev->bus); + if (!hwpt->domain) { + rc = -ENOMEM; + goto out_abort; + } } /* -- 2.34.1