From patchwork Thu Sep 28 07:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 146246 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3503195vqu; Thu, 28 Sep 2023 11:08:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVjs1hsU121qEDeutDc9rocRMAfFRghzzM7reRoQ6mDYLj4V8ZoDASveBN6vEHF8egZDyZ X-Received: by 2002:a05:6870:1815:b0:1d6:65d1:7989 with SMTP id t21-20020a056870181500b001d665d17989mr2257325oaf.24.1695924519534; Thu, 28 Sep 2023 11:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695924519; cv=none; d=google.com; s=arc-20160816; b=wyAH1v+7pY0PcNAt/E4601gw/hyl7cnCNBkMwdzvbRGPvbw6uDlVuM51gAQcMykBSV C7eMMEKUMTXWrRhXzHkikhLSBGsuaAfcQrPonrHzOHp/EnUVLktsmt/l0KJP5YIp+0tK ovwRIdatnur7xOAxjuAItbQ5eY02THf3j5J294ZLiNieIpcok8uCLmlSDYQFjH58455k b4hil4zSuWbu0wW/VT/fPU20NIZQmp5+z3j1stDnKvl2gtMVIrn6OkZ2v+SY55kxPqfY 3KC0jsvZ2wR6qGXr0Cr71QcBu0VvgfEyvw0Ywr0fHjkh3uHI0kO/68QEjCTLGI52OT5Q ZHTg== 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=1C8MC5VZQA2hu1oaMgBguNv/m/esGQVWCeab4v6z2d3kN6LZJQZQbCv/DtOP5ksxeu G1ob+sHT/0D8Dv0clSDV0MeWcMuk9wafH/ta3N9ah54247/lYyiC82lK5HJBpVR7KVYc FWHdiqSIE9a1k5g7nGU2UQHJNEui6tJegBGO4V+22qt2YeZkdwfwEggME12ahui3NZhl vNbpFW1OPMTU8yR05RmmCu7i+Z+n0PB87aONCFxmO6wKlLwRK0heUEpG38xiNfP2ny/M kfC08kKxDn2634sF/Rq7CZlfxbDAIxo3z9KKcTIIphvGVzUccIE6CNEiVrSA2AzUF3zv inIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bRsbCqsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y184-20020a638ac1000000b00565660b78d3si18663316pgd.591.2023.09.28.11.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 11:08:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bRsbCqsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 37C0D8115461; Thu, 28 Sep 2023 00:17:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbjI1HPo (ORCPT + 20 others); Thu, 28 Sep 2023 03:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbjI1HPe (ORCPT ); Thu, 28 Sep 2023 03:15:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53018CC1; Thu, 28 Sep 2023 00:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885333; x=1727421333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2u453SswpKakc0NOsEhGqMN9HDyZwW3XZ2U2N48J7YQ=; b=bRsbCqsjStpeOY40igeSQZ4spXGTYYTWuUKvdeoYZs62TCLPt1YULpgU LcKQPS7tc4INFyeVZhEMPsvc9BXZMNgqnIXKONItbL11a8Zh8T7345ynp 1wEE/kjYSNqRY5pRgi/8XYqgNVZ4m0zOiJr6L61mce8sZ3AtrgIWKqUkn HFo8kGxEZrZN3cxXWF3GWyQjgdknUCxvW+eUzduk7P1c7hC20amszj/P/ 5YwivSCByqLcL9lF6geeltn3HpV0G4vpXCzw9I8mT5e6jyjs6H0N9Nqwb dpf0iT+5ps/bGvNWsFuXOXIsikcYVroESs/YiFlbejQCvt8DD+aaZazs9 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914835" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914835" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784601980" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784601980" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:32 -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 v2 2/6] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Date: Thu, 28 Sep 2023 00:15:24 -0700 Message-Id: <20230928071528.26258-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-1-yi.l.liu@intel.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 00:17:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778305749013981478 X-GMAIL-MSGID: 1778305749013981478 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; + } } /*