From patchwork Fri Oct 20 09:32:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp931935vqb; Fri, 20 Oct 2023 02:33:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRuq8CHJkXONna/5HbcNp8rguZP1+SWT++XEzOs0te1dhONUutbHkalAb54sFndTwsuYHv X-Received: by 2002:aa7:888b:0:b0:6bd:9281:9446 with SMTP id z11-20020aa7888b000000b006bd92819446mr1296088pfe.10.1697794383940; Fri, 20 Oct 2023 02:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794383; cv=none; d=google.com; s=arc-20160816; b=a6+fSq10/HOVfU4psBtBbVlN8WXlo/8orh6iYuk6UMVynRgTJZnV9sHLRtjc+YYCLv RrY1zKiecbgbmaE3SrTECi8DTaSDWeb/SX5iCMvlIHoJYIUXGXlqq27hGk1mzcHIYCto pepREIMU5bC5cJ1D8rTUv+2sB4H5WsbPhwxLah5tH4G415kzV7TMVmTAsG8xhoBunWPS Jpx1L5yDKXFItGvkegHkIaaDRdR5D69ou4VDhpSzzxLGMKKro2MRfUK7ok8+O/g1ULEp EOyOAfA557BrkNM2bYcLdzv1UjOQnpKWpH8AnOyCwvJOXNDQSBtBb3PdAjMRH/7YOdJA vv5A== 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=Zh8S3XlLW2/ul5i4g1MbO9BJhGw2bDPeJg+EvgkuWlU=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=q9/L+0eUc/jhR9cDGmy+ML8YHnMhpvpUAi8Jx8zGnNmdQ1T+OvRwxfb55LUfg8LGmv BC7XPCSDgZHeP0HrkfPc61ENIN/BxfmV5qf5vRxz5dqHoM9Jja0sYrhCbhxPL2yeE4qj ijwVihye+sDv04Z7kdqXJ8PkbVYdNFNzNRp3wNYYvEPxbnNsASFNST0YqPm5hhObLmd0 q3cOYxkxG7EgAQ9ZbMb85pZHA5LBMg2lB7In0DXeHZfRfoVsnZ+7kBZ54+4sixW8WG+u of1qgVeSn6sFW61pMuzE86K2Bv2cEWyM++6ef37HQb/xsDt5hKMkkT0e9nLbxEGYSu4W DZpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UCzGZEpC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g28-20020a63375c000000b00585a454179fsi1441659pgn.162.2023.10.20.02.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UCzGZEpC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 174D482CAC1C; Fri, 20 Oct 2023 02:33:03 -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 S1376699AbjJTJcy (ORCPT + 25 others); Fri, 20 Oct 2023 05:32:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376682AbjJTJcv (ORCPT ); Fri, 20 Oct 2023 05:32:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF27CD49; Fri, 20 Oct 2023 02:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697794369; x=1729330369; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fFn6Ev4d2j4fnS20q4JAEtrpLg+WWBPIqtUwgZSmJGA=; b=UCzGZEpC0jTjkRP8iRy4NCeEJM1H6kP2LOcgz32/XXUo2P94hbGP4hwa lsIsEbwmIPGW8/hUPgbCSyIICjBptmDKozOFlnmLxJ3Zk6wFmkNLQfDQ6 F/keDJt7RrDKYtVYDZsJMQtTl+8TNnWYSnKy+yu77utGxxw4/T4drCQxA EKbBQrapxXbhGpXdoy6k+hidUNUDzD4cPhYRhTj7YZTwwWNRTHs93HGbq 7y2wHELqyFGKYlixVEBEDMXQ9QtK4VnzrMOS4j02pOCTAk1tCCjj0fos4 sKzn0jqKSwBVatHJRMRizAYZsMpzadT9VUTxdS+vAkMs8phxkdkqmHEUb A==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691673" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691673" 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:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906290" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906290" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32: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, joao.m.martins@oracle.com, xin.zeng@intel.com Subject: [PATCH v6 1/8] iommufd: Add data structure for Intel VT-d stage-1 domain allocation Date: Fri, 20 Oct 2023 02:32:39 -0700 Message-Id: <20231020093246.17015-2-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=-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,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]); Fri, 20 Oct 2023 02:33:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266444377879433 X-GMAIL-MSGID: 1780266444377879433 This adds IOMMU_HWPT_DATA_VTD_S1 for stage-1 hw_pagetable of Intel VT-d and the corressponding data structure for userspace specified parameter for the domain allocation. Reviewed-by: Kevin Tian Signed-off-by: Yi Liu --- include/uapi/linux/iommufd.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index fc305a48ab81..9b843a197ea8 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -357,12 +357,42 @@ enum iommufd_hwpt_alloc_flags { IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0, }; +/** + * enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table + * entry attributes + * @IOMMU_VTD_S1_SRE: Supervisor request + * @IOMMU_VTD_S1_EAFE: Extended access enable + * @IOMMU_VTD_S1_WPE: Write protect enable + */ +enum iommu_hwpt_vtd_s1_flags { + IOMMU_VTD_S1_SRE = 1 << 0, + IOMMU_VTD_S1_EAFE = 1 << 1, + IOMMU_VTD_S1_WPE = 1 << 2, +}; + +/** + * struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table + * info (IOMMU_HWPT_DATA_VTD_S1) + * @flags: Combination of enum iommu_hwpt_vtd_s1_flags + * @pgtbl_addr: The base address of the stage-1 page table. + * @addr_width: The address width of the stage-1 page table + * @__reserved: Must be 0 + */ +struct iommu_hwpt_vtd_s1 { + __aligned_u64 flags; + __aligned_u64 pgtbl_addr; + __u32 addr_width; + __u32 __reserved; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data + * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE, + IOMMU_HWPT_DATA_VTD_S1, }; /** From patchwork Fri Oct 20 09:32:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932130vqb; Fri, 20 Oct 2023 02:33:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6/rCCxDp1+asYt5dilYIg/G/hV5bcLMqt/RpMbehSVXPlxjPJaHMiN3dKhLj8kT3Dnv7t X-Received: by 2002:a17:903:1c1:b0:1c3:bc7b:8805 with SMTP id e1-20020a17090301c100b001c3bc7b8805mr1572607plh.52.1697794410890; Fri, 20 Oct 2023 02:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794410; cv=none; d=google.com; s=arc-20160816; b=KuEpI0d5xWqluZkNhqszWu3kT6rlakMQZ5WinqsxfckimpHwaABJF/xEVxdQaRTaa7 rpy8NLeJrRbx1JYWBvM2pNzim5Ow9FmBtAnDp5bmXIMEA7NpnWU0begThL8sft1c4Ibc w47OKE+/vntZoUbeO+O1nggilCbQjygY3EKJca8wEY/4sM8ThMf1heX0rjR/gteF7Ee5 CyiwfaQ5UVFiEdvPmtBbxqJ27/HaXT+FPmsC8dJqUtquElfh0GKk4spcva9t0UWbXR/A CbeQ3JEgJhoKaQ0lK3vuXz2PVgr4JmEcZEsUNYQU2jUMgiWu4ZvxHwvEIkNOJAtm252J UEag== 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=K/cirNSQp1TcimgwX9d6H5a2Qz9v8Jv/N9NK/HzO8jI=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=0rgb/2tm6r99a7eSfxlYxN+FIAPMCS/uD+dtrbEXtezjIIw9MeIMnyERBAt6mAJAoq kdA8Ghs1FRlnnESMWEIlTkDUqwyfqBcDCBbngMOL9xzNfvTGNHbZht6wzcDoYN/etoqS tAKs1Olbrahxzd19zED/weWkX2LLnnEWnlUk1P2TQqicSEWsSYicEVW9majKi8VidRat GGC6j7IJsbLJl3LIdT5AZCte0I86syIwL0+dHgaZwac8+yX8rZF5QhzCwoAgnirCkIYz xElFbjt5PjbImMjmEPRqfmI236cWsig8tZZ9uMO7BCBsYaGQ0Koc7pUCICtZMgl7PuX2 cGlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hSgVNbpD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l13-20020a170902f68d00b001c9eed814dbsi1505216plg.562.2023.10.20.02.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hSgVNbpD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id E2D77833F8C5; Fri, 20 Oct 2023 02:33:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376710AbjJTJc7 (ORCPT + 25 others); Fri, 20 Oct 2023 05:32:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376601AbjJTJcx (ORCPT ); Fri, 20 Oct 2023 05:32:53 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DFE4D53; Fri, 20 Oct 2023 02:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697794371; x=1729330371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DXIvRNOCtaIRDhqetLa0HFPc3lYj6M16Uhk2EvUaat4=; b=hSgVNbpDtaV3CptMg2CVioBF3rkK4FBj3VsVk82x1Yub6QacO7DF7ghQ oUnf8ofDhEFfCDtn/Wi/U86jXjVWTK7Rta9BPdEWmbupHBGeXQhpdQ9Pu c6Uf9DXg0N2oP0iP3j+z6yq/y4XolamAZ/+CVno+yJf9J1ce4JStSMQKS plEQIWFwwhtDFeSf0MeKgrtQeLwkdASxzWki5Xdm/CWaZ5LL9nMF2QSmp TYS/TltUslpP+3MDYYEW9cfZwBskeAYSDw31spxBIlzRvwPMe4+fhbwDT qhkOzty7Gnu61V89hifC9o02rdnyNnKgUkBQ3NNMKFgIMe3DLB0Yp1NXf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691688" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691688" 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:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906294" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906294" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:50 -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 2/8] iommu/vt-d: Extend dmar_domain to support nested domain Date: Fri, 20 Oct 2023 02:32:40 -0700 Message-Id: <20231020093246.17015-3-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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:33:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266472231296894 X-GMAIL-MSGID: 1780266472231296894 From: Lu Baolu The nested domain fields are exclusive to those that used for a DMA remapping domain. Use union to avoid memory waste. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index c18fb699c87a..a91077a063ee 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -25,6 +25,7 @@ #include #include +#include /* * VT-d hardware uses 4KiB page size regardless of host page size. @@ -597,15 +598,38 @@ struct dmar_domain { struct list_head devices; /* all devices' list */ struct list_head dev_pasids; /* all attached pasids */ - struct dma_pte *pgd; /* virtual address */ - int gaw; /* max guest address width */ - - /* adjusted guest address width, 0 is level 2 30-bit */ - int agaw; int iommu_superpage;/* Level of superpages supported: 0 == 4KiB (no superpages), 1 == 2MiB, 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ - u64 max_addr; /* maximum mapped address */ + union { + /* DMA remapping domain */ + struct { + /* virtual address */ + struct dma_pte *pgd; + /* max guest address width */ + int gaw; + /* + * adjusted guest address width: + * 0: level 2 30-bit + * 1: level 3 39-bit + * 2: level 4 48-bit + * 3: level 5 57-bit + */ + int agaw; + /* maximum mapped address */ + u64 max_addr; + }; + + /* Nested user domain */ + struct { + /* parent page table which the user domain is nested on */ + struct dmar_domain *s2_domain; + /* user page table pointer (in GPA) */ + unsigned long s1_pgtbl; + /* page table attributes */ + struct iommu_hwpt_vtd_s1 s1_cfg; + }; + }; struct iommu_domain domain; /* generic domain data structure for iommu core */ From patchwork Fri Oct 20 09:32:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932188vqb; Fri, 20 Oct 2023 02:33:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN5rujQ23mQxDfozhAakscOj5qmLatkHTmC/Bwx3q8Az7B4APuA5zH6EyoFwjk5EypAHWI X-Received: by 2002:a17:903:1212:b0:1c8:92ee:108a with SMTP id l18-20020a170903121200b001c892ee108amr1560005plh.23.1697794417325; Fri, 20 Oct 2023 02:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794417; cv=none; d=google.com; s=arc-20160816; b=C0gIbZ5BhVBEnIbDLSOzAxqa+NodxHt94VYaDXV/Fgr3b+nCtobFggGoQMUm6lMn/o KNLpMSMRdgV1m0SVFnJxTbIKYbelvEeK1azHz4B2S2lUuadb+tKHNMYJhk1OMBkzXm9R mSJaYljBCqlMO3koLTppkYbFgTMvN1wLdH/izdsAwkOuqtvdGbNs5V5jicXT/IyBSrfe Rp3z2RgTOOtybaCluyJVIQF45H108T77jbb+9kV6gIRt4M36C1PhrcHpEdg0jLveSwXM c07QScFz4j1hjb86rJW6NBrNfKRHRQgox+DbBKwFDNXe1jZ2t5aINtmswsTeCevV/8Iu LVhw== 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=JlZ6JqOpeQtb12X40LlIfRRlmAJqn3Hx15vfe8psn2k=; fh=IZyM1AM0bATemv9EzafoXv7q5+geru1rOhtf89P+YN0=; b=FoHtxN8un6hcfJVWgHN/T3LNxinwQtdoOOWvhk0iho/2xAOktAmc+jX6VW3eVDMVsW CNgLivI79y3mlNWd1Bh/jKh2/xhFxPDw/rxvp3C9Cz9id0Himp49EbovqgVBR2YFutfi I4ClwjWKRPXDdqy3FN/r1daVb8Yvtq3rqdxO88aHgOhkmAb7ZouFT1zxisVJtig+KL+T CsXJ/Z1phttJBEri4+i+HNcrddMj85nbX51H020jrHEtdb0HBgC3bK5vzhn7xDIDRobQ t5SDbUVdRVHYw6UR7I2/9zRpHg/ZzUooyQdkhSRoRyiks0rs6EyT7JtzFpVt13L8aaEn Wrcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KKJ35bEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id v5-20020a170902b7c500b001ca122454a9si1342114plz.563.2023.10.20.02.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KKJ35bEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 23ECC82878BF; Fri, 20 Oct 2023 02:33:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376682AbjJTJdF (ORCPT + 25 others); Fri, 20 Oct 2023 05:33:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376649AbjJTJcy (ORCPT ); Fri, 20 Oct 2023 05:32:54 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2109AE8; Fri, 20 Oct 2023 02:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697794373; x=1729330373; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UhxPLZHsNBaJpuPmPuZrs6VDspZflofqLeRUV4csYhM=; b=KKJ35bEH4NiF3L+pJuxuilZoyuXpcQ+4IX5QMG87sCHZR0lWwkG/QxCH eFN0rMph4t8HZPlzvqp0/7VHnTMXI/ws5B597phEyMGM93ODh8Gjgr6eO hUmmDSRNkm330aylFL8h3fXiKe5n/Z41uMXZEZQioCTsMlzpnXrNXHA+Y nsY+1Vgvf6GfBc4DotXXb+VU0ioiNoeZAuS+/kf4C0jRWTkhQIpsBuyQc Uud4oFS0bcpVKUPkDPBAXk+D8PCxcjXrwLoUoK76XwltbbkjOgXdlZ4NI pT7z5TQSnT/9fxWkNURHXtemusqVul5fCdbyEI/IcvGm5AA2+pUZSk6DA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691703" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691703" 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:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906298" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906298" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:52 -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, Jacob Pan Subject: [PATCH v6 3/8] iommu/vt-d: Add helper for nested domain allocation Date: Fri, 20 Oct 2023 02:32:41 -0700 Message-Id: <20231020093246.17015-4-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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:33:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266479237442726 X-GMAIL-MSGID: 1780266479237442726 From: Lu Baolu This adds helper for accepting user parameters and allocate a nested domain. Reviewed-by: Kevin Tian Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/Makefile | 2 +- drivers/iommu/intel/iommu.h | 2 ++ drivers/iommu/intel/nested.c | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/intel/nested.c diff --git a/drivers/iommu/intel/Makefile b/drivers/iommu/intel/Makefile index 7af3b8a4f2a0..5dabf081a779 100644 --- a/drivers/iommu/intel/Makefile +++ b/drivers/iommu/intel/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DMAR_TABLE) += dmar.o -obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o +obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o nested.o obj-$(CONFIG_DMAR_TABLE) += trace.o cap_audit.o obj-$(CONFIG_DMAR_PERF) += perf.o obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index a91077a063ee..ff55184456dd 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -866,6 +866,8 @@ void *alloc_pgtable_page(int node, gfp_t gfp); void free_pgtable_page(void *vaddr); void iommu_flush_write_buffer(struct intel_iommu *iommu); struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn); +struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *s2_domain, + const struct iommu_user_data *user_data); #ifdef CONFIG_INTEL_IOMMU_SVM void intel_svm_check(struct intel_iommu *iommu); diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c new file mode 100644 index 000000000000..5a2920a98e47 --- /dev/null +++ b/drivers/iommu/intel/nested.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * nested.c - nested mode translation support + * + * Copyright (C) 2023 Intel Corporation + * + * Author: Lu Baolu + * Jacob Pan + * Yi Liu + */ + +#define pr_fmt(fmt) "DMAR: " fmt + +#include + +#include "iommu.h" + +static void intel_nested_domain_free(struct iommu_domain *domain) +{ + kfree(to_dmar_domain(domain)); +} + +static const struct iommu_domain_ops intel_nested_domain_ops = { + .free = intel_nested_domain_free, +}; + +struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *s2_domain, + const struct iommu_user_data *user_data) +{ + struct iommu_hwpt_vtd_s1 vtd; + struct dmar_domain *domain; + int ret; + + ret = iommu_copy_struct_from_user(&vtd, user_data, + IOMMU_HWPT_DATA_VTD_S1, __reserved); + if (ret) + return ERR_PTR(ret); + + domain = kzalloc(sizeof(*domain), GFP_KERNEL_ACCOUNT); + if (!domain) + return NULL; + + domain->use_first_level = true; + domain->s2_domain = to_dmar_domain(s2_domain); + domain->s1_pgtbl = vtd.pgtbl_addr; + domain->s1_cfg = vtd; + domain->domain.ops = &intel_nested_domain_ops; + domain->domain.type = IOMMU_DOMAIN_NESTED; + INIT_LIST_HEAD(&domain->devices); + INIT_LIST_HEAD(&domain->dev_pasids); + spin_lock_init(&domain->lock); + xa_init(&domain->iommu_array); + + return &domain->domain; +} From patchwork Fri Oct 20 09:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932342vqb; Fri, 20 Oct 2023 02:33:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhih8y0Gnt7afN00+zfnIwraU99FVqqcA8FdmKhj4f8bB6hBCadv1ZyC7sQriwpz9gnOQ/ X-Received: by 2002:aa7:8b85:0:b0:68f:c2f7:cef0 with SMTP id r5-20020aa78b85000000b0068fc2f7cef0mr5689232pfd.4.1697794439330; Fri, 20 Oct 2023 02:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794439; cv=none; d=google.com; s=arc-20160816; b=U7dHx7JA7rx8q88dBaXLthQNEY4ijS2k1sbRi5HDSMEDwUM1fABFm1gb5bw7ehqIXu VsXAqLHm8s/oOhKVBgm+PlBv2+f1RjQPAVZpbBt6slBEqclNRjy3Ixi0cy3l7zxp9kNQ +4tGWExtTchStIhpI4KCibR1YlmDb2l5MANC/r0pSIQLdtjL5vsblXGt2XBiIdqjmw3D 9nS0ByymNFZImuaP0y+HaU0tM2x5/taeycnZDf1HfJU2l296feU7CFmR9aIImjiHjM36 D3HbzjxbGjggbJuEEMeOGRXhzQPCAdmGEdpgwAQLK1i6d9M++9iWPowdJ51MBCX/vdqc TGXg== 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=iBrsb1fr7a8Kd4H9GnlIF2XrDWr525fJRrZuUlYI9Pc=; fh=IZyM1AM0bATemv9EzafoXv7q5+geru1rOhtf89P+YN0=; b=s3NI9jkcH73hhbIUs6qUbVxrdA1kYt1WZqGtbzhSLBLJoPhfjUUvygJuuZf2OyIeTw q3XxLCv7l+Tt17cVjfyTmhbhURlMZ9tZFFJB6+AptiqT4CSX/1MC1/uYlEr8SR6afQaj clYPhA9dcYYwRMOmMwvBFOUBed+VKsrW8SumuXPt8WXYOvdFwAXWg4gjKpOHhkl0tiig a15mxbTg/sp+jRTBKkcpflXhP9tLR8N4nShR0e+TVCNTa3sXldCLQoiBiDIKmfhINM/Y 1n2zzTkYc0/04pd68EaW/RwBvBRVNSphLl2auy2N5sLiJRz3Ga3aIUQ455qR1RLAJiG3 /amg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZmfDVQm5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id f22-20020a631f16000000b00577f4d85fdbsi1519451pgf.548.2023.10.20.02.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZmfDVQm5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 6A2B7833F8C4; Fri, 20 Oct 2023 02:33:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376803AbjJTJdP (ORCPT + 25 others); Fri, 20 Oct 2023 05:33:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376678AbjJTJc4 (ORCPT ); Fri, 20 Oct 2023 05:32:56 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32641D53; Fri, 20 Oct 2023 02:32: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=1697794374; x=1729330374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1MJ8HhGHI+SlSgCrNpxntgU8HIg/xhXNDAYWmNsWBFI=; b=ZmfDVQm5sHwyVuSsAVtGcpzP2TDxV+onhvxnao/l70n7ZbiccgCuKWmO a/0om8vq8TySXImC95gpKV8Tt49FJGloRwDWC4unhBkJljJCOIRtfjA4r GX9VEjoZqLO0Ff3V58VDv5yTOF0aqeMiImvmI7+MK8lkBsDeEcVJm/4jq Z07htuL1RjMMRwvvo6iliy+m+v5pqivQGAfE4XG7wM/qV2SR6ocLtas8U O/t3e4Y28Fc+hL0Jx/ixG1Kc00bR97xtThuAleReMzIzXAK+pv/oxaocu ZeFlmpIRFZ5CQM85B2TRAH5r6bTRagXyJfrQcwfGXunEX6+lVDI6Pj8/2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691715" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691715" 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:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906302" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906302" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:53 -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, Jacob Pan Subject: [PATCH v6 4/8] iommu/vt-d: Add helper to setup pasid nested translation Date: Fri, 20 Oct 2023 02:32:42 -0700 Message-Id: <20231020093246.17015-5-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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:33:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266502018414881 X-GMAIL-MSGID: 1780266502018414881 From: Lu Baolu The configurations are passed in from the user when the user domain is allocated. This helper interprets these configurations according to the data structure defined in uapi/linux/iommufd.h. The EINVAL error will be returned if any of configurations are not compatible with the hardware capabilities. The caller can retry with another compatible user domain. The encoding of fields of each pasid entry is defined in section 9.6 of the VT-d spec. Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/pasid.c | 112 ++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/pasid.h | 2 + 2 files changed, 114 insertions(+) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 8f92b92f3d2a..fbf71f56653d 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -335,6 +335,15 @@ static inline void pasid_set_fault_enable(struct pasid_entry *pe) pasid_set_bits(&pe->val[0], 1 << 1, 0); } +/* + * Setup the SRE(Supervisor Request Enable) field (Bit 128) of a + * scalable mode PASID entry. + */ +static inline void pasid_set_sre(struct pasid_entry *pe) +{ + pasid_set_bits(&pe->val[2], 1 << 0, 1); +} + /* * Setup the WPE(Write Protect Enable) field (Bit 132) of a * scalable mode PASID entry. @@ -402,6 +411,15 @@ pasid_set_flpm(struct pasid_entry *pe, u64 value) pasid_set_bits(&pe->val[2], GENMASK_ULL(3, 2), value << 2); } +/* + * Setup the Extended Access Flag Enable (EAFE) field (Bit 135) + * of a scalable mode PASID entry. + */ +static inline void pasid_set_eafe(struct pasid_entry *pe) +{ + pasid_set_bits(&pe->val[2], 1 << 7, 1 << 7); +} + static void pasid_cache_invalidation_with_pasid(struct intel_iommu *iommu, u16 did, u32 pasid) @@ -713,3 +731,97 @@ void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu, if (!cap_caching_mode(iommu->cap)) devtlb_invalidation_with_pasid(iommu, dev, pasid); } + +/** + * intel_pasid_setup_nested() - Set up PASID entry for nested translation. + * @iommu: IOMMU which the device belong to + * @dev: Device to be set up for translation + * @pasid: PASID to be programmed in the device PASID table + * @domain: User stage-1 domain nested on a stage-2 domain + * + * This is used for nested translation. The input domain should be + * nested type and nested on a parent with 'is_nested_parent' flag + * set. + */ +int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, + u32 pasid, struct dmar_domain *domain) +{ + struct iommu_hwpt_vtd_s1 *s1_cfg = &domain->s1_cfg; + pgd_t *s1_gpgd = (pgd_t *)(uintptr_t)domain->s1_pgtbl; + struct dmar_domain *s2_domain = domain->s2_domain; + u16 did = domain_id_iommu(domain, iommu); + struct dma_pte *pgd = s2_domain->pgd; + struct pasid_entry *pte; + + /* Address width should match the address width supported by hardware */ + switch (s1_cfg->addr_width) { + case ADDR_WIDTH_4LEVEL: + break; + case ADDR_WIDTH_5LEVEL: + if (!cap_fl5lp_support(iommu->cap)) { + dev_err_ratelimited(dev, + "5-level paging not supported\n"); + return -EINVAL; + } + break; + default: + dev_err_ratelimited(dev, "Invalid stage-1 address width %d\n", + s1_cfg->addr_width); + return -EINVAL; + } + + if ((s1_cfg->flags & IOMMU_VTD_S1_SRE) && !ecap_srs(iommu->ecap)) { + pr_err_ratelimited("No supervisor request support on %s\n", + iommu->name); + return -EINVAL; + } + + if ((s1_cfg->flags & IOMMU_VTD_S1_EAFE) && !ecap_eafs(iommu->ecap)) { + pr_err_ratelimited("No extended access flag support on %s\n", + iommu->name); + return -EINVAL; + } + + spin_lock(&iommu->lock); + pte = intel_pasid_get_entry(dev, pasid); + if (!pte) { + spin_unlock(&iommu->lock); + return -ENODEV; + } + if (pasid_pte_is_present(pte)) { + spin_unlock(&iommu->lock); + return -EBUSY; + } + + pasid_clear_entry(pte); + + if (s1_cfg->addr_width == ADDR_WIDTH_5LEVEL) + pasid_set_flpm(pte, 1); + + pasid_set_flptr(pte, (uintptr_t)s1_gpgd); + + if (s1_cfg->flags & IOMMU_VTD_S1_SRE) { + pasid_set_sre(pte); + if (s1_cfg->flags & IOMMU_VTD_S1_WPE) + pasid_set_wpe(pte); + } + + if (s1_cfg->flags & IOMMU_VTD_S1_EAFE) + pasid_set_eafe(pte); + + if (s2_domain->force_snooping) + pasid_set_pgsnp(pte); + + pasid_set_slptr(pte, virt_to_phys(pgd)); + pasid_set_fault_enable(pte); + pasid_set_domain_id(pte, did); + pasid_set_address_width(pte, s2_domain->agaw); + pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); + pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED); + pasid_set_present(pte); + spin_unlock(&iommu->lock); + + pasid_flush_caches(iommu, pte, pasid, did); + + return 0; +} diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 4e9e68c3c388..7906d73f4ded 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -109,6 +109,8 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, int intel_pasid_setup_pass_through(struct intel_iommu *iommu, struct dmar_domain *domain, struct device *dev, u32 pasid); +int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, + u32 pasid, struct dmar_domain *domain); void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev, u32 pasid, bool fault_ignore); From patchwork Fri Oct 20 09:32:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932170vqb; Fri, 20 Oct 2023 02:33:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3xixfKdkQxElFy0Q47XI4DqYzTkZDUq9bzJubpsRMgMP5sKxlXGF5wQhFugtFSlxSEuJf X-Received: by 2002:a17:90a:4d:b0:27d:76e2:ab18 with SMTP id 13-20020a17090a004d00b0027d76e2ab18mr1449713pjb.9.1697794415250; Fri, 20 Oct 2023 02:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794415; cv=none; d=google.com; s=arc-20160816; b=dYh8DUOk+V67uAnNanX8oVAGpXoZCEfOqo9d3h1wb8NUzPZJY7vs4fFU4dre1GsrVs sNlGyHUpoF4906D0rnsVP0O77e1ZeSqwHJSMJerkmNjIsr/L5a8ZV9KXUtfbdz0j4UZ/ v8XL2qo4vl3nbAszg/jr10dB6qjrp1FohbqgfV1G6DSPhQRTV6G5pftVjAOWENu3TxCg 4+by/KZ/MywsG17mzhYzgNzDUlZjG7cGTDjikcYqiA+8i9Pes2rRNYwyczXKSaYnM+I9 /xfmON5/5/Ic0nR3NUzFga7ZnTOwtC4jxsb+gE9lar/PSb3dD54Gn4tr597g7xP1SuMt lqUQ== 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=lURTMBZJbTtTrXFmMC/EBBIoEfvhN8dYrqlyQ22r/Uk=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=maie9il+HRLrGXekXX6thYNTltsHyj0LtsCmHVWI9N31XlxPUi7hG+HI1yfKNsA28f MZZS/g5aCJbHusEB28srP2kaiv4zJ+Fssey+6y59MbRc8/uPMfqp9qBL2vf1f8QmUCYy B8AOwMNJaMA4KI93hWVZ4MjBv5U/4cW2hxs65CPceBXuh2cdic7sOr+Nh8rQvsNfB9Ws 3l3S+tvShVNSx+p19yLqUmq+zt3x42t7LYHVTbQsWpBhsA2ZP6vB+A5N5IYHWq0YSdx3 j8WYl54ztPXV80DhzCLT6ur/0I1dvZ5v4njFAlAPXOWyvgOVxa6RSw79QFGBOnASoICx AiqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Dc4z6UaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y11-20020a17090a8b0b00b00276c22ca6a4si4007816pjn.147.2023.10.20.02.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Dc4z6UaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id C60998050915; Fri, 20 Oct 2023 02:33:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376822AbjJTJdV (ORCPT + 25 others); Fri, 20 Oct 2023 05:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376708AbjJTJc7 (ORCPT ); Fri, 20 Oct 2023 05:32:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868BED55; Fri, 20 Oct 2023 02:32: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=1697794374; x=1729330374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ib1IMmuWc4reT62H1wiulcc7gMI+m46FXf0FSrS+Cos=; b=Dc4z6UaXI8oaeVQBnI/cSI7NbEZyXoCRmb4FZr0+qrUQxq1eyljZIhsO gVj21uhxqNQHmj03dKAl50BWq8m5HpuEcJKGDdKAheN02vxHofCft1so5 B2+6KU4pv+Cnyd6sVj2Gs44WHNgaJz/+Cwj1Z8HA1Qlc4VEgd/HFalCcJ Ly18nTgKG9kWesvDURfQdaDcM8ECtOmOduC5qEvBw7Z97+a/JAAWz6XA2 sM0GGVlOBPSfP0jc9HNKEgaHVp4dtSioLfQm5jVoUl+05hDuXNjpPJCl4 5T2zb3nKbpNPlPykERMhxmPHrkW8BaW3cnNYCo9SAVxhQuiUplsV4ynw/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691725" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691725" 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:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906305" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906305" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:53 -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 5/8] iommu/vt-d: Make domain attach helpers to be extern Date: Fri, 20 Oct 2023 02:32:43 -0700 Message-Id: <20231020093246.17015-6-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:33:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266476800405811 X-GMAIL-MSGID: 1780266476800405811 This makes the helpers visible to nested.c. Suggested-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Yi Liu Reviewed-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 15 ++++++--------- drivers/iommu/intel/iommu.h | 7 +++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 8d78149e793e..b47025fbdea4 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -282,7 +282,6 @@ static LIST_HEAD(dmar_satc_units); #define for_each_rmrr_units(rmrr) \ list_for_each_entry(rmrr, &dmar_rmrr_units, list) -static void device_block_translation(struct device *dev); static void intel_iommu_domain_free(struct iommu_domain *domain); int dmar_disabled = !IS_ENABLED(CONFIG_INTEL_IOMMU_DEFAULT_ON); @@ -560,7 +559,7 @@ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) } /* Some capabilities may be different across iommus */ -static void domain_update_iommu_cap(struct dmar_domain *domain) +void domain_update_iommu_cap(struct dmar_domain *domain) { domain_update_iommu_coherency(domain); domain->iommu_superpage = domain_update_iommu_superpage(domain, NULL); @@ -1778,8 +1777,7 @@ static struct dmar_domain *alloc_domain(unsigned int type) return domain; } -static int domain_attach_iommu(struct dmar_domain *domain, - struct intel_iommu *iommu) +int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) { struct iommu_domain_info *info, *curr; unsigned long ndomains; @@ -1828,8 +1826,7 @@ static int domain_attach_iommu(struct dmar_domain *domain, return ret; } -static void domain_detach_iommu(struct dmar_domain *domain, - struct intel_iommu *iommu) +void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) { struct iommu_domain_info *info; @@ -3974,7 +3971,7 @@ static void dmar_remove_one_dev_info(struct device *dev) * all DMA requests without PASID from the device are blocked. If the page * table has been set, clean up the data structures. */ -static void device_block_translation(struct device *dev) +void device_block_translation(struct device *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct intel_iommu *iommu = info->iommu; @@ -4109,8 +4106,8 @@ static void intel_iommu_domain_free(struct iommu_domain *domain) domain_exit(to_dmar_domain(domain)); } -static int prepare_domain_attach_device(struct iommu_domain *domain, - struct device *dev) +int prepare_domain_attach_device(struct iommu_domain *domain, + struct device *dev) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); struct intel_iommu *iommu; diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index ff55184456dd..b4560983b8b9 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -860,6 +860,13 @@ int qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc, */ #define QI_OPT_WAIT_DRAIN BIT(0) +int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu); +void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu); +void device_block_translation(struct device *dev); +int prepare_domain_attach_device(struct iommu_domain *domain, + struct device *dev); +void domain_update_iommu_cap(struct dmar_domain *domain); + int dmar_ir_support(void); void *alloc_pgtable_page(int node, gfp_t gfp); From patchwork Fri Oct 20 09:32:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932301vqb; Fri, 20 Oct 2023 02:33:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHk+HHKTciRcV4Bl2ociR8JR2o3KuNPr0NPTnX+IH9RO5sKR9wb9vauXMN3CioENsVDlPSf X-Received: by 2002:a05:6a20:7290:b0:134:a478:5e4a with SMTP id o16-20020a056a20729000b00134a4785e4amr1451085pzk.17.1697794435082; Fri, 20 Oct 2023 02:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794435; cv=none; d=google.com; s=arc-20160816; b=UT+0YYcy9D5gVQnBrRweoS/bgHIiUy41Z3PvPg+5JWB5GnsbUK3WC7yPj5CuKHTWTE KMMZ8fQS9SFPa4ixHtKAwaMJ2MPzyvJmADqNw59t/Wg23NNsXGRyl2nq1G2oqY0e6cXY vCcMkMB8CPxbnecupluvelBHk/t7ji7r7RnfzkFma6wsLP7UPRDQUwmvYdO/AnIASGK7 2jid0EjPncZl1J7pH/3+L7V0f8dmKkq6cxgjfrrBuRSp+Z+JsGzG0dB294nYRFVTG3se rXbnT9gNKlvMxy4U1/8If1DRxhvLgm2jy0nlIB7Txf/k6wpppTzdvHpWJ9QLLUQaCTqd SKXg== 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=OPNw+O8OIMnZT+a2PdGUWAmhqns6ox0VBxHIMx64Qf4=; fh=IZyM1AM0bATemv9EzafoXv7q5+geru1rOhtf89P+YN0=; b=b64JZLLgI2MNi2H1drbkT4nL04ns7b+FTRiIzGjwDJmlCUc1uXIhGOLYDv7CuEKkUb er0ccG/bLGBRdS0VnhCq0jvSkoUOk44DI3QD0HE0dxelbbIEz5g0COXmx9cucAu2bgx8 T2Po+PlZhjRvnucqDQjUWxYsE0KM3vc0mIs0NxwR+q8esdNIx4D9H3a3yKdlMbeKoBdO Bj/cRYF0dtNA9dw+nUCjrRgdic519a9CpELCXAalnP6BeA2pUFqBm9f1l0lb1yRKQCbe lfs+1h8onZLKNlYnxThYOn4QmzB8y6QQl1WnR4Nwc436kzEcH53+fpiITBkOl+bBUWqA N9Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GAbEhM6v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id mj3-20020a17090b368300b0027450695a78si3647717pjb.172.2023.10.20.02.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GAbEhM6v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 7B75582878AB; Fri, 20 Oct 2023 02:33:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376835AbjJTJdY (ORCPT + 25 others); Fri, 20 Oct 2023 05:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376709AbjJTJc7 (ORCPT ); Fri, 20 Oct 2023 05:32:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD2BBD5D; Fri, 20 Oct 2023 02:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697794375; x=1729330375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SiOnd5LkRXUXCS5mAkcNqw6aqRwvfv1UQkCHpPzwFmw=; b=GAbEhM6vLP/9sCjvGToH8zsVZel/i/KL5vEkRasKOdNhXAZIfaz9pDwK iVgHeWGWHdyv6n2CtSnMpJZ3EMR8RlUEuJEUn2FXal3bhXTuOHQItSnlE YBpZgE05PMI+My2DsFdGs0dG0FYC2ZGgnouw30LkKArKDH0Kp0YmGpOvQ 4c0JyJF3Xrn4Qd84kLOOQ/O+1e/1o8/dHduMf6Q7Hs/P4eaPiYgNcPcom G5OlHB9rKM+y+1R0pwxBRNSWSevdaUhmkqu3RUs9fCaP7iWGP6sMyU30q 4dnIJN+sRfSmQNsSBd4q/8sl1hpD5fBvCSMQ3bRIIbcvbukm9GXCn/k7y Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691736" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691736" 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:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906308" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906308" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:54 -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, Jacob Pan Subject: [PATCH v6 6/8] iommu/vt-d: Set the nested domain to a device Date: Fri, 20 Oct 2023 02:32:44 -0700 Message-Id: <20231020093246.17015-7-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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:33:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266497097773472 X-GMAIL-MSGID: 1780266497097773472 This adds the helper for setting the nested domain to a device hence enable nested domain usage on Intel VT-d. Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/nested.c | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 5a2920a98e47..19538fb616db 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -12,8 +12,61 @@ #define pr_fmt(fmt) "DMAR: " fmt #include +#include +#include #include "iommu.h" +#include "pasid.h" + +static int intel_nested_attach_dev(struct iommu_domain *domain, + struct device *dev) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + struct intel_iommu *iommu = info->iommu; + unsigned long flags; + int ret = 0; + + if (info->domain) + device_block_translation(dev); + + if (iommu->agaw < dmar_domain->s2_domain->agaw) { + dev_err_ratelimited(dev, "Adjusted guest address width not compatible\n"); + return -ENODEV; + } + + /* + * Stage-1 domain cannot work alone, it is nested on a s2_domain. + * The s2_domain will be used in nested translation, hence needs + * to ensure the s2_domain is compatible with this IOMMU. + */ + ret = prepare_domain_attach_device(&dmar_domain->s2_domain->domain, dev); + if (ret) { + dev_err_ratelimited(dev, "s2 domain is not compatible\n"); + return ret; + } + + ret = domain_attach_iommu(dmar_domain, iommu); + if (ret) { + dev_err_ratelimited(dev, "Failed to attach domain to iommu\n"); + return ret; + } + + ret = intel_pasid_setup_nested(iommu, dev, + IOMMU_NO_PASID, dmar_domain); + if (ret) { + domain_detach_iommu(dmar_domain, iommu); + dev_err_ratelimited(dev, "Failed to setup pasid entry\n"); + return ret; + } + + info->domain = dmar_domain; + spin_lock_irqsave(&dmar_domain->lock, flags); + list_add(&info->link, &dmar_domain->devices); + spin_unlock_irqrestore(&dmar_domain->lock, flags); + + return 0; +} static void intel_nested_domain_free(struct iommu_domain *domain) { @@ -21,6 +74,7 @@ static void intel_nested_domain_free(struct iommu_domain *domain) } static const struct iommu_domain_ops intel_nested_domain_ops = { + .attach_dev = intel_nested_attach_dev, .free = intel_nested_domain_free, }; 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) From patchwork Fri Oct 20 09:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp932235vqb; Fri, 20 Oct 2023 02:33:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdWS7d3itGwTaiA69CQlVXnT/4RNKrcxuH3SErxsVm3NyDhrKBCx7R4rNzdpoXLA8gRwd3 X-Received: by 2002:a17:90b:3646:b0:274:b12a:37ad with SMTP id nh6-20020a17090b364600b00274b12a37admr1404601pjb.37.1697794423307; Fri, 20 Oct 2023 02:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794423; cv=none; d=google.com; s=arc-20160816; b=oHvJf7CCcZu9VkAHxOxsokKo6zVZJss8lej6gz2sBps3RARUV/qWZg2YhgIiqERf52 houVnwQpFiiOEEiyUCjkCiTrsDpeqtQcZ31Ra7aWZvPMhK2LB6RTM+wATYHPqhaRqWWY bRLEiPmKD52FGBRcQQuWGcI2tWxz8BRcKNL2t3r4n88un+fX8ktBh1U8Zsoda4QKmKJ1 rPfZFGCB0nSQ8cxmbJlmmf2UTtjECP1NuUVdWZ2zDAVIRHcrAIm2+T3s5MnsWp0s3OuJ nzMl5+ksbR7qqimTZPWslOpNFzfwA9fgAjbsCblC7P4BWvlet0wQYveWdQOrWXvc0MJ0 4IZg== 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=UKFvIsAZU2WJc8bTcq23EcWckb8rg70IVVyq/f8dFu0=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=HcVfXo+Gn00Wv/DuJDPmAbn7S9EgzgPSd3h4h9UqHgNuLqUi21xpaUAlZFFJeaZBGu 9LELgNCQP18ir2LXFlWj32/Y513GB6XI6PImtOibBqRjsYfEDCNkN2ZpUrJSAWNuEh2X CsE/Tki5khDmQjlA21zo+JDHjaSVY71Y35sHXLUTdDNm4K5g7hvvyjWXuhRpe+qqgcA7 xrC1/CFbW2tXIT7DEL2BarQKkT6TIPsjTHeWZab865nwzkBWShLg1HQIQe+n0AA7ScHk VEU5Ox6t7l54CwZez0DN2CJvhK1wa4frwyo7tDxoomizd1FAs6KqhfgPlt61ZyXLwZdZ VaHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b8yipmwx; 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 s12-20020a17090aad8c00b0027768e7a9aesi1454459pjq.120.2023.10.20.02.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:33:43 -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=b8yipmwx; 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 1EC3F8260C0F; Fri, 20 Oct 2023 02:33:40 -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 S1376805AbjJTJda (ORCPT + 25 others); Fri, 20 Oct 2023 05:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376728AbjJTJdD (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 C0CD2D63; 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=KFY6DFqQdqzEYR8dbOOBhT/l5R4uXZhFdyT3GIHn4js=; b=b8yipmwxKtahFd/uMSiql8+IDUeohAWadYqTasLREw5pBUvfQBOl2hRE LrOwCi8KcfVkJq7J3/aZgX7UPt+Byfv3tYAFf5/QiPteOscIdRvs6r6Xs X7f5Guv2lOFQlThW6XuiEpGv3xwbnFdNAk4IrHCiafJxUC0Hm7UqcVrOp ICXLlJ+AOGjgsfOT/s+XyPjqXTStOdZl8s+3UHjgOuZZysHsLH5Zugm/F TvzUietGs/ufI+sb6mceGZb+XRb98KW9uR3ayooj96qznhDuMca35/4SJ 1lGgjzgl0P7kZXRtcFunH7K1j9l+RJ/xLef3LtfgVuNLeLlOfOEtijMo7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="450691761" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="450691761" 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:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="733906314" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="733906314" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga006.jf.intel.com with ESMTP; 20 Oct 2023 02:32:56 -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 8/8] iommu/vt-d: Disallow read-only mappings to nest parent domain Date: Fri, 20 Oct 2023 02:32:46 -0700 Message-Id: <20231020093246.17015-9-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 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]); Fri, 20 Oct 2023 02:33:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266484740319494 X-GMAIL-MSGID: 1780266484740319494 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 | 9 +++++++++ drivers/iommu/intel/iommu.h | 1 + include/uapi/linux/iommufd.h | 12 +++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c7704e7efd4a..a0341a069fbf 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2193,6 +2193,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->is_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) { @@ -4101,6 +4106,9 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, domain = iommu_domain_alloc(dev->bus); if (!domain) return ERR_PTR(-ENOMEM); + container_of(domain, + struct dmar_domain, + domain)->is_nested_parent = request_nest_parent; return domain; } @@ -4839,6 +4847,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/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index b4560983b8b9..0539a0f47557 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -593,6 +593,7 @@ struct dmar_domain { * otherwise, goes through the second * level. */ + u8 is_nested_parent:1; /* has other domains nested on it */ spinlock_t lock; /* Protect device tracking lists */ struct list_head devices; /* all devices' list */ diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 9b843a197ea8..c8f523a7bc06 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -439,10 +439,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