From patchwork Thu Sep 21 07:54:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 142964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5182173vqi; Thu, 21 Sep 2023 15:36:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGozc9Hlurph6cl2zSpMWz0S8RJWWlRQD55YcZ+7vVNEZpJthG2gjitklAwpWvxW/XS7oIN X-Received: by 2002:a05:6a00:2289:b0:68a:5449:7436 with SMTP id f9-20020a056a00228900b0068a54497436mr8138691pfe.32.1695335788714; Thu, 21 Sep 2023 15:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695335788; cv=none; d=google.com; s=arc-20160816; b=m4AzS05pT0Mcv3RPJkKWy3MRW2aAb/2UyotEMEp228713IzDYY5xbgvCtLeK5DLIG6 LosZoFnusipGaxl3o9DgYXcIp1fGjWxGXXdhvj9J6W2drpxgCQAFtWuFX2RsgCWINH4X dBjSy4yFLFMLx7mxwP+jndZuwX6D65bv2JQua0CK1tODbG8lhwpgD+iTt/KlZWVXPalf Eonls3ALZiqDgUuCHZelVlt+n23AAvW2kOUAWgiYYZgdxE02ZfB1KKw7aNtYQh3BSbWJ fhbsf47WY2i5AiYT4YhGZPLyOAIT3yike1ZNeYVMAFl7WM43Es17AidH98I+wT2UOQCi 5LzA== 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=awtNc02s8+T0HnA7RLomW7nQk3tkQfDW4xJWpBc7q3c=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=h4B9OghPmbId95WDoxoV1NR11kVjVxhp8I4CO4Mxr0fmtkLFO+rSusa2EYrqQc5zxp FzPO/vKduSAoiGqpcBmuqLMWRtgsPFcIlFi3OrmIlbPcToproeNI4iY7qLk2hMHNQUbG JqlNEZztJV09+x6W5lxWtdGZ14VGxoxt+zMaTkB2yERLxXL1Cm66WEJzjHvPUp2F7/sK Zhmn1ENln/UiMYRNAdBnZKQa6PxFhA/Xa6jCBwasNiUwXoa4Yco6LnCin+QI9zakY9Hs 40iyGXQUfrtvURxfpErQw3JaizVvrA8Khnf/guPJLYKZ4+X5KdVWDoFU3qDUVfReLPtM HXlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=clQJTOPR; 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 i186-20020a6387c3000000b0056532a14f54si622360pge.900.2023.09.21.15.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:36:28 -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=clQJTOPR; 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 4E6E48241E1A; Thu, 21 Sep 2023 15:21:03 -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 S233194AbjIUWU5 (ORCPT + 29 others); Thu, 21 Sep 2023 18:20:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjIUWUl (ORCPT ); Thu, 21 Sep 2023 18:20:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D827DB9; Thu, 21 Sep 2023 10:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316241; x=1726852241; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+z5+5JtzJUHTDziH7GhRN2oy4j2s7kOBGRou6Rfz7PQ=; b=clQJTOPRsL93Dn+FImNt/8MPtkrIxdixF8hEXdjzYlIkLGhFQDQWQqzL MLNLKbEIs2qidBgrZ+EFx4k01ikA+w6h1RxFD1mOWddO9LAl+URcaN1lS 6n3qzCOIMmwlXq8eULWVoYq9sDmLKuP+BF2EIgX9hdyDNAxX4r8DccBG4 blSuJjSFNUmHHncb3GOo3BlHX7QHBCpcfTXVYx6yo+pC1K0jOJanyp2Y6 v70f6ASgi5NF6nJPSLz6GjQP+3sCrRcrd+/uw14OGgaZrBMtqMjdaqX54 y2O4D9S9eEeWm0L5FLyFSDCtKhegR1oEi+vZVjLA3EdbJhd0Z+QTGNQvt g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764372" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764372" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523013" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523013" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54:43 -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 v5 01/11] iommufd: Add data structure for Intel VT-d stage-1 domain allocation Date: Thu, 21 Sep 2023 00:54:21 -0700 Message-Id: <20230921075431.125239-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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]); Thu, 21 Sep 2023 15:21:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777688420172503786 X-GMAIL-MSGID: 1777688420172503786 This adds IOMMU_HWPT_TYPE_VTD_S1 for stage-1 hw_pagetable of Intel VT-d and the corressponding data structure for userspace specified parameter for the domain allocation. Signed-off-by: Yi Liu Reviewed-by: Kevin Tian --- 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 2083a0309a9b..18a502e206c3 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -358,12 +358,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_TYPE_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_type - IOMMU HWPT Type * @IOMMU_HWPT_TYPE_DEFAULT: default + * @IOMMU_HWPT_TYPE_VTD_S1: Intel VT-d stage-1 page table */ enum iommu_hwpt_type { IOMMU_HWPT_TYPE_DEFAULT, + IOMMU_HWPT_TYPE_VTD_S1, }; /** From patchwork Thu Sep 21 07:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143108 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5281366vqi; Thu, 21 Sep 2023 19:45:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFO0G9tOHbJ8Td8bUx2/fuh0jKieDd/0RukJqTIxuGmi3MQggJVGSq7XEqmr71PNkBMWd5D X-Received: by 2002:a05:6a20:9144:b0:15a:4c23:86fd with SMTP id x4-20020a056a20914400b0015a4c2386fdmr8316913pzc.19.1695350748120; Thu, 21 Sep 2023 19:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695350748; cv=none; d=google.com; s=arc-20160816; b=wjCQOkWFfSbIBsBAGk+BxjPFPx3Heohfmoe4/ulmRYe/KvNx4KfM5tdGXzg16rQzUN K7uJ8h9t7tT5RT+VcBL3n+3GdXABx10xJGrHbfezD1UGKZN79QCjLnkLlfZyyLGccJRQ t8+yU5BFnuTFgUjJAgIusoBcTy8+0iUccv3j+EyCAU7o0XbDfXCxIjJXpotb2VXASKnq Wc5FMlgrozw1vG36+UVFUxNnewL5G9Zy33MatpRQ7reW32v0K8nNJbWr+y0cegozUpIR RJpNcElNeTP2GGlAy64y4fINgsjJioZerCugQAJJlwcW6Ec4m3LO5naUHG+puESK6VjH 4rjA== 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=3hvulYsPgV27Z8Orcb1PSTQXzFEgO3g8Ic3OB3m5z4k=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=SVwNCbOcQdweiK0CyiUoghq3Fzhx6ntfX+WXHY4AYGigwewCGeL7/T7sfGUEtsMqTd Us+sO5mv1txZ5ps2vcSMEMn8CTGvOSj0VZWu2MkpCMc5QCB6TK0Zw2+eApZckDv96Ls4 Z2B7/tE1KS2o65Eo7iMEMxW3LpRePd7hd5Wgy4V5aNYPFfYENSKNsCuZO3f9Pm2vr8c+ Z+ZbDIt/B9h0o9kU13V5QmMgOfRY5BE4httaWN3ujnJY5b/ERr+jYiZ95jEnND0pnQbi 0l15Ku3EBCsgeFl17epyMycTxcRL0OEsSKa97T4b32voCop02hX/gu1S1FdxOtI8MwKQ j89w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kXGNE3tn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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. [23.128.96.33]) by mx.google.com with ESMTPS id gv24-20020a17090b11d800b00262ebe643a2si2775970pjb.186.2023.09.21.19.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 19:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kXGNE3tn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 DAD0482A88B5; Thu, 21 Sep 2023 14:19:33 -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 S229691AbjIUVT1 (ORCPT + 29 others); Thu, 21 Sep 2023 17:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbjIUVTE (ORCPT ); Thu, 21 Sep 2023 17:19:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E38BC7DBA; Thu, 21 Sep 2023 10:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316242; x=1726852242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2qafvDTEA4tHJGGUOtUPjMOBwx7ln2B9qY4E8ARD9Lg=; b=kXGNE3tnjII73oaq+TCn5QHy2JltX0wmnnWnFwAj0MMCJzLexs/Ub+/M 4CVR4+9m2SQ7RPbKSZ2aOyQOjwnAvR3kSspiK+B3XskX/4DU1eZqwgh62 ngl9z2yq9jKJdJKlhpxfC0PbIO6wqz4duzzXYIUTtKgALRYa0vO/ji+7K Bgmxe6PXX0O7jrZMBYvumQ4ntEtQudiU8nFe8nqSTgmAYWhx5c97LfeY2 wjc1L1xSPUKIpa9ptPx7ggSTNImIlkEvOcig4miYnFokle3PoJ6DpxJBi RBSgi6qNPNGfH4+ZDn/zIEhIxrEn0DV827iQhfxouOCF/fOzOGKyUAlcz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764386" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764386" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523053" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523053" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54:44 -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 v5 02/11] iommu/vt-d: Extend dmar_domain to support nested domain Date: Thu, 21 Sep 2023 00:54:22 -0700 Message-Id: <20230921075431.125239-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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]); Thu, 21 Sep 2023 14:19:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777704106099658552 X-GMAIL-MSGID: 1777704106099658552 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 | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index c18fb699c87a..4a7f1cc16afa 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -597,15 +597,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 Thu Sep 21 07:54:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143199 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5348382vqi; Thu, 21 Sep 2023 23:01:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5OQ9Idj85BcLwl4NTvrtAjaRH/MUcfDziYWhyME4//R/326PWBvvF5vOnYQAkH7WpDhKw X-Received: by 2002:a17:90b:1e03:b0:273:e073:1d02 with SMTP id pg3-20020a17090b1e0300b00273e0731d02mr7816911pjb.38.1695362509733; Thu, 21 Sep 2023 23:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695362509; cv=none; d=google.com; s=arc-20160816; b=z42AToVQcSGSBf4fPoBGyK90u3RXLdbpDjd55l9YSRKeUG7CtnIkmKSdSZTuOsSkow +e9HkGwR030DgEJeQf5DJtdvRtuCvdZGkKO9MQ1UyImXRGJl6lgqN4elBYCS4lHihdsN FNr/GmfjnBHjaEszEubJZLlkuUI5z++v+29D/oKfiubDLrWvjcITSabRMnWpnGNi91dM IkfOZ4Nefe6BKc37sJG0Jsl7qBqSIhLjFehlvl0dZ5OtUoMNPpXv20vUlGSpBMKovgj6 cFx83cHaRlBT/3nTbThIAOqAIbAcX0GRpeifEo386sq543u8KrV3rd7lIg3yTHVQNpfa Mfnw== 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=hvFeGDYpovhQ1giWbbLY5PK51AM+cPeqO/5d3sFXa9k=; fh=4LHR+mUxVAoNBe0WLhXgnzbMgf2Oz4cgAvP5fO84YrI=; b=fyjg9lkird4uInIxNXhwtV/V3EjGRMwTxD4TlYQ9G8M+N2bnOrsRmnyB+6hn1dlMY2 0mBYzBzM0iMcJ1bryRAi7R8e774NRVnNteQIw/3fTayuWgcUxtDvgv6sVWZqxkVMvYsx BIMFrBTWGWWIHSw7Cu/yK4UIbbO0l0mr3AKO60OfmE+WY80EF3FXoks5njCsipRzRuB0 8LhIC5JQuzhViHmCwu/9eHiflQu+zBPe7NL1dWo98a3aRsXjYjs2oUnM0jXiOR/Bh+Jo el6fyTFyFfIcLj5bj9CFNSaV8cO50Yi+c3w3Gl0tjqLaKXqtTgGNWxzEYqZl8YGaj4+D 2xHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z5qZI3t1; 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 x20-20020a17090300d400b001bbc40ac12dsi2938892plc.132.2023.09.21.23.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 23:01:49 -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=Z5qZI3t1; 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 BADCD8082054; Thu, 21 Sep 2023 13:10:44 -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 S230232AbjIUUKo (ORCPT + 28 others); Thu, 21 Sep 2023 16:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbjIUUKY (ORCPT ); Thu, 21 Sep 2023 16:10:24 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C8FE9012; Thu, 21 Sep 2023 10:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316261; x=1726852261; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t+k2G75egWOCXj1vZiBpp5H5yozqcf2ftiKJs05q63Y=; b=Z5qZI3t17/SEWbtr33vbiDnrXcX4YECTIwGXhvStZRbGTpHdss3c+4yy qMQbDU3KNcsZtdZThbVp6is14/B5+6FppgvOmDA3Rse8COaRXfgoxTjMq USbesgx0wW1HHFGMPI5kMcyv3uK/YI7qsY337cq01ariemYi3x7mxORNp mpNjO1e/C6p2j/80MQIL3dDWlID2EpMHND+XUKYiR17xlIVsCDqtVWRzw uVzh/opRmqzKBCDGxyEJ12maTPgB3i7ns5TNcRESnYAZzSeyv8N7iHk+r Q2IMEe52bd0JLkRMGgSIllqsiwvbRPo6sJIphy4bNDDI2TJZkUgzffp0W w==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764399" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764399" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523067" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523067" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54:46 -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, Jacob Pan Subject: [PATCH v5 03/11] iommu/vt-d: Add helper for nested domain allocation Date: Thu, 21 Sep 2023 00:54:23 -0700 Message-Id: <20230921075431.125239-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED 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 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:10:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777716439095427208 X-GMAIL-MSGID: 1777716439095427208 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 | 54 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 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 4a7f1cc16afa..a82e232abae0 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -865,6 +865,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..012d5ff60265 --- /dev/null +++ b/drivers/iommu/intel/nested.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * nested.c - nested mode translation support + * + * Copyright (C) 2023 Intel Corporation + * + * Author: Lu Baolu + * Jacob Pan + */ + +#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) +{ + const size_t min_len = offsetofend(struct iommu_hwpt_vtd_s1, __reserved); + struct iommu_hwpt_vtd_s1 vtd; + struct dmar_domain *domain; + int ret; + + ret = iommu_copy_user_data(&vtd, user_data, sizeof(vtd), min_len); + 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 Thu Sep 21 07:54:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 142981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5188708vqi; Thu, 21 Sep 2023 15:51:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNoDuVQPETRg7asGBrfJpIsZ+2vQsyvfw70wPrbYrGWUt14XjL7x1KlgrolRYnaNTzMdM+ X-Received: by 2002:a05:6a21:9987:b0:15a:7d2:a418 with SMTP id ve7-20020a056a21998700b0015a07d2a418mr1399827pzb.19.1695336704771; Thu, 21 Sep 2023 15:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336704; cv=none; d=google.com; s=arc-20160816; b=ivTM1Z760KsyWHcH0mlVrWEYwxBrwdtoHFkgmS5ZAqyp58Rc0CsQV2rgGhOwaZ7b72 IDQUEUUPaEvh58kjpulGatd/3D3kpCzTb87RyhsXrL8CrSeZ6O3JN76yevVjhGaws5PS AFRo1CTeqmJzDvDMfBwEicQekNS9k9HQbSEJ4JMJn8AUMP6HJevu/BmK9K8zpHM6lqjZ 4iN1ZB7WQSFgT8bBrKfwegZqkoQK9D1WXoAd4zqObCFB4yzLzZUTQc42sTFHqN6Mg8c+ Q5MV0LtmQAIWVzuOC+NraDEKgnSo01EP7n3kXZ6iRgJyEmi5Tpx5BxGDjkkzF8rs4Hp8 GgQw== 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=/5Z5+c1XIKFByh/O88M1hFMZvo+HIaGI6QQ9mXZwLnQ=; fh=4LHR+mUxVAoNBe0WLhXgnzbMgf2Oz4cgAvP5fO84YrI=; b=TDetGNjbE1FavsfzOd0PGo6cDgcBVZC9Ora4X7aIysipYagjO5KFnKcYaCQH17OIpL udkBLuzwFmCvvVs4oo1WUG1IB9BghvT2un3b0dhlPmlPuoSQwvtNKZJ8HCsaq7Q9jBoK NpM+Ah6GZsktIt64lajce7GouAZyxD+85lvFebCYpIcxgZcOuo3V1HU/cYtIM4nQNAZj n1rpmAZARHN58M2e5T28wHdMp0JbL5eULwgywtXBIUjxUWRjs6uNHqPGtJ9924OLhouT o5s8LShSAu/NCq+ohfFpT28Y9bORp6WnyJG3So1oPqdqE3xi/L+3cRMRdDEynU+FrFJg PZiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RUnbErXM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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. [23.128.96.33]) by mx.google.com with ESMTPS id w64-20020a636243000000b00563da455862si2456808pgb.311.2023.09.21.15.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RUnbErXM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 20AD6825CEDF; Thu, 21 Sep 2023 13:20:45 -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 S229781AbjIUUUU (ORCPT + 29 others); Thu, 21 Sep 2023 16:20:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjIUUT0 (ORCPT ); Thu, 21 Sep 2023 16:19:26 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF75D7EC4; Thu, 21 Sep 2023 10:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316261; x=1726852261; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8kLHHoEGx8VOMsxlCOgaSdq9RP42gUjf6mYcaQ0jE14=; b=RUnbErXMBGqXSAaid93iOklccURgEiJnbkOhAy/V5qhJEAEYn6WJsT6O H5Rg1aUFhJuCsK4JpPfBVdiuzswelqWLTdP6XvovTOEsMjIUymGnYor2H /FEfquaYXh8E+KW5puSGdyjzxbWMH4qZ0ZNf26H2baeY/HlE5lnd9BbZP kuh7jut5IB2YkYppHPu76fwWVCrgjbA0AE8x4f03rrWSKOM2a9nZqJ6RI FW1XJfdMeTpi2jo9E0z2jfhVN1ozJQCZVREHhBgIpMxL6Ib+Ue4NRiYRb wX5xnVGAqQN3mVbma7hXQj0eAL2BWBne8CPwBW4w3XChmzm81h0llWmVt w==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764411" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764411" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523097" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523097" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54:47 -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, Jacob Pan Subject: [PATCH v5 04/11] iommu/vt-d: Add helper to setup pasid nested translation Date: Thu, 21 Sep 2023 00:54:24 -0700 Message-Id: <20230921075431.125239-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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]); Thu, 21 Sep 2023 13:20:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689380648506824 X-GMAIL-MSGID: 1777689380648506824 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 | 125 ++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/pasid.h | 2 + 2 files changed, 127 insertions(+) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 8f92b92f3d2a..8a290ab07697 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,110 @@ 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 first-level domain nested on a s2 domain + * + * This is used for nested translation based vIOMMU. e.g. guest IOVA and + * guest shared virtual address. In this case, the first-level page tables + * are used for GVA/GIOVA-GPA translation in the guest, the second-level + * page tables are used for GPA-HPA translation. + */ +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; + + if (!ecap_nest(iommu->ecap)) { + pr_err_ratelimited("%s: No nested translation support\n", + iommu->name); + return -ENODEV; + } + + /* + * Address width should match in two dimensions: CPU vs. IOMMU, + * guest vs. host. + */ + switch (s1_cfg->addr_width) { + case ADDR_WIDTH_4LEVEL: + break; +#ifdef CONFIG_X86 + case ADDR_WIDTH_5LEVEL: + if (!cpu_feature_enabled(X86_FEATURE_LA57) || + !cap_fl5lp_support(iommu->cap)) { + dev_err_ratelimited(dev, + "5-level paging not supported\n"); + return -EINVAL; + } + break; +#endif + default: + dev_err_ratelimited(dev, "Invalid guest 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 Thu Sep 21 07:54:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5336301vqi; Thu, 21 Sep 2023 22:27:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHy3W2lIlkGb4r1nKah57L6yITJK94pAmIdYyiHykTTSAxuTss4D2QD4NGfJYeSwvjFgB+1 X-Received: by 2002:a0d:e813:0:b0:58d:f1fe:5954 with SMTP id r19-20020a0de813000000b0058df1fe5954mr7697646ywe.32.1695360462882; Thu, 21 Sep 2023 22:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695360462; cv=none; d=google.com; s=arc-20160816; b=mKD0umRubt41hN2mAvIiSqp9IiJrfPcyWsVgFe1HwN8O41VutL41jioge03gWEfYsO 2N07mxKFneaWq2iMYLNjkuo9fNzTxRnhPuv74Or2iUYw5OoGgn8++U7kZaO3imM5bLe8 YPKA7OzUCG+itfWNn6wwb1+kSgcU4VjSWSeLzv7ozECKsikWurmIT3TefE8IA2CqOEhJ PCe7foiOMBOGS6/gCQzxPQmcGTsgT46c2uLj5HeO8pR+3Ew9MtbeYmfvnGOem7FgkExE atqnOaaVDP55w3k6xaHYnscqC7JNHUIxIaox75oM8QwpDUw2PyrPnWhsL1wT7SmWpsTk 0pzA== 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=10TL/EVB4eMLw56XjFleP2GL/QjsuikXWMZ68nCBGPk=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=F9QjnAyW0wVT2cKkrZv5SC42LmiL8rA5jDJhqdxrowAtQY0UlXrgyy8iGcjJS2mVcD o7EKTTNDnKz28gpazEXkAZR04V9fxl/9h28DHzG6NZrOcvM6wEJKsUfa72m4dRQlubQT WoBDOzcfGDBAJF6Ptu87ProFcquSRIp/QxEEg5DDuFONroyBCMW7AkO7ifz7nTRn2TQH /ctNyuU0wJDwmtmNS/xbzdoIB5ki8MQNxADdGlc/q6QV6a8N7db6lWFQWjo7pI3xBXbr 5a6ys4i1HYyy3bHcP2PgUizmnD+BhUvQm1x0IHpDEicdhSZ7wrvZu1sSaZqdR4LyZg4f HG8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hgdbIRys; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b00563fac86c55si3051298pgj.134.2023.09.21.22.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 22:27:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hgdbIRys; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 0E8CF8097284; Thu, 21 Sep 2023 13:23:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231737AbjIUUWz (ORCPT + 29 others); Thu, 21 Sep 2023 16:22:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjIUUWc (ORCPT ); Thu, 21 Sep 2023 16:22:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF87C9027; Thu, 21 Sep 2023 10:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316263; x=1726852263; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aQnDRlYxK4u5p5FtxL9YdlZ+I6ppODJXxT8vFfaQbkw=; b=hgdbIRyswsM9tk0tgkMHt8NE7jufUXckrOB9FpJDJRY6lAESWzYKfEmS dNl2OHv1os18uObbxzS66aTVqtY9YYoFqYEbf1ge6ci8zovbC1Hdnx1PV dJ/G8McR4pgIL9dm0a2d/NQOzHA2tWkL9bKqw0/e95xef6JIjrj7Gyrso 9seSy/cQh9E1EAli7v3JyaJSWdeT2wtetCdPaCdV3skY4zOsaZqKnkoLf znAtlcmmq4UgEbPimxmbf46EXvNuuj7f7ZCsdy7p7KA912rsfGP+skGJk Y6iEBOdkgnXIBWIcMRgxjqPzJolBmoq0scF9XTU3E9hfRkVWmJnd5BVaQ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764426" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764426" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523117" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523117" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54: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 Subject: [PATCH v5 05/11] iommu/vt-d: Make domain attach helpers to be extern Date: Thu, 21 Sep 2023 00:54:25 -0700 Message-Id: <20230921075431.125239-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:23:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777714292512443866 X-GMAIL-MSGID: 1777714292512443866 This makes the helpers visible to nested.c. Suggested-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Yi Liu --- 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 4ffc939a71f0..7b75f407c623 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; @@ -4102,8 +4099,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 a82e232abae0..411cde769787 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -859,6 +859,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 Thu Sep 21 07:54:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 142828 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5053231vqi; Thu, 21 Sep 2023 11:28:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBwnK86RBC9CpveJgpz13ygT/I0q5CvIkxBnUa49J+kTfpo7Wuj087pSWXE7stTyh96IzK X-Received: by 2002:a17:902:6bcb:b0:1c5:634e:e12c with SMTP id m11-20020a1709026bcb00b001c5634ee12cmr5147616plt.37.1695320889925; Thu, 21 Sep 2023 11:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695320889; cv=none; d=google.com; s=arc-20160816; b=oDbWK9uO+o9e0gqHLsWx1FAtHsKT+Agdm+GGtRZE6nECeYvCysW3uls7tifQMjW9Wj 41slJelUIZpb7x/deGi3RqrXhvIM4mJ5YlRcW2bvh5TVkx0jWqX0EXM9keK+ny4HyEAY U0jPOr3x4tTllDD/9O4UPRsITh/k6xN9qivOZwguT2RKSm0fhZVY83LmRM07VFs7cqoH tuHvVVfKBlK0myFAxaPPVGIC8fdVCEgXyYSgsKt9FMyDjmGi1sIEGxvIWiWjON+nCrq3 gTlgS+KAbKjliiKliW7M7zND5c1IiQJklCw/n1BqEqgg+s7rWfqpOhJx9+xVIoBwQS52 GBPA== 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=V3m3usbyRqZdXZUpEakeHDdqVZQ5/OHwNosqqkD2OFk=; fh=4LHR+mUxVAoNBe0WLhXgnzbMgf2Oz4cgAvP5fO84YrI=; b=ogVKoYAL7lkTnPIG9dZO3azwtSB3QQkDf4wvtJlFL/LTcN/NEfgynTcyNW5l1s3d4R BUIo0rgUuMk4Mlz8lVVX97N/AAa91XhIb9TqrB2PqacghWLdGKopUXoF70F0c8LYjuJq 1dt8BL9VxIx74KHcm9WseAFQY1Rtr4pVH+uxxekDpiGsCyz5TseVW+DDDBKrpEgimSO0 uPZ7u1Ftl12SZcliViYwODY6rGhkPkMMPT4lWhHqO2GZlLMPO4SZvPFF7uuPwDFBrKXW EeuzZ45frYfqEGEbCPREvvy/OspygGLlvAnZzRcppKPG4M52tQE6/bknX6+zFW30EF5C UcuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AI+OKJaL; 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 d10-20020a170903230a00b001c5b9ef1d34si1998926plh.340.2023.09.21.11.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 11:28:09 -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=AI+OKJaL; 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 19E5F819BB4B; Thu, 21 Sep 2023 10:23:26 -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 S229796AbjIURXV (ORCPT + 29 others); Thu, 21 Sep 2023 13:23:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbjIURW5 (ORCPT ); Thu, 21 Sep 2023 13:22:57 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01EC6901D; Thu, 21 Sep 2023 10:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316263; x=1726852263; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TKXjR4j9x1jDQI3p6zjb5Rlhbhk6itQVPUNBhJA2+j8=; b=AI+OKJaLLtZOh1MPuG5RMXEbkuHPxHAWEfEkA/prH+x3l50Li+BAHC0E SdNpIjGZHNARKA2a46WKf5j46QnAovK5WF9IgYXl9TdeTaBgBxx14bhAU 6hTR1rtoqEc2tc5QxHZV9MyjRnkPxRYpC2pwkyWVD/YBhpla3E7Yn+iK3 AGOFamuF6KJ/QRlbmWtiqyGOwAjzqb9MJkVIsXnnJjf06M/OUM9K2wW8u 7jBKtH1YxgGM/AARNh0Ku2jPAXOSwTl6vfIXLhIBmTrKZHV2u5Ffn160S 7zFO6D7HBGV+q6HWK/FR6D6A4bpVLm9r1kHq+VRqoo7SbDdnw2izW44m6 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764439" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764439" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523157" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523157" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54:49 -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, Jacob Pan Subject: [PATCH v5 06/11] iommu/vt-d: Set the nested domain to a device Date: Thu, 21 Sep 2023 00:54:26 -0700 Message-Id: <20230921075431.125239-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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, 21 Sep 2023 10:23:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777672797848232231 X-GMAIL-MSGID: 1777672797848232231 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 | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 012d5ff60265..f9c6ade72416 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -11,8 +11,57 @@ #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; + } + + /* Is s2_domain 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) { @@ -20,6 +69,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 Thu Sep 21 07:54:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5385631vqi; Fri, 22 Sep 2023 00:36:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpm7G4t9+RbnKy9EtRYrPsNJxneVTjAGxuqWiGfEPurqXc144vlaLlLu4Zo7iT6F/OJlna X-Received: by 2002:a05:6870:7029:b0:1bb:a468:9e6c with SMTP id u41-20020a056870702900b001bba4689e6cmr7781350oae.23.1695368218128; Fri, 22 Sep 2023 00:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695368218; cv=none; d=google.com; s=arc-20160816; b=aaq9VJOBh06bfluotwIVhpaWveuGKP+fF0qe61XbsYGqVKsXrPXHcim2mZiR2O0r/v 2maWtMM5cFH6AM2l9bIOiLjUqCotoxd4WAfnJpUiBwVWByjhiDzo6CXrjNojw8epujgY DBFxqLhS//zK0IZi7iJ8RB9XWGz/TnFTN6jzAS1gVzw7P7CyvhcImYhZkhKOroiqzYo5 RxYChVS6q4p3AIpWc53CMhJWMIniC1hQbyBSfDa7ie4WDoGwj6akjXTPmV/RJaJEIiKp agb3EA/WLebkuAPlxaBDe75DT50phFq3VmzYGAhnNPiPlqPdYOqa6xUn7eDAsSWukIX8 f0wQ== 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=8udoG3rzquTYDtvmQfSiJYZO3xj7W0ikf5XL/vIs0I4=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=msXVFM1YH+K8IUTorGvjDyiLzv8xFfJiijET5R9dgnGx52uaVVFmN5F8AtpL2qqomO MDssn3BEV/YId7hr77t11G8hJrBX+FuSfxIA/W72HnlY3HJ5MVjz+gN/0VlW0seyWwvF S4e7ghb2eFZU6o0IO02WSe7BPZX7Ry6KDYGS7o5CfXFHp3ilMcU5OtnR18R/f+QpI7zV IpIf4rkzyUDrgAPciMRFjW/kuvLxBzZKIv7ON7GFuh7cNvKW3Gg9DnGy60TM58sh4K9a HHusk8l/bQshUBLiQBj0ERJ0aDHTJy7HaWurhAQixgZqWiJnbg4Mv9DZstFB4yafRwqq HBcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jcDgCkeN; 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 bs193-20020a6328ca000000b005526bd0c526si3053933pgb.641.2023.09.22.00.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:36:58 -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=jcDgCkeN; 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 2258882F34AD; Thu, 21 Sep 2023 13:20:54 -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 S231379AbjIUUU3 (ORCPT + 29 others); Thu, 21 Sep 2023 16:20:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231921AbjIUUUE (ORCPT ); Thu, 21 Sep 2023 16:20:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF62FAD21; Thu, 21 Sep 2023 10:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316280; x=1726852280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S7OPx85gN2G+8RHarCfjHgmntx38eLMzDBOfexGdmYM=; b=jcDgCkeNqhdoytre2wP3usuY6Ibq/k2L8CW0yCKU1TLPiDv+v3HyxDnS aXzEpvR7Rytu27rkHs2qXsAS3Yw/n/BjTR9/ayUwEL3TU9f0nheYRuPts PIwsZkHF+dGYp0s+AK6HN6VnXQVESjr/hBQ50DPGjjVlne7pGVZGy+H+6 MfE1hYK2fHZT01uhnhikNx/EC+XDe0izY15KvBsWrgcbcQfALqKCznqOz C5tolYr0haI8xyDPIzVCDh8MohakGLPH6/VSd7PnHDxx5WXjDP2ttP+qw yn8vFN4LJegOghvfva0y8B/E0MSDOlrr0X/LrAArw56x6YMis28F8RINI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764450" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764450" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523164" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523164" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54:51 -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 v5 07/11] iommufd: Add data structure for Intel VT-d stage-1 cache invalidation Date: Thu, 21 Sep 2023 00:54:27 -0700 Message-Id: <20230921075431.125239-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED 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]); Thu, 21 Sep 2023 13:20:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777703310829571459 X-GMAIL-MSGID: 1777722424329250189 This adds the data structure for flushing iotlb for the nested domain allocated with IOMMU_HWPT_TYPE_VTD_S1 type. This only supports invalidating IOTLB, but no for device-TLB as device-TLB invalidation will be covered automatically in the IOTLB invalidation if the underlying IOMMU driver has enabled ATS for the affected device. Signed-off-by: Yi Liu --- include/uapi/linux/iommufd.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 18a502e206c3..3050efbceb57 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -510,6 +510,40 @@ struct iommu_hw_info { }; #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO) +/** + * enum iommu_hwpt_vtd_s1_invalidate_flags - Flags for Intel VT-d + * stage-1 cache invalidation + * @IOMMU_VTD_QI_FLAGS_LEAF: The LEAF flag indicates whether only the + * leaf PTE caching needs to be invalidated + * and other paging structure caches can be + * preserved. + */ +enum iommu_hwpt_vtd_s1_invalidate_flags { + IOMMU_VTD_QI_FLAGS_LEAF = 1 << 0, +}; + +/** + * struct iommu_hwpt_vtd_s1_invalidate - Intel VT-d cache invalidation + * (IOMMU_HWPT_TYPE_VTD_S1) + * @addr: The start address of the addresses to be invalidated. + * @npages: Number of contiguous 4K pages to be invalidated. + * @flags: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags + * @__reserved: Must be 0 + * + * The Intel VT-d specific invalidation data for user-managed stage-1 cache + * invalidation under nested translation. Userspace uses this structure to + * tell host about the impacted caches after modifying the stage-1 page table. + * + * Invalidating all the caches related to the page table by setting @addr + * to be 0 and @npages to be __aligned_u64(-1). + */ +struct iommu_hwpt_vtd_s1_invalidate { + __aligned_u64 addr; + __aligned_u64 npages; + __u32 flags; + __u32 __reserved; +}; + /** * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) * @size: sizeof(struct iommu_hwpt_invalidate) From patchwork Thu Sep 21 07:54:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5234071vqi; Thu, 21 Sep 2023 17:36:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESraHEbrhEcY33+TYPI8/JfaR9n5fSSehjdCd689xjuO7MnzKjTSdLubwXhbNjsNemArBq X-Received: by 2002:a05:6a20:2594:b0:14d:e075:fc5d with SMTP id k20-20020a056a20259400b0014de075fc5dmr6387855pzd.40.1695343007870; Thu, 21 Sep 2023 17:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695343007; cv=none; d=google.com; s=arc-20160816; b=sdawIlrsGQjCOng47CYYlxrwT3xw0PfQOe3NF6sxT/KyaCU2KxJAIz06poyA9Qtbft LHX/RDGelN6aNl93N+KlBXL9jHFiEPgLtlSZiyoSZ5hiLXCqkTt2XeUYC0zBd1VnLuy8 EKkLCouyrs0a9AbvqQNNG0GsMxboQl0KnpjgDl/YEZ2YNhRvtYQ7L4Dus6GtXVr6n16B ZpUL1+n9KAo+btlk82tLhP6V4NdEAcctLsn6LMg/suFHTj2ElV27jU0VP7mYtLPO+hZs YB6lPudQISdxxhRch8rzSLW/D7I+XWTq2n3oTpigjQ/RjvJK+E72UMMpFLGZzML+jxRo 622w== 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=k47QArb9ysZyNqR/XxMEOfRW1qk0ixTpvptWQD+9Kp0=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=zLx4x+ockjrHvs5xsMjLun5mYqu8Jceeyyp7SwavlGsPK80706t3A2j1wc/xYRrwdr 5WfGod5PAJTtv9D7iBxebNAKD1pHatOzf1ZzAkcmvWf+qKGq1FIqwADgjC90C/Qs43XH lO1ghb/ZoyHM62GsiZ8hiPojiNj0PRbp09B629VwqlPeRit91ToEglZRHky6fDNulH3z 18KaXQdGfFQmbUmHyGVB0ujWoWfkzg7p+PpQzhrbZrBsxOP1/Ovw36h1uYZLJTYR8Vgl N+zaraRA8zr46r4DLFWlhQtjRMioG9326A5XVOJk15jGM/tb0xzW/2PavBXP5wyctSPm iofg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XVON4yOg; 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 u16-20020a170902e81000b001b9e82a6beesi2762380plg.548.2023.09.21.17.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:36:47 -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=XVON4yOg; 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 7FE04840FE37; Thu, 21 Sep 2023 10:29:52 -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 S230247AbjIUR30 (ORCPT + 29 others); Thu, 21 Sep 2023 13:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230251AbjIUR2o (ORCPT ); Thu, 21 Sep 2023 13:28:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55695AD25; Thu, 21 Sep 2023 10:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316280; x=1726852280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cxZTRu44xkZvSgweNgQ/ax7l1RyCji4jcedyDtK8Vag=; b=XVON4yOg04xCNnkdgBFkWMeci+MqVoSO6VSmPOUxgf+qdoJKSgTZBKpf 731eLZwmO1IABgPBwORUH6NkuErTzFZWagfjhlM6ioDiDsQsleAa6eayD P2+rsgeUousP1BLPqdZJjCHKRasQooszd604jI4jfM8+sO4m7GBAIXnVJ BUQpfc6n9PKvCbz1SNWfWDLF7H8rfJ+9SC6SCfimOLvFQ8KwKvqUaDoLz Rw74R5IFxabZfA0qx1mi39TB/fBb/pim9B8TN5tdpsdZBvYwueyPAy9cH Nf3BFgXWUjDmbQ0mI0JclQet+AHMj4BONJzhRcgG+NdROVKNUUrCQzDe2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764470" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764470" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523171" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523171" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54: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 Subject: [PATCH v5 08/11] iommu/vt-d: Make iotlb flush helpers to be extern Date: Thu, 21 Sep 2023 00:54:28 -0700 Message-Id: <20230921075431.125239-9-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED 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 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:29:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777695989933314313 X-GMAIL-MSGID: 1777695989933314313 This makes the helpers visible to nested.c. Reviewed-by: Kevin Tian Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 10 +++++----- drivers/iommu/intel/iommu.h | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7b75f407c623..c93c91ed4ee2 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1511,10 +1511,10 @@ static void domain_flush_pasid_iotlb(struct intel_iommu *iommu, spin_unlock_irqrestore(&domain->lock, flags); } -static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, - struct dmar_domain *domain, - unsigned long pfn, unsigned int pages, - int ih, int map) +void iommu_flush_iotlb_psi(struct intel_iommu *iommu, + struct dmar_domain *domain, + unsigned long pfn, unsigned int pages, + int ih, int map) { unsigned int aligned_pages = __roundup_pow_of_two(pages); unsigned int mask = ilog2(aligned_pages); @@ -1587,7 +1587,7 @@ static inline void __mapping_notify_one(struct intel_iommu *iommu, iommu_flush_write_buffer(iommu); } -static void intel_flush_iotlb_all(struct iommu_domain *domain) +void intel_flush_iotlb_all(struct iommu_domain *domain) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); struct iommu_domain_info *info; diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 411cde769787..ac23b9d22d20 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -865,6 +865,12 @@ 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); +void iommu_flush_iotlb_psi(struct intel_iommu *iommu, + struct dmar_domain *domain, + unsigned long pfn, unsigned int pages, + int ih, int map); +void intel_flush_iotlb_all(struct iommu_domain *domain); + int dmar_ir_support(void); From patchwork Thu Sep 21 07:54:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5288071vqi; Thu, 21 Sep 2023 20:06:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGovj7kL8hpLEqFDvEr5IgdrjUQCsh2q9bF1HjPLfS5AJpwCKwCP3eQRsP9iJ1QrYqPxZB3 X-Received: by 2002:a67:fe97:0:b0:452:62b2:36b with SMTP id b23-20020a67fe97000000b0045262b2036bmr7419356vsr.30.1695351971092; Thu, 21 Sep 2023 20:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695351971; cv=none; d=google.com; s=arc-20160816; b=psqn4Ke4ViYgAcS5uoS5rdi1loUHaly4+RXEFn7hQq+7xl2xqaOj+RBsaS6AgbF0OQ HLgqE5LQ4JN4NlHrgneYI7iiGmm4UQSPHD4Mz/71S81FkgOl3f6tUNgsI+HXiXQxjF7v TLSHTUYoPXdM9Ooevq1sSN51pO03+NlWIbVUNWb3p4nNvPv6x77Y/oz+wUzCiR1toXC7 YoaZP0Mj1VkkxSWwMA2WlUuAmjaEK4bJEnDyOzmViinY1zlr4g6JLxagnNGIXJ9KB/HH 3so1aFm4w2U35RgExkxHz8SR57otX2WIgVTB61liYfqkX/WJ+hTZn0U687JEPnbBWtmp ejJQ== 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=K7pnCL5RK0+S8qa5h2jtgd6S+Kxo3reCeAYwAa+ZJv0=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=PoUjQvfVqhBi+Xhkk+PDMLbosNXoJGfXjkpJD+3GDfLYMzMc3lizaj6gRLbdfYKvRr 0QedFaggp5DdnRT/zIR7oBd/NZZruWu00Y9/1Z9m2pxtk73TaMOvqpMNbCUDS8SsTk5Z l046S20pZyhh2cRrCsKZKnD0IrCWzltrQiJgk3HE6fmHVJLuix2RvTAJAzoc4iwoJYd4 jIrK9+oQkX1mSULDcoTonmuhtVVyFHG6PeA0TwH12WvQd4TNutBUNUhV0U6gWWetpnDD XQ8dfKwVJy7mCYHq/VVDhWCswmVybDUE9oTGFQMG/l60PnkVSUH0MI0O48dOPR+bmMqQ w7IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MEdebZSM; 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 y8-20020a63e248000000b00578ae22988csi2727523pgj.327.2023.09.21.20.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:06:11 -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=MEdebZSM; 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 CA02D83732B8; Thu, 21 Sep 2023 13:19:34 -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 S231623AbjIUUTQ (ORCPT + 29 others); Thu, 21 Sep 2023 16:19:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbjIUUSq (ORCPT ); Thu, 21 Sep 2023 16:18:46 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AAFBAD3A; Thu, 21 Sep 2023 10:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316281; x=1726852281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ihUYRjoLeUil0+83SWKCMw5Ae603CawjFlOOBmk9pjQ=; b=MEdebZSMSyXQZkh+tSNtb60a9ssQEdTshoqIwUw4T/z7/kgg/xi6tkdZ kZpHnvaDiSmPXpLkB6xoGR4GuVwuOgg8lbNx0AWgCaXBAswpT+9lnQTT5 kjlHpGMF2WIdFSJ5laKxQVCGxyAhkIu9m78W/WDTdlOJMoKfhsJbQtP1i uooaRjIL4miVgwlyYA6P/kIGqsDMT8SzgJmNQrReNP5VQTWuAvfFxK2dp CdgV8GcflaJwJwIaeJXEq76NjVdqH4zl862vULeb5L3Uz5t296JAUa3LN /60YwIIiUoVW/zIFiFOpT1zNcFVHcS3wN1EfU+c9Dq7oUWTPc0Gx4RY/2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764484" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764484" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523177" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523177" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54: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 Subject: [PATCH v5 09/11] iommu/vt-d: Add iotlb flush for nested domain Date: Thu, 21 Sep 2023 00:54:29 -0700 Message-Id: <20230921075431.125239-10-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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]); Thu, 21 Sep 2023 13:19:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777705388519108625 X-GMAIL-MSGID: 1777705388519108625 This implements the .cache_invalidate_user() callback to support iotlb flush for nested domain. Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/nested.c | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index f9c6ade72416..4853fee216d9 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -68,9 +68,67 @@ static void intel_nested_domain_free(struct iommu_domain *domain) kfree(to_dmar_domain(domain)); } +static void domain_flush_iotlb_psi(struct dmar_domain *domain, + u64 addr, unsigned long npages) +{ + struct iommu_domain_info *info; + unsigned long i; + + xa_for_each(&domain->iommu_array, i, info) + iommu_flush_iotlb_psi(info->iommu, domain, + addr >> VTD_PAGE_SHIFT, npages, 1, 0); +} + +static int intel_nested_cache_invalidate_user(struct iommu_domain *domain, + struct iommu_user_data_array *array, + u32 *cerror_idx) +{ + const size_t min_len = + offsetofend(struct iommu_hwpt_vtd_s1_invalidate, __reserved); + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + struct iommu_hwpt_vtd_s1_invalidate inv_info; + u32 index; + int ret; + + /* REVISIT: + * VT-d has defined ITE, ICE, IQE for invalidation failure per hardware, + * but no error code yet, so just set the error code to be 0. + */ + *cerror_idx = 0; + + if (array->entry_len < min_len) + return -EINVAL; + + for (index = 0; index < array->entry_num; index++) { + ret = iommu_copy_user_data_from_array(&inv_info, array, index, + sizeof(inv_info), min_len); + if (ret) { + pr_err_ratelimited("Failed to fetch invalidation request\n"); + break; + } + + if (inv_info.__reserved || (inv_info.flags & ~IOMMU_VTD_QI_FLAGS_LEAF) || + !IS_ALIGNED(inv_info.addr, VTD_PAGE_SIZE)) { + ret = -EINVAL; + break; + } + + if (inv_info.addr == 0 && inv_info.npages == -1) + intel_flush_iotlb_all(domain); + else + domain_flush_iotlb_psi(dmar_domain, + inv_info.addr, inv_info.npages); + } + + array->entry_num = index; + + return ret; +} + static const struct iommu_domain_ops intel_nested_domain_ops = { .attach_dev = intel_nested_attach_dev, .free = intel_nested_domain_free, + .cache_invalidate_user = intel_nested_cache_invalidate_user, }; struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *s2_domain, From patchwork Thu Sep 21 07:54:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 143042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5238601vqi; Thu, 21 Sep 2023 17:49:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAIZbcbNuANzy90bv4SJz5CzA9DntNSZIGgxON14vrdQHXHl6OPkQRWAdXCW32kJz75x6V X-Received: by 2002:a17:902:74c6:b0:1c5:8401:356c with SMTP id f6-20020a17090274c600b001c58401356cmr6868577plt.62.1695343759094; Thu, 21 Sep 2023 17:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695343759; cv=none; d=google.com; s=arc-20160816; b=jyxuHDNla/Ah/2OmnSxDecquPFe8vZI8SNw73W2WKufEFAa/mxQF7fL+4pPLA7Rxhj lwfat/Vf7TAELOLlHi5YQCff3g8s32eN1/CBs4y/wz6kMcrAdRZ1ZZ9U1dfir+zIWeng ObZbiPO6Q3XOVI/aQdsakD/kx+pmt4XTSFtjsaPZUCxk5L3T1isCYsrgeAiTLPGCQaHO vyGQugvvX5ZAfI7HY4UVy6Nnfd4pJzNBxxuO0JUT7J9k1MnNkKTmkfPyRFAlRhCm5SWS 4BZjK+QqG1TaAigsr/e9uEFkAfbYp+1gHzY1hS+nWLv7ud6s14vKXCM/TXdxJ1WLuJor QnFA== 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=L3wTurz7Vi1SKiLAWyTrePO7pA08jqYlvkU4S3dTws8=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=mr21+pGK02K9+KEMVCTiIQ5XWFMN8hn3JjyxEmz2wVT5209uSBp3b5oAOH9vdM/9jg WsEmzhJ/75e9vyT6ebcmFjYvaSvizu9hXaSjkszU3m9gynKmkRSMIfKZ5ZQGijdaUw0Y 4PCEpcoTK4wNv2AjqugjHswnHJkyZPGgxqyb5oa18sBd6SxpzJS+rTnB0J9pRyY/7ITU e4VV/o/HB5+yPnpdiQJeAkjNMcog40RxQ1ofOXeN4f0tKUQHEs0QinypkorOHcaw1gx9 2T/Sqhuu+lW56LxxNLLRaaFKTNKDOWOdeAWOB1oS4M8Z9KYb3Mm7BSGHbL0NdjuOi9ij 5OjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=deszTiL2; 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 u12-20020a170902e80c00b001b9eb5d1ea2si2923633plg.198.2023.09.21.17.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:49:19 -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=deszTiL2; 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 E5F66836B5FD; Thu, 21 Sep 2023 13:19:22 -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 S230337AbjIUUTM (ORCPT + 29 others); Thu, 21 Sep 2023 16:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231499AbjIUUSp (ORCPT ); Thu, 21 Sep 2023 16:18:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC7BAD3E; Thu, 21 Sep 2023 10:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316281; x=1726852281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t9shzln1aiQ0VVrVLLLhztKgUvVIxQF/AjCqw0E9eAk=; b=deszTiL24loTM14oU0l0QMq5Qo6TsLOT5UeO89Ta0p4UuTqeCIexV9hB wBMlDOXzdtLqQuhy01dlS8dPlnzxRgBezn44bmU2YhyaCa2wnsThzqhUY GiTEdn7h7NfBWLEtmmVHxqLs7qfYyGS7+w4EHSxkDc06EbSa9/Sn10Lh7 K9CwMGK6nkryfrxH7s1PN8ESd8Nc/v1o+lRdqWYES1N06n7RW5lHficIE nWdGlZB6DP2QIWjLZBLaszZ24OJJoufi7f9DVLPeK60xW31e3E76Sce0m zUPUgxqKfIozOU1Z6LD/j5UJQzp+7OMHkOkDOYYDJ38lUTMov3Yu0zBNo g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764493" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764493" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523184" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523184" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54: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 Subject: [PATCH v5 10/11] iommu/vt-d: Add nested domain allocation Date: Thu, 21 Sep 2023 00:54:30 -0700 Message-Id: <20230921075431.125239-11-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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]); Thu, 21 Sep 2023 13:19:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777696777652278828 X-GMAIL-MSGID: 1777696777652278828 From: Lu Baolu This adds the support for IOMMU_HWPT_TYPE_VTD_S1 type. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c93c91ed4ee2..9b10e4b1d400 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4077,19 +4077,35 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data) { + bool request_nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; struct iommu_domain *domain; struct intel_iommu *iommu; + if (hwpt_type != IOMMU_HWPT_TYPE_DEFAULT && + hwpt_type != IOMMU_HWPT_TYPE_VTD_S1) + return ERR_PTR(-EINVAL); + + if ((hwpt_type == IOMMU_HWPT_TYPE_DEFAULT) == !!parent) + return ERR_PTR(-EINVAL); + + if (parent && request_nest_parent) + return ERR_PTR(-EINVAL); + iommu = device_to_iommu(dev, NULL, NULL); if (!iommu) return ERR_PTR(-ENODEV); - if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap)) + if ((parent || request_nest_parent) && !ecap_nest(iommu->ecap)) return ERR_PTR(-EOPNOTSUPP); - domain = iommu_domain_alloc(dev->bus); - if (!domain) - domain = ERR_PTR(-ENOMEM); + if (parent) { + domain = intel_nested_domain_alloc(parent, user_data); + } else { + domain = iommu_domain_alloc(dev->bus); + if (!domain) + domain = ERR_PTR(-ENOMEM); + } + return domain; } From patchwork Thu Sep 21 07:54:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 142857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5089829vqi; Thu, 21 Sep 2023 12:34:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6pPuVWH4lTIi0TYXCanakQwKIZ7gpPM4yMGhzu5R9WrO+PU80TI7w+bfz8+dOIdB2sh4p X-Received: by 2002:a05:6a21:3e14:b0:133:be9d:a9e6 with SMTP id bk20-20020a056a213e1400b00133be9da9e6mr6000846pzc.17.1695324839969; Thu, 21 Sep 2023 12:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695324839; cv=none; d=google.com; s=arc-20160816; b=rSaeYIJCmsIzMejm8N6qLnapLqXxe5Hutydc9pRDAwAlVRgD3wRKt98tcRTqORAgFG c4DhANKa6sSmky4BmNFg7qyBv4qCortI+VmjF7crHxTyaCoaDE8+2N4VYOOFKMl4DZ7R +cEawWu1rlv0xFt8nWvTO+fB8ga7WEOaLoM7PVcDckdBXtDx4UHtAhyMIzDKG/oXqZua 8e5M6wa/4wCKNr58fJsySxyI/+be9rY/oAqc8RgrQLojBrVBDH2eCqfr8D22vPVugzgW BQXWo8/vA5Xr8fqqTRLZm1LGc5RE9uv0O9Yp8UXclckM6njAxOLxUztw4h5iHyKGptJF GhJw== 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=c3i7lJZo+Lujz0d8aDd+ksAXcEeoImOPlBHTM7pW8q8=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=lyhfJ+vetUUtbm3Ug4qybTXtzOmdJv+AMo7pS/lWdKRYvln9FlKvpbr3bG4+ZO57l8 RlCKwJkQ9JsCux9wANMFD5Bi09irrkcOOA1JpozE9Y15DOsF9XPePG/5+BgX6I3eprk1 vMdOvNMjrXIjycjOl0dy+M7b56e/c2s5rW1ibx2yOOFYinuh54pFaLuukp3fy2Ohg6ln pDyjcy/GF7yuTAzH83QOG0mUv7WJYL6PZyGxztr3fGbT79dv0JSAy/wxlfWkEBMe6yzv cSn9CTx5J2mSgu5iD0xY9cFoBaYNzyqX5Ogr2kDijcp3uaV9Iwz4nDNenlBHMRM1u3zb iWKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fJfrXwRK; 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 y24-20020a63ce18000000b00578a5f62edcsi2003744pgf.625.2023.09.21.12.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:33:59 -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=fJfrXwRK; 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 BBE648104F57; Thu, 21 Sep 2023 10:24:15 -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 S229832AbjIURXz (ORCPT + 29 others); Thu, 21 Sep 2023 13:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbjIURXd (ORCPT ); Thu, 21 Sep 2023 13:23:33 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBE9010935; Thu, 21 Sep 2023 10:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695316281; x=1726852281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FMm83P7beXWMiji6R1eFj/4s+rv6p3/F5Z6Swx5xKU0=; b=fJfrXwRKOYbKdwqSK5pUfEbo4I7uYX2awFltlmFUShU5TvTiKR3Wqhs9 n+l142v33IkkagWsUV+IJNuKvmnGOHjdrjSMyd4FjlB0T6vOEtzZzg1hR FhKDXGk9OcWIKX+Gd4luabSWOKR4G+LLti3nf31H5AoMDIElQXqvxM1CX zprk6zXhAcpctYAPqLiALQJe3+oN+SFI2zJluIEL2OpveJ+6jxPaajqqm b2FAbIhv6BEtTPMtKpnzaw1PgKo7p7P16f7LrZzMLs1zpPADLiU2DIxsP LlR1iMYj9xpClYXyfYtUQZIV4nppdJ76a2dvfy5eVK54hdgDpB5sepcCt w==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="370764506" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="370764506" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 00:54:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="812523193" X-IronPort-AV: E=Sophos;i="6.03,164,1694761200"; d="scan'208";a="812523193" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 21 Sep 2023 00:54: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 Subject: [PATCH v5 11/11] iommu/vt-d: Disallow read-only mappings to nest parent domain Date: Thu, 21 Sep 2023 00:54:31 -0700 Message-Id: <20230921075431.125239-12-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075431.125239-1-yi.l.liu@intel.com> References: <20230921075431.125239-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,URIBL_BLOCKED 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]); Thu, 21 Sep 2023 10:24:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777676939435144497 X-GMAIL-MSGID: 1777676939435144497 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 Signed-off-by: Lu Baolu Signed-off-by: Yi Liu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 11 +++++++++++ drivers/iommu/intel/iommu.h | 1 + include/uapi/linux/iommufd.h | 12 +++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9b10e4b1d400..dbcdf7b95b9f 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) { @@ -4106,6 +4111,11 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, domain = ERR_PTR(-ENOMEM); } + if (!IS_ERR(domain)) { + struct dmar_domain *dmar_domain = container_of(domain, + struct dmar_domain, domain); + dmar_domain->is_nested_parent = request_nest_parent; + } return domain; } @@ -4831,6 +4841,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 ac23b9d22d20..8d0aac71c135 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -592,6 +592,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 3050efbceb57..99401d7d70b2 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -440,10 +440,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