Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1966971rda; Tue, 24 Oct 2023 08:27:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlti4mD/o+91KX/WDlyjzAQ0aEs1PrQ3HgzBVZSg7E0QswRtG2K5PUAsCoMSSY/37nARPw X-Received: by 2002:a17:902:f945:b0:1c9:d667:4e4a with SMTP id kx5-20020a170902f94500b001c9d6674e4amr10427741plb.69.1698161246288; Tue, 24 Oct 2023 08:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698161246; cv=none; d=google.com; s=arc-20160816; b=OveJ+xE43yDDR5RWDSOZK7SZon8zknCVPZxPMFbYtrjdsQlZee7GRmVYAebcckj6JK dFom1LloF749QJxxGEqaNGMNHgRQoZEAj+8P1UhKjylmRKdCF/VIcOtEi6kHUBaxE1OG y/OKWM8vgiJzbQphsbrgCLyJpIUD5i5ivSRcT/nEWb7QbcdzizFEFdiBnFyYHjb1Tdkp nd+YKlgeaDKlts37zUPere21q0tV3zGiShqW91QPjpHtScw+efMkXzn3YAP7N/koO+AF CWIoXyqCh1j5gza47n6Z9vUTCqRKDNkHKFjJiBm1AUIYrs7R0D8rpTxKeRjhHRP25MyL zc5w== 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=5aNGRQv+z4tKSO5snxoOlURnqCTEFQdYvNDf/vddssc=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=dVvTPBadqIrwYwPloHXmEleks9shwksD1SW+IZM8eujexxgBtfoz+chN4fi8p/r4Br Ub8J/Imndy+sKbngek7P7EyEcgV1yHD0v9vxp2WgZAxFKhwbDMFjDIWt+B5BalwpX85C kH6WWw2ppdTHeZHStlgSA7VBTzl8M116q9DSrNX7yQa8Lw7uXyiroZruhIgbbIABuwfm vLEEg1WwUzZYaKAK346r8wnAexFq0w+CLcg0b5hSezcRfWxidFyjyxZ8ilN2SK9EQylO W7ShDz6U1ffvH4OUzWyCDy4Sk3C//BvN9pVDTzt3Aweo9OXa/DPxW6yqUQ+5F7d3a2dh uAZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Zb8y2Tq7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ij29-20020a170902ab5d00b001bd9e2b4b46si8117463plb.601.2023.10.24.08.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 08:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Zb8y2Tq7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 182AF802C698; Tue, 24 Oct 2023 08:27:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234779AbjJXP1T (ORCPT + 99 others); Tue, 24 Oct 2023 11:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234820AbjJXP1F (ORCPT ); Tue, 24 Oct 2023 11:27:05 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A65626B0; Tue, 24 Oct 2023 08:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698161154; x=1729697154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EvYYap6jVoXeJ39dE5VX3YkM1fWw70nq/hojBtiJ2Lc=; b=Zb8y2Tq7DrRWnrpOPGfFV6DBz4Izfm0ojzpUClO4PpC7cTI4WBZJJe2C VwGW7wNy464ZsNipgPIO4OdRgMrQmupeEKwd8/qv6qmW4XlLmtRiq2J5u QSje+2MZM97HQf7JGYSqhHlkH8RXR2K+QKf3+LCbWwdoCuKxwZMfehVjL pcpmkQuNVPUBfzGzpou6V6Toqi/Fl3TWLPqyci78pmFGX5+0DTwsQmL9f MhPhV5f9rZee/+vH327H9G+PVsB/SddCmAMBerbfNSPPJiEyPa4llfKCC uEiVkA7u8iF5TlqFFPN2oBV33g/Y4CwZm8XQlaSuiZ16hdQVAjeO25npW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="418212230" X-IronPort-AV: E=Sophos;i="6.03,248,1694761200"; d="scan'208";a="418212230" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 08:14:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="1005688935" X-IronPort-AV: E=Sophos;i="6.03,248,1694761200"; d="scan'208";a="1005688935" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga006.fm.intel.com with ESMTP; 24 Oct 2023 08:14:18 -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 v7 8/8] iommu/vt-d: Disallow read-only mappings to nest parent domain Date: Tue, 24 Oct 2023 08:14:12 -0700 Message-Id: <20231024151412.50046-9-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024151412.50046-1-yi.l.liu@intel.com> References: <20231024151412.50046-1-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 08:27:25 -0700 (PDT) From: Lu Baolu When remapping hardware is configured by system software in scalable mode as Nested (PGTT=011b) and with PWSNP field Set in the PASID-table-entry, it may Set Accessed bit and Dirty bit (and Extended Access bit if enabled) in first-stage page-table entries even when second-stage mappings indicate that corresponding first-stage page-table is Read-Only. As the result, contents of pages designated by VMM as Read-Only can be modified by IOMMU via PML5E (PML4E for 4-level tables) access as part of address translation process due to DMAs issued by Guest. This disallows read-only mappings in the domain that is supposed to be used as nested parent. Reference from Sapphire Rapids Specification Update [1], errata details, SPR17. Userspace should know this limitation by checking the IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 flag reported in the IOMMU_GET_HW_INFO ioctl. [1] https://www.intel.com/content/www/us/en/content-details/772415/content-details.html Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 6 ++++++ include/uapi/linux/iommufd.h | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 85366862fb5e..1a50d3f53713 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2194,6 +2194,11 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0) return -EINVAL; + if (!(prot & DMA_PTE_WRITE) && domain->nested_parent) { + pr_err_ratelimited("Read-only mapping is disallowed on the domain which serves as the parent in a nested configuration, due to HW errata (ERRATA_772415_SPR17)\n"); + return -EINVAL; + } + attr = prot & (DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP); attr |= DMA_FL_PTE_PRESENT; if (domain->use_first_level) { @@ -4872,6 +4877,7 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type) if (!vtd) return ERR_PTR(-ENOMEM); + vtd->flags = IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17; vtd->cap_reg = iommu->cap; vtd->ecap_reg = iommu->ecap; *length = sizeof(*vtd); diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 3a66d3888393..cb7d17e3b4e7 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -444,10 +444,20 @@ struct iommu_hwpt_alloc { }; #define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) +/** + * enum iommu_hw_info_vtd_flags - Flags for VT-d hw_info + * @IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17: If set, disallow nesting on domains + * with read-only mapping. + * https://www.intel.com/content/www/us/en/content-details/772415/content-details.html + */ +enum iommu_hw_info_vtd_flags { + IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 = 1 << 0, +}; + /** * struct iommu_hw_info_vtd - Intel VT-d hardware information * - * @flags: Must be 0 + * @flags: Combination of enum iommu_hw_info_vtd_flags * @__reserved: Must be 0 * * @cap_reg: Value of Intel VT-d capability register defined in VT-d spec -- 2.34.1