From patchwork Fri Oct 20 09:32:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932093vqb; Fri, 20 Oct 2023 02:33:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnguAGZVqaOPiZQFeFfp3r1dI31jqS/Cc/9eLKMbiuWuHYEgPl6NIFmdVmoON+dTeH3adF X-Received: by 2002:a05:6808:f89:b0:3b2:e0ac:b85e with SMTP id o9-20020a0568080f8900b003b2e0acb85emr1679853oiw.5.1697794406858; Fri, 20 Oct 2023 02:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794406; cv=none; d=google.com; s=arc-20160816; b=e7RfkJ/6VD0ZGBNHdBFrOwYHmEWkg+75sm4tmVJcfG8/p46NgVfzjYjP0hYvuHGqEN MNVico55LRnoNv2Lv/o7H5/OouMjN2OPWVUfNJ9V055bydQ2SqtxphleBJxUvJORzZ0g 78+x5ZGLEpHTOme2eOE4QjfDJ7myYz6RGSok2ktR07IvGi6QCHqBaeeHGhJpkPyrYNTw m4DzyVw/7WANalHHtgv4BEFm8054HAu4yoYL0ME4P4+lf7ryQl4gVrr8BSd7+NxlexxD tEnaK0b9sCxwgJiKTU+H9UbjOu4VMdZVd4OI4KR3XZIels6wVV5u4SrJjw0nNPKQwnRN 2TRw== 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=DNenBS9PnqwUrk8F6c9LmC5oPqxZvVNih0bDRoYfAgc=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=dR+qaGu8WPkWnmawNyp//pNBTZgsy6G/24kd7tPpWa2M2In9nW+70p5065xz1vUqpH mPUnJ1Luup+lpASE65vUb9CLBWSyXgTodxU+sx7sFugAJZtRKZ38Xa4C/6GiF/bKF9iY rQc/rYad/xf5mEZKyh/0htKy8J3aY+gf1BDYjXNor35nIGNtNAOfSJs8dtZMBmh+iFV7 AAHrnGhqQmiPEENr482fsV4puJd50zWOTMrNhl/uATgRzfGlMhzgGFi+zIFLQvyeqqUl BXC5N2WPZze4WhP2LArnaALAyuKlF1suo7WVbDkxJ1nrkNRz1CFQTg3wL1qRQjrferjI JLDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CAnUi3Vc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bn2-20020a056a02030200b005898699b2b8si1443642pgb.317.2023.10.20.02.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CAnUi3Vc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 90D29832A050; Fri, 20 Oct 2023 02:33:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376770AbjJTJdM (ORCPT + 25 others); Fri, 20 Oct 2023 05:33:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376720AbjJTJdD (ORCPT ); Fri, 20 Oct 2023 05:33:03 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39701D60; Fri, 20 Oct 2023 02:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697794376; x=1729330376; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L8v6hkJ+JIrDo8fqWs8a0xtoOtnuvQ0CSEXJ3O4E29A=; b=CAnUi3VcB1BoyEt1OGnhJqYbQvUSHLjNQbzZF/OYoR6IvbKDDPdw9HFM 5e6J69zmgPVYOejCzAIgD1LH+IKsdfTh9lUPsLlP7ZX15KmqDlOuobnFj 49nVmCbsOQx9+TdfZkda1Sn8g/JcSDNg2vSHcoNSl7YTo3zGEt5LA+w12 /8b5HNvIz8g5dc0HmYmBNNinCom9/Z7I7xYWx+yHFEdmH8d/MDjrOLd7x UZP/wik1R3W6y+GvcKh8EN3GIjFxdyLslxBCRw7tICcUfRQIASibimS2G 1s8S5aQ0iwEXCDqXNyRWSGcV+ynoC0hhMoGXFwwxKLOAWTtgXZYKzQ+Cc w==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691749" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691749" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 02:32:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906311" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906311" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:55 -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, xin.zeng@intel.com Subject: [PATCH v6 7/8] iommu/vt-d: Add nested domain allocation Date: Fri, 20 Oct 2023 02:32:45 -0700 Message-Id: <20231020093246.17015-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020093246.17015-1-yi.l.liu@intel.com> References: <20231020093246.17015-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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:33:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266467763903903 X-GMAIL-MSGID: 1780266467763903903 From: Lu Baolu This adds the support for IOMMU_HWPT_DATA_VTD_S1 type. Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b47025fbdea4..c7704e7efd4a 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4076,7 +4076,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data) { - struct iommu_domain *domain; + bool request_nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; struct intel_iommu *iommu; if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) @@ -4086,18 +4086,35 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, if (!iommu) return ERR_PTR(-ENODEV); - if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap)) + if (!user_data) { /* Must be PAGING domain */ + struct iommu_domain *domain; + + if (request_nest_parent && !ecap_nest(iommu->ecap)) + return ERR_PTR(-EOPNOTSUPP); + if (parent) + return ERR_PTR(-EINVAL); + /* + * 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) + return ERR_PTR(-ENOMEM); + return domain; + } + + /* Must be nested domain */ + if (!ecap_nest(iommu->ecap)) + return ERR_PTR(-EOPNOTSUPP); + if (user_data->type != IOMMU_HWPT_DATA_VTD_S1) return ERR_PTR(-EOPNOTSUPP); + if (!parent || parent->ops != intel_iommu_ops.default_domain_ops) + return ERR_PTR(-EINVAL); + if (request_nest_parent) + return ERR_PTR(-EINVAL); - /* - * 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; + return intel_nested_domain_alloc(parent, user_data); } static void intel_iommu_domain_free(struct iommu_domain *domain)