Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3224555rdh; Thu, 28 Sep 2023 06:20:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYp7u8BggZ14U7rrVQArwllyiP7MewqqrcahAhzidA8WmptUVutIgnP62RETJ0x81BrTwA X-Received: by 2002:a9d:6215:0:b0:6b8:9932:b8ad with SMTP id g21-20020a9d6215000000b006b89932b8admr1129205otj.1.1695907236051; Thu, 28 Sep 2023 06:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695907236; cv=none; d=google.com; s=arc-20160816; b=JIxF+zKqtLjDmE/718hgxh3lnLc/u0c9NMwWI2mjBZYAhDw7HPW7M7TJtmxBUfzE2r cSVYj3NX/8XsPOdyIv5pfViut5kpfhWo0HwccbNQpPfdMM/VDUnvPpowwUc9IZJ7v4gp gao4hkthz5viF5vos4A97wfMnaHUVkdSU/3Q2+cd6CBteARoD6WlxE6NL5tbJvMnskpF bNyctm0HsiENnVUSesYFm9OtseEGsKd41Ycv8ssv6TReO11+NyOlUIKxVVB5B/BJ7LtX rDd9FEnvaGPX4cVdFbMn/nwcJ4kBgl/O7D6MWmrIvSQMoxmF2SLujGflYV7OlkjVqlP/ AN8g== 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=JzUKFE/KvWUYjVSFlZ4behPSUQYZski/gyvV9fUSra4=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=rQfCg4/dAwZDFwlIhWMFot0emj+3BtzRchD/nx/iwuQovVXDRXgiISh/7H2sY28zJO X1AvvGxESuaUvX78sRh3nwok8OqEcWse0FDQ9A4d3kX7NpavU11bjt3/30nqAWg+0jEE mrp/23jeWcrT59SZkTQvDRdznIzRDp0vBKk/Zn+TGcBQfVhzwa+HirJ+AHofaO6HTgQ3 w0Es/MmL2AWBxE4VWPnqvM2Qm50P5sza5vxsavZOdCo25UUbJz33tEVaY2JTT9itEWLZ sggSx2AcI1uLKMTp80sdB5UIScnXmo1yyixEGOZ6ZXhbJqhlzeZnYrDjD+5rDyQGXWsr POzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NT6bCq7u; 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 Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 19-20020a631753000000b00577ae8b603fsi17551860pgx.314.2023.09.28.06.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:20:36 -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=NT6bCq7u; 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 A665580A4326; Thu, 28 Sep 2023 00:16:33 -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 S231627AbjI1HQF (ORCPT + 99 others); Thu, 28 Sep 2023 03:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231322AbjI1HPs (ORCPT ); Thu, 28 Sep 2023 03:15:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B0AF9; Thu, 28 Sep 2023 00:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885343; x=1727421343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WOT6Nvcwlk/4tcNAsxhrAgOjJcTJ1AZiQvr9aESlkuA=; b=NT6bCq7uT3UdwoUU/nXxlVQ0NsGn+pAVRZSPbOQHs2/rYfPRoPR/aNvm VB1AVpfEpap325ejnnT22+GPfyTQi3BWpGh5J7x2ET+qdU01u2YeTEHAC gYWGW0HyxxKXcNF3Hp4btvYI0wQJF4MR5z7t5HIxPqfdyezRxnupjt4ON SAGH1osCkKZadOpuDQAyfztkPhKsLsPVOgei6fFAnOBE7vrbCgnI6Sjjv nEUh7VHIZkMPDS7TdpkavQLOTL6uBNAHXogzbf7sNl/Ed9eoi4dcyr0Qd b2/VjQT/RrYGfbMjqUSkcuBalyrCHeWyhMkTAjiWu5BRyjoGy+Nbgm2NB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914902" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914902" 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:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784602111" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784602111" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:41 -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 6/6] iommu/vt-d: Add domain_alloc_user op Date: Thu, 28 Sep 2023 00:15:28 -0700 Message-Id: <20230928071528.26258-7-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 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 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:16:33 -0700 (PDT) This adds the domain_alloc_user op implementation. It supports allocating domains to be used as parent under nested translation. Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 5db283c17e0d..017aed5813d8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4074,6 +4074,33 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) return NULL; } +static struct iommu_domain * +intel_iommu_domain_alloc_user(struct device *dev, u32 flags) +{ + struct iommu_domain *domain; + struct intel_iommu *iommu; + + if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) + return ERR_PTR(-EOPNOTSUPP); + + iommu = device_to_iommu(dev, NULL, NULL); + if (!iommu) + return ERR_PTR(-ENODEV); + + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap)) + return ERR_PTR(-EOPNOTSUPP); + + /* + * domain_alloc_user op needs to fully initialize a domain + * before return, so uses iommu_domain_alloc() here for + * simple. + */ + domain = iommu_domain_alloc(dev->bus); + if (!domain) + domain = ERR_PTR(-ENOMEM); + return domain; +} + static void intel_iommu_domain_free(struct iommu_domain *domain) { if (domain != &si_domain->domain && domain != &blocking_domain) @@ -4807,6 +4834,7 @@ const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .hw_info = intel_iommu_hw_info, .domain_alloc = intel_iommu_domain_alloc, + .domain_alloc_user = intel_iommu_domain_alloc_user, .probe_device = intel_iommu_probe_device, .probe_finalize = intel_iommu_probe_finalize, .release_device = intel_iommu_release_device, -- 2.34.1