From patchwork Thu Oct 26 04:42:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424487vqb; Wed, 25 Oct 2023 21:44:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoN7ckN5WUwU1ydgXvtlu4hlbUS1gXL+slcRI/64dbR32UdzzF7llgcWFvBjbKQS5hbpvP X-Received: by 2002:a05:6122:3c81:b0:49a:9146:ec02 with SMTP id fy1-20020a0561223c8100b0049a9146ec02mr19739825vkb.1.1698295443648; Wed, 25 Oct 2023 21:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295443; cv=none; d=google.com; s=arc-20160816; b=JXm3t3MAEE/4EbqHdgA1jOy7US2cWB1oTuG7ZtiwOildd/fhXkxKY5aH2NxKRDEGls vyPCcm9y862T2vZxVq4SuEfHnFGQLHaJxr6VRyOtueo3egHnPCBYC8GjG2kl2riq/UCw 3AZyLqAQZLXYI5CAdEWxqx3uA/o73fQsO9uHDrioevLVV6qAvmsDxFm6JBXKm20/zX3U 05q7s+VliZioYCrX9EU888LJOh7ActKXHCPwgb55LJV6N4O+KGvp6/2p0yYFLizPx5WN /9RDZih/OOZoR377cOLxjGMULohMF57IFxrPASl/Wz8808TORLhXk6ecciRTgRGSYNLW +dAw== 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=kFmZ4+WIl5/uxEChBDxTaiVQXCTNpqbKhCYl7rDyvXA=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=A57Pg9GvJXSaXjKnLM49hr3S7Y7Ud336hJsvS0SHAxQ6o3rr5F1asxh5iBDzpdQZoK Q59AOwodgumP3dEpFUbY5PVYYMm1Zew7uyUr6NuOfZQo1ZEHF8hDrSzp0yt0bho9nHP/ OuP/2x6soQh6X2mq50mVr0iOuCj5uoPq89781VdaX6+8MraYfaxk4RI79Elw1bioe+7A 0gkF3SIFtrZN6pJn1Qw0PeE16pzfT8SRGczMFhhbxWbYPvDEGeO5MAhbyToeJCyqYEvn cotDks/V2CwY84Ifa1lMplA974Uuo6ytwNJKLUSN1xbPufkgUHfcBvK8ksaRve9oi7x9 YJig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZFOZPb1T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id w9-20020a816209000000b005a7b8fe714csi14065378ywb.63.2023.10.25.21.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZFOZPb1T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BB6C980EFF8B; Wed, 25 Oct 2023 21:43:51 -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 S234789AbjJZEnW (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235072AbjJZEm4 (ORCPT ); Thu, 26 Oct 2023 00:42:56 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD9B1734; Wed, 25 Oct 2023 21:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295371; x=1729831371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kJQbhlGr3UHL/vwCI8YpVWg6//iOWpSzH/c2w2J/uEw=; b=ZFOZPb1T3Gj1YYCYU+F6E0D5EgWm4vkkAKtZmjyRtg15IlhoYyVAV0Tq Di3kvMw9F/7q+WM5pIM9pdofavzIgEr9GKKhjCVqqGp0ff/QTqZ2NgPES FgPyl51/fni3P0chEkzUpkW/itGFeYCD8w/EJZWbiMhdHua2RbzmLqong sIfuty+nznhyAwKXfm7g4EFA8UtO6IrhFsvHqrkTRZt89K+xzWslYp5in x+iQZLspbt7nwaPSXV3egkrXQQjuQnshQgXyHvJa24i9B8C2OVy4oDfd3 f47FVrZ9zB4JKknXFNdTPOEVQFscL6oGsBkCoHeHAS+scXCJqtL6RgZI2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670720" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670720" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478509" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478509" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:19 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com Subject: [PATCH v8 1/8] iommufd: Add data structure for Intel VT-d stage-1 domain allocation Date: Wed, 25 Oct 2023 21:42:09 -0700 Message-Id: <20231026044216.64964-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 25 Oct 2023 21:43:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791843277647292 X-GMAIL-MSGID: 1780791843277647292 This adds IOMMU_HWPT_DATA_VTD_S1 for stage-1 hw_pagetable of Intel VT-d and the corressponding data structure for userspace specified parameter for the domain allocation. Reviewed-by: Kevin Tian Signed-off-by: Yi Liu Signed-off-by: Jason Gunthorpe --- 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 d816deac906f..3ce5ee5f09b6 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -361,12 +361,42 @@ enum iommufd_hwpt_alloc_flags { IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1, }; +/** + * enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table + * entry attributes + * @IOMMU_VTD_S1_SRE: Supervisor request + * @IOMMU_VTD_S1_EAFE: Extended access enable + * @IOMMU_VTD_S1_WPE: Write protect enable + */ +enum iommu_hwpt_vtd_s1_flags { + IOMMU_VTD_S1_SRE = 1 << 0, + IOMMU_VTD_S1_EAFE = 1 << 1, + IOMMU_VTD_S1_WPE = 1 << 2, +}; + +/** + * struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table + * info (IOMMU_HWPT_DATA_VTD_S1) + * @flags: Combination of enum iommu_hwpt_vtd_s1_flags + * @pgtbl_addr: The base address of the stage-1 page table. + * @addr_width: The address width of the stage-1 page table + * @__reserved: Must be 0 + */ +struct iommu_hwpt_vtd_s1 { + __aligned_u64 flags; + __aligned_u64 pgtbl_addr; + __u32 addr_width; + __u32 __reserved; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data + * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE, + IOMMU_HWPT_DATA_VTD_S1, }; /** From patchwork Thu Oct 26 04:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424516vqb; Wed, 25 Oct 2023 21:44:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9ZtXkGk+PZhfU96FpARfk4JU/z1xU3Q8xoW53acog8CdZEjXR8TweISvbYCVk7UwfCB4j X-Received: by 2002:a67:c318:0:b0:458:6173:8d4 with SMTP id r24-20020a67c318000000b00458617308d4mr12946154vsj.20.1698295447998; Wed, 25 Oct 2023 21:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295447; cv=none; d=google.com; s=arc-20160816; b=bQxaxUcYAHl+SAq54my4JXa+znlDTIXiSshlzOiOkjse/VpSeiooNqkws4QIq+dMtI yvwh3MOWa669YjDXKnq8d4gadc+COvOrNBa45XMLrGRg/aPbq5LlcxGkRkhJ2oBSUv+S qBl/htmtqCi2+YX+asaaVBYV0xUeTnx9PlPyqeJ1bk+WfKIMabErxzRI0ptQU6jTlR0R /FynX15m1N9OoqnVlybsT+mfCkKoZ2x8Vuzpd95wXFhpjgaEzZ+EkYsBE1VxShYFAGCN fq7/AMeapFD4WeBz4nO6PP4r+3+IKCJLC5PTlUfQhNvai0bwVaTH36DhriuMWInZGdja VFIA== 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=tZnC0DKzMXODj3eCYCL0rR46azJytS39N8el7lOjk/Y=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=pkOOcxyKufQ4yBn1J8ljt1ryasTGB8jr79b8YjwjAiSrF5W+oL1e5LDP+OzXEGBWjZ qWOZC0gD1VQkm0s394yFfiGQE90qoRmMOrt+NqrnmB42BaDCmeXkaiq7p4GQ4+ModN38 ivYy48Oan8rKSfHtVC8ZG8ZNB3g+Na8MoJ5jEMl3nJ5kU4IBc5qlJqn01KyymQm9lN8U KHYox3QObDlb6Bv8z0AFJnpsvRMTMZ4O7JcdVIdZLuO8Ri/l4G0/zVz3XH2hFOO76yjK q8mlDAkpxVNzIeGHllyBkjGHYD52X+Aia66EPN/07qI8ee404KWJiKUQ9UXJqBZa2KUH DTKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gNxNEw0R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g35-20020a25ae63000000b00d9cb02219e1si13109556ybe.265.2023.10.25.21.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gNxNEw0R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id F0B0181A328C; Wed, 25 Oct 2023 21:43:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343906AbjJZEnR (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235073AbjJZEm4 (ORCPT ); Thu, 26 Oct 2023 00:42:56 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7401B3; Wed, 25 Oct 2023 21:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295372; x=1729831372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ES8n81i3PjoHeEkR3Se1CXSo3INruHcGQ//e8Uega0E=; b=gNxNEw0RLJ1EykI5mzGOmsq5rpyiz3VhQ5rS77mTlpz6CXyc0z4oPwMA gMnokYNXZFGbx7KZ9ZWrfdIMwWrupIVobmBZg/Zj9gWGnCsVqFIAlCA9Y AvdBI45QrFb1A3ELBeNrxI8t+sFWOvBqvxjQmmS22ygXPCsCZYacslWxH U2BjloxehVoHPEnigtT8Vgto8SSUi8YGPQ3iIwGa6z9sOLj6RDtY4+7Op g3PcfA7vOdUS4KGIKaM6OlTxj9dAkDraOc+IamIsX6hdkzVfydM6+ZAwX k4jF3dVNbFmJF7MYB+5XUDH7Jde8afAW357LnYIScdutDeN8sL79aPxPS Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670731" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670731" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478515" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478515" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:20 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com Subject: [PATCH v8 2/8] iommu/vt-d: Extend dmar_domain to support nested domain Date: Wed, 25 Oct 2023 21:42:10 -0700 Message-Id: <20231026044216.64964-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 25 Oct 2023 21:43:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791847729462281 X-GMAIL-MSGID: 1780791847729462281 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 Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index cc7301579773..244f111ea0bb 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -25,6 +25,7 @@ #include #include +#include /* * VT-d hardware uses 4KiB page size regardless of host page size. @@ -605,15 +606,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 Oct 26 04:42:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424374vqb; Wed, 25 Oct 2023 21:43:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOmmKgdsrSpdDunUz5KHleMmHLN/QIVlC8O10tP6E/YDiE86864NAY+t6Lz45cUu40+6oJ X-Received: by 2002:a25:260f:0:b0:da0:3e97:1c58 with SMTP id m15-20020a25260f000000b00da03e971c58mr6853114ybm.51.1698295423683; Wed, 25 Oct 2023 21:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295423; cv=none; d=google.com; s=arc-20160816; b=OQhBV22xKzkher+5iOXbHBj2FhRVzNuoJf3YC31bEyojuyboy18aHuQWDYGoj1e6ml /L0ba1KAyZ4oKvceLMMEJfy5//0sCf74hl1LBWlQWVlW+iB53b6duKMe/CqQqnFM5aFe ZFOEG4rGSN3J7uz2I55JBZOudyryA2S3CLbNU4ipRohd5HAaMVLvMfxKZpWt8/sO9kaL dwnotCPoaZ7gAeGoC2zYVFCiC2zwuZ1+hDnSRS3wSex/JbJyTwtfHZXUq0mqID7lB4O2 tqw8mT+/gEP+2nHSU3VBeTCn7Sv63/yHIzw9Qb/WRiyPZNXl9MuMjhvpSEE0zQm+oiv4 A0pQ== 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=Mu1L7B+K/nCpEeP1F/Z+69ngBTroMMxLFRMluljKnck=; fh=IZyM1AM0bATemv9EzafoXv7q5+geru1rOhtf89P+YN0=; b=PJvEuw2LwAmwPgznqr5e9OZW1wjoiIs6Z8opDn7uMYXmmzSh+4uVS/d0yotB0LOa9h m7ITjGv0E3qMtMAbi/gg3bXegA1MvDkMahIdMxKpmSdNiwjJ5i1/4cQlVd44uWmC0TuO kGMidWJyfC1pFJado8pZLGKxRkeC1Bn3XDmLQuwK2scj9cDn2IDDSDmDWqx7dVqrm8x9 v1DcTZjCZxVJ8r95T/K82ii+FxPcneE+EM/6Ogm2OR4RzzFlJUf0lBFaPTxGf9AEWFhf GIlgUUBAEWParnaoC3B3K7HNHrRTEa5TOSk4iKBOo/EQ8xRmw1UweHFc5MqZmEEimLLk CDvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PILol6QI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w83-20020a25df56000000b00d801af7c4a8si14563504ybg.385.2023.10.25.21.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:43:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PILol6QI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8951481BAF0C; Wed, 25 Oct 2023 21:43:42 -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 S234971AbjJZEna (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234816AbjJZEm5 (ORCPT ); Thu, 26 Oct 2023 00:42:57 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E33196; Wed, 25 Oct 2023 21:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295374; x=1729831374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RX/YiODYnr/18kMPdL9OzJCsH/vcj1oBcuT0PcyHDyQ=; b=PILol6QIQ7mRxmLXEAHZNe+yBo0kh/Z8/qSwpkGxe83MN2Nu1TmW/7Uj bMIGp786YsvqfI7fCbDttWJovLfPvbBYqPceJ5ZuwR3JlnNlqwwr3ilDA SDdCa1Sf3GoAjcDLg8lVi7Qc8uNlnMACcz+i/uFgn20xKlZond+ePfD5n T75udLbN5asOaU8nJ/Fzkd5lxgXv5ipgnVKkn4JWo8X2AsYeCpAHlOfZo oLMhkRaQdvUg/fyp1TMQPsUEgEAmKsI3qPpR4pRfp701VFR+bpoUbsfO/ wPMMBWGDiu3RSdBxmLikTyZWMP/UKubxDyQgKN5ZJ99pqa7Mz/M6ToIbm Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670744" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670744" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478524" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478524" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:21 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com, Jacob Pan Subject: [PATCH v8 3/8] iommu/vt-d: Add helper for nested domain allocation Date: Wed, 25 Oct 2023 21:42:11 -0700 Message-Id: <20231026044216.64964-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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]); Wed, 25 Oct 2023 21:43:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791822224247752 X-GMAIL-MSGID: 1780791822224247752 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 Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/Makefile | 2 +- drivers/iommu/intel/iommu.h | 2 ++ drivers/iommu/intel/nested.c | 62 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 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 244f111ea0bb..f59a9374f62d 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -884,6 +884,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 *parent, + 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..56bb205fca06 --- /dev/null +++ b/drivers/iommu/intel/nested.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * nested.c - nested mode translation support + * + * Copyright (C) 2023 Intel Corporation + * + * Author: Lu Baolu + * Jacob Pan + * Yi Liu + */ + +#define pr_fmt(fmt) "DMAR: " fmt + +#include + +#include "iommu.h" + +static void intel_nested_domain_free(struct iommu_domain *domain) +{ + kfree(to_dmar_domain(domain)); +} + +static const struct iommu_domain_ops intel_nested_domain_ops = { + .free = intel_nested_domain_free, +}; + +struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, + const struct iommu_user_data *user_data) +{ + struct dmar_domain *s2_domain = to_dmar_domain(parent); + struct iommu_hwpt_vtd_s1 vtd; + struct dmar_domain *domain; + int ret; + + /* Must be nested domain */ + if (user_data->type != IOMMU_HWPT_DATA_VTD_S1) + return ERR_PTR(-EOPNOTSUPP); + if (parent->ops != intel_iommu_ops.default_domain_ops) + return ERR_PTR(-EINVAL); + + ret = iommu_copy_struct_from_user(&vtd, user_data, + IOMMU_HWPT_DATA_VTD_S1, __reserved); + if (ret) + return ERR_PTR(ret); + + domain = kzalloc(sizeof(*domain), GFP_KERNEL_ACCOUNT); + if (!domain) + return ERR_PTR(-ENOMEM); + + domain->use_first_level = true; + domain->s2_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 Oct 26 04:42:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424497vqb; Wed, 25 Oct 2023 21:44:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYRV7fiGf4p7uxeqEOJzWWPaiuPc6ImF+VAV4gzb4WxhE+pX6iqbCgs5WFDTD8WrNJM8Qw X-Received: by 2002:a81:92c5:0:b0:5a7:e400:b23b with SMTP id j188-20020a8192c5000000b005a7e400b23bmr17882241ywg.5.1698295445130; Wed, 25 Oct 2023 21:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295445; cv=none; d=google.com; s=arc-20160816; b=v/Mw7lOTt3pdT97bjGrkwplSjXZhIKH2msp917TGAobxoHyFJR7Zun8jv+fBmUSWV6 LWQp5XNksXRWgLk9i0/n4ZW7xIDBe1d25GGd0dkY9GLT7GIFzopkPb5/D42HVQonvLlR MPOdqY84UomQG4L35duYZms+ifvbE1tY/w3M3sBv4QLdfXk7BpSbLb6xiZviNSPfTdiz wvIvDi4tdZUeLdWjcvC4SYt6Qp1WkjK5w11QA57dq8IQ1QGXLX8fVnDizXbopG7BnZz4 T9UvvGYLJZa76lTasCmRLy/zHz9kOsC/9zgnqGDv5OkQcFN2EAUUEzim91/XokaiZT24 yf6A== 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=5cJfMcl7DvA/ZkkacfcS9M4uskRDAmsaF3hf5wJhPf0=; fh=IZyM1AM0bATemv9EzafoXv7q5+geru1rOhtf89P+YN0=; b=wsEcjg0RZ7Q8DEiDsgAgHgpZHCUd+KHjfvIDHHMw5qUXMbqRaO0DyH0ZWmKQL9DDOD t6w0RK7fT54+y8nsOWKpo4Hz1EGDON0wxr+g86AQD8gJLpTMP7nwCSiwA+Iv97NfzlUG 3K9dp3iPnbOW4x/EPuTWNg/M0KQi6cWTMgNezhLaS8Rt/Cr27zRNauwdN9D2nbcdKl5t T+PYi1lOMkxuMWydyQz/rdYJUuU+QvTLP99foqM7VHiQIxSI8V8vzSqLoxCFfaxoZOtI d27B2OIsq6iK9Hr2NtYnFzd1hI6UvpUZZbaH9RrfR3GLnTlaG6fP8lbBfdVBlLgZYGKl ClZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k5mXtQi9; 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 w65-20020a0dd444000000b005a511c90db7si14452111ywd.229.2023.10.25.21.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:44:05 -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=k5mXtQi9; 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 1FF9881BBA38; Wed, 25 Oct 2023 21:44:04 -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 S1344280AbjJZEns (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234828AbjJZEm6 (ORCPT ); Thu, 26 Oct 2023 00:42:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2B4D193; Wed, 25 Oct 2023 21:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295375; x=1729831375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F1KN5Wxh4+xwtDgUqGDWT2IF4dm9998xnyNQbiGHIDM=; b=k5mXtQi9SgTC8FJC/s9fG36HE56sJmJmJ6OI1ZJmSEVCUbf/J66QqMoQ f9J8/VyfEvWmwwbXzB7NcDRP+prxC3k6UlCTXTBwk2moDYc+SVV+3Ksl5 SEjg/I5v5uZzjZJLapIyYYW5LL8LmHAoSnf3tG55iiviLNGWJtsAx0otE NVBOnhOxO2ZqvDZb4wiNx3SobHscoKP9fm85P6EvlTMObl5WVNLGmyRWZ dA9kJPfuioVKBff56pwREj2Vran83IrCcMqkIGaD+enSI2HVCAFnXFmtJ zp6II9Nepsb2BSyYq/JvK4qsDbE2YgDnx4DfAoa6A82l3iUMsS9EFM6cM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670755" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670755" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478541" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478541" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:22 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com, Jacob Pan Subject: [PATCH v8 4/8] iommu/vt-d: Add helper to setup pasid nested translation Date: Wed, 25 Oct 2023 21:42:12 -0700 Message-Id: <20231026044216.64964-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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]); Wed, 25 Oct 2023 21:44:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791844948459220 X-GMAIL-MSGID: 1780791844948459220 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 Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/pasid.c | 112 ++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/pasid.h | 2 + 2 files changed, 114 insertions(+) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index b9264b9174e8..74e8e4c17e81 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -370,6 +370,15 @@ static inline bool pasid_get_ssade(struct pasid_entry *pe) return pasid_get_bits(&pe->val[0]) & (1 << 9); } +/* + * 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. @@ -437,6 +446,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) @@ -822,3 +840,97 @@ void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu, if (!cap_caching_mode(iommu->cap)) devtlb_invalidation_with_pasid(iommu, dev, pasid); } + +/** + * intel_pasid_setup_nested() - Set up PASID entry for nested translation. + * @iommu: IOMMU which the device belong to + * @dev: Device to be set up for translation + * @pasid: PASID to be programmed in the device PASID table + * @domain: User stage-1 domain nested on a stage-2 domain + * + * This is used for nested translation. The input domain should be + * nested type and nested on a parent with 'is_nested_parent' flag + * set. + */ +int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, + u32 pasid, struct dmar_domain *domain) +{ + struct iommu_hwpt_vtd_s1 *s1_cfg = &domain->s1_cfg; + pgd_t *s1_gpgd = (pgd_t *)(uintptr_t)domain->s1_pgtbl; + struct dmar_domain *s2_domain = domain->s2_domain; + u16 did = domain_id_iommu(domain, iommu); + struct dma_pte *pgd = s2_domain->pgd; + struct pasid_entry *pte; + + /* Address width should match the address width supported by hardware */ + switch (s1_cfg->addr_width) { + case ADDR_WIDTH_4LEVEL: + break; + case ADDR_WIDTH_5LEVEL: + if (!cap_fl5lp_support(iommu->cap)) { + dev_err_ratelimited(dev, + "5-level paging not supported\n"); + return -EINVAL; + } + break; + default: + dev_err_ratelimited(dev, "Invalid stage-1 address width %d\n", + s1_cfg->addr_width); + return -EINVAL; + } + + if ((s1_cfg->flags & IOMMU_VTD_S1_SRE) && !ecap_srs(iommu->ecap)) { + pr_err_ratelimited("No supervisor request support on %s\n", + iommu->name); + return -EINVAL; + } + + if ((s1_cfg->flags & IOMMU_VTD_S1_EAFE) && !ecap_eafs(iommu->ecap)) { + pr_err_ratelimited("No extended access flag support on %s\n", + iommu->name); + return -EINVAL; + } + + spin_lock(&iommu->lock); + pte = intel_pasid_get_entry(dev, pasid); + if (!pte) { + spin_unlock(&iommu->lock); + return -ENODEV; + } + if (pasid_pte_is_present(pte)) { + spin_unlock(&iommu->lock); + return -EBUSY; + } + + pasid_clear_entry(pte); + + if (s1_cfg->addr_width == ADDR_WIDTH_5LEVEL) + pasid_set_flpm(pte, 1); + + pasid_set_flptr(pte, (uintptr_t)s1_gpgd); + + if (s1_cfg->flags & IOMMU_VTD_S1_SRE) { + pasid_set_sre(pte); + if (s1_cfg->flags & IOMMU_VTD_S1_WPE) + pasid_set_wpe(pte); + } + + if (s1_cfg->flags & IOMMU_VTD_S1_EAFE) + pasid_set_eafe(pte); + + if (s2_domain->force_snooping) + pasid_set_pgsnp(pte); + + pasid_set_slptr(pte, virt_to_phys(pgd)); + pasid_set_fault_enable(pte); + pasid_set_domain_id(pte, did); + pasid_set_address_width(pte, s2_domain->agaw); + pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); + pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED); + pasid_set_present(pte); + spin_unlock(&iommu->lock); + + pasid_flush_caches(iommu, pte, pasid, did); + + return 0; +} diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 958050b093aa..dd37611175cc 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -113,6 +113,8 @@ int intel_pasid_setup_dirty_tracking(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 Oct 26 04:42:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424356vqb; Wed, 25 Oct 2023 21:43:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKi9KyapZjXWT+IWuS3voT65OQ/T7lx3VnffFUCz0TE1iEUsbrY4M1TWLh9aGImbfj9Cfk X-Received: by 2002:a0d:d941:0:b0:5a7:be61:d52b with SMTP id b62-20020a0dd941000000b005a7be61d52bmr18399509ywe.24.1698295420051; Wed, 25 Oct 2023 21:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295420; cv=none; d=google.com; s=arc-20160816; b=Rj9PJe8wYqGuqXmXZVIH92LTjZiwIN7jg7ocsliS/bjDu8ChO0Wbu7zW6u90fvCyM2 v671lW9XRWJ6FpTRSj+NqcbhzDL2bPyE71kbnyuxo30sifR3WCyaNANodeA2emwRD7XU 2fEJEgtUMOc1VusojWqx5oT1k3U1xNxGwwiTheFs9/P/4lBXmsVROydP/r/pWVHMzDAP 1dY2Wf7iywlE+CyYlmmDkFPUMFy10/0xWDOelhB3wpYVH0ZLfcMKVXaEDvr19NYxVQt/ EWKYfSTke++XLkbXzqaFTVsaT52SFUptHcAaKCtCTAclXXIL2ogdIii1I0paYj1qZtnL DSHQ== 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=YiKIxrdLGCa9ZukZISS8ZMv3yLVTuAcbYv1Ihz8AJRA=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=n+3MNoMnvvrnkV8+2QpGrArQwL5L1WdHN6NK2FqcUvz8mhJy4+gfOzQ0QP//a0nPGS Y0cO588TSAsx2o3UBVBbpyepgTip5QR0tZ9Co17kY/UfDyxeVCg4YRmRiJTw4ffF3oCq rEOdOztQf5zs5wnM2Ksq8KEzdFiEZ/RRcvPdWknID9cpm9ad3DHZTAs+8VMAxpR0fy/+ M29qfoQin5zAYQO9XAccJvkBPL+5XCDhCdyiYPQO+w2h9LeY1NdP5+AGWi5y4iDq4hWY hU69sczqsczseu+uXFwla0jwn+QQqpm5pohl94zYLxYkDR7Z84YaQz3S068GznnbQwy2 TTiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EOUTxwlE; 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 q188-20020a0dcec5000000b005a7e46262e7si12212392ywd.375.2023.10.25.21.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:43:40 -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=EOUTxwlE; 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 74A9181BA643; Wed, 25 Oct 2023 21:43:38 -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 S234520AbjJZEn0 (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233183AbjJZEm6 (ORCPT ); Thu, 26 Oct 2023 00:42:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368B419A; Wed, 25 Oct 2023 21:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295375; x=1729831375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RvKdWV+FSUYNPeoWJYd2Pc/eewINNmcStt1FxD5aggM=; b=EOUTxwlE4VoTEci/1YGtzyeo/jPaYbui15bJUCCXt0pDEIi35aZz48tU u9ktDonPIKI1gLyLNVecwsKlgjzSUaJDo6ndrVsCSJ3UVukbmiTkBqNKz BtH3kj90SBYeOMhv9ePJhfgsSAnx5n1OIMRLiMLVx1CtJt2LEl6sDchNT O4yjYV5nAO0iMxIVCfJEyjFXVdiZBAi9YC2eUzGddt4300tMB76I14rk9 YL1UZmt21BD/PeHunayEdk1doS7iZaEnPb86c50h1sZ7Ea5EHeIr3GNSK 7ql9eVl06+5lQknNfVSeYQPgltL1v2zvojiPG2R49eenvvJyYQa50XRNA w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670766" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670766" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478571" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478571" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:24 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com Subject: [PATCH v8 5/8] iommu/vt-d: Make domain attach helpers to be extern Date: Wed, 25 Oct 2023 21:42:13 -0700 Message-Id: <20231026044216.64964-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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]); Wed, 25 Oct 2023 21:43:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791818618506842 X-GMAIL-MSGID: 1780791818618506842 This makes the helpers visible to nested.c. Suggested-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Signed-off-by: Yi Liu Signed-off-by: Jason Gunthorpe --- 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 cb64759b3d95..292baa64188b 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); @@ -561,7 +560,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); @@ -1779,8 +1778,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; @@ -1829,8 +1827,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; @@ -3975,7 +3972,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; @@ -4128,8 +4125,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 f59a9374f62d..6a97711f947a 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -878,6 +878,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 Oct 26 04:42:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424736vqb; Wed, 25 Oct 2023 21:44:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5fTvGg4iY9yoVjNV/B8mgUs77vlgdF8WcEpl1u8b+nGhGE7W68wQLGhSkeMwdapxu+r2j X-Received: by 2002:a05:6902:507:b0:d9b:87f3:54f7 with SMTP id x7-20020a056902050700b00d9b87f354f7mr17892327ybs.49.1698295485862; Wed, 25 Oct 2023 21:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295485; cv=none; d=google.com; s=arc-20160816; b=JzJLV1DQLtwue0WuMhFByWgKRQ005x/HB10udN8MdEbXPIjXOzLZFoRWEPC9wSy3OR EzFUVgtAxR3cxMHchEiQBcvyLOgjmuvo4xy0xxND+H4uLxFZfZyusoIkukoUrTuU9rmj rsL5AL//d6ok9bCh1AfkX4EAboZ2/Eqidh7E8nZQWP2VPT+dGMhNGc87Aq4lVqydMufk O//AiaABI12S4iVj/NuwrlyrGGSyv5aKbeZL/1afA0mtgh+gYLVtNCcDUDuopGvC/f7g Po3KrIwetCSUOcE9HQ0l6H5nKk2FrPcarFChEj2RMCYfrj1Gmr6ELC7FMISUHGCvxOe9 T9aA== 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=dkzDEvBxzmMaB0OcWJQDLSDsprizT3xBhdcV+nnDRTA=; fh=IZyM1AM0bATemv9EzafoXv7q5+geru1rOhtf89P+YN0=; b=tePpeM8FVx3yD8tsHVcV2Ldx+EORkvu01TCWA07H6YDSaIIaWuS44/F8uB3wnt+hUg mf2YpSBolX6w6wo9LqybbB4nwF6gM3NuE2ZnqFUv1sBe5U9JM3tCvqMaa/tMnHXmUDXX /+qfrc8McFX+8aenUIjCBQWrOxyuvvsa+3Z09MssqmxNEbuuJ9hltEBDZmlyiro/MdCm f3+F9aADMwfASzNp28N+5DeFkEfjKxXGC3Nu1MXT3EOZL7EVt3P3A9+lRfHxcdjMEyR8 SkSfVbk6g1I3ybrwlcb1C0lhQzj9/Hvm6j++UaHj9JaMiiVYt/b3fsp4uETK0/J9eqPS lIYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b4xzFrz4; 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 e187-20020a2537c4000000b00da04908d3e1si5930729yba.613.2023.10.25.21.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:44:45 -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=b4xzFrz4; 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 6DB5580F4E3A; Wed, 25 Oct 2023 21:44:42 -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 S1343976AbjJZEnp (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343812AbjJZEm7 (ORCPT ); Thu, 26 Oct 2023 00:42:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9774B1B6; Wed, 25 Oct 2023 21:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295376; x=1729831376; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eEUcP5KcutX2o5j+Ufm6y0KGFrXJgHvpAP1Vmptmk8I=; b=b4xzFrz4UvpxXND4UP32DT7Nj1Jt57BY7JlQnuxVm8B418QsJAxxtIwU CMurICzLsr/U39grCbRYzh2KXYUatMZOfVhxebMxzvUdt01NWciAdxpEV 7kOt9dfE5+zG5+GCOLO7kRB/89UAGjlOUieMQiqUpQM6lskWRqrFRzPQw AKuUuU7MPqnT27TXvNUY8XIFrxfSL0sRqXYFyI/2AmZIJMYnaCU0lShf4 jPODkqTlpAnP2SkAvaAwyBP44C1FcZGkyBP81FOrkrBPB88s5Pjmz5+bl kgXGKv2LzbERxdsyIlWSQu8teYa4QVBiAYqwPznk+ElbR+TS8VUo6bJIl w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670776" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670776" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478580" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478580" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:26 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com, Jacob Pan Subject: [PATCH v8 6/8] iommu/vt-d: Set the nested domain to a device Date: Wed, 25 Oct 2023 21:42:14 -0700 Message-Id: <20231026044216.64964-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 25 Oct 2023 21:44:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791887139278409 X-GMAIL-MSGID: 1780791887139278409 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 Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/nested.c | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 56bb205fca06..b560ab76e126 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -12,8 +12,61 @@ #define pr_fmt(fmt) "DMAR: " fmt #include +#include +#include #include "iommu.h" +#include "pasid.h" + +static int intel_nested_attach_dev(struct iommu_domain *domain, + struct device *dev) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + struct intel_iommu *iommu = info->iommu; + unsigned long flags; + int ret = 0; + + if (info->domain) + device_block_translation(dev); + + if (iommu->agaw < dmar_domain->s2_domain->agaw) { + dev_err_ratelimited(dev, "Adjusted guest address width not compatible\n"); + return -ENODEV; + } + + /* + * Stage-1 domain cannot work alone, it is nested on a s2_domain. + * The s2_domain will be used in nested translation, hence needs + * to ensure the s2_domain is compatible with this IOMMU. + */ + ret = prepare_domain_attach_device(&dmar_domain->s2_domain->domain, dev); + if (ret) { + dev_err_ratelimited(dev, "s2 domain is not compatible\n"); + return ret; + } + + ret = domain_attach_iommu(dmar_domain, iommu); + if (ret) { + dev_err_ratelimited(dev, "Failed to attach domain to iommu\n"); + return ret; + } + + ret = intel_pasid_setup_nested(iommu, dev, + IOMMU_NO_PASID, dmar_domain); + if (ret) { + domain_detach_iommu(dmar_domain, iommu); + dev_err_ratelimited(dev, "Failed to setup pasid entry\n"); + return ret; + } + + info->domain = dmar_domain; + spin_lock_irqsave(&dmar_domain->lock, flags); + list_add(&info->link, &dmar_domain->devices); + spin_unlock_irqrestore(&dmar_domain->lock, flags); + + return 0; +} static void intel_nested_domain_free(struct iommu_domain *domain) { @@ -21,6 +74,7 @@ static void intel_nested_domain_free(struct iommu_domain *domain) } static const struct iommu_domain_ops intel_nested_domain_ops = { + .attach_dev = intel_nested_attach_dev, .free = intel_nested_domain_free, }; From patchwork Thu Oct 26 04:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424616vqb; Wed, 25 Oct 2023 21:44:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQN/aVCausxcR8h3EIqm1qvRJZy3o7wlA2RxxjPA8bjRQUtND4MNqL+mg9OqKIezhLGKoa X-Received: by 2002:a25:5046:0:b0:d86:5844:a897 with SMTP id e67-20020a255046000000b00d865844a897mr16937319ybb.5.1698295465852; Wed, 25 Oct 2023 21:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295465; cv=none; d=google.com; s=arc-20160816; b=g3XP4+n/C69LMzkREHjE1jhIve7aDZIto27acSv8UsijsnhVQJhwGDuCtGBKrc2QlH pOqaKLsj2sQQvfzlm3Eg3tuoncuwNdqHuVAjfi+iUaFLDw1mKJh+ZSt9i4u0rbpVDxbl h6/2pEgjc50uhfQqcvbgdftS6pOqDoMGTU8XdYCFVCeBYTtlStgK2Y91h2uAsxakvfWZ aL0B7oMNGK+UrJ1M5xYEZfVb46BTV9Gm/NsBynChnEoStxcqh9jFe/OQi9kJKiu5g2Ah Kw1jdWJ647VCMGoYreUmpTYY2rDV7PpupuaPQrXgV4MRvx5223IXpSQDhspvU0aC6v5U kbpQ== 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=19bKxkt241CPJtgRcVzt2nI99T/b6TYZ78VGXRtezmg=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=WNHGd9G+Up7ycXuIubsYkwQcBSSkYKwZOlGg4QlcFOvFcys7S0EYG5xlQjD+4mdHJk vcFsG9zkd4ef3WjfeRhS9ufIgQ9DcioDUvXweDxikACaRwXVyG1noiVCXin6PL2YKUj5 zTt5vhmPbFAkqt+kDeKxIrsG9+AzD6JX7rkqu/SdyAPexHtJ4UbcXWC9tM0Xso4naUd4 BaIEI+qR1rlMckFo1RZe4QYNFKbUtu18HWS/NLH7WM7VDPFt/wXJsXvuu829RI0Hg+V3 1RODAl8Wg0PKRxtZkDP7TNFnnHaBq+ZGO/Av9z401/IyEVGKEmjMuvkmtVmxmqEz9j9N 8s3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MEfyeyS3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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. [23.128.96.32]) by mx.google.com with ESMTPS id f4-20020a256a04000000b00d86625e8ad6si6684591ybc.115.2023.10.25.21.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MEfyeyS3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 39EFE809024E; Wed, 25 Oct 2023 21:44:23 -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 S1343865AbjJZEni (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343824AbjJZEm7 (ORCPT ); Thu, 26 Oct 2023 00:42:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149BC1B9; Wed, 25 Oct 2023 21:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295377; x=1729831377; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6rYDQz/MWEAW+IS0pl99symy0Ie0OKVXnjfTmOy5Xes=; b=MEfyeyS3RvC76bRWVxKZBZmlc89iXvst9n9Lf+fXI0wYXI0+l6dtDrx7 YHHscLw4kVcEzDoYxXd1hzSr476a4u6AKjIfF+MoXaKe+EVCoLL2PTgUT D/YOOnXaumf97ALusHUeA7rFcaejyG2JQ7x2YZy4WyUTPlfX3quKbBpzS +GD2AqkO1fOFQ875cPiI4bVw/mZFwUO84/Tl6fM81hDir3mC4lFN21jaK xlO3V0bP8A/wOqFWWSnWPmpiRHx5AlIBNqRoX5kiT5jEB7C21b6qw6lzu 13dLgv8ZxldvqOHbTtBQJUQzxFQqhgKAtAcsqfMSvsQoFZj6QQEijPmdM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670790" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670790" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478589" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478589" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:27 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com Subject: [PATCH v8 7/8] iommu/vt-d: Add nested domain allocation Date: Wed, 25 Oct 2023 21:42:15 -0700 Message-Id: <20231026044216.64964-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 21:44:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791866125700889 X-GMAIL-MSGID: 1780791866125700889 From: Lu Baolu This adds the support for IOMMU_HWPT_DATA_VTD_S1 type. And 'nested_parent' is added to mark the nested parent domain to sanitize the input parent domain. Signed-off-by: Lu Baolu Signed-off-by: Yi Liu Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 39 ++++++++++++++++++------------------ drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/nested.c | 3 ++- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 292baa64188b..4ce372d5d4f3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4077,38 +4077,39 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data) { + struct device_domain_info *info = dev_iommu_priv_get(dev); + bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + bool nested_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; + struct intel_iommu *iommu = info->iommu; struct iommu_domain *domain; - struct intel_iommu *iommu; - bool dirty_tracking; + + /* Must be NESTING domain */ + if (parent) { + if (!nested_supported(iommu) || flags) + return ERR_PTR(-EOPNOTSUPP); + return intel_nested_domain_alloc(parent, user_data); + } if (flags & (~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING))) return ERR_PTR(-EOPNOTSUPP); - - if (parent || user_data) - return ERR_PTR(-EOPNOTSUPP); - - iommu = device_to_iommu(dev, NULL, NULL); - if (!iommu) - return ERR_PTR(-ENODEV); - - if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !nested_supported(iommu)) + if (nested_parent && !nested_supported(iommu)) return ERR_PTR(-EOPNOTSUPP); - - dirty_tracking = (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING); - if (dirty_tracking && !ssads_supported(iommu)) + if (user_data || (dirty_tracking && !ssads_supported(iommu))) return ERR_PTR(-EOPNOTSUPP); /* - * domain_alloc_user op needs to fully initialize a domain - * before return, so uses iommu_domain_alloc() here for - * simple. + * domain_alloc_user op needs to fully initialize a domain before + * return, so uses iommu_domain_alloc() here for simple. */ domain = iommu_domain_alloc(dev->bus); if (!domain) - domain = ERR_PTR(-ENOMEM); + return ERR_PTR(-ENOMEM); + + if (nested_parent) + to_dmar_domain(domain)->nested_parent = true; - if (!IS_ERR(domain) && dirty_tracking) { + if (dirty_tracking) { if (to_dmar_domain(domain)->use_first_level) { iommu_domain_free(domain); return ERR_PTR(-EOPNOTSUPP); diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 6a97711f947a..ba9be915eb84 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -601,6 +601,7 @@ struct dmar_domain { * level. */ u8 dirty_tracking:1; /* Dirty tracking is enabled */ + u8 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/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index b560ab76e126..b5a5563ab32c 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -89,7 +89,8 @@ struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, /* Must be nested domain */ if (user_data->type != IOMMU_HWPT_DATA_VTD_S1) return ERR_PTR(-EOPNOTSUPP); - if (parent->ops != intel_iommu_ops.default_domain_ops) + if (parent->ops != intel_iommu_ops.default_domain_ops || + !s2_domain->nested_parent) return ERR_PTR(-EINVAL); ret = iommu_copy_struct_from_user(&vtd, user_data, From patchwork Thu Oct 26 04:42:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 158391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp424722vqb; Wed, 25 Oct 2023 21:44:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECeDEYF+W4GIc/B0KfJ40AxHK7C11/dXgczAlpKNr44Q8R3+m5zcdtkmrhMA2NswX+M/2E X-Received: by 2002:a25:37c7:0:b0:d9c:ceb5:938f with SMTP id e190-20020a2537c7000000b00d9cceb5938fmr3121862yba.4.1698295482212; Wed, 25 Oct 2023 21:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698295482; cv=none; d=google.com; s=arc-20160816; b=yZmtwzUmjCcTgU18Zuz80UESb01xC8pH+WM3eMAWYc4ErpCbBuqYPAm/5iJFziR9fO 3avN6RyrTGDw1Kddn5vLtRqxgZuRMnQ1quneKy5c3NutfrxBHimWapKPJ9tTnNRpz6eZ QLkPtRlqI5NmRwafVlEzW/rOrYSTsw88Wt5qMYpKq/xu9gM4pBj54kIchq+mIfK9YthZ ZBjnrDKfrsY33JvvHTPV7xl0ZQhBbyjRUPIrbSxr8RBsXahLoNGWwsNSSPcq94pwT0XD PuTZOHB49lVB6KDBLjCdnWvii9VclckRlMG1soQJwRlcnAs5M3+wxWPldqCI9auSPu4z ugYg== 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=jcg3p1b64zfQJiDCSHEqWH3eQZ9mJ7oi8TfB+HNXNxo=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=Swji/7Fg3eIyxr9vav9CDSqWoMmrYdrKvFsC850l5mihnreKXMcA/MTcZhrhciwnJs uFAf/S7CAFy0X3C50tYYRokxSADqjswS35pVaRJYS29ApD6ZbHN1CxQ7skka+cygUNxg RDDHYkWM4+rTVVf3EIDiYFZTJiWEVDNsnL4kJggE8S29idwjmvMFYBYO5Tz3ewtvT31T GFZP4/6LEi7y2CgCcGuscqIXoMckEyezCy+CzV4HXz6ClkppTqZ4dBW5ghIwzX593Q7E t3f5LaD7LfjcHh+nxY5NTPqfwsh/3MJf959BlsPH8FbUHC9YggcXDnTYX8whtUTJdjGg 7cyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F5NVRdyD; 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 o197-20020a2573ce000000b00d9ad271d8b1si13625037ybc.557.2023.10.25.21.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 21:44:42 -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=F5NVRdyD; 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 E385680FC090; Wed, 25 Oct 2023 21:44:38 -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 S234976AbjJZEnf (ORCPT + 26 others); Thu, 26 Oct 2023 00:43:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343802AbjJZEm7 (ORCPT ); Thu, 26 Oct 2023 00:42:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F0451AE; Wed, 25 Oct 2023 21:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698295377; x=1729831377; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KDC9jbEWS+pUOjSnJASBzBnQmqmwgvSEBwA1Yc2XCvQ=; b=F5NVRdyDSePTP+CoSkWw9GYcamC4QahcnclkuS4KD9vVAVFcLrUVsrdo i4u78rL9W8k6C2M9shaPi2hIOIuRGqgQLNH3CIAAg2QTi+th9WG6MGt8w u8G5fibLfL4zvQaSgMzbXy/l7uXL39NNtpwvYkaglK4th1gempnASX2DJ vkqNPhRf8BUilU/1IqYfUP3k5xlab63JlCRpqv7L/nQipk17NzuLFtsw1 s9UUtEmhukYnxpAx37pQI8cxoSZ8II9jx7xIxqVYeaOe8dMa35dDH6uWd GpaezkrLmwZa2QVvT9ZXxtPz2ptdivKVNuHhfdt1oKvbqeQRkrkP6jsc/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="367670804" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="367670804" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 21:42:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="829478598" X-IronPort-AV: E=Sophos;i="6.03,252,1694761200"; d="scan'208";a="829478598" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 25 Oct 2023 21:42:28 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com Subject: [PATCH v8 8/8] iommu/vt-d: Disallow read-only mappings to nest parent domain Date: Wed, 25 Oct 2023 21:42:16 -0700 Message-Id: <20231026044216.64964-9-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026044216.64964-1-yi.l.liu@intel.com> References: <20231026044216.64964-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 25 Oct 2023 21:44:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780791883473890092 X-GMAIL-MSGID: 1780791883473890092 From: Lu Baolu When remapping hardware is configured by system software in scalable mode as Nested (PGTT=011b) and with PWSNP field Set in the PASID-table-entry, it may Set Accessed bit and Dirty bit (and Extended Access bit if enabled) in first-stage page-table entries even when second-stage mappings indicate that corresponding first-stage page-table is Read-Only. As the result, contents of pages designated by VMM as Read-Only can be modified by IOMMU via PML5E (PML4E for 4-level tables) access as part of address translation process due to DMAs issued by Guest. This disallows read-only mappings in the domain that is supposed to be used as nested parent. Reference from Sapphire Rapids Specification Update [1], errata details, SPR17. Userspace should know this limitation by checking the IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 flag reported in the IOMMU_GET_HW_INFO ioctl. [1] https://www.intel.com/content/www/us/en/content-details/772415/content-details.html Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Signed-off-by: Yi Liu Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 6 ++++++ include/uapi/linux/iommufd.h | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 4ce372d5d4f3..a2c429855cc0 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2194,6 +2194,11 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0) return -EINVAL; + if (!(prot & DMA_PTE_WRITE) && domain->nested_parent) { + pr_err_ratelimited("Read-only mapping is disallowed on the domain which serves as the parent in a nested configuration, due to HW errata (ERRATA_772415_SPR17)\n"); + return -EINVAL; + } + attr = prot & (DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP); attr |= DMA_FL_PTE_PRESENT; if (domain->use_first_level) { @@ -4850,6 +4855,7 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type) if (!vtd) return ERR_PTR(-ENOMEM); + vtd->flags = IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17; vtd->cap_reg = iommu->cap; vtd->ecap_reg = iommu->ecap; *length = sizeof(*vtd); diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 3ce5ee5f09b6..0b2bc6252e2c 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -443,10 +443,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 read-only mappings + * on a nested_parent domain. + * 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