From patchwork Thu Feb 9 04:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 54717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp122957wrn; Wed, 8 Feb 2023 20:35:55 -0800 (PST) X-Google-Smtp-Source: AK7set8wATIV4RlxD5FunzrAyAh8Y3BOXvvgNXZXJ2CUIOzlV2oRI57/7ntrlMzrHOh8eeuv84Kf X-Received: by 2002:a62:1b8a:0:b0:592:fc9f:8ae5 with SMTP id b132-20020a621b8a000000b00592fc9f8ae5mr8899401pfb.23.1675917354747; Wed, 08 Feb 2023 20:35:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675917354; cv=none; d=google.com; s=arc-20160816; b=A+Ugfl74xd90Fu5t1dGA2JV8RbbzI9LTU29VNWRu461twAe+9Y/+uU0EeswmqTxKbv s8UAZUsm4IPvw5BQsoZ8m8BgU4KF69/rM2JJciE39OdqMQRIv3P03POBIDd3yWAOxKX+ ygidthnIQYe8WYRcM+f7mVBl9nr+u5mmUsWOU5aSVpT7cTRoFk+7qRul+rVo2iBbQlgB +S1SsavQOa4f5qTqON7H6gC1wS+p835X5/yDJ4hHVBqLpDTgn4N5NLuK3IHlFI4YNpBq oZaEKtIvUi6zEgR3FYRcs3d70wy9xufjhsNZ1DLokIy5mMJvlJKq/JMx44BdrvjLY+xk hgXQ== 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=smO5V9LAFQ7ja89jzY9g4h3VPl2ZBc8crPz5rVtwUqA=; b=i1dBG+F3ea6b/K0n7CnD/iJ0kzVYoETCtCun+2J/yna7XPDoBxGYPEkhbalFU9eTc7 bU1Xx1rRLuknXfV2a8mmDgapBV16gv7HTStdCBqw6W8Hk1FnflDLMHmlRa4HJ+XiTL8Z O0qAp1WQoScFDL+MRMeDoaDQ+RrttUtdmA78KwQr6ODxRAMhrLkNJj6ecfnkporWCsx/ s1qn3Jhp8LkpqlL8BsQ26eTVkoOaZS9BZTYBIPJJ8CEyZaovwTuQ1AjIybjH3RjvjGJc xo47AQVOvqllDgoFSDmIuatPfBZoqi0YhEv/St/beHcpef9UyX3rs4kedYlpjWDl4pHv eG1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NHzfZHWV; 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 w14-20020aa79a0e000000b0059becf3743bsi775029pfj.35.2023.02.08.20.35.41; Wed, 08 Feb 2023 20:35:54 -0800 (PST) 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=NHzfZHWV; 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 S230383AbjBIEfQ (ORCPT + 99 others); Wed, 8 Feb 2023 23:35:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbjBIEdw (ORCPT ); Wed, 8 Feb 2023 23:33:52 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37E8147438; Wed, 8 Feb 2023 20:32:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675917169; x=1707453169; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ja+t+nxs1FvQ3VSNmIfqBCGaB8PSH4Fy0AP9hils4l4=; b=NHzfZHWVM9kKCABvKlMZx/1IvJMsit2/8FoAUzH0lwRIZuEAz5zc0sOk 9VC2a72ZbIISOKCy/umcg2tlOY8ycNB8lUWLj9GAi/2VTuq9GNb2XuNBi 4TWWlhKYx4VQdIQhNr2r0gOqR0YVu8BHAgv+h52JbX1L/VFFSNGk9O8Hv uB+/QGfjQ750u44cDsonfN5N8+uKZ6eIuxT8BbplU615hWfPN5hm8aBfb FUnas1ROCFukRtyy01S0LSAFl/eP1jg7zgm/l0ZafUBJPJ6/VNFZoZSiM Pbg9T/jW27OOqapVgAPSznlLiI049bL/Rw/1iMyM/p106IWpT2InkrCMe w==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="331298748" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="331298748" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 20:32:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="669447547" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="669447547" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga007.fm.intel.com with ESMTP; 08 Feb 2023 20:32:12 -0800 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.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, baolu.lu@linux.intel.com Subject: [PATCH 08/17] iommufd: Split iommufd_hw_pagetable_alloc() Date: Wed, 8 Feb 2023 20:31:44 -0800 Message-Id: <20230209043153.14964-9-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209043153.14964-1-yi.l.liu@intel.com> References: <20230209043153.14964-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 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?1757326716171659683?= X-GMAIL-MSGID: =?utf-8?q?1757326716171659683?= to a helper which accepts the parent hw_pagetable pointer and user_data pointer. This is a prepareation for supporting userspace hw_pagetable allocation as caller needs to pass the two parameters to domain_alloc_user op. Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/iommufd/hw_pagetable.c | 41 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index bda21ec737cf..ee97d2f3cf43 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -22,24 +22,23 @@ void iommufd_hw_pagetable_destroy(struct iommufd_object *obj) mutex_destroy(&hwpt->devices_lock); } -/** - * iommufd_hw_pagetable_alloc() - Get an iommu_domain for a device - * @ictx: iommufd context - * @ioas: IOAS to associate the domain with - * @dev: Device to get an iommu_domain for - * - * Allocate a new iommu_domain and return it as a hw_pagetable. - */ -struct iommufd_hw_pagetable * -iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, - struct device *dev) +static struct iommufd_hw_pagetable * +__iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, + struct iommufd_ioas *ioas, + struct device *dev, + struct iommufd_hw_pagetable *parent, + void *user_data) { const struct iommu_ops *ops; + struct iommu_domain *parent_domain = NULL; struct iommufd_hw_pagetable *hwpt; int rc; lockdep_assert_held(&ioas->mutex); + if (WARN_ON(!ioas && !parent)) + return ERR_PTR(-EINVAL); + hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE); if (IS_ERR(hwpt)) return hwpt; @@ -50,7 +49,10 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, goto out_abort; } - hwpt->domain = ops->domain_alloc_user(dev, NULL, NULL); + if (parent) + parent_domain = parent->domain; + + hwpt->domain = ops->domain_alloc_user(dev, parent_domain, user_data); if (!hwpt->domain) { rc = -ENOMEM; goto out_abort; @@ -75,3 +77,18 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, iommufd_object_abort(ictx, &hwpt->obj); return ERR_PTR(rc); } + +/** + * iommufd_hw_pagetable_alloc() - Get an iommu_domain for a device + * @ictx: iommufd context + * @ioas: IOAS to associate the domain with + * @dev: Device to get an iommu_domain for + * + * Allocate a new iommu_domain and return it as a hw_pagetable. + */ +struct iommufd_hw_pagetable * +iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, + struct device *dev) +{ + return __iommufd_hw_pagetable_alloc(ictx, ioas, dev, NULL, NULL); +}