From patchwork Thu May 11 14:38:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 92676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4435453vqo; Thu, 11 May 2023 07:53:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jAb1lDektWG60kk9vfPScZFkQRbbhgbkgV8egxe4NBIbNL22KzAbEONWjV/WPUOFnmwc2 X-Received: by 2002:a05:6a20:1587:b0:100:af1c:f6b4 with SMTP id h7-20020a056a20158700b00100af1cf6b4mr18395839pzj.41.1683816817941; Thu, 11 May 2023 07:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683816817; cv=none; d=google.com; s=arc-20160816; b=Tc4AIBZjkpQif3GfGuCs1hqOUabqE+8Y0StH1q2HpsjBc5gIIorCByfkjTOe8Fn6lQ eyjO/aM8+yxGLA9PS5q+9G0GInpMG0A/ZglFAMjmhM9D5b1TSiPTVAvzQApEYALgDDxo 3nhC6Ucs2DT7R/CRYeIHCgxSgmArideKu9/py6b9kI/M+D0ackT45OR1N9pfyNAJSkLX nEZ/2QX+U7+CxZJRDm7gY/lUgd3iQbYP0bJZiuzxmx115GLlIMCFzJXg4YFoJfot8IKJ i5uwxpR9Nk6ViOBfT1NrgzYLR7zvwfhJFx5wnnp36OGdifnO9m428qBj2zyEG0khJcRx QxqA== 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=GbgkZFz841rSMMYOaQo4zWSCHCqEA9H2kr+Uq45uhjk=; b=k1D7rrx7VW2TtGj+d3ludLRjEgxvNLvyCUYho+hDZ6dHM3RxUsiQvAEIUtpo0rZWzh qH1mCE534cWrGDnGdP/V58wk64ZfsBijexnqJJUqUpod7d4ZWlEWFZnX0Jnc50UYYHlY bRl3Ae5lG/WRFGvB6ROx2btSBBBnuZty+DPfbfUbb6CIoYf4eB0y5hBo22U7uQnuJetr gcM1mzo3juxok6VPo4o+zIKBku3jm3RLsJSR+Uwz+LeogqX1agJzsd+sEan+Cmqb+rbE RwkdwIab4fsN8pVO1A5gbWgoCbLceJpfPdSeQ4ApLDW6hf/It7fJHubr7TFiYgAAxlO8 jS6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jM23FZQC; 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 bu17-20020a632951000000b005303d78c47asi6495517pgb.726.2023.05.11.07.53.24; Thu, 11 May 2023 07:53:37 -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=jM23FZQC; 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 S238673AbjEKOnE (ORCPT + 99 others); Thu, 11 May 2023 10:43:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238613AbjEKOma (ORCPT ); Thu, 11 May 2023 10:42:30 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 962DC124A3; Thu, 11 May 2023 07:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683815930; x=1715351930; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9oxvupeqb12UC7Ej2KuinDMGVCV9GTwjqOvc7w7xUds=; b=jM23FZQCqnzDBE3hzIwtVtL8xl7m3LulKkmqBSnqLXEFA/0hMwDn7MtI 1yUcnfoJBeti1LFVtc+rHL9QevlwtIQreYO9jc2WqEYjN7uYra09NZLP8 Ed7eidOYNPUaKVZuwnHUBby2st6Nj8znb1Rmpa6VMp37M8LHjybRFxLpO 33Vmpw75YXY2dabfT3cm0dPOivD9yU5PlRvMRIWRkV7D/RrvSTzZcAPzj +QGZ4E/toTQNG8zNpLJ6QehROC63wNJP3MBWjvwh9gSoqvgt6BwcpFh/H ZNVxIRMztlnwm60txxhKas9hAh35tGR/m5YK7c+KVq1pRcLISMl8Xi3nc Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="339812875" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="339812875" 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:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="730382611" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="730382611" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga008.jf.intel.com with ESMTP; 11 May 2023 07:38:48 -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 03/11] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Date: Thu, 11 May 2023 07:38:36 -0700 Message-Id: <20230511143844.22693-4-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?1765609903810979533?= X-GMAIL-MSGID: =?utf-8?q?1765609903810979533?= 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 nesting support. If the iommu driver doesn't provide domain_alloc_user callback then it falls back to use iommu_domain_alloc(). Suggested-by: Jason Gunthorpe Reviewed-by: Lu Baolu Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/iommufd/hw_pagetable.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index cf2c1504e20d..b6323ad9c32d 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,7 +90,10 @@ 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 (ops->domain_alloc_user) + hwpt->domain = ops->domain_alloc_user(idev->dev, NULL, NULL); + else + hwpt->domain = iommu_domain_alloc(idev->dev->bus); if (!hwpt->domain) { rc = -ENOMEM; goto out_abort;