From patchwork Wed May 10 03:33:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C987C77B7D for ; Wed, 10 May 2023 03:34:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbjEJDeZ (ORCPT ); Tue, 9 May 2023 23:34:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjEJDeX (ORCPT ); Tue, 9 May 2023 23:34:23 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2079.outbound.protection.outlook.com [40.107.95.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A13C91FF3; Tue, 9 May 2023 20:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gWonM3qM/FXWfx7IxJmXr8wChJT3NrSVdNx/Jw/EJalWGCtjZkwT5yuViSJ8HmZW4gtBWzVxla01cgd+Xra/q/cLW8OcNRTDqvRCA5gH+HAmioelL/XPL5BNmVHYqM41MPS0AFLcYYG/E40y1V4UFJ544xXTCCp6PwJciyHQy4rwvZZFIAzrLVb5J6gI/gwLf3hWN8Ub9k6OAvpBdJ1baGeWEWZORvCVHlJjU6ce0jK7SWq0dW7majMP05tVfLvzgNyk0/TX/V86p4l7HfKr5nA0En8ckYEeoQzg77er924vXrlf/Dpa6/oADf8RMcWCyEMB0X5hEhoq7MlDrwptsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hSbSlCr03XeDRoHeAnKC4x+Qxv/DX5Kz0F0kI7nfSzg=; b=L/SAx1HcQ3aPGIgz+ufgvI03FygA1QSZxND5doj+rNu3IjeA8qFp9MCsWXkzehT36/Q308AI8XgQlvF+UMVnExWBGB15z05I1ydSLz8dTOmFGYQFxrsRVSSpwDGV10Fca5wUAtIdszwlseT2fS6ipBVW1c4tVkbLyRvQUA8IUHf0vH99u76wxdsEH+ZnuCKfCSm8T8y1TSTKM0N66XQ784oeUcfcq1C9ckVSVvX7ERp81RjrU8njOTxSEATF8ENjtumcCNVCx1apPjblkqPqo5GgYiz7V+JTCtkbeqEKCTNcbzk26bdsoRDBQNJt5S/E41IdBSeb4GIjeHOjYZYt2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hSbSlCr03XeDRoHeAnKC4x+Qxv/DX5Kz0F0kI7nfSzg=; b=F5BZhaZOLLXyAznV5M3eRAnMWf6TiQWAXn3GJnyj+3mgUPwKYQaohbtO99A/ddvctRBOs9wh7NtakCCi171Odkhid33vfulb90h90g7Ql0JeP4Ux4kaE42rm/aXk1R1ZCDs6QTlKslGMLHfJ8oeb3rOfknLLMb/l6yWnIquvgGNbu9XeN1k6EDMzt8zwLC4ChiVHFVG1WcXdSnL4DzZfVaLGZNkXfG00CIpMD5FvGwh/Plkox+bsnyXmIF2sw18u5ZnI2XSznr5qtaeY8EohTq33B/0pPUfjPGq4sJvUWIYgjy+gFV9+WdphXkKYSoorReWZ177awX43s8Am2SI+VA== Received: from BN9PR03CA0359.namprd03.prod.outlook.com (2603:10b6:408:f6::34) by CY8PR12MB7100.namprd12.prod.outlook.com (2603:10b6:930:60::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.20; Wed, 10 May 2023 03:34:19 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::7c) by BN9PR03CA0359.outlook.office365.com (2603:10b6:408:f6::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:19 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:10 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:09 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:08 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 01/17] vfio: Remove VFIO_TYPE1_NESTING_IOMMU Date: Tue, 9 May 2023 20:33:21 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|CY8PR12MB7100:EE_ X-MS-Office365-Filtering-Correlation-Id: b9537d55-329c-45f6-213e-08db51077032 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3Iav346U5iebInO33CVa4wASxQ3gObKo/IPk2OGOdYloceIt7kRK8ThsWZe5wTBceTvr6/ay6j0QYMPGkDe/jPgTLDToEOYKfwvFpYE/pkPm27iV9K1Dt3SWmsES685yW9MMhVTpEtRy/Z3M0V1fWe1OoTYu6mkJ1hzKK+T5jJuUmuo12jiX4Vbr5YCA1zqf06l1MWdTWUuAN2x8xPfcX9qkRdJEvRtCGkKvawI2T4aio1+9jwp9Sh/4fW5TJGJ74uupvTNNS0+MEym0qX+sVmvl8esQU3cr9Uo/nwPmGLb6MWXl4uFPdcGfmQeCcWIoA5w0xWq70FckGEmgoONyt+RMwNOOfubX+E7Yichnmdt9wpQvVRs3ZPWWAnb9fc2ca3D9Ywg/wvm/YNV1coQ0IWcg9hyxXMDSNKHscY8SA3YBN6zt0zzD5XFtv0hnPIY1uUj4u6Wq2g+ECe2uJ+sTVOe6dyny1wwfz0voAalhl/sHW7WBjbYIoVihuHWAtMvUY+lRJsYyNVE5sZheIePaKYdTX1ljrUy/xFRcHeIEt0mPcx3V1DvD7veQ9RxCuQ1ZUDy3QX2z7kEaWqMscpr1wyoyUoXfwwi1HbhsxRT8R2gkpHAR+Vr3rkL5GaU0O8T16FxxwVtiw6bgc0wsiYxE44ILk2g2Wxon4xHDrc/u7bkMXj3hlcF91bzn33BRTZyUsJ1hoSiRAi3HiOPwZjaAQdMZ5NigGkxlTL/mD9JLgB4GjqwvQ2w3shb0eSjbDOqT X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(346002)(39860400002)(136003)(451199021)(40470700004)(46966006)(36840700001)(4326008)(86362001)(36756003)(82310400005)(2906002)(70206006)(478600001)(7416002)(40480700001)(47076005)(83380400001)(336012)(426003)(6666004)(7696005)(186003)(966005)(316002)(26005)(110136005)(5660300002)(70586007)(40460700003)(54906003)(8936002)(356005)(2616005)(41300700001)(8676002)(82740400003)(7636003)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:19.0136 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9537d55-329c-45f6-213e-08db51077032 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7100 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Jason Gunthorpe This control causes the ARM SMMU drivers to choose a stage 2 implementation for the IO pagetable (vs the stage 1 usual default), however this choice has no visible impact to the VFIO user. Further qemu never implemented this and no other userspace user is known. The original description in commit f5c9ecebaf2a ("vfio/iommu_type1: add new VFIO_TYPE1_NESTING_IOMMU IOMMU type") suggested this was to "provide SMMU translation services to the guest operating system" however the rest of the API to set the guest table pointer for the stage 1 was never completed, or at least never upstreamed, rendering this part useless dead code. Since the current patches to enable nested translation, aka userspace page tables, rely on iommufd and will not use the enable_nesting() iommu_domain_op, remove this infrastructure. However, don't cut too deep into the SMMU drivers for now expecting the iommufd work to pick it up - we still need to create S2 IO page tables. Remove VFIO_TYPE1_NESTING_IOMMU and everything under it including the enable_nesting iommu_domain_op. Just in-case there is some userspace using this continue to treat requesting it as a NOP, but do not advertise support any more. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 16 ---------------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 16 ---------------- drivers/iommu/iommu.c | 10 ---------- drivers/iommu/iommufd/vfio_compat.c | 7 +------ drivers/vfio/vfio_iommu_type1.c | 12 +----------- include/linux/iommu.h | 3 --- include/uapi/linux/vfio.h | 2 +- 7 files changed, 3 insertions(+), 63 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 3fd83fb75722..2c53849cae30 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2740,21 +2740,6 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) return group; } -static int arm_smmu_enable_nesting(struct iommu_domain *domain) -{ - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - int ret = 0; - - mutex_lock(&smmu_domain->init_mutex); - if (smmu_domain->smmu) - ret = -EPERM; - else - smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED; - mutex_unlock(&smmu_domain->init_mutex); - - return ret; -} - static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args) { return iommu_fwspec_add_ids(dev, args->args, 1); @@ -2881,7 +2866,6 @@ static struct iommu_ops arm_smmu_ops = { .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, - .enable_nesting = arm_smmu_enable_nesting, .free = arm_smmu_domain_free, } }; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 6e0813b26fb6..97d3fbcbd7f3 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1484,21 +1484,6 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) return group; } -static int arm_smmu_enable_nesting(struct iommu_domain *domain) -{ - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - int ret = 0; - - mutex_lock(&smmu_domain->init_mutex); - if (smmu_domain->smmu) - ret = -EPERM; - else - smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED; - mutex_unlock(&smmu_domain->init_mutex); - - return ret; -} - static int arm_smmu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks) { @@ -1579,7 +1564,6 @@ static struct iommu_ops arm_smmu_ops = { .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, - .enable_nesting = arm_smmu_enable_nesting, .set_pgtable_quirks = arm_smmu_set_pgtable_quirks, .free = arm_smmu_domain_free, } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b44fd1a76997..13a2e0e26884 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2680,16 +2680,6 @@ static int __init iommu_init(void) } core_initcall(iommu_init); -int iommu_enable_nesting(struct iommu_domain *domain) -{ - if (domain->type != IOMMU_DOMAIN_UNMANAGED) - return -EINVAL; - if (!domain->ops->enable_nesting) - return -EINVAL; - return domain->ops->enable_nesting(domain); -} -EXPORT_SYMBOL_GPL(iommu_enable_nesting); - int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirk) { diff --git a/drivers/iommu/iommufd/vfio_compat.c b/drivers/iommu/iommufd/vfio_compat.c index fe02517c73cc..2c5a523b5354 100644 --- a/drivers/iommu/iommufd/vfio_compat.c +++ b/drivers/iommu/iommufd/vfio_compat.c @@ -291,12 +291,7 @@ static int iommufd_vfio_check_extension(struct iommufd_ctx *ictx, case VFIO_DMA_CC_IOMMU: return iommufd_vfio_cc_iommu(ictx); - /* - * This is obsolete, and to be removed from VFIO. It was an incomplete - * idea that got merged. - * https://lore.kernel.org/kvm/0-v1-0093c9b0e345+19-vfio_no_nesting_jgg@nvidia.com/ - */ - case VFIO_TYPE1_NESTING_IOMMU: + case __VFIO_RESERVED_TYPE1_NESTING_IOMMU: return 0; /* diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 3d4dd9420c30..0bce568f129a 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -72,7 +72,6 @@ struct vfio_iommu { uint64_t pgsize_bitmap; uint64_t num_non_pinned_groups; bool v2; - bool nesting; bool dirty_page_tracking; struct list_head emulated_iommu_groups; }; @@ -2200,12 +2199,6 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, if (!domain->domain) goto out_free_domain; - if (iommu->nesting) { - ret = iommu_enable_nesting(domain->domain); - if (ret) - goto out_domain; - } - ret = iommu_attach_group(domain->domain, group->iommu_group); if (ret) goto out_domain; @@ -2546,9 +2539,7 @@ static void *vfio_iommu_type1_open(unsigned long arg) switch (arg) { case VFIO_TYPE1_IOMMU: break; - case VFIO_TYPE1_NESTING_IOMMU: - iommu->nesting = true; - fallthrough; + case __VFIO_RESERVED_TYPE1_NESTING_IOMMU: case VFIO_TYPE1v2_IOMMU: iommu->v2 = true; break; @@ -2643,7 +2634,6 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu, switch (arg) { case VFIO_TYPE1_IOMMU: case VFIO_TYPE1v2_IOMMU: - case VFIO_TYPE1_NESTING_IOMMU: case VFIO_UNMAP_ALL: return 1; case VFIO_UPDATE_VADDR: diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 1e1124f79b56..470b088a13f7 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -360,7 +360,6 @@ struct iommu_ops { * @enforce_cache_coherency: Prevent any kind of DMA from bypassing IOMMU_CACHE, * including no-snoop TLPs on PCIe or other platform * specific mechanisms. - * @enable_nesting: Enable nesting * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*) * @free: Release the domain after use. */ @@ -393,7 +392,6 @@ struct iommu_domain_ops { dma_addr_t iova); bool (*enforce_cache_coherency)(struct iommu_domain *domain); - int (*enable_nesting)(struct iommu_domain *domain); int (*set_pgtable_quirks)(struct iommu_domain *domain, unsigned long quirks); @@ -566,7 +564,6 @@ extern int iommu_page_response(struct device *dev, extern int iommu_group_id(struct iommu_group *group); extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); -int iommu_enable_nesting(struct iommu_domain *domain); int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index e57112f63760..ecbd013ae6ea 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -35,7 +35,7 @@ #define VFIO_EEH 5 /* Two-stage IOMMU */ -#define VFIO_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ +#define __VFIO_RESERVED_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ #define VFIO_SPAPR_TCE_v2_IOMMU 7 From patchwork Wed May 10 03:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95CCFC77B7D for ; Wed, 10 May 2023 03:34:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbjEJDea (ORCPT ); Tue, 9 May 2023 23:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjEJDeY (ORCPT ); Tue, 9 May 2023 23:34:24 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2047.outbound.protection.outlook.com [40.107.92.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA0302106; Tue, 9 May 2023 20:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cdZwJpdqqtI4g7vhqGYeHhDHluBPi5Ay26IOAQFYo5pN0anXZdfJlkBTv7JiQ2bRU5o6F23k7UBqMmLDFsjCrgMppZDCA8B23QWRuMndycL9WmlPkWqtu7XcNwGprxov7HHaeXDuPVHp94Gxmboxuuap7qKFRlRTTDuslV5/A/X2busjG/zDg1we6X9xiH8F7WKfCD8homr0ffX8rTYcymgTHx4KVjgHXAIEm5gYgLtUt6Ms+mw8heshjuiwnid3ZUTzYbaGo4M+PcY+jM2CUtkCNK0zHUOJ8IrBb+TSZ6TCRUCFiSkBmImqhcCeBYbidxzg150YUFU8cZWx2q3/4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cvHjgyKrQ480jN7N7o/cm/ZBNxT5I7wslxk6qwbvXhY=; b=TO4fFBc+iGqGbrsBwUuqtvb68doroR06ThVLyJR5zroAOG83ayLXDxQeuScm+wQnH9m2hZi3cINB+NlI+Bl+DDnMXjoEBhmb5TCzKhGMa0b5HuxydNLyQDZLI7ZAuTqjk/m0xDF4rPbNNYMAehtFTrxlEw5fqMNjNA4enZ8jfnWm/X+sUOKaA0R1a48knlAcHe9WyPS5VjiioRi1yzpTfX/+mzDfilDDslO4/R+gcN2RlnHuj3p5h8BApvQ9aDJvXHIReOa5mulJbgLmcCRZcg/h4mIHGQQcKzwXekh9tTbNzPB4wj6kHmxl9K1fMBMm1T3EOE2VP19n7JTyntrS/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cvHjgyKrQ480jN7N7o/cm/ZBNxT5I7wslxk6qwbvXhY=; b=eaJhWZ0+H71c2KErsS3WqO9r+OQccTUBUAAunEgN6vcT1mDTAuaiNsycZKTxGO3TIS4Zu2gyfGjEYmR+X/25dr1SCPh90tlpX5n482Y1K20v3cQQvPhgrHNZfE3sjg9b8uB5DIW0/25n+ZraMfN6LRNL13YhUrckaR55tEfvXbDbAiSWDVIC/BU0PWfMlgvteQc34tjUYTGbDU33weXM5i0X4ieYa66yZxF8W99IvnhLGV+TuUAf51qPBMESYYFQCnZMFuZkHUu+haBcZG998qF2P7aKtM4cIBpac4dT0YxFYQlizvfffQN5DrKCqK8YgQjJ+sKFl2cxuvdqXXHR4Q== Received: from BN9PR03CA0343.namprd03.prod.outlook.com (2603:10b6:408:f6::18) by BL3PR12MB6426.namprd12.prod.outlook.com (2603:10b6:208:3b5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 03:34:21 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::21) by BN9PR03CA0343.outlook.office365.com (2603:10b6:408:f6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:20 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:11 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:11 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:10 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 02/17] iommu/dma: Support MSIs through nested domains Date: Tue, 9 May 2023 20:33:22 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|BL3PR12MB6426:EE_ X-MS-Office365-Filtering-Correlation-Id: ff651d43-f752-46eb-c2db-08db5107713a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YoKPqQADIGX6r+CfrPepnocVJv7x8pT4zKAjLH5ueK9tZZjQZyrfPKRNSoCc/90SsR1zhuI3D3CCEHxAhQptP1mkqrJNWNE2tXQHczfRZnm2ie5oBPwvUSiLjLmyQehoJk7MafecQh9ng4823lLDlKaL3VcY5A+eafqfmjI6szCuuQHX5YUZCVPEto4big3DKeRfcqmCgZibP+h+oDekxCDzOTfW9iV/w2xzBhZDEV3PLxkh4WCB5+70EdiF6SYYzYxkKryXkdGbBKEOCiXawtSxnU5SLiPBL57YJw7k9SAybQ2RBlcTcMopbhLXnM2yaTnrq/TaqpsNDraJRNB0hThxanF3QIfy7Ae0VewJ95wFa31OVofEI4AyG5cCu3/xDIMRAdjlGLENkx/gjV3VR/pIDrC5XxSBYBmrZ/roj56fxDljgUUop64Ek6YNgaBOvDRqkBnAL0Xu+KeNEnERVRXlKOVER7RBRvt+L5IjQ2pN4F/HzkppLzdw0NJLxJ9nlZVf4oBqQrPRklGCsUb4AJjeaZl48bKC2iybHCNxHmDMdW2KS/LrZLM7DFmO6OAd88HnFh9lTq2VtJmZecP7yYJQkUDlzQ4sYJLsUmJQIE7HDHkHK+ZC6lozjSHxRHLAYkf7f9p/USNSH7lQYOogO/wWt2sSCJsaoge7+FzJq7CDOx0+TjJ2YcKWXgV24X6nvmJGwNoOPKW2N/n4O8Oblg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(136003)(376002)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(86362001)(356005)(7636003)(316002)(41300700001)(40480700001)(40460700003)(2906002)(7416002)(36756003)(186003)(36860700001)(8936002)(8676002)(26005)(5660300002)(478600001)(82740400003)(336012)(426003)(110136005)(54906003)(6666004)(7696005)(83380400001)(70206006)(70586007)(82310400005)(47076005)(4326008)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:20.7479 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff651d43-f752-46eb-c2db-08db5107713a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6426 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Robin Murphy Currently, iommu-dma is the only place outside of IOMMUFD and drivers which might need to be aware of the stage 2 domain encapsulated within a nested domain. This would be in the legacy-VFIO-style case where we're using host-managed MSIs with an identity mapping at stage 1, where it is the underlying stage 2 domain which owns an MSI cookie and holds the corresponding dynamic mappings. Hook up the new op to resolve what we need from a nested domain. Signed-off-by: Robin Murphy Signed-off-by: Nicolin Chen --- drivers/iommu/dma-iommu.c | 18 ++++++++++++++++-- include/linux/iommu.h | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7a9f0b0bddbd..da2b28eb9723 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1642,6 +1642,20 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, return NULL; } +/* + * Nested domains may not have an MSI cookie or accept mappings, but they may + * be related to a domain which does, so we let them tell us what they need. + */ +static struct iommu_domain *iommu_dma_get_msi_mapping_domain(struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + + if (domain && domain->type == IOMMU_DOMAIN_NESTED && + domain->ops->get_msi_mapping_domain) + domain = domain->ops->get_msi_mapping_domain(domain); + return domain; +} + /** * iommu_dma_prepare_msi() - Map the MSI page in the IOMMU domain * @desc: MSI descriptor, will store the MSI page @@ -1652,7 +1666,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr) { struct device *dev = msi_desc_to_dev(desc); - struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct iommu_domain *domain = iommu_dma_get_msi_mapping_domain(dev); struct iommu_dma_msi_page *msi_page; static DEFINE_MUTEX(msi_prepare_lock); /* see below */ @@ -1685,7 +1699,7 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr) void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg) { struct device *dev = msi_desc_to_dev(desc); - const struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + const struct iommu_domain *domain = iommu_dma_get_msi_mapping_domain(dev); const struct iommu_dma_msi_page *msi_page; msi_page = msi_desc_get_iommu_cookie(desc); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 470b088a13f7..cb517898f55c 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -362,6 +362,8 @@ struct iommu_ops { * specific mechanisms. * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*) * @free: Release the domain after use. + * @get_msi_mapping_domain: Return the related iommu_domain that should hold the + * MSI cookie and accept mapping(s). */ struct iommu_domain_ops { int (*attach_dev)(struct iommu_domain *domain, struct device *dev); @@ -396,6 +398,8 @@ struct iommu_domain_ops { unsigned long quirks); void (*free)(struct iommu_domain *domain); + struct iommu_domain * + (*get_msi_mapping_domain)(struct iommu_domain *domain); }; /** From patchwork Wed May 10 03:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F235AC77B7D for ; Wed, 10 May 2023 03:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235126AbjEJDeg (ORCPT ); Tue, 9 May 2023 23:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbjEJDe3 (ORCPT ); Tue, 9 May 2023 23:34:29 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2045.outbound.protection.outlook.com [40.107.223.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 099B110CF; Tue, 9 May 2023 20:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HD8tRB0IPEw+Yp09ezmjSd5GYpS9WKkjIa8+wRpUceEywCy3XzRZZZ7CzlspHVisxW9BzCea2mHBNw6RjF/s+jfVbYh1TBH4tHIHgN+XDR90mcIKjsRmjlYwqAaq3ZvUpyVcoWm/jTS9qpJAh42m4YRSpzbXsLqcOvJNf5ZDE087VRy43g4cSOBTR+iRTQvFCyaDMXfKkpWdEUUzxQsYuqvkVOmpJKtABaxPBVqG8m7xVUpI4zJgvxTQ2Wk/xIGKDuNCq5ec1Uy3djyEA+RR1VD2DQeP0sLAZ2xXboAi86kCCx0AucGIPfJD0bgrnVk51V5/ODb5OC3WZfM3kdWAIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ywo+aUUeXF8oao0a2+KD1hp1U0/c3xW3/reF5Dp9LNE=; b=WFlZLocKT4GSA5AsmrbFzufH2Kjs+YIbhg/GjTTatTmwopOl175yHdadayH9srxg5tJhCuZDalTqYaJ1GUA5ZSkVhi2OyfglTy7EzSm1kM/cY3XGB/UGBFeh99X5rnGUt/rfAb0Cfn9E3Cy/c0yn1P/KV4vCF6A9om5qgI9TPPtq+dR2lzqUEj8MagHUUzw0UHBpw+/7M7M6dKw6Vd4gL9zJulO1lVwTLII8MUGVC9rvQCO5bWKqk/IaDfi1PSeTGpZX9tysx2bitSefvo7YT9cI16kd97UNAilwmBGRExWaQ0qCKoECPu/5hj+wLn2mNBUCPbhzLLfXQnhtev/Ccw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ywo+aUUeXF8oao0a2+KD1hp1U0/c3xW3/reF5Dp9LNE=; b=NmMkPIJJWIUOHjmEmKvM3DtwVuwahN5CSew1kFCG0pmm1ctwbQI07YFaa/KuQ4yU0H3l1Jk+yFDBwsYCy3GTfYfPbn6SM0cLqlnWRm6qIj6hvzVI6OzItorJyQI1PDUof6hXqRgs6gSXkpEdSys65OA3aDDFbtcvP9KcUFa5xrxCR3wmipSQVzzjEuzzHivI4A1lL3sLPUqrkHvM8G4v40kBL+nAgEY4LoJNiIT+dnBxrX1MPqNayEtxRN/T8natTEnp7Giq/U1j76BGFZCHB+GN0wfxsP/5YeLdo2FX0NAAolWofwtuCHTKOJT7ueXLp5cgOstMi3GOnXhmqlvBww== Received: from BN9P220CA0004.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:13e::9) by BL1PR12MB5190.namprd12.prod.outlook.com (2603:10b6:208:31c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 03:34:24 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:408:13e:cafe::8a) by BN9P220CA0004.outlook.office365.com (2603:10b6:408:13e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:23 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:12 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:12 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:11 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 03/17] iommufd: Add nesting related data structures for ARM SMMUv3 Date: Tue, 9 May 2023 20:33:23 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|BL1PR12MB5190:EE_ X-MS-Office365-Filtering-Correlation-Id: 3dd222a3-07f6-4038-f5cf-08db5107729c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ud7BcwgHJ63Nrjs30POp4n56YBr6R9l++6mgn3WNVElIatGs0uOmrwLQW60Hh5Xu9o9pcVep/MycmbOdibO1NcnLHAzQ4k6BFlKNjAAhEpZKK4Cf6nMS2KwwCARaR8zmixknt4uqB0JYA0TOxHvggDk8/rKpmjjAfwOnVUK+YqPvIR9B3hUT8BigufW4cbeYVUctNHKtHx2nKYB54ma4PpPUFQTBefi5UymzjUIYBESKqZhP014mu2HBxJQ0LS7SBI1h9NOx136oMCCuDTLETooJpFn+hXrKLwN2cx7uQZXACWLc9cVEWyoMHu314jTqp+sjz3U5Qgc1TjtIZjeU4IOzQb2gxtg6uCGEcJYJmo4Aa4Q/GsOe3hEFdIiaJ891b8gJM2hpFG0ruVQNLKj/vXm4MqVqtE+OoSb/UWm63uRVZiI9eiUvgFNZ8PNeiZpl/tXaykO5LuF8w3IbY0Ckwi6XIpxGjE/K7F96OvhgTbNfIjyn/KcVawLMz+UjWQDbB57mm2BPlR2+XoxieO+CebQZlSMABI/sbu3YmPO3/nXSQfsnpvL2vg3bAnOMYwfwdAEXYcsoV4JvSBBXQ5UvCatJb4wslOfkDvtzPai7a2acXKC0d9+KhaRGvrasSest41aCR9uI2gYaFPrqkm1g+cdDKNcwUWk1yKAlbb3XQTc8ugEazzE5KV4rXNoFV7gyZcPV/D3jhq9H4JOpiEPM6Q== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(46966006)(36840700001)(40470700004)(7636003)(26005)(356005)(47076005)(70206006)(70586007)(86362001)(40480700001)(7416002)(2906002)(40460700003)(4326008)(336012)(8676002)(82310400005)(316002)(54906003)(5660300002)(41300700001)(8936002)(110136005)(478600001)(82740400003)(83380400001)(2616005)(426003)(7696005)(6666004)(36860700001)(36756003)(186003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:23.0692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3dd222a3-07f6-4038-f5cf-08db5107729c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5190 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add the following data structures for corresponding ioctls: iommu_hwpt_arm_smmuv3 => IOMMUFD_CMD_HWPT_ALLOC iommu_hwpt_invalidate_arm_smmuv3 => IOMMUFD_CMD_HWPT_INVALIDATE The iommu_hwpt_arm_smmuv3 is a data structure to allocate an SMMU specific translation table, either a stage-1 Context Descriptor table or a stage-2 translation table, which would need the user Stream Table Entry or just a simple S2 flag respectively. The iommu_hwpt_invalidate_arm_smmuv3 is a data structure for a request of stage-1 cache invalidations that could be for TLB invalidations, Context Descriptor invalidations, and Address Translation Cache invalidations. The data structure contains all the necessary information about a user-space Command Queue, so the kernel can handle all invalidation commands with a single batch. Also, add IOMMU_HWPT_TYPE_ARM_SMMUV3 and IOMMU_HW_INFO_TYPE_ARM_SMMUV3. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/main.c | 1 + include/uapi/linux/iommufd.h | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 7d7c11c1c912..8461b12c43b7 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -288,6 +288,7 @@ union ucmd_buffer { */ struct iommu_hwpt_invalidate_intel_vtd vtd; struct iommu_hwpt_invalidate_request_intel_vtd req_vtd; + struct iommu_hwpt_invalidate_arm_smmuv3 smmuv3; }; struct iommufd_ioctl_op { diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index c8f5801d3439..6845ce6e1e76 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -354,10 +354,12 @@ struct iommu_vfio_ioas { * enum iommu_hwpt_type - IOMMU HWPT Type * @IOMMU_HWPT_TYPE_DEFAULT: default * @IOMMU_HWPT_TYPE_VTD_S1: Intel VT-d stage-1 page table + * @IOMMU_HWPT_TYPE_ARM_SMMUV3: ARM SMMUv3 Translation table */ enum iommu_hwpt_type { IOMMU_HWPT_TYPE_DEFAULT, IOMMU_HWPT_TYPE_VTD_S1, + IOMMU_HWPT_TYPE_ARM_SMMUV3, }; /** @@ -413,6 +415,32 @@ struct iommu_hwpt_intel_vtd { __u32 __reserved; }; +/** + * struct iommu_hwpt_arm_smmuv3 - ARM SMMUv3 specific translation table data + * + * @flags: Translation table entry attributes + * @ste_len: Length of the user Stream Table Entry + * @ste_uptr: User pointer to a user Stream Table Entry + * @event_len: Length of the returning event + * @out_event_uptr: User pointer to a returning event, to report a C_BAD_STE upon + * an STE configuration failure + * + * If event_len or out_event_uptr is unset, remainning at value 0, an STE + * configuration failure during the hwpt allocation will not be reported. + * + * The data structure can be used to allocate a stage-2 translation table, in + * which case only IOMMU_SMMUV3_FLAG_S2 would matter, i.e. all other ste_* and + * envent_* inputs would be ignored. + */ +struct iommu_hwpt_arm_smmuv3 { +#define IOMMU_SMMUV3_FLAG_S2 (1 << 0) /* if unset, stage-1 */ + __u64 flags; + __u64 ste_len; + __aligned_u64 ste_uptr; + __u64 event_len; + __aligned_u64 out_event_uptr; +}; + /** * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC) * @size: sizeof(struct iommu_hwpt_alloc) @@ -448,6 +476,8 @@ struct iommu_hwpt_intel_vtd { * +------------------------------+-------------------------------------+-----------+ * | IOMMU_HWPT_TYPE_VTD_S1 | struct iommu_hwpt_intel_vtd | HWPT | * +------------------------------+-------------------------------------+-----------+ + * | IOMMU_HWPT_TYPE_ARM_SMMUV3 | struct iommu_hwpt_arm_smmuv3 | IOAS/HWPT | + * +------------------------------+-------------------------------------------------+ */ struct iommu_hwpt_alloc { __u32 size; @@ -465,10 +495,12 @@ struct iommu_hwpt_alloc { /** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type + * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type */ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_NONE, IOMMU_HW_INFO_TYPE_INTEL_VTD, + IOMMU_HW_INFO_TYPE_ARM_SMMUV3, }; /** @@ -603,6 +635,31 @@ struct iommu_hwpt_invalidate_intel_vtd { __u64 inv_data_uptr; }; +/** + * struct iommu_hwpt_invalidate_arm_smmuv3 - ARM SMMUv3 cahce invalidation info + * @cmdq_uptr: User pointer to a user command queue + * @cmdq_cons_uptr: User pointer to the consumer index of a user command queue, + * allowing kernel to read and also update the consumer index + * for a successful call or a failure with a CERROR_ILL code. + * This pointer must point to a __u32 type of memory location. + * @cmdq_prod: Producer index of user command queues + * @cmdq_entry_size: Entry size of a user command queue + * @cmdq_log2size: Queue size as log2(entries). Refer to 6.3.25 SMMU_CMDQ_BASE + * @__reserved: Must be 0 + * + * Both the consumer index and the producer index should be in their raw forms, + * i.e. the raw values out of the SMMU_CMDQ_PROD and SMMU_CMDQ_CONS registers, + * which include the WRAP bits also instead of simply the two index values. + */ +struct iommu_hwpt_invalidate_arm_smmuv3 { + __aligned_u64 cmdq_uptr; + __aligned_u64 cmdq_cons_uptr; + __u32 cmdq_prod; + __u32 cmdq_entry_size; + __u32 cmdq_log2size; + __u32 __reserved; +}; + /** * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) * @size: sizeof(struct iommu_hwpt_invalidate) @@ -620,6 +677,8 @@ struct iommu_hwpt_invalidate_intel_vtd { * +------------------------------+----------------------------------------+ * | IOMMU_HWPT_TYPE_VTD_S1 | struct iommu_hwpt_invalidate_intel_vtd | * +------------------------------+----------------------------------------+ + * | IOMMU_HWPT_TYPE_ARM_SMMUV3 | struct iommu_hwpt_invalidate_arm_smmuv3| + * +------------------------------+----------------------------------------+ */ struct iommu_hwpt_invalidate { __u32 size; From patchwork Wed May 10 03:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A01B8C7EE23 for ; Wed, 10 May 2023 03:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234932AbjEJDee (ORCPT ); Tue, 9 May 2023 23:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbjEJDe2 (ORCPT ); Tue, 9 May 2023 23:34:28 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2048.outbound.protection.outlook.com [40.107.92.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 765BF2106; Tue, 9 May 2023 20:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RU05401MY08BiS6xiy1FcOla3aAyiHL5xbJuZUzZ3T83pK8jKLo9orTcQNWl4v1+FYTfCrViLudfZSFSCkHWXclsBXciTpF1LfVTCAPCq6t81qeMXJ+fWUdRCg/yPiNqN1QuXL78dT7nPSbPKQC+rWqg4ghYJzDH1afa7L2oGSmBzLXq8mdNwBxdK20xLkaLrx/yJNjfM7M1oGvZ7WhzgvKYT29S6BbM1ePxcuCgIRKraE08hST6b2XYvBQT7F4wRyhN8X0QfQ/5a9nhHva7Y77AzSfZZEJEZF3YjQnf+2M7wNmyjFwOEPhtPuq1eJZZmaN2C06OF+aSVdXuMPrghQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ykmkw5RtWsKK04pdCG62YjB2lEQt4XEWrgruyTEakjg=; b=ju02c9p8SVmp6KtzGQ9V2lh96OCEMdvP7w/a1rp7+0kX4M52e6HDtnmNCysKsWYOQ3ufNYPFNPVIhgXTBtmeJ0nlcdqURIEgyXmbnNgbOlf4dTCJPbomwBuONdKoItkFyPK1nE6yTTdaxVxZYTwjezXM3NYDYQ7i779lqo97z5S7o48CRNOa9TFTtiWnsb4U/4NfpN/yzq/vMft+KsBPHci91R7YiSEUxgi0+0uxxgBHbO3Ab/WzEBIDy3HqwICInLaQMfiWVvNm4otZte43bFFV+TfMFK2HWm/CukIo1aEiRhYmx1R5uOd+lfyHAMy9SUBp+fohh68YWGGZDuwg1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ykmkw5RtWsKK04pdCG62YjB2lEQt4XEWrgruyTEakjg=; b=ZRLPY+KPFSI9GqHMJtr37x/zX22E+vhyNKq2+bGv4vwZCkTrVE9SZxQTvxzONWOMifbcC5ismhiS7DRsce+X5rRuLx+evoO1RxdbYEIOeYZwmIjFht5p5sEGAKNoYJtYeOJ2bEMiNEipuc+rADjMpAXL6kWEsVnQrZnCxv4zSJ90IDRSrKuLt1J6CCDeiUzuRogVKHaFjZhaYZtZs9q1GiUlNyw0aqYvrZizAPHFwQCx2So7025IWxnp9451M2FtfOYSpLeoV7YhNNytazxZwEhHtQzsK65SROjQFU2Vqh8pWDKUqrwhEw7uH9lxle6iMSaFKZZByv26g1sD1T+ocw== Received: from BN9PR03CA0197.namprd03.prod.outlook.com (2603:10b6:408:f9::22) by DM4PR12MB5392.namprd12.prod.outlook.com (2603:10b6:5:39f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:25 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f9:cafe::76) by BN9PR03CA0197.outlook.office365.com (2603:10b6:408:f9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:24 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:13 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:13 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:12 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 04/17] iommufd/device: Setup MSI on kernel-managed domains Date: Tue, 9 May 2023 20:33:24 -0700 Message-ID: <4e70a7985a2921db3a91539c690a9a86c4e1a184.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT009:EE_|DM4PR12MB5392:EE_ X-MS-Office365-Filtering-Correlation-Id: 4241ab29-525e-485f-d4a2-08db510773a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /TQvlcdFER7jTdnoZZ6x31g26uR4mJVOMmllGXwcaNepKQlYFoQ/4MiSbLcX/ue/N4PtpvGFBfYdeEPwaxMZAIrS19e4T8d4OmpDf6J1VKQfYqlU0s5JdV04a8CUldHzXxv+DlbpEcyNSWN4irB5KodH8gR8Mui4wn6t4nQY7aL+D8/NGS0lQ5ckNQsZgAXFM3YEfxUY02xK5dTpg44lH+8hr170/vmmGNyykSm5GVIUqBPm481SpmCXlFWZDmoyzj/mkEl9pgpJUlPoYZUrjrnl+CC+EDbcCYINlzx56kc6su7GDLF1JasvWeyHtGzJd7INL2NP2Ufuwpp4eCFQUTPL9WEu6ShQeay3RQN0yDS2bCQmydK/3ty5n28ZKLccCJ9vdyxI3RUFcUwksfxp8WmxrCit7/H/pn0wt828J5gyJ+l1ML93SmkOrGvGbHWyXcBk7FRFJM1Fu02nZQm8+VIyr8GoUcEgV50F1sgoxjWZfFGnDMD5JaaX3RZiLV7JWY7BNCQ0TT6LjuHURCYOHHWlvt/sHMyuC/Dz1h864JxpLC4ln23fHmSmQv7m/cK5brFrcUZPPziFSXwWYMFoyHygwCOg7C/C5uW0C7QVVhvm70WRwX5qzgJagIFH+Jk2qjbLQ3DvOFk7UrEMNv8XVPXvbj4YzXlaWhc+NZHxOW+oqCR1h7XToPWlvvy7JWkMRuzKH+2E5VlHRpQJvC4pZg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199021)(46966006)(40470700004)(36840700001)(86362001)(36756003)(6666004)(316002)(54906003)(70586007)(478600001)(4326008)(7696005)(70206006)(110136005)(40480700001)(82310400005)(5660300002)(8936002)(8676002)(47076005)(7416002)(356005)(41300700001)(2906002)(82740400003)(7636003)(186003)(36860700001)(26005)(336012)(83380400001)(426003)(2616005)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:24.8076 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4241ab29-525e-485f-d4a2-08db510773a3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5392 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The IOMMU_RESV_SW_MSI is a kernel-managed domain thing. So, it should be only setup on a kernel-managed domain only. If the attaching domain is a user-managed domain, redirect the hwpt to hwpt->parent to do it correctly. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index e40f576fdf0e..e403cf6c336d 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -351,7 +351,8 @@ static int iommufd_group_setup_msi(struct iommufd_group *igroup, * call iommu_get_msi_cookie() on its behalf. This is necessary to setup * the MSI window so iommu_dma_prepare_msi() can install pages into our * domain after request_irq(). If it is not done interrupts will not - * work on this domain. + * work on this domain. The msi_cookie should be always set into the + * kernel-managed (parent) domain. * * FIXME: This is conceptually broken for iommufd since we want to allow * userspace to change the domains, eg switch from an identity IOAS to a @@ -359,6 +360,8 @@ static int iommufd_group_setup_msi(struct iommufd_group *igroup, * matches what the IRQ layer actually expects in a newly created * domain. */ + if (hwpt->parent) + hwpt = hwpt->parent; if (sw_msi_start != PHYS_ADDR_MAX && !hwpt->msi_cookie) { rc = iommu_get_msi_cookie(hwpt->domain, sw_msi_start); if (rc) From patchwork Wed May 10 03:33:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ECDCC7EE2A for ; Wed, 10 May 2023 03:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235560AbjEJDfP (ORCPT ); Tue, 9 May 2023 23:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235593AbjEJDeu (ORCPT ); Tue, 9 May 2023 23:34:50 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2054.outbound.protection.outlook.com [40.107.96.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69FCE5BB5; Tue, 9 May 2023 20:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UK7gS24+JR7UiOLcZZgpVkQ4wGFhtCrjIphfknhu3bxsxjDxIvwHmNBOYlMHFhRT7Y4uA+L+ByCRtZpfyUNhlBHCv768d6yW1Vpej2fmmUkRuhTGHZo126eUvsMQNetxhBmo/yQiSbqL2EMrFNAykadEcym360tbsl9kYxCzcRnpkZfANkgA38jAT9HS0PstSy0R3WoxOCryOiEvUnFuC7HHH9zzTtxGzcUmkq3xiR3qlsGJHfmKmoNJtv4dI+gd3nP8zwDCQy5OyKbsbTZzq1g5hQYCO+C3gc5IgrGmLnCoiyTE8SnbYusruNPCc8OczcUxKFIA56ainsrIsfIaTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yJebtEKrtrvbLCiBOy7gpOUhYpCLuJx46uKWTr4rd0w=; b=LZpwr3UJfHIGx+w+3WJqSnUuxju9BDpFwHRQoNvkfuMXrt1fY3sA/WK6a5APPTRaZKObU9e4c0Neb7yt/mtS8p0xHgsFeR3zVCLw/ZOTeQ3GT2ht1bLHVg13BvRxx8vY9f7mJ9cTBuGsvkgNm5D0EAM5BUSsoNX293C54bfuQMrtnPfvBIJbgtKNOY2evpqC/0T1qhMRIWOUEQUIS4Uhs7iePDdCW7Rw8kCAuoerZnxKmQnc+J/QFuhdxcyV7L8ljAZmXl/TcAPFzOLQ5aYer8eQB04QAcB4MyyzO0uzbquYJ7WERWP2Cpw2Bl1ukn3g+bMZKydykNt/anv0o7tmIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yJebtEKrtrvbLCiBOy7gpOUhYpCLuJx46uKWTr4rd0w=; b=Lc5l/fR04Xb/f2jenYtbrCR1qLipx0THIdj7T4S5A4BzNB8mdP/d+NwZjB7NzZijnvV7PwA30sjGT2yxBgzoUok3QExcl9xndMm6SMHr9wS2aRrVlQlO+eUyxi795F8vqgYDCQQO4B6IRfypTOcoCQ7a1QG5v71+MPjeor4S/PieLNcwOgqFXcqd95zdG0Rk8t90OQloK++8Zc1dYbFISp9RFygdy7wkkRbS5CuJrk1qzQuaYLUNFRPonBCW9YpwSN1jNUr61nF/9DMkKK3n7nftPEi2Y9Ky2WCZVm3lNrI+8uUcq3EtujTI8g0oueewNb5wtyVqRlE4tdGY6xC7OQ== Received: from BN9P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:13e::31) by SJ2PR12MB8926.namprd12.prod.outlook.com (2603:10b6:a03:53b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:30 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:408:13e:cafe::32) by BN9P220CA0026.outlook.office365.com (2603:10b6:408:13e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:29 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:15 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:14 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:13 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 05/17] iommu/arm-smmu-v3: Add arm_smmu_hw_info Date: Tue, 9 May 2023 20:33:25 -0700 Message-ID: <07c9c019eb6cc9226d0117373dcfe0daf8436fee.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|SJ2PR12MB8926:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e4e6883-18b7-4fb7-52e3-08db51077686 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CfOwJiVZitsY2TPfj5ClKtX1U8UjXlX3cka5i7mi2Kt02/9H1Eg52FEgPg8WmBlltwuuT/9IcNaEttIaNcGsM5N6ha27Iqb1f+hRQdfIBEHdZ4QOnGbrsHYNa8SsdmTx2GDzcaSde1t7krXkELzakrjzYOwAXkcpspajo7eKZFfDAfqgB+3nJM5ahQuRSyOqDkD8b2kh3SUzexiYtcCkGfAO3aiaStKRQQtzMusjgzHlKBdCjuZXkDvy7WVvb8fCNtMwwXf+uoDtD7yuioUtERQ6E198lCBOxS6KQJQUcuXYSpZV/DWIZ2kBbhbstzHYNaO99lPou2UQQjFr46vB0j0gC/0Hm8Tv++txyN2KGMJJHDryMS4ZOGd4SplR9DUAFrV1PiVPfkwSLUU54NfFvuZzYjCQYObjjYPud+hEemCUX9oa/02PaQYGR4mGxqMdVRVe5WRrf09pHs6gWr/O7lPOG8OBxZt7k/YXFcphtC10PHSVYTJhH5P+6DyWb6wZscgXI19/yJeC2NDcEpgDouzq8Wj5/pSfXLRPk+VMLdI729YRPuEogTe50WwB11bU9AdLlFAzHdlCm8Z54rcjTN/bMMsI2iyRrwoGoJt4OcEU5oSFG2b4/AvYmLK0pbACqTftMi8t43RZlfZnGGGMbd63X9SXyOhAxlgF5bmnFyDnFWO4ysHEVesS5LzORKRasN3vmmDynj4n7wajtkc0fQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(39860400002)(136003)(376002)(451199021)(36840700001)(40470700004)(46966006)(47076005)(36860700001)(26005)(186003)(478600001)(426003)(336012)(2616005)(40460700003)(7696005)(6666004)(8936002)(5660300002)(8676002)(86362001)(82310400005)(316002)(41300700001)(356005)(7636003)(40480700001)(70206006)(70586007)(36756003)(2906002)(82740400003)(110136005)(7416002)(54906003)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:29.6161 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e4e6883-18b7-4fb7-52e3-08db51077686 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8926 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is used to forward the host IDR values to the user space, so the hypervisor and the guest VM can learn about the underlying hardware's capabilities. Also, set the ops->hw_info_type and ops->hwpt_type_bitmap accordingly. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ include/uapi/linux/iommufd.h | 14 +++++++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 2c53849cae30..89daf50be87b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2014,6 +2014,29 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } +static void *arm_smmu_hw_info(struct device *dev, u32 *length) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct iommu_hw_info_smmuv3 *info; + void *base_idr; + int i; + + if (!master || !master->smmu) + return ERR_PTR(-ENODEV); + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return ERR_PTR(-ENOMEM); + + base_idr = master->smmu->base + ARM_SMMU_IDR0; + for (i = 0; i <= 5; i++) + info->idr[i] = readl_relaxed(base_idr + 0x4 * i); + + *length = sizeof(*info); + + return info; +} + static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) { struct arm_smmu_domain *smmu_domain; @@ -2846,6 +2869,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) static struct iommu_ops arm_smmu_ops = { .capable = arm_smmu_capable, + .hw_info = arm_smmu_hw_info, .domain_alloc = arm_smmu_domain_alloc, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, @@ -2857,6 +2881,8 @@ static struct iommu_ops arm_smmu_ops = { .dev_disable_feat = arm_smmu_dev_disable_feature, .page_response = arm_smmu_page_response, .def_domain_type = arm_smmu_def_domain_type, + .hw_info_type = IOMMU_HW_INFO_TYPE_ARM_SMMUV3, + .hwpt_type_bitmap = BIT_ULL(IOMMU_HWPT_TYPE_ARM_SMMUV3), .pgsize_bitmap = -1UL, /* Restricted during device attach */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops) { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index b574c58a3487..5fa010c6fe20 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -14,6 +14,8 @@ #include #include +#include + /* MMIO registers */ #define ARM_SMMU_IDR0 0x0 #define IDR0_ST_LVL GENMASK(28, 27) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 6845ce6e1e76..b1fe4c59ab82 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -534,6 +534,20 @@ struct iommu_hw_info_vtd { __aligned_u64 ecap_reg; }; +/** + * struct iommu_hw_info_smmuv3 - ARM SMMUv3 device info + * + * @flags: Must be set to 0 + * @__reserved: Must be 0 + * @idr: Implemented features for the SMMU Non-secure programming interface. + * Please refer to the chapters from 6.3.1 to 6.3.6 in the SMMUv3 Spec. + */ +struct iommu_hw_info_smmuv3 { + __u32 flags; + __u32 __reserved; + __u32 idr[6]; +}; + /** * struct iommu_hw_info - ioctl(IOMMU_DEVICE_GET_HW_INFO) * @size: sizeof(struct iommu_hw_info) From patchwork Wed May 10 03:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6C5EC7EE23 for ; Wed, 10 May 2023 03:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235465AbjEJDfM (ORCPT ); Tue, 9 May 2023 23:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235540AbjEJDeu (ORCPT ); Tue, 9 May 2023 23:34:50 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2045.outbound.protection.outlook.com [40.107.102.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E4C43C00; Tue, 9 May 2023 20:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TPW+vSAlHTTi4NdlARaR3d/dgi9tLMh9kuqMxAokXKDrUCduJq8xobMJ0nF+QYsI1W3bLrrshu01LCshhvIyI4Ea6OxgwhfeYGQoSIpGuF5eE19m+BQZ4Xt4JFGWccfMq9+RS3E84LtIdzwd3wHG1zkhoOy2CRXuTNA2a+BxEo+yUPBampXj/x5aXJkA+VBMvxvw3iDYP/gVIls0YFL1KGXRNPKS+6Z9dNw5G3XWVkfKqI49M9uBmcEr61y0C+1aj87D6eQs6XC1rfB+WOpqJIfc4G5rjOf1BiNS9PsDnJtICd6pjx9YxVl1mMs4phWuabV5b6YjTbW+7pRcG6Sa4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8a6MaHRoRL4e1jrwRkkp6NkI75mJYRczGK5OsDxgW94=; b=Etq1q8g9Hoqmk4IPboBoczwFLBPBerdfB9TMV4eILVg9FBEZk1KBrPmo9nn0UurL/z3kC28LmqiAZH4hvYwTwl+ZOeGer4A5DO8/6gBeEwBLS3VAb9Tw4c+pYW8/WXyiHcmemK7Sq4AxHlMGXzUjY/ed8yVMw67euEhreMPVO1x7VmmRYTBj8ck+BTNxtaNtkflmVziEJv7WvNA1wFXWggInnkpjUl9PwAmD9NWP+ACJC2W2FwJNam5/lFVhvv3pBsPMmpQVqptq59QT+2ImubQNylHdrDh2G3Q0XoJDejelOe98ED/MRGMQEGMxdfuJndNgVsYrhiLLhENYCDNFCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8a6MaHRoRL4e1jrwRkkp6NkI75mJYRczGK5OsDxgW94=; b=Gx3QiiKwsAHBtRfP8ybqgcRA9GciguA9qF4LY04QRf+88VAoW2eiGUE4bXbU+sSRM257Wp7tGHKaW96nMrpzLt+ovb8a25WdmLjJcX0zXNuO3Sa26YA03+iYAMURqh4haOpMPKuUXUE4jOa2yZghoIWcJIHFFFOh1wiJt6JA+QssHGAeMMKsrzG05lbADJOtOcCMGQzbkWmeRXHxE5a0BiEqAUmCMz0Fndmb7bWQ6FVEuAyYb3UKr3ZSrAdEdbn74KaAU8Tswi0pITO5Bspozy+x9U1W1Le4PBaoJthfT4n7AeCRgWq4b2IJhrYH+5J7IwjTzsqVY746QXYYNT7JKw== Received: from BN9P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:13e::6) by SJ2PR12MB8925.namprd12.prod.outlook.com (2603:10b6:a03:542::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:31 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:408:13e:cafe::46) by BN9P220CA0001.outlook.office365.com (2603:10b6:408:13e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:30 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:16 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:16 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:15 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 06/17] iommu/arm-smmu-v3: Add arm_smmu_set/unset_dev_user_data Date: Tue, 9 May 2023 20:33:26 -0700 Message-ID: <9bcf79fe2b93eca097b4ea8eaef43c4c2a4bc8d3.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|SJ2PR12MB8925:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e9c8be0-efb9-47c0-238c-08db51077739 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f9B/zjpSuc7eSN4/7FgKXqsBsvxQPUcZs36dVAM+VT8LFCd5tf5XuScDLhsA3+YzPdFJc84AwmuGfYzV4hDtdBzQxc6yVm3NqT0jFGjyD8ASRWy+nfAHqpa2Urx28yf5gwqJSnShgRy9MFPY+cyN6XQ8cw35jniiuWdbJuWEiYknlEHETDgZBjHMI4eI75fcxzeHta0Fz6tYfhT85f0QNLNPFRg1ccW9mV4CYVbrrIjGeZI8VqhBuCff3JkyzlnCAXDiNkN/HBh2k1SZDC3N9SAXEvnrXbnttdwmojDB3Gelw+hFEvSuOV58y+yamFHhRdm+it2ktEm5iyhFGShPSE81vfsx4k7a+y2t+ab5B5ghM1sVM//wuus7wNiQcjK5WnO8W2zlN+fi5XUBDP/yn0mAHeTjLkKeYxsWH6X/JkFhnOEzIFmM3Xu8E6aFtYHrRqcTGtvco8LprjgC3G6bB1UK/bWWSnr/omNNcqBXb8AaFWcNpLPfwsu3PlGtVaMbMEy4fIvBdcY7/LQFArkEXJYThQSoPmMcnHr/zbKIkvzCupG44qVmZI8KbjcppyWB5pprtTVSLWBeIB/BQQAq4Ax6NA64/5OgxSw5AJuTN5fcGtrcByq+TZSzwhoAukgConeJrd1OqZ1VYPr1j32WPjbPTe0JIVtxGuljeEoufTffwuVCJSxByCGYX0DXlLB8qLK8NPYpAM4PRWKInVuYSA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(396003)(376002)(136003)(451199021)(46966006)(36840700001)(40470700004)(86362001)(426003)(36756003)(6666004)(4326008)(110136005)(54906003)(316002)(70206006)(70586007)(7696005)(478600001)(40480700001)(82310400005)(82740400003)(5660300002)(2906002)(7416002)(8676002)(8936002)(41300700001)(7636003)(356005)(186003)(47076005)(36860700001)(336012)(26005)(2616005)(83380400001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:30.8036 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e9c8be0-efb9-47c0-238c-08db51077739 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8925 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Implement the new set_dev_user_data and unset_dev_user_data ops, by using an xarray to store the stream pointer indexed by a given user Stream ID. This will be used by the user cache invalidation hypercall, to check the SID field of an ATC_INV command and replace it with the physical SID. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 44 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 + include/uapi/linux/iommufd.h | 10 +++++ 3 files changed, 56 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 89daf50be87b..327819663547 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2746,6 +2746,46 @@ static void arm_smmu_release_device(struct device *dev) kfree(master); } +static int arm_smmu_set_dev_user_data(struct device *dev, const void *user_data) +{ + const struct iommu_device_data_arm_smmuv3 *user = user_data; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_stream *stream = &master->streams[0]; + struct arm_smmu_device *smmu = master->smmu; + u32 sid_user = user->sid; + int ret = 0; + + if (!sid_user) + return -EINVAL; + + ret = xa_alloc(&smmu->streams_user, &sid_user, stream, + XA_LIMIT(sid_user, sid_user), GFP_KERNEL_ACCOUNT); + if (ret) + return ret; + stream->id_user = sid_user; + return 0; +} + +static void arm_smmu_unset_dev_user_data(struct device *dev) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_stream *stream = &master->streams[0]; + struct arm_smmu_device *smmu = master->smmu; + u32 sid_user = stream->id_user; + + if (!sid_user) + return; + + xa_lock(&smmu->streams_user); + stream = __xa_erase(&smmu->streams_user, sid_user); + if (stream != master->streams) { + WARN_ON(__xa_alloc(&smmu->streams_user, &sid_user, stream, + XA_LIMIT(sid_user, sid_user), + GFP_KERNEL_ACCOUNT)); + } + xa_unlock(&smmu->streams_user); +} + static struct iommu_group *arm_smmu_device_group(struct device *dev) { struct iommu_group *group; @@ -2873,6 +2913,9 @@ static struct iommu_ops arm_smmu_ops = { .domain_alloc = arm_smmu_domain_alloc, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, + .set_dev_user_data = arm_smmu_set_dev_user_data, + .unset_dev_user_data = arm_smmu_unset_dev_user_data, + .dev_user_data_len = sizeof(struct iommu_device_data_arm_smmuv3), .device_group = arm_smmu_device_group, .of_xlate = arm_smmu_of_xlate, .get_resv_regions = arm_smmu_get_resv_regions, @@ -3108,6 +3151,7 @@ static int arm_smmu_init_structures(struct arm_smmu_device *smmu) mutex_init(&smmu->streams_mutex); smmu->streams = RB_ROOT; + xa_init_flags(&smmu->streams_user, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT); ret = arm_smmu_init_queues(smmu); if (ret) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 5fa010c6fe20..1951a80af241 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -676,10 +676,12 @@ struct arm_smmu_device { struct rb_root streams; struct mutex streams_mutex; + struct xarray streams_user; }; struct arm_smmu_stream { u32 id; + u32 id_user; struct arm_smmu_master *master; struct rb_node node; }; diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index b1fe4c59ab82..2ecb6240ec69 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -592,6 +592,16 @@ struct iommu_hw_info { }; #define IOMMU_DEVICE_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_GET_HW_INFO) +/** + * struct iommu_device_data_arm_smmuv3 - ARM SMMUv3 specific device data + * @sid: The Stream ID that is assigned in the user space + * + * This should be passed via the VFIO_DEVICE_BIND_IOMMUFD ioctl. + */ +struct iommu_device_data_arm_smmuv3 { + __u32 sid; +}; + /** * enum iommu_hwpt_intel_vtd_invalidate_flags - Flags for Intel VT-d * stage-1 page table cache From patchwork Wed May 10 03:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8138C77B7C for ; Wed, 10 May 2023 03:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235348AbjEJDfJ (ORCPT ); Tue, 9 May 2023 23:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235566AbjEJDeu (ORCPT ); Tue, 9 May 2023 23:34:50 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061.outbound.protection.outlook.com [40.107.92.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16E5B2708; Tue, 9 May 2023 20:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eUj9u377C6xgshN1vntxfqCEIli+5SjaEi6UNcQo2Nir3oBTRgF49rcS2tF+N2LSK/p4DXrrv5aqGRAsDAqMmZjVhs2s42U6HAplw94aIWKm/8B2tnAw/7gVC6HYCIPvRomXYIlY8g2dzyCD1Kt8v7v7ANCF4mte+eLEUJZbENO7lr0yDKw/xwHIpVQrlGm/PD4QmBm6w7egrD9Upqq7xcExAQXGnFF7cwywTgV0TofE3BjLL1TAuye+ydgjkWs3Tp894VYFOkQRJwXq5/n8cZaFWa4tg9K/VNBOZsB8Pew3OKu8RIN2lLlZQEEw4qGjo0BJrMBbVrf0NujLa6ly3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KilUKsgNQaYyodsalejBktPmpC1gJMYroH2P450/6Ew=; b=dnsFl/dXAQbmaML698y59iOUfVy6lwKO8WUFgRv7gA6lgUB8Ig14xl4zmnaK60UGP4bZKwMoGwb5Zu+GIpFM+cs//PMyjBh26j1GuEmo+HYm66bxYHIn12Qdfi/nC1BQFnLce5qa0l+XLX/Eub26mnZGc0/D9VUTH2hTkenZTahpd/Ic5L9v5hXMrBFw0Es4NlTOEEOgMbrpUxOBPlJQ18zGqNRKNR9pK73YOVIASLCxpRgVkxq0f+I6P3CuF6oiPOFVcxqSzsZxRvpmD94WdWZwsi9X0acW093HPTCbRgiQ44M/JvH0erLtYVZWnrEmPfVxPAF3uyMnifSTf4R+xA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KilUKsgNQaYyodsalejBktPmpC1gJMYroH2P450/6Ew=; b=kAJ2/biJJAlJooQL06FzDI+0lzyIktOszM/3YpeRLyCXBbc/ZrRd8QPsfA2vQJSE40ntHOZu6w8o8FjbqAfuyhHwXdRqaU3uxCA4U52cHmtAjwPDDjUYYRBptn4geu5rtILzke2p80hpoa4pHNY/OL55Q7PH8mSTFrb75+mUEPPLhenovd2AmChdYCnhjjmw+DD8ejrwRZSd/mJPNO2sKb5fQviJGIrnG6XzC2QGFoVifGDQBHte/7iHaKZ5kvKknXTvbrDooZwzAXLxm8JwF/lzfn7gg6kKHKKRsxXdTvBqBSA670Ya0mPxQWzdUkdfAexS7RPLoUTftti/u21/Rw== Received: from MN2PR11CA0027.namprd11.prod.outlook.com (2603:10b6:208:23b::32) by BN9PR12MB5162.namprd12.prod.outlook.com (2603:10b6:408:11b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19; Wed, 10 May 2023 03:34:32 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::cc) by MN2PR11CA0027.outlook.office365.com (2603:10b6:208:23b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 03:34:31 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:17 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:17 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:16 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 07/17] iommu/arm-smmu-v3: Remove ARM_SMMU_DOMAIN_NESTED Date: Tue, 9 May 2023 20:33:27 -0700 Message-ID: <1cf96ebe77f52c9f9114827ffb905ffc17a570af.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|BN9PR12MB5162:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a6f6353-193b-4dd7-34cc-08db510777b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: viwcTidQvCWMZor8jDZgZ2XE1R2vX2GbLo/dAuN7oT7r0Aao+fJkHdiWKVmYmUVWOoYjaEalyMFZgzqQsVvHEx3WjR4FBGoIEL8YAhlxUMxHABcqr/7x2tlcY+uOwp4b0o8ZEjj7PF8xu5ZHFWD+1jnVR1+S9RbmF3sLVyVsq/+HJzT6vqfWIDZtlhzXZREQqv2qEu5o+DzY52sigkS6UMfyQDME/oFMZGqKusvloFJMQ3jHFEzseV6jm1dz3tg/wg9/y+WdCyv8Fky+fZWKEo+viTifbfvLzFyZN5mGsWRQLFe6Ry9dSsfGEJT3vAXYjrzC4JHYJiw/q3HSIiORA4IMvVycWoQk9tGM89okBmRWyASBxy/PMyBaRTnjdBSHzHQdVbVUcATilQaHdW0BwRl7ODFmoThbHpUEarmqLwfadWI5TWt0L6G+a3I3jNs6Edd5mf46XPeLzGdmlq3OBP8hVVsBxrsZw3TdXc0axbzkpk1gzVeMcVF+e7BhyF0XZcHdPHtN16FFNjbGBVmO/azY20GkIzRjnJc1PMbSwIN/ye8yb72XgxQ7T1EbzO6GUs8KhayikdED77/oMOq0DsZ7pE3md1NnOGS/xj7qnDO7hpU9ZutXDVUVEGUGs07a/ez+M7BbyTOyClhjP/m/HIwYGXS2iF1qZIFo40DW5UwXfkGvAcOPEZPG2bqw/JjU5DN2dLlebuj+7GuQoJx55sCm30ZZaTEyB5VT23fi22Gjg+vkTb6E5Up2l4lDLb04 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(376002)(346002)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(2616005)(86362001)(2906002)(83380400001)(186003)(36756003)(4326008)(70586007)(70206006)(26005)(47076005)(36860700001)(426003)(336012)(5660300002)(7416002)(40460700003)(7696005)(82310400005)(41300700001)(54906003)(110136005)(6666004)(40480700001)(7636003)(356005)(316002)(82740400003)(8936002)(8676002)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:31.5879 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a6f6353-193b-4dd7-34cc-08db510777b3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5162 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org IOMMUFD designs two iommu_domain pointers to represent two stages. The S1 iommu_domain (IOMMU_DOMAIN_NESTED type) represents the Context Descriptor table in the user space. The S2 iommu_domain (IOMMU_DOMAIN_UNMANAGED type) represents the translation table in the kernel, owned by a hypervisor. So there comes to no use case of the ARM_SMMU_DOMAIN_NESTED. Drop it, and use the type IOMMU_DOMAIN_NESTED instead. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 -- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 327819663547..c57c70132c0b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1291,7 +1291,6 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, s1_cfg = &smmu_domain->s1_cfg; break; case ARM_SMMU_DOMAIN_S2: - case ARM_SMMU_DOMAIN_NESTED: s2_cfg = &smmu_domain->s2_cfg; break; default: @@ -2229,7 +2228,6 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, fmt = ARM_64_LPAE_S1; finalise_stage_fn = arm_smmu_domain_finalise_s1; break; - case ARM_SMMU_DOMAIN_NESTED: case ARM_SMMU_DOMAIN_S2: ias = smmu->ias; oas = smmu->oas; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 1951a80af241..e9e45ce7a899 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -706,7 +706,6 @@ struct arm_smmu_master { enum arm_smmu_domain_stage { ARM_SMMU_DOMAIN_S1 = 0, ARM_SMMU_DOMAIN_S2, - ARM_SMMU_DOMAIN_NESTED, ARM_SMMU_DOMAIN_BYPASS, }; From patchwork Wed May 10 03:33:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B766AC77B7C for ; Wed, 10 May 2023 03:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235177AbjEJDfG (ORCPT ); Tue, 9 May 2023 23:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235195AbjEJDem (ORCPT ); Tue, 9 May 2023 23:34:42 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2056.outbound.protection.outlook.com [40.107.95.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49B044EE7; Tue, 9 May 2023 20:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pi8rzNti27EHeztc8Twq+MvzCuFTbGaoWKI8lnaK4zB4M7eubC8CJZ4ELo65XIMNVMOcAHWqbyH+j1uZOx9HnMsHZBYhLbhbCdM4kGD6lj4ZPQGpDV1Us0SNElCmWkFAEL0JEd5ratmWZ9PFuARGnligldgPzlOROt3UPkxMALo8wYvajdZlPsAcDgUx7AFiF1MdMjBqgANB6KsWQ0alI1eF/fhNohYeG0+LZ18MIgFNrNiGUpxI5JgFtcUuaJ+xgXodg1OAaLbytiCAtar4KeNa8PkCtleaswe5BJLtQmJK7Qp0ALB6f4ViuLM4adDGyj2I52s5z+mt4BzuEWciow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WziNHnp2+kajlgqBbWkc4kOYY/UsxfTOTYH9hMvKzOU=; b=QmapikBhAJhbPcb5CHqw6tWAjpof5p4ETpgPI15YA3VRMpr6gNLE6c4+sbfkB3hsY+rfWCurbLIoUSWbYKw3R6aMegciWmv5fyvCh+xIoRGNld+Vofc+91PfT7IBkxBHYMIztONCdMbIMnhkONYJXL12FoFxacXX/pMTQKovFJYidyFttLr4lDSOCEI7iZ8UTmyusesYDjqXrU0lQy/oXv9/A3slo1e+qnHbGvdEZo4c2QaxlJpoTlNHWbIM4ia8y9RyyAN8yN1W09HC35mWdHbXFP0IcRJXQdVw+AoocHj5a3PKJ55dbv6KfGRtf4Ngh6z/tk4BiQYIphTcU4a20A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WziNHnp2+kajlgqBbWkc4kOYY/UsxfTOTYH9hMvKzOU=; b=POTGJowO+fSaAlAW50pvh02UbmA8UFuXuCUAPy1hHkKubs97hf9nYDtFz5fhFoDulkrFW2X4Afxevvnb82wNBut/MzO/L58y34iYKPVAAtZh/VgecTcdBbaq1seja/GnpHi5wlCXeE5ZiVqliS4y5ezGywwuxnOtqgIQHtVEg78xAH8EsdfWVy32/eeP6ykQyJwkv9BqUxupVSwmiZ3dDfmfkVN4qdkIhjUS2SivEDXw4qIlZ/F7E+D+6YTUUilhW3z4PgiJXyYZr9SW392QcXtbdBSh2EZmf8Ab5b9nZJNAJ5FF0ZrRIb3n+IRjn0iBjBDARWbNLR+8v/msDHkzQA== Received: from BN9PR03CA0201.namprd03.prod.outlook.com (2603:10b6:408:f9::26) by SJ0PR12MB6830.namprd12.prod.outlook.com (2603:10b6:a03:47c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:29 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f9:cafe::2d) by BN9PR03CA0201.outlook.office365.com (2603:10b6:408:f9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.34 via Frontend Transport; Wed, 10 May 2023 03:34:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:29 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:19 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:18 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:17 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 08/17] iommu/arm-smmu-v3: Unset corresponding STE fields when s2_cfg is NULL Date: Tue, 9 May 2023 20:33:28 -0700 Message-ID: <8f95a33f3f28d97750afda64536de312772ce60b.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT009:EE_|SJ0PR12MB6830:EE_ X-MS-Office365-Filtering-Correlation-Id: 63f1edcf-e6da-479f-e847-08db51077667 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DZM2jghLOt1hcy+SmCGeW31I9OLqYUnYcb7j6RAH0Cf4yRUx0XdI/ZYL1eqFPxd8LiLRqYXUD3hy2+i8xfqRbuPNeQTolTUqPBXdDElYtD75IF+Pm+AJNqVcByzWoZvyp6U9veMswoZQS4iQ3hBDjBPSd0UfFK/A4IvMQQkOzm3TLCVZZb76JRoX68/BcU7WXolI0epqDc6tOs/DKhv0ZJ6XOU0b9C6E1usVo3GEei6PI5yhEk38JknhgWu5zOuuPPwDi0BByOPj+Sa6QEXYFBxSkJT+Ub4TBgfR1ZcrrFSxSp6+nNZA1jCMnNvxVspt+9Y45btNJNdTZDF+th8DTXGIXK8I1a6y3Neugw4WuoK7k/CarUyjby7cceQBc1nqkjsp0tj3o3W0w7JO8rgbIOmrF+HOJbssnjGq51krFds71flzGg4GVtug3W7DRT7F/NFvwdbgIjQBZGohT7rzblnBDFJZLrvcaUGy0GMRoFktMgK5wU+SJx8+w7lBV2EwWwn8dsYagpJWcNmpoe7vt/WcuxWBj2bmHXY8ARL91gyA8m7T8Pd72ZRqmS+yiLK4kkQDCyXproC+0mbB2iYt2OhtLmWXmrnzT2MErV6MruLoHZd28IFEwsH6oBaNrh4ccZi92+tOo14TxlMmSTiTaKd0vTHgYSnW8UxQhTIDGti8CbJh5yBdgE1fsvCr4XJWmz8MPohAtUlTvTpsbBo3k/0BA8003Cif1DyurEWw9S7qehMPs0PgHn9lHTkyizcv X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(396003)(39860400002)(346002)(451199021)(46966006)(36840700001)(40470700004)(40460700003)(966005)(4326008)(7696005)(70586007)(6666004)(70206006)(316002)(110136005)(54906003)(47076005)(36756003)(86362001)(478600001)(336012)(36860700001)(26005)(426003)(2616005)(41300700001)(7416002)(2906002)(8676002)(8936002)(82310400005)(40480700001)(5660300002)(356005)(7636003)(186003)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:29.4324 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63f1edcf-e6da-479f-e847-08db51077667 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6830 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Despite the spec does not seem to mention this, on some implementations, when the STE configuration switches from an S1+S2 cfg to an S1 only one, a C_BAD_STE error would happen if dst[3] (S2TTB) is not reset. Explicitly reset those two higher 64b fields, to prevent that. Note that this is not a bug at this moment, since a 2-stage translation setup is not yet enabled, until the following patches add its support. Reported-by: Shameer Kolothum Link: https://patchwork.kernel.org/cover/11449895/#23244457 Signed-off-by: Eric Auger Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index c57c70132c0b..792e8a788e2e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1373,6 +1373,17 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, dst[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); + } else { + /* + * Unset dst[2] and dst[3] to clear stage-2 configurations. This was observed + * on a HiSilicon implementation where, if the SMMUv3 is configured with both + * stage-1 and stage-2 mode once, it is not possible to configure it back for + * stage-1 mode for the same device (stream id). The SMMUv3 implementation on + * these boards expects to set the S2TTB field in STE to zero when using S1, + * otherwise it reports C_BAD_STE error. + */ + dst[2] = 0; + dst[3] = 0; } if (master->ats_enabled) From patchwork Wed May 10 03:33:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21368C77B7C for ; Wed, 10 May 2023 03:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235626AbjEJDfV (ORCPT ); Tue, 9 May 2023 23:35:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235606AbjEJDe4 (ORCPT ); Tue, 9 May 2023 23:34:56 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2064.outbound.protection.outlook.com [40.107.237.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32AA93C20; Tue, 9 May 2023 20:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZD2VOOB4lindLKsi8miTB8FAbzBp3InDVpPKPEKASQwbDfTZxHBeNFYD5xs2gop8YU+Wca+NrfMcbfBHjzZGOhLWkut/F4waoTUmaMkwvqTkJZqbOk6mE0F3aeb0AniSW3OqWD6CXyt4ZvcD74awSKoPCMFSmrhAJu/QJDbg3lTcH/769L5aWpDynAWJbI/S4pXTvgqerg7lsXt7SIUExKyOZREknnErl30CyFRmjEjgR7Lqvxc9XLWCfrTXhfW5oMBky9rRRrLllQeJBhv7qEYYhP873HMt4WE3Gt2lSSjyRbDTRi3imQ94aNV+rDZxcbn+MCMI/4mE2ASiqQBlvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cwcuyL0Wenf+rIDKm3eUfiEWymz6Zi4dcQXl/CBlqGQ=; b=BXy1UZUYJYKruJxErlhnru9x4l96rNYFoPjGBDpg8qxIpNsIgZQOZ9xqKk3wY6N2HiBy05ndt37lR61VlwfqB41eA1NvWbWHMz6A9w3VkXHu+3M93PbHjPecfm3/pP5Ms5eeF6iG1iBx1mogJO3cbka9CwwL/JkOyeoFjVsf9sAbHmMy09H4TabvN6u0DP2JPnudQi19KtT3XRCcWfmzG4cPbLGmdWtNzqVjmRNvkN5oWYuNHexLcg4FXGtuKXpSzfj6diK8EdKFMrbat04+SoL4pUVYmlbSG7qwSTY24YWRSPx6gyXvMquMrIJUa6BfpNIxjJKcIE+VzmXSH7btjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cwcuyL0Wenf+rIDKm3eUfiEWymz6Zi4dcQXl/CBlqGQ=; b=Qn/PVT3D3BLnTT7+iTsxVwWwwW1IUOvOKrxLv9UJUXKFl90sXqFQoT0dl7J6gWsgRDiCg/biRrtjuckjR/PndcprtYRyB2FHr+j+RgYCejE52r/Doe/37E+uxWLgNTaz3az1pjkGRI6m+ZBp1k3EDIvNLeQwsg+gs6eyiwaUXGUmpO55rqyA1VCQRlhYyvROEjXXeLki3pAnEfNRV5Mwy7vvwGYM2xOj3hMph8JF2v6qxZ4F9636uhw1PB+WbxPy6SR+lpthhU+zQ33JsdtYh9b7J8bRotr5Xh9wRD1utxLZ7UrtNM8qj0ZQHrIHxI4aIQ7SANMZI635R9F3Y9hqGQ== Received: from BN9PR03CA0430.namprd03.prod.outlook.com (2603:10b6:408:113::15) by CH2PR12MB4971.namprd12.prod.outlook.com (2603:10b6:610:6b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:31 +0000 Received: from BN8NAM11FT083.eop-nam11.prod.protection.outlook.com (2603:10b6:408:113::4) by BN9PR03CA0430.outlook.office365.com (2603:10b6:408:113::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT083.mail.protection.outlook.com (10.13.177.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.34 via Frontend Transport; Wed, 10 May 2023 03:34:31 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:20 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:20 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:19 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 09/17] iommu/arm-smmu-v3: Add STRTAB_STE_0_CFG_NESTED for 2-stage translation Date: Tue, 9 May 2023 20:33:29 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT083:EE_|CH2PR12MB4971:EE_ X-MS-Office365-Filtering-Correlation-Id: 92eeeef8-77e5-4e2f-bc0b-08db5107776a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xw/ZN1qedewAPXDf+YsoFom6RUxb9FT5dEDJAVB3kCz8vO48QiiYaUMO4O8qf4HiudHWozqj9ha6pSDPQ9ilyfTDHhf4hAkfabw4wqVV7s/ez6yqqon5ZIWbKQjhE8El4yzm+MJd52QRxYDhB62jMsqUQI4n7a9YA0/vnqQoXr+DQuP5ExTyufDp9jHaZRtnaXzlaXWKO0ROS/0+xzSEC2fdsy44OQAdeFxUq5BtFH/Uy/+txie2Ug6/b6vu7e5QRvGDzG1zfjDwqolU5nWywdZVlxEOHmVHWfVL6tkVF0KpFEgGJE0dICY2+C173MyfcKEhiqZ/FQAaOU1JamowM/arG5VbN6P+ye94ybcDGFKSl2Zxh0DCtLeRhnrek7jfs6A644VoixxR7q7J3TGdoK6pjBHAFWgLWg6zINuuTixGJrboOXWW6cgjlqgtm4weYqCCkVJR0VncnzUQPdQa0A8PybShy7yefsPWuu9SzaEqNl3xyNkJIj7MS4aRy6/sGb3VS76jMvuekanydDn7WffVrfLoGeu7Mwhj9p9d+C8Nf6Cu1sjjetLuNGXnTc/c9CmvgCldyBLvVcY4Jx71mFPf/dYQ02TfhNAEx/8j/+PUSKO1dMGT6Jx4LxfbNJx25ro/r0DHBDfmrsH8kmmQ7uWRzOnIIPci/EK/+a3oLnw1Y3NeI22sa/4RvImUPgYdnZKL2EFJeclOhnKHUoVDPw== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(40470700004)(36840700001)(46966006)(26005)(7696005)(40480700001)(336012)(426003)(36860700001)(2616005)(36756003)(86362001)(356005)(82310400005)(186003)(40460700003)(82740400003)(47076005)(110136005)(41300700001)(54906003)(4326008)(2906002)(7636003)(5660300002)(8676002)(478600001)(8936002)(316002)(7416002)(70586007)(70206006)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:31.1286 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92eeeef8-77e5-4e2f-bc0b-08db5107776a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT083.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4971 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger The value of the STRTAB_STE_0_CFG field can be 0b111 as the configuration for a 2-stage translation, meaning that both S1 and S2 are valid. Add it and mark the ste_live accordingly. Signed-off-by: Eric Auger Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 792e8a788e2e..74e38abf5f4c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1304,6 +1304,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, break; case STRTAB_STE_0_CFG_S1_TRANS: case STRTAB_STE_0_CFG_S2_TRANS: + case STRTAB_STE_0_CFG_NESTED: ste_live = true; break; case STRTAB_STE_0_CFG_ABORT: diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index e9e45ce7a899..e73707479119 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -208,6 +208,7 @@ #define STRTAB_STE_0_CFG_BYPASS 4 #define STRTAB_STE_0_CFG_S1_TRANS 5 #define STRTAB_STE_0_CFG_S2_TRANS 6 +#define STRTAB_STE_0_CFG_NESTED 7 #define STRTAB_STE_0_S1FMT GENMASK_ULL(5, 4) #define STRTAB_STE_0_S1FMT_LINEAR 0 From patchwork Wed May 10 03:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29874C7EE23 for ; Wed, 10 May 2023 03:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235587AbjEJDfR (ORCPT ); Tue, 9 May 2023 23:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbjEJDez (ORCPT ); Tue, 9 May 2023 23:34:55 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2060.outbound.protection.outlook.com [40.107.212.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 836285BBD; Tue, 9 May 2023 20:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oJRV3P3EMIRvoc+8qlfAUKe6nstqP9EScJZdJuhs0gaZzAb48/oVgicqjgBO9QPrQwodfOkbbt35QiWtqqb0COeLPTVuQzYiVdDhxx38/oQE1WsIdbstOIaPQs+HBkBfVjSKomOYefPLMJlbWYef/ywoaQidcDsriBXyzuOC7CzfepTZj7Yp4HTMCpQjmq5erzP4OhdtWovBWdiL0R9w2N6wtVqvxrfskK3mOLUZJOnSU+oSShorHK0DCYSfM0YItH48/Z3mPiLCNNpkJgwTFiL6J7xeIZFJwjdKgufOTMhWx67t5tIleQt4LtCsJLGAu5SbS1S+8/KCrvMJviGEng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UZ8gL1brtpEsAHRv15orVOC1CnEqZShd4tHOccLP/Rw=; b=KmH0rTX2TKxo68kFy/iW98ccgwdCyr6/VSQLswy0dqCqc33Bu33MbuxIpLG0rx5vSPLWWTfAkd84oXMOU3gfyP24U7wwd/xJgLg5nYOoPoTIK+aKKGKiW3NAu4riS/vEVBITWFUXX1BtVawt4EYknrWJRmBZ4QUJhW4G6/urppE01p8sySCCFYeQvb6CIEOhfpy/FVLJ6QdKYvdC4HPZshrEdLwK9s/G+IRjMqgl2EhUOLw8mJnX2Zl6c/DT0w44OeXkuZAEXcyCryHkDVh0vY8gManNtjdGHPlvY0cWKVUrqva0hJ2/rygOcLj7/AjX97fRazOStdWYb26lREW/vw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UZ8gL1brtpEsAHRv15orVOC1CnEqZShd4tHOccLP/Rw=; b=M+iVomSpVB4a1EP4vGjkz+fzH5piY41aThT5dTCLvLYXHRSJGAjzNSutvN/IeI8s6JuZqMxnlf83E08P+MMcHZCDEaJ7rqRYfFSvi0h8KUFaP4L5KxcGQEEiSYf7RFtpnKq4l4vLovVE3Uz0hMJHYVhbNO5F+LlwlvIv8uO6QAArNIzPLuXeJ6+Qei8ySUw1VrbgdXNG+h8GjnAiWrn0ujbcralqIArgrmMtVzqqxfv1oXdz8sGmd3XyxcbYW8AydHK3qErPKGZX100OVDznzPITre+GcOii96jaza6ykvmNdamWqLI8oSNMLP6BMRta71pZ2UG9kfs5Vxyl+odq8g== Received: from BN9PR03CA0193.namprd03.prod.outlook.com (2603:10b6:408:f9::18) by MW4PR12MB7191.namprd12.prod.outlook.com (2603:10b6:303:22d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 03:34:33 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f9:cafe::fa) by BN9PR03CA0193.outlook.office365.com (2603:10b6:408:f9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:32 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:21 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:21 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:20 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 10/17] iommu/arm-smmu-v3: Allow ARM_SMMU_DOMAIN_S1 stage to access s2_cfg Date: Tue, 9 May 2023 20:33:30 -0700 Message-ID: <8e0b5fbdea1817485c86a442a072b032c9fe0ca1.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT009:EE_|MW4PR12MB7191:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d5aff3d-0983-4822-14a9-08db51077866 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: drEI47y5AvKWXNUgUkLJd5KbGi/zEe4uG85MhpMkc/T/0oxXSF88ygac6jQzsgWXPaC3sqpqD+XYBhg4mS7GFEjLRzJAq6rVjYau7olpI4XEjWvJ+oLWMvQagqMP+p8f94swlo/El2xAopsB2ffzpl3KmJ6U5B3UIFR4y0n1iEm/1cfhQIXpjKnMP6wU7GTcVIMgR2zDPbnVgPNiIOIN2NxQMysdBP4yQWOU9/q42oGX/DCaQ+Q57IwtZrRnVevwieT1PJ9yEBh0UNXoGC40m+NdG/APkgP/VSYFIb6c/lDIlAb4MyRbKfAh3pQJ6a4NbQrA1iCzPFJvB12d5mCwJCYglEG49l86svJgCY5YlordvM/zXTXf0Y8rWQzbSles3aE2UacBck/H39XMNfaZ0Wkg3BTOJnFUzujcMThw+BrKjNukDK2WYsLDTdUq5WYYkkAnl4s8Zak+Qp9uaAjqiQF8T4xFhaOVo27nbJRCPwDR4Z9MzdjJMTQeaO7UFleJYyLgmQ5sDHIgqWu3c0JAvq8bBuvFKfByJAiU0b0YvhzPpHFiOs/MkP/byiWqNme+9ZSUHFJvA1grJS9eFkS10QzcQ39rv2TN7CVbJwgVO3rE/a+eX1GVv9kk5LI47Ma8VPBOADVWYPuDWNEymz7RBFQB57kkUnhJbEXL7o+KRGJv3ZkOmkVSlwjjwIhJ/TAwkX9XVdmYcB57MUTI+jitCQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(346002)(136003)(376002)(451199021)(46966006)(40470700004)(36840700001)(36860700001)(47076005)(82740400003)(40460700003)(86362001)(40480700001)(36756003)(7636003)(356005)(6666004)(7696005)(478600001)(2906002)(110136005)(7416002)(70206006)(70586007)(4326008)(54906003)(8936002)(5660300002)(8676002)(41300700001)(336012)(316002)(82310400005)(2616005)(426003)(186003)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:32.7915 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d5aff3d-0983-4822-14a9-08db51077866 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7191 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In a nested translation setup, the device is attached to a stage-1 domain that represents the guest-level Context Descriptor table. A Stream Table Entry for a 2-stage translation needs both the stage-1 Context Descriptor table info and the stage-2 Translation table information, i.e. a pair of s1_cfg and s2_cfg. Add an "s2" pointer in struct arm_smmu_domain, so a nested stage-1 domain can simply navigate its stage-2 domain for the s2_cfg pointer, upon the availability of a domain->s2 pointer. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 ++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 74e38abf5f4c..fd3ac4802907 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1289,6 +1289,8 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: s1_cfg = &smmu_domain->s1_cfg; + if (smmu_domain->s2) + s2_cfg = &smmu_domain->s2->s2_cfg; break; case ARM_SMMU_DOMAIN_S2: s2_cfg = &smmu_domain->s2_cfg; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index e73707479119..232a2dda5d24 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -711,6 +711,7 @@ enum arm_smmu_domain_stage { }; struct arm_smmu_domain { + struct arm_smmu_domain *s2; struct arm_smmu_device *smmu; struct mutex init_mutex; /* Protects smmu pointer */ From patchwork Wed May 10 03:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD918C7EE23 for ; Wed, 10 May 2023 03:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235685AbjEJDfh (ORCPT ); Tue, 9 May 2023 23:35:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235656AbjEJDe5 (ORCPT ); Tue, 9 May 2023 23:34:57 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2071.outbound.protection.outlook.com [40.107.93.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDC5249D4; Tue, 9 May 2023 20:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fhTOWTmpUARNxF6H5MRX3XHcutvGbiCks3JzpxwyYU43Utrweuf2DcfB+kd8LhjIcI0LToqnKyj8ycg4EJgyHFFTk+ITO1YRXDTPsefz3F822b+JgGhZSI0zSgeWESumPMicrFgTA8zdmZJy9K6jxMZuuvE2CG3fW9OHklv4YCUormBmwMtzUytEkNlKVaPdr0XC3r1f8RyO1NEPW6OkWKT2VI1ktE8/2T2aASOdHC2Gi5/hMHQ5BKJglLClVc953/8ZmsLN8HWxPo8YGBk3cq+zeaxlsLjSXkxl8NhzV6DoBt2GyVh5i21mE//J1wwqVCkgQjN/QxFK1tBmB7YiSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oArvuULAtrRr2QLD+BcfOd2SmPnve2z8ByIqyo8lKU0=; b=j9mE6cLyuksfHq9XiGPrvDZsw1oe/86/nve3t5qHrAQoWqjtIYESrM/70lkTE2jjqbvBw+9iwoxuPmavryKJ/mM9ruXFWdNbR4j8dCjGhcG4i1p2y6n9uf9SLdUONWstmsPdFDJMn3ojLLTZtyUZDvJpVrmpH38ZpcwsMOJkQIlJSzAUSNeKC50gS0RY7o6pOgYs2MqJ5nhRC+gPEbpkmHDUCg/EcDaZQL197ehB3wKGViH1AZgdv3C+VLAR1FD9VnflZe5CvkD7oNKmerLfk9nEJ83b7vE+xEN9d6wDLAVrwmT+et1ZuxkIhEVbow9OUfyiOvTYfpzmoesYUdMz9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oArvuULAtrRr2QLD+BcfOd2SmPnve2z8ByIqyo8lKU0=; b=fKwszb47YvoY3t5h8buzRvT8ww5zCzXr2oOZScfDRQ5h44U43GR59VrHV4OJsmRFLFsJA806cFLyrc8UNx0qHzZX0v9jiATPzEonAAIdim190ER4C7MZxAcTsUIRoU8s4W0oXK/4WAZNm7Moxhg6dnICU/khKAsIVGISLjGIZxxNcEeswzx6A46bJsUmgR10YjBrRnWUqJnGRU/S7kNLx48dIx/FPIpBRpQHc268DK3bZlRA62IbyktDYVOkf9ouGmHw8l0UbY216MMm7PHs+iYJwbnWUEZ+4QyK7enNK5XziNKS8nOPZQGqeze4A3BT/PdBIQnvorYUPMg4Aer0og== Received: from MN2PR11CA0005.namprd11.prod.outlook.com (2603:10b6:208:23b::10) by DM6PR12MB4090.namprd12.prod.outlook.com (2603:10b6:5:217::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18; Wed, 10 May 2023 03:34:35 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::4b) by MN2PR11CA0005.outlook.office365.com (2603:10b6:208:23b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 03:34:35 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:22 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:22 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:21 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 11/17] iommu/arm-smmu-v3: Add s1dss in struct arm_smmu_s1_cfg Date: Tue, 9 May 2023 20:33:31 -0700 Message-ID: <84f013e02f50f24f00eac77c2b5c416c18fc5a2c.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|DM6PR12MB4090:EE_ X-MS-Office365-Filtering-Correlation-Id: fba4f925-a911-4312-cdcf-08db510779d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5MoqweVoKc4fZM1ZA4lzo5fIW+g20/orGvOm3Ktu7bWulUnoB/nAQCzl92H29fwGLsI5g2ukbogqQeDnmliGN7beMEVIyJj9l1EkvwQrCt7aIU8m+nJ5WbC4P2DxSiN1zMReHvIdvGOVILyQ+TETXib9ps6zXAIBqlaVGmOgKA0vCCOV8a4GiqES/thZJR/SyvDw/kHNWUUbbuyVZRMQLajxuKvAJwIUvlLKamKGWIhtyYbc4lP4A3OVvcQw9DjjnDxT7OqjO/axFcZRzzVnjvckdeKQxTYW1Ozm7kjLRwddLD/Lctw8GpBg+7KZL42xCYQMjo5ls2P6wbKOz+mh6/i69B3UX5l9DrD2qAg2p7gtWCJGUUXN2kUA10FCU/LVXB2p7N3UcgHDPyVHVDxi4lNTj1WB+kecYtBPw+6ebEutoj2qYcSx27zUYzx1lLY/6R+W4Ue6E3YwwKceHAWSoNLYuUXuCwNRFMSosYqntJabkHcIDkhwoxMEm9KFUSEQpUUQSJKoJfWKCo9zvcH5E0rdQMRxa/MTCrewuJF9Xt04R0f8v1UvadhfwGP3FBOLhbeNCGlYxPklMjPchVu53SSIHhAwXOp4sTmwVmVNyvXDIYkv36i3G08kqu8LX7/bU8aU3DoZA4/Sg5Z1zHRMFgGj3QfoAmuTUyburYp9doPt2Qkhh7S3QAv9R7BqVP7dChZTZtjG3HSzKZuawLEyotGgbU+Z3emBrSj+XZykoA5g6ZiN5kZfJhEZ3GzFdg95FJh+5A3KgLrDsB5oRZ6JGOMApBy6ZCpNNHbNDLc1k0TLOF3OjBrpp6SVEf3XNHL1 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(376002)(136003)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(6666004)(7696005)(83380400001)(5660300002)(36756003)(47076005)(82740400003)(2616005)(336012)(426003)(2906002)(41300700001)(36860700001)(8676002)(8936002)(7416002)(86362001)(26005)(186003)(40480700001)(4326008)(316002)(7636003)(478600001)(356005)(110136005)(40460700003)(70206006)(70586007)(82310400005)(54906003)(32563001)(473944003)(414714003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:35.1661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fba4f925-a911-4312-cdcf-08db510779d2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4090 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The s1dss has been so far hardcoded with a value STRTAB_STE_1_S1DSS_SSID0 in the STE setup routine. Yet, with a nested STE support, it should setup the value coming from the guest OS. Add s1dss in struct arm_smmu_s1_cfg, and set to STRTAB_STE_1_S1DSS_SSID0 in arm_smmu_domain_finalise_s1(). It will be setup with the value from a guest OS in a separate pathway for a nested use case. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index fd3ac4802907..8b827247f4b9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1346,7 +1346,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, BUG_ON(ste_live); dst[1] = cpu_to_le64( - FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | + FIELD_PREP(STRTAB_STE_1_S1DSS, s1_cfg->s1dss) | FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | @@ -2144,6 +2144,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, goto out_unlock; cfg->s1cdmax = master->ssid_bits; + cfg->s1dss = STRTAB_STE_1_S1DSS_SSID0; smmu_domain->stall_enabled = master->stall_enabled; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 232a2dda5d24..6ed86883d52e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -598,6 +598,7 @@ struct arm_smmu_s1_cfg { struct arm_smmu_ctx_desc_cfg cdcfg; struct arm_smmu_ctx_desc cd; u8 s1fmt; + u8 s1dss; u8 s1cdmax; }; From patchwork Wed May 10 03:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16BA8C77B7C for ; Wed, 10 May 2023 03:36:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235134AbjEJDfx (ORCPT ); Tue, 9 May 2023 23:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235734AbjEJDe7 (ORCPT ); Tue, 9 May 2023 23:34:59 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2081.outbound.protection.outlook.com [40.107.93.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E27B30EB; Tue, 9 May 2023 20:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lwjiB+Dex2a/2oO7z7AgmwPskpBEOs7VyNI48bDjNeKhRc1N0ARJdb7IBXMZk0FJ+N+gDWTTV1BIeDR8qxL1T7KlQXq8IYHaDh7fH9UfFtfyapTqJ5wa0K5R6wAYAGBiq8s6xa6WVyYWh05ONO3cyrcVEiS4v1vgd/hBSLXjtQUtzKvn91GI8+NROHCdiRfIv1e25d3L0wJb6A+56r5umYVRDfg3Bgl6zgyzpk1KGlpNcd05oZ1MrfhHSyXjkZ40GS2f4Jo4L2Yzf6ClT9EtK8VpGm97xuHzwF/Urzs6sZ5jyGbx7C3n48QwL/VUIP3DU8NiYHIQ/kHkZO57SW2D9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=V0NElZ4X9QBwVbXtfVudA7k/g7fQ8jmLjhQm8mdt5gk=; b=KUOyeRAQHwGZTVurwMbCXiUfJEfpmpeq7AtM+67HarhvAOTf3f6E4pBszqo9gvNU5h9LyJVAzaShq93UPHV8b34PoBfoRhyISKq40IcXeTqCO6oMG3OHwG95h3SVz3OvAfFf15Zs5vElmwRRDaBQvxnx+MjymFksI38V9qRLmgav+5efMhvaalhXiMRcaDBaieZoEOfjX9L1EVwV8pQbYMDvndcc6RlDJpE7QlTzdb6i1eqpahi+gjCIiqVUdSW+f2TJOWyicq7KzQ7IKvWskM4ZS4rA7LToyXw9ZjwPrf1Uk8whLTmw/y/Zz0xmY/LQvKJAw9z0MkY1/UX94EcRwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=V0NElZ4X9QBwVbXtfVudA7k/g7fQ8jmLjhQm8mdt5gk=; b=mN/UqVsVZnmdh1ZudAeP5mHfWJs0chumqHN9Z5jHajGn0bEIBzmqaymCPJFELrVXrUGRzqmSg2CKEhiC4d2rxzBJRESmLSW+qKMuO+jh9otUOlS/rYe2eOgVHTqktyxg9KzwdE6ELR5xIryZ0Jb72dWKX4eIz7DBfdu6PZ2O1yqilXsGJrsGOOVsgygAViJsHvdOdIQjhkWYAGvEyOI+3H2AjZGqNIaOz8IgBnbmOa/h/GvUtpZDV6t7AghqPA30VQKXjPGJbllzmxFXnKWPxRkhLB8/yptuTFdcK7OvtOHSEh4I1tqvKPW/apM5grplCbOhfTaYhEikUdxCWPu+Fw== Received: from BN9P220CA0018.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:13e::23) by CY8PR12MB7633.namprd12.prod.outlook.com (2603:10b6:930:9c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 03:34:36 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:408:13e:cafe::94) by BN9P220CA0018.outlook.office365.com (2603:10b6:408:13e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:36 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:23 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:23 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:22 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 12/17] iommu/arm-smmu-v3: Pass in user_cfg to arm_smmu_domain_finalise Date: Tue, 9 May 2023 20:33:32 -0700 Message-ID: <931282642f7b2a6a73cdbdcecd428bdeb1ecad27.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|CY8PR12MB7633:EE_ X-MS-Office365-Filtering-Correlation-Id: e3eaa902-9adb-4c20-eb73-08db51077a6a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EkEKUI0WHX+cT1/+hH2mZ/O9ReNzF/kjIHpIu9T+Vx/+UAOnJ8ty4e52ZcqVcy20jvI4KI4Qa3TT6V1noWiD497NjlZed+ep0x7y0STZqHnnBQLmZtaXZry+D+wiCNA+h+cdDEhSyD3e+dkax8hVb8gTczjI3Ph+Bw3WzUVk9H7kbO3EdOWbonV+eN8fGPmQH7MgKpfd54ssiF6cUHROeijFuR3x/YgKoHjQbIVOPpppVq0iUm+WJqF/SNt+KWMe0YZHh1uXbwPK0IeffqryonLucw8bxqgOk4auutnNGHLkAQsbu5xhih8ayRuKM95mlnl+otGCm+8WCLN+XyJG/HfVvCr3R2+H8LvXJfGw1IH0QjCSVMaNOzSr/DeSB0nCZWSuA2eIDbQaaElfU/hZI5A8e3WClCycD4oFpWxaDaMcbke3bp8b/s+HSS9doAG+dJ5X9SwcwwZP4/6Ts76t9Ks2vqPutPhnaHnA0ZpwdpKcY6RfGQIK6RjSEP18pqLY2virC8mNvnCOGZ/MUv6LhEIHx/uHkLiknuDDoxGKnsYBLVqAVXm3Vwy9C9vaWP0xzg32SUT14e584FAQfSiT/BWcVldNpPWcH/tYqtPif+FfJbjiIiRefQEhcq6yHhGEJGsTHYgngyp2cRNuOhroviSrNSeB8IRyzx0tPXyaEtDB67Mc2yRX2B+vW8ZsUviU21m0tvEyImUW1mdxkOs4VA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(451199021)(46966006)(40470700004)(36840700001)(110136005)(4326008)(70206006)(82740400003)(356005)(70586007)(316002)(7636003)(40480700001)(8676002)(336012)(8936002)(426003)(82310400005)(47076005)(54906003)(83380400001)(26005)(86362001)(41300700001)(5660300002)(36860700001)(186003)(7416002)(478600001)(36756003)(2616005)(2906002)(40460700003)(7696005)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:36.1474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e3eaa902-9adb-4c20-eb73-08db51077a6a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7633 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The struct iommu_hwpt_arm_smmuv3 contains the userspace Stream Table Entry info (for ARM_SMMU_DOMAIN_S1) and an "S2" flag (for ARM_SMMU_DOMAIN_S2). Pass in a valid user_cfg pointer, so arm_smmu_domain_finalise() can handle both types of user domain finalizations. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 8b827247f4b9..b8c189b732ba 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "arm-smmu-v3.h" #include "../../dma-iommu.h" @@ -2211,7 +2212,8 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, } static int arm_smmu_domain_finalise(struct iommu_domain *domain, - struct arm_smmu_master *master) + struct arm_smmu_master *master, + const struct iommu_hwpt_arm_smmuv3 *user_cfg) { int ret; unsigned long ias, oas; @@ -2223,12 +2225,18 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, struct io_pgtable_cfg *); struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; + bool user_cfg_s2 = user_cfg && (user_cfg->flags & IOMMU_SMMUV3_FLAG_S2); if (domain->type == IOMMU_DOMAIN_IDENTITY) { smmu_domain->stage = ARM_SMMU_DOMAIN_BYPASS; return 0; } + if (user_cfg_s2 && !(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) + return -EINVAL; + if (user_cfg_s2) + smmu_domain->stage = ARM_SMMU_DOMAIN_S2; + /* Restrict the stage to what we can actually support */ if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) smmu_domain->stage = ARM_SMMU_DOMAIN_S2; @@ -2472,7 +2480,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) if (!smmu_domain->smmu) { smmu_domain->smmu = smmu; - ret = arm_smmu_domain_finalise(domain, master); + ret = arm_smmu_domain_finalise(domain, master, NULL); if (ret) { smmu_domain->smmu = NULL; goto out_unlock; From patchwork Wed May 10 03:33:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 538DEC7EE23 for ; Wed, 10 May 2023 03:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235735AbjEJDgL (ORCPT ); Tue, 9 May 2023 23:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235768AbjEJDfA (ORCPT ); Tue, 9 May 2023 23:35:00 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2057.outbound.protection.outlook.com [40.107.93.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6824B59E5; Tue, 9 May 2023 20:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LsjJgsSik2z+2Hcfv/3LiJttY8m9xxYSEwNfTvVef5hO/twhXm9LVnpt1zbkyWe/Jaj+BMrVS219WwQ1tQT4XN4vWOj2zL7ekrn4CwdsamIye9TONCz/6WzG8MM28L/H2dt6Kpi29cWqhnEOs7oNjp5XpIXnQdnEPJzZIMtF+KfCsQpz0+stGRK8VBacfbxhSZyCH+fbyLtlczk28mv9/a2D6N+vwQRJE7X+XC9iKZhBBKMTE/o56H3gAdzxSLaeLtLIcSQhwIOpIKJqSB+e0NdNqrBE2oRKA41X1jUtrOJU9dccar4S3AJbQ2+8GXM4qTqjbNM9L4kbdPBCnWhIjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=780CyHHRhVckiPXJb45VGjzPkDA6ekdv9KzzU9BWVfM=; b=LZ5/LkbNmP5JcIzE2uSDhHOfUNJtvkSMNY44KDcarVsjNlzaE0dUxrb8Er4YtGk0CmSTky0F66IgujyZlEHEW4zs+2KblX/4E4scvkXcnPa8bqiX1CndaahdyCpv24h/2pn6NFtPbMUg1NqRjg3wfREut5jxR2xTH5BQWjkMr5J/FvwR1qRSwAqf0AqTm6N3ImCCMLa9mJDw0DJNHb0V3+BELg82RMSJU/ZgxuIn5z05PmEjNsEUlJELEO5gtIpu51QLeEOa9X+Opo0fS2X4w+R05AHXTKiqV8eOBaeLQAACSGVZ9vD/HY7Th0H9NR8nQVXRnyh/9U0EluPFjLWIfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=780CyHHRhVckiPXJb45VGjzPkDA6ekdv9KzzU9BWVfM=; b=f9BiNtNrmBecueW03eifhyrNa8DZkcst4tqZEc+/gvUdcsvjvRbTIBCKH47zUrIKz19D//0n2ivDAo379ZxovpncKaSbia9evSeiuBlKUqsf0sltqjuAVgMmraNS0QjFb7cwYwml+BNfBui0uHgMw8btrurNgocmYVFpskipKqi7GEBioMk/gGjnvkQ7TgClNhtEAdGaSekJYof3nxhrtAwtLV+HVw54VYW6zUyIj5v/hrZ41pBNd0dKxGa3KkHhPRCrnjEp9Q4o+D3Vq3zlov5Ar+GX2Uyojyx/oIurBrKt8MOWXGRgOWLAqP/PQv0Ewmz8XEfRecM+8IkY0z4krA== Received: from MN2PR11CA0006.namprd11.prod.outlook.com (2603:10b6:208:23b::11) by DM4PR12MB7504.namprd12.prod.outlook.com (2603:10b6:8:110::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:37 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::d4) by MN2PR11CA0006.outlook.office365.com (2603:10b6:208:23b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 03:34:37 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:24 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:24 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:23 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 13/17] iommu/arm-smmu-v3: Add arm_smmu_domain_alloc_user Date: Tue, 9 May 2023 20:33:33 -0700 Message-ID: <7d8caa89c156b6915d3da5307b9ec3b8f218359e.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|DM4PR12MB7504:EE_ X-MS-Office365-Filtering-Correlation-Id: 14c95795-96fb-4ac2-be87-08db51077b27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /vNfD551WEGAgNBjRf3ExSCsLdaTxJmRaHkJfSYOCJjPOdPpen4BKvbnaNw1OaAvHq8Yj/JoR5jm7Rjr3mnjezozm7bDlTHHTMYKsHaVSrXezteou4kA+Q/iKE/3GQDtcWU1FGGs9SLND9v9OthMEMgcg9HkUu7pVWc1LSWTAfaBWkYfYYAiTOOJs5odB1hTpePzGReKzxCOxe2NLo2Ugc8oFb39IKOGweFZUQSnAQsrnYFLgYpXr3++T1vcbxkmndoBJHpGloPCZMD1+knhAf3vyo6Lg8WFBWHumAV9z+j9h7ERsX4mVNxavqRXpVhX27kQOW698RLFwgBbfJ3pwPG9JRS0K77DDLxR/v9COuLEG2oSLnY0cJMOLYnwBaQ7SvGf5hFbPgvr7NMUeY33HUrYQiwBPAhualXJDJkoiIe9613cQ8oYUKHyuxSMgCziq78wSD1pbCGfMsLZ+S/WmQBH6EivIVefcw9wqEZ/PqmIEAECfWjyHFVLvHgFWTx/SR6+nsfifiuLM+fx+Tl825kKbPVeG5bR8D8Pa4ppcApVCokPdCH2anXhzj/ypSrqdq+ufAnRAf0AoaS08fKNaRqUIwRfIXQmn4bfDZ1OR1VcEBz12v218gD/eCF24jn8yOislmYaL2GalxJiNkQYmyUM9a7NanX0idhn2lrkoHluYqaf9TW8lVlzuYbfXEX0deWDZ0xDFquFMSF+JOKaTQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199021)(46966006)(40470700004)(36840700001)(86362001)(36756003)(6666004)(316002)(54906003)(70586007)(478600001)(4326008)(7696005)(70206006)(110136005)(40480700001)(82310400005)(5660300002)(8936002)(8676002)(47076005)(7416002)(356005)(41300700001)(2906002)(82740400003)(7636003)(186003)(36860700001)(26005)(336012)(83380400001)(426003)(2616005)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:37.4005 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14c95795-96fb-4ac2-be87-08db51077b27 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7504 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The arm_smmu_domain_alloc_user callback function is used for userspace to allocate iommu_domains, such as standalone stage-1 domain, nested stage-1 domain, and nested stage-2 domain. The input user_data is in the type of struct iommu_hwpt_arm_smmuv3 that contains the configurations of a nested stage-1 or a nested stage-2 iommu_domain. A NULL user_data will just opt in a standalone stage-1 domain allocation. Add a constitutive function __arm_smmu_domain_alloc to support that. Since ops->domain_alloc_user has a valid dev pointer, the master pointer is available when calling __arm_smmu_domain_alloc() in this case, meaning that arm_smmu_domain_finalise() can be done at the allocation stage. This allows IOMMUFD to initialize the hw_pagetable for the domain. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 117 +++++++++++++++----- 1 file changed, 87 insertions(+), 30 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index b8c189b732ba..75ee928c2390 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2051,36 +2051,6 @@ static void *arm_smmu_hw_info(struct device *dev, u32 *length) return info; } -static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) -{ - struct arm_smmu_domain *smmu_domain; - - if (type == IOMMU_DOMAIN_SVA) - return arm_smmu_sva_domain_alloc(); - - if (type != IOMMU_DOMAIN_UNMANAGED && - type != IOMMU_DOMAIN_DMA && - type != IOMMU_DOMAIN_DMA_FQ && - type != IOMMU_DOMAIN_IDENTITY) - return NULL; - - /* - * Allocate the domain and initialise some of its data structures. - * We can't really do anything meaningful until we've added a - * master. - */ - smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); - if (!smmu_domain) - return NULL; - - mutex_init(&smmu_domain->init_mutex); - INIT_LIST_HEAD(&smmu_domain->devices); - spin_lock_init(&smmu_domain->devices_lock); - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); - - return &smmu_domain->domain; -} - static int arm_smmu_bitmap_alloc(unsigned long *map, int span) { int idx, size = 1 << span; @@ -2928,10 +2898,97 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); } +/** + * __arm_smmu_domain_alloc - Allocate a customizable iommu_domain + * @type: Type of the new iommu_domain, in form of IOMMU_DOMAIN_* + * @master: Optional master pointer for the allocation. If given, this will be + * used to call arm_smmu_domain_finalise at the end of the allocation. + * Otherwise, arm_smmu_domain_finalise will be done when the domain is + * attached to a device. + * @user_cfg: Optional user configuration for the allocation. This allows the + * caller, mainly user space, to customize the iommu_domain in the + * arm_smmu_domain_finalise function that decodes the user_cfg data. + * + * This helper function is shared by domain_alloc_user() and domain_alloc(). + * Unlike ops->domain_alloc has been so far only called by the iommu core that + * sets default values of domain->type, domain->ops and domain->pgsize_bitmap, + * the ops->domain_alloc_user could be directly called by the iommufd core. So, + * this function should set those default values for an ops->domain_alloc_user + * call. Note that domain->pgsize_bitmap is set in arm_smmu_domain_finalise(). + */ +static struct iommu_domain * +__arm_smmu_domain_alloc(unsigned type, + struct arm_smmu_master *master, + const struct iommu_hwpt_arm_smmuv3 *user_cfg) +{ + struct arm_smmu_domain *smmu_domain; + struct iommu_domain *domain; + int ret = 0; + + if (type == IOMMU_DOMAIN_SVA) + return arm_smmu_sva_domain_alloc(); + + if (type != IOMMU_DOMAIN_UNMANAGED && + type != IOMMU_DOMAIN_DMA && + type != IOMMU_DOMAIN_DMA_FQ && + type != IOMMU_DOMAIN_IDENTITY) + return NULL; + + /* + * Allocate the domain and initialise some of its data structures. + * We can't really finalise the domain unless a master is given. + */ + smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); + if (!smmu_domain) + return NULL; + domain = &smmu_domain->domain; + + domain->type = type; + domain->ops = arm_smmu_ops.default_domain_ops; + + mutex_init(&smmu_domain->init_mutex); + INIT_LIST_HEAD(&smmu_domain->devices); + spin_lock_init(&smmu_domain->devices_lock); + INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + + if (master) { + smmu_domain->smmu = master->smmu; + ret = arm_smmu_domain_finalise(domain, master, user_cfg); + if (ret) { + kfree(smmu_domain); + return NULL; + } + } + + return domain; +} + +static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) +{ + return __arm_smmu_domain_alloc(type, NULL, NULL); +} + +static struct iommu_domain * +arm_smmu_domain_alloc_user(struct device *dev, struct iommu_domain *parent, + const void *user_data) +{ + const struct iommu_hwpt_arm_smmuv3 *user_cfg = user_data; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + unsigned type = IOMMU_DOMAIN_UNMANAGED; + + return __arm_smmu_domain_alloc(type, master, user_cfg); +} + +static const size_t arm_smmu_domain_user_data_len[] = { + [IOMMU_HWPT_TYPE_ARM_SMMUV3] = sizeof(struct iommu_hwpt_arm_smmuv3), +}; + static struct iommu_ops arm_smmu_ops = { .capable = arm_smmu_capable, .hw_info = arm_smmu_hw_info, .domain_alloc = arm_smmu_domain_alloc, + .domain_alloc_user = arm_smmu_domain_alloc_user, + .domain_alloc_user_data_len = arm_smmu_domain_user_data_len, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, .set_dev_user_data = arm_smmu_set_dev_user_data, From patchwork Wed May 10 03:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DADBFC7EE26 for ; Wed, 10 May 2023 03:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235759AbjEJDgN (ORCPT ); Tue, 9 May 2023 23:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235312AbjEJDfE (ORCPT ); Tue, 9 May 2023 23:35:04 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2072.outbound.protection.outlook.com [40.107.92.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5630F268E; Tue, 9 May 2023 20:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CA7yT+6yF6DkdyYoOyaLuNN2vva4TjFcKUjLITHTpdGj5xX0NLzlJ7Xx//ihvumy2kg6vzm1hpHz4UeK8pq/F3ABHa/yWvqRCxsdppyzdw1kB4f1b7/di+vkgfDUMcR/qaIInx77mHlQTdn7H/rAKe17b2YEbgoG7hVpnzKCI7QijZV9usIDIR4vWS3dK8gcovFo2yc14YHmRaSlGQgeZEv6kNoxKpXSbiSjU61fe4h0sFvWMSKCRPS8+nm6mkxZp5GIphHLuusAViNYHwwjUZIEaWMIPw3luG8dmXwv0EH8I3KkDd+kQ/a0ztrB8fYKJsIntsZZTmRRbZldWKbuRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wkozRIdnZ+SDWZ7LNbdDRxamnFQ7ndzENLR3RmzKDHM=; b=UaeDbL6Ip7tzk7KQFzUvBWmkfH+1qtyY7rHLJpa6CEXN6C+6JbeJCkzu2ySqDV0uXCjCuRl1LG5WdsKqGkodKrDl4QZRM938k3zl/Q/kevgF10xVAEid6bkFwCzkSXD2mngWwX9VEbAKeOQuR/ISZYzU8TAd/Bj6TcT0ISZvVwQpb6dMEEoSxh8zzDF48budRzGZ97ks1lLcA+WQ+4Z+0BDb9m7BWUJWeYSFvizo8fxd7omFQ40nJ5gYqns8rRfSqMNrl0DieB0E4EhcHfU+CoeEmrBQuecmzgsFBloFY2p2heLSqMjuFuUd/oB2kS5U/tF0e/MVisJU97n/H+5AXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wkozRIdnZ+SDWZ7LNbdDRxamnFQ7ndzENLR3RmzKDHM=; b=EpxKatNRt3Ffco8fD3OcXSX8xHUbVnhKLjeJZZrUphaYQYJ92pP48mOYXBlqwRRTq57ZPvo/2uPRjoBmSOMFVG9dpFSyxOE+aSgGOt7x7Qk11qJC7O1L3kYFBNy6KgRuM/qGqlHWq0+5leCDla6b/g7ctm0WvgKw002dDKRCJbVcgX09Hwch+4tShQLV5HG0isIboRgRS8kH3QgBDEfsdlgrrKrgkJxjON//0brER8P+oUlvfKlb8njiqwofpSgLb20g8oFWNW9u2c8sKRIRFR57/0FSc+NdR4m3E+1P4CuB1d81TbuUNbsmVmDBknYuQTC1+a6GmmkQVorUQTcxBw== Received: from MN2PR11CA0027.namprd11.prod.outlook.com (2603:10b6:208:23b::32) by DM4PR12MB7525.namprd12.prod.outlook.com (2603:10b6:8:113::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18; Wed, 10 May 2023 03:34:39 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::8a) by MN2PR11CA0027.outlook.office365.com (2603:10b6:208:23b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 03:34:39 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:25 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:25 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:24 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 14/17] iommu/arm-smmu-v3: Support IOMMU_DOMAIN_NESTED type of allocations Date: Tue, 9 May 2023 20:33:34 -0700 Message-ID: <75b2fb9e4473cfacbd762f451f8a3c35189a171b.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|DM4PR12MB7525:EE_ X-MS-Office365-Filtering-Correlation-Id: 11b42380-0ce2-4681-d91b-08db51077c45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rhLC/ih8q615fmnw3v/jAFHXsljIDUv9FEa6vbAKr12fHu6kBhAcB9DbaqHex85iSWkDiHfCXM91p2xTh+3IDjpDoKOLGLJN6Th0jAMtiTtL8Opayc+7u603S0Zt0i688vfMaIKQ6UAB8jzNfA57J2S+9TNFJG+gE0G6zHdAdn/yi1vXARqRmEWRE4/U8y0ZWBdG0P+xOx6mPqVJxjc2emd8Eiwp6iDDkfUupS3kEBTac/5L4Nl5A5zH4rSPSd+VZTa3chD7q1U7Ozl2u6cyOV9jldZISrwG1PyM5Z1+VfSFYBQKCZSvrzsTUMS5NRusSdrbIPZ8QmjicpOlXawCzSRFIRces+qTR64/iiK7xNwB9/2/YJdx4+8hf36iLhoENlaWISnlzpZPfla62DoEO++mDaoIxoiG9oEEy2JuCKuDnDeYwCFrY8F3AvwgzyUnfLxQVxIwC42i0bDOtA3GIG5pJw5LLUmpyVC7DMfifx2QuQnr3pZl7ZqcwYiHx16pMmZ7IWZAxAiRZpvyie12pUDaICS6qhBvxGGnmwmkFj8Djt9qJETcRgObokASZRS/LtEucjQXiWAdjhz77t8GoC7XknhbO2DfmCPwtrz0ZyT29X8rXyFGt6SUvW6VDFUtc8mdZD/pA1IGi7d6l8PyFGwfeBkFT62JopiRhwEKtkt0lqxRDvDjM8dPFRSBK4qOGfyAtWGIrnDjDfrts8wCqpXl/0/vgFS/p1L05RJI+jIja/0jwTnaP+lLx9XhzjBazAjLqv0PMMojRcjz6qgumMhElTlLPRDvnawss6HCtcQ= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(39860400002)(346002)(396003)(376002)(451199021)(36840700001)(46966006)(40470700004)(54906003)(83380400001)(47076005)(70586007)(7636003)(7696005)(356005)(316002)(36756003)(5660300002)(186003)(70206006)(4326008)(82740400003)(2906002)(41300700001)(6666004)(426003)(36860700001)(336012)(86362001)(110136005)(26005)(82310400005)(40460700003)(2616005)(8936002)(8676002)(40480700001)(7416002)(478600001)(414714003)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:39.2599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11b42380-0ce2-4681-d91b-08db51077c45 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7525 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add domain allocation support for IOMMU_DOMAIN_NESTED type. This includes the "finalise" part to log in the user space Stream Table Entry info. Co-developed-by: Eric Auger Signed-off-by: Eric Auger Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 112 +++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 110 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 75ee928c2390..3d150924581f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2181,6 +2181,76 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, return 0; } +static int +arm_smmu_domain_finalise_nested(struct iommu_domain *domain, + struct arm_smmu_master *master, + const struct iommu_hwpt_arm_smmuv3 *user_cfg) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_device *smmu = smmu_domain->smmu; + bool feat_2lvl_cdtab = smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB; + bool feat_s1 = smmu->features & ARM_SMMU_FEAT_TRANS_S1; + bool feat_s2 = smmu->features & ARM_SMMU_FEAT_TRANS_S2; + size_t event_len = EVTQ_ENT_DWORDS * sizeof(u64); + size_t ste_len = STRTAB_STE_DWORDS * sizeof(u64); + struct device *dev = master->dev; + void __user *event_user = NULL; + u64 event[EVTQ_ENT_DWORDS]; + u64 ste[STRTAB_STE_DWORDS]; + u8 s1dss, s1fmt, s1cdmax; + u64 s1ctxptr; + + if (user_cfg->out_event_uptr && user_cfg->event_len == event_len) + event_user = u64_to_user_ptr(user_cfg->out_event_uptr); + event[0] = FIELD_PREP(EVTQ_0_ID, EVT_ID_BAD_STE); + + if (!feat_s1 || !feat_s2) { + dev_dbg(dev, "does not implement two stages\n"); + if (event_user && copy_to_user(event_user, event, event_len)) + return -EFAULT; + return -EINVAL; + } + + if (!user_cfg->ste_uptr || user_cfg->ste_len != ste_len) + return -EINVAL; + if (copy_from_user(ste, u64_to_user_ptr(user_cfg->ste_uptr), ste_len)) + return -EFAULT; + + s1dss = FIELD_GET(STRTAB_STE_1_S1DSS, ste[1]); + + s1fmt = FIELD_GET(STRTAB_STE_0_S1FMT, ste[0]); + if (!feat_2lvl_cdtab && s1fmt != STRTAB_STE_0_S1FMT_LINEAR) { + dev_dbg(dev, "unsupported format (0x%x)\n", s1fmt); + if (event_user && copy_to_user(event_user, event, event_len)) + return -EFAULT; + return -EINVAL; + } + + s1cdmax = FIELD_GET(STRTAB_STE_0_S1CDMAX, ste[0]); + if (s1cdmax > master->ssid_bits) { + dev_dbg(dev, "s1cdmax (%d-bit) is out of range (%d-bit)\n", + s1cdmax, master->ssid_bits); + if (event_user && copy_to_user(event_user, event, event_len)) + return -EFAULT; + return -EINVAL; + } + + s1ctxptr = ste[0] & STRTAB_STE_0_S1CTXPTR_MASK; + if (s1ctxptr & ~GENMASK_ULL(smmu->ias, 0)) { + dev_dbg(dev, "s1ctxptr (0x%llx) is out of range (%lu-bit)\n", + s1ctxptr, smmu->ias); + if (event_user && copy_to_user(event_user, event, event_len)) + return -EFAULT; + return -EINVAL; + } + + smmu_domain->s1_cfg.s1dss = s1dss; + smmu_domain->s1_cfg.s1fmt = s1fmt; + smmu_domain->s1_cfg.s1cdmax = s1cdmax; + smmu_domain->s1_cfg.cdcfg.cdtab_dma = s1ctxptr; + return 0; +} + static int arm_smmu_domain_finalise(struct iommu_domain *domain, struct arm_smmu_master *master, const struct iommu_hwpt_arm_smmuv3 *user_cfg) @@ -2202,6 +2272,11 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, return 0; } + if (domain->type == IOMMU_DOMAIN_NESTED) { + smmu_domain->stage = ARM_SMMU_DOMAIN_S1; + return arm_smmu_domain_finalise_nested(domain, master, user_cfg); + } + if (user_cfg_s2 && !(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) return -EINVAL; if (user_cfg_s2) @@ -2898,9 +2973,16 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); } +static const struct iommu_domain_ops arm_smmu_nested_domain_ops = { + .attach_dev = arm_smmu_attach_dev, + .free = arm_smmu_domain_free, +}; + /** * __arm_smmu_domain_alloc - Allocate a customizable iommu_domain * @type: Type of the new iommu_domain, in form of IOMMU_DOMAIN_* + * @s2: Optional pointer to an stage-2 domain, used by an stage-1 nested domain + * allocation, pairing with a valid user_cfg data to configure the domain. * @master: Optional master pointer for the allocation. If given, this will be * used to call arm_smmu_domain_finalise at the end of the allocation. * Otherwise, arm_smmu_domain_finalise will be done when the domain is @@ -2918,6 +3000,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) */ static struct iommu_domain * __arm_smmu_domain_alloc(unsigned type, + struct arm_smmu_domain *s2, struct arm_smmu_master *master, const struct iommu_hwpt_arm_smmuv3 *user_cfg) { @@ -2929,11 +3012,15 @@ __arm_smmu_domain_alloc(unsigned type, return arm_smmu_sva_domain_alloc(); if (type != IOMMU_DOMAIN_UNMANAGED && + type != IOMMU_DOMAIN_NESTED && type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_DMA_FQ && type != IOMMU_DOMAIN_IDENTITY) return NULL; + if (s2 && (s2->stage != ARM_SMMU_DOMAIN_S2 || !user_cfg)) + return NULL; + /* * Allocate the domain and initialise some of its data structures. * We can't really finalise the domain unless a master is given. @@ -2941,10 +3028,14 @@ __arm_smmu_domain_alloc(unsigned type, smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); if (!smmu_domain) return NULL; + smmu_domain->s2 = s2; domain = &smmu_domain->domain; domain->type = type; - domain->ops = arm_smmu_ops.default_domain_ops; + if (s2) + domain->ops = &arm_smmu_nested_domain_ops; + else + domain->ops = arm_smmu_ops.default_domain_ops; mutex_init(&smmu_domain->init_mutex); INIT_LIST_HEAD(&smmu_domain->devices); @@ -2965,7 +3056,7 @@ __arm_smmu_domain_alloc(unsigned type, static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) { - return __arm_smmu_domain_alloc(type, NULL, NULL); + return __arm_smmu_domain_alloc(type, NULL, NULL, NULL); } static struct iommu_domain * @@ -2975,8 +3066,23 @@ arm_smmu_domain_alloc_user(struct device *dev, struct iommu_domain *parent, const struct iommu_hwpt_arm_smmuv3 *user_cfg = user_data; struct arm_smmu_master *master = dev_iommu_priv_get(dev); unsigned type = IOMMU_DOMAIN_UNMANAGED; + struct arm_smmu_domain *s2 = NULL; + + /* + * The type of the new domain stays at IOMMU_DOMAIN_UNMANAGED, unless a + * valid parent domain is given, turning it to be IOMMU_DOMAIN_NESTED. + * The "stage" of an IOMMU_DOMAIN_UNMANAGED domain, however, is decided + * in the arm_smmu_domain_finalise function that reads user_cfg->flags, + * to set the stage accordingly. + */ + if (parent) { + if (parent->ops != arm_smmu_ops.default_domain_ops) + return NULL; + type = IOMMU_DOMAIN_NESTED; + s2 = to_smmu_domain(parent); + } - return __arm_smmu_domain_alloc(type, master, user_cfg); + return __arm_smmu_domain_alloc(type, s2, master, user_cfg); } static const size_t arm_smmu_domain_user_data_len[] = { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 6ed86883d52e..9540926b4598 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -380,6 +380,7 @@ #define EVTQ_0_ID GENMASK_ULL(7, 0) +#define EVT_ID_BAD_STE 0x4 #define EVT_ID_TRANSLATION_FAULT 0x10 #define EVT_ID_ADDR_SIZE_FAULT 0x11 #define EVT_ID_ACCESS_FAULT 0x12 From patchwork Wed May 10 03:33:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236266 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9643C7EE23 for ; Wed, 10 May 2023 03:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235698AbjEJDgJ (ORCPT ); Tue, 9 May 2023 23:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235770AbjEJDfB (ORCPT ); Tue, 9 May 2023 23:35:01 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2080.outbound.protection.outlook.com [40.107.92.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9379E525A; Tue, 9 May 2023 20:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ViK41yWdiX+hoJT5RUNHY67SOgeQe+36wD5vWJpNSeUXS8GfK/gOtOLfWhAD1LTr/GxRhOAOwhMz0kySaE0bIfWtN6sr9Ek/0ZcZxoK6QW6rfMgYSbNhbjyyY+02Gsj6UXhYQWWokML+N/lD1yaysYl7JuW7tjfmpZWcyP2uHyJ1QCxvRjpULgVOV145CGOoMbfxeniaRGw/DKhr/uR/e1W5q6n8Ods9er8EsVrKfkbX7eMCjlAUd4HDYMSHhz5cVcODTT2JxgsQL4me2I81e2gUeKwUvNO3GOSVTbRtBazFr9st7xIbU7C15ZxyNIzSNcKC189qKfO6h2NhWBf/5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xk7hDUbKBv1jVjD+J1XEus0mhyRJ3/Bd28rc2bhE5ww=; b=GkC5CiyE1e4bqnDStRHqApMVSCbSyKl8IT+nKf+DmqXKbYEwuQHNOptFYzVG9PTdD2INrIMzJgwn4AGYKfRAtTwoVjXCiUZWHQze3uSw6dBwawaVSMK6tyEawbsQSQ7c/6oQYYz+BGftEDotT+RGUg2gjJzy6pvXwG0NNv2eUyVnaznXt2D/n9vWbAUZ/qNhiKevhjX3xxmPXZVAp3c+UYRI1Pqhlaj3PMlFnrK69t2OmedUej3+EfEhjNx0S5+bLCqNf1u1db50t5MCrcrRBV8WfuL+nR3WBMsAhNS1NeHxU2cKBrrCG32GYo16JxJ9DYwPAx8xFaRj4/M5o1iL6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xk7hDUbKBv1jVjD+J1XEus0mhyRJ3/Bd28rc2bhE5ww=; b=LTKqs4N04N/sicXTXibtE9kOdrHnDvbnZKlkZkYeP/1uuWGuADi695vuUM5zxICspBY2aGHQivRxa+JLoZBzgPR4wBNDpQaZ1aK5bagwVesH+G7N5hpY6u5eLlp92Lo043kBjnwdZJVKVEYGNxhrjszKPM2sqqUBfEpqgap2ZOT57ntAKs8VDVc2Y6lVK25l2sXG/bjmsuaRVvY4yvVtmNMIxiMBlU6rMeIp7DWJpynFPmGFd6aJJMkjzSnEj36KS5Zoa5trZLCMAhp963RDfJNP3BiAyfTmOsX4wdBxanNyxgsa4lGI39+itlaM/EgJ8zARRCO9R2zzmy5WB/0bIg== Received: from BN9PR03CA0636.namprd03.prod.outlook.com (2603:10b6:408:13b::11) by DM4PR12MB5392.namprd12.prod.outlook.com (2603:10b6:5:39f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:39 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::e6) by BN9PR03CA0636.outlook.office365.com (2603:10b6:408:13b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19 via Frontend Transport; Wed, 10 May 2023 03:34:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:38 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:26 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:26 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:25 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 15/17] iommu/arm-smmu-v3: Implement arm_smmu_get_msi_mapping_domain Date: Tue, 9 May 2023 20:33:35 -0700 Message-ID: <4f67087fdb777c4b7822c8b95cec92161124301c.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT048:EE_|DM4PR12MB5392:EE_ X-MS-Office365-Filtering-Correlation-Id: db0bfe14-3528-4779-e05a-08db51077c11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g72qJfFLMssQJm5dqYWTxze4hhF9XFBfu3TNDTy7O5c9eO/w+B+GXr66gzm7j127HxC6WGLVWXC8EOg3lAsxMj/Lgsxxvwsy6qInRRMXrZURhm/Mip0w1HlVHHCAjOIDEpBcgntZ+jMB2LcndGhIqFPKll+mQ8VPPT01RlWyDIQ50gOE/gmUyEagJ22SXLMr7WN/ENg6hh0ZPyAiCAvWiT1z8meYHchmgcuCAeMjd38RfcrpK5ZAQEB0sZjbQ5sAjlE48gmkN7k1Ak4UdL2HqAGe5QDsdcey1gsmdBRLwJWrNxxAGBWe4JzYquslrUsCziZwMhNJQduj+ktDN+I7RLxdR/y1jMFKPimx3SNnFC8HpuYnduxW0+XLP88jjCpmTrNnmsvComozFv+AblOZqKgVosGO+C+S5gmvva3ZVp1cwJ/abg+zcPAPkECHutQIoyzOXuUOn66jSVr8T+wENIhn/3+oUfS4DH07VP9uAbi24OjFGO7ho3Wm63KR7ZRrxc40MGP4fhc46fLRPP1OWJAYtoI1DeWhqKdP0bUMwiQ2cMkIk2waJMudPsluPoHhB70hEoor15HaWrkWykI8H/fTnH/Hq8RZNbBOnqJKF01cyVBV7bllrPL3mBn9CqGcKvgpFuoIjDFMTfxFms9ZsBCwQySg+D2DFKT6KRVoeZBA3HiF3B0anW0wa7IUPP5FpYbvXpIeUncXtYV15UaMSw== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199021)(46966006)(40470700004)(36840700001)(86362001)(36756003)(6666004)(316002)(54906003)(70586007)(478600001)(4326008)(7696005)(70206006)(110136005)(40480700001)(82310400005)(5660300002)(8936002)(8676002)(47076005)(7416002)(356005)(41300700001)(2906002)(82740400003)(7636003)(186003)(36860700001)(26005)(336012)(426003)(2616005)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:38.9349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db0bfe14-3528-4779-e05a-08db51077c11 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5392 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In a 1-stage translation setup, a device is attached to an iommu_domain (ARM_SMMU_DOMAIN_S1) that is a kernel-managed domain. In a 2-stage translation setup, a device is attached to an iommu_domain (ARM_SMMU_DOMAIN_S1) that is IOMMU_DOMAIN_NESTED type, which must have a valid "s2" pointer for an iommu_domain (ARM_SMMU_DOMAIN_S2) that is a kernel-managed domain. The MSI mappings for dma-iommu core to use are located in a domain that must be a kernel-managed one. Thus, add a function to return the correct iommu_domain pointer accordingly. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 3d150924581f..5fe7fed825d0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2095,6 +2095,17 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) kfree(smmu_domain); } +static struct iommu_domain * +arm_smmu_get_msi_mapping_domain(struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + + if (smmu_domain->s2) + return &smmu_domain->s2->domain; + + return domain; +} + static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, struct arm_smmu_master *master, struct io_pgtable_cfg *pgtbl_cfg) @@ -2976,6 +2987,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) static const struct iommu_domain_ops arm_smmu_nested_domain_ops = { .attach_dev = arm_smmu_attach_dev, .free = arm_smmu_domain_free, + .get_msi_mapping_domain = arm_smmu_get_msi_mapping_domain, }; /** From patchwork Wed May 10 03:33:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3B8DC77B7C for ; Wed, 10 May 2023 03:36:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235779AbjEJDgQ (ORCPT ); Tue, 9 May 2023 23:36:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235869AbjEJDfb (ORCPT ); Tue, 9 May 2023 23:35:31 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2080.outbound.protection.outlook.com [40.107.223.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E11F6A48; Tue, 9 May 2023 20:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FHcy1DKcWiFK3wPhMT/bgS3SMHXk/Z05VclWok39dYGMNvWSR4ZAwWtPpICGoGsvt1Otw0RgTdBhIWWBpYT80WvLVrLp61rYgm/5/BNmtvf5yK77UH/3g5Po6QK0pG6Tt5VEzl5Z2JonVDhmfoojkzu6IZMk3Lb4OVNpLG/C7JaHla7m0O05tyQzLQt7YCvvSsmvAUgigFGky93w5tmOM2qsDU0HsXCUiFYobNLlFgSDRTEOZr7Bs08yjbdHu/BKHHmzQkRRwxm73MHUJbSv/++Yf0B9CSIbq7Wq5moO0OZN0vWCniQH4iTd7kRylHsBpuTL5ADQDWfL0FNs9JjzDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H3rtvKMREw8MQARcTr6aa6xYz4uEqadpb+U5I9v5Lw8=; b=nUNmaUMRBhTnyQw2Yty9KYY55rApKALj7DVv5MtcHTfWjXhheCtywAD6J09jHn4NBQcWMb080ZJkjGRyRD+uDAZUvmarl62ff6xvl4JePluck7gmToam8Woe9IGYBkpR8LOVKCAZKmmBBN/6MVF+TM0Fh3/5D7/hwtwf3ELUjDyJrYIe6jUl6p8k7atahot0Oa9un+7PNQx6+aT86vyj9e0MoPFWk+TphrUqIMAMmjA+qexZtMcRrYrljPQXJ4ZmPiyICicohkZsYScf1VvIlU7UHrIBoByzuJCaREJsgJ8ARip8L56PSr7/ZWWm5TFSfDFQnZqVPnUt5buOw5c4gw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H3rtvKMREw8MQARcTr6aa6xYz4uEqadpb+U5I9v5Lw8=; b=I6Z9OCx73lj37dotzhUe1pp2kftQw7J4t/f5loaINsQp5kHmJb2VHyvyD2044o5nSfD58xT1zoLgyjnLCnKzBHUEzi6CH3nlgPkNDx4Y9j5iJkNK4qE3biF4WoHujjzwDF4nvi9XE0XHZafOzGYglwdO1fliqSSQYpUMHB602FZc+0IBJTb61J1B1rm16yWuKjbbyVlcP2AxIfnIqOazv9C+udtrMM9RLPmg13dM4gvs9EUi+4iPULsaXrRzorBI+T8iLe0ReNbob3aImT0QpLwfsnDy6D/7l09vok+68Yg2cPbmnPhAqnFwKJrAUPGJSbRMSw7JsrB/FLXdW0b8HA== Received: from MN2PR11CA0002.namprd11.prod.outlook.com (2603:10b6:208:23b::7) by MN2PR12MB4208.namprd12.prod.outlook.com (2603:10b6:208:1d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:40 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::22) by MN2PR11CA0002.outlook.office365.com (2603:10b6:208:23b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Wed, 10 May 2023 03:34:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 03:34:40 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:28 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:27 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:26 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 16/17] iommu/arm-smmu-v3: Add CMDQ_OP_TLBI_NH_VAA and CMDQ_OP_TLBI_NH_ALL Date: Tue, 9 May 2023 20:33:36 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|MN2PR12MB4208:EE_ X-MS-Office365-Filtering-Correlation-Id: e047e666-40a5-4cc6-bc79-08db51077d0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yAuFpRqIjpiYcq4zHXx1sy3HsXvM1WpFSdAe+nC9WX4zejjgmrUOja1ks2B3OaCTgc/TqHQPulOLvviNwOwWhiZ18TW10pw00isLGsx7n3FxjcymbpxPNjKCmvr2TnM2NmufGKLD6NIT/dyCG1DrgB8htqaLoba0sfDsHNxRKroAQLivhoeUSzGoxxJKBurbB8//psU4xHnOoko/6R/wb6OQajjjSi9dfLzPsTFavR63uG+YhauvId/3ZH5cytpEL3/iGbqjk5GBt3EWmvuj7zJunBrbduu45yb2LKEirzhCJ+x7ixT7nR3Juwfj2oase/3G1RC8x/uHsVqS+MWz4YQHPyx5lPVHkU9Av7yhd9U7tQ3H67pcVTkde96QvvpxKS9G6ty1pkzEjB+p64W1eJHpe6GgB+OAEYM08O1nzOyfSBV7FKUwXUJR+NOUqeyaFH+IkJ50R5SAgdkpP2rL10ZhmZ7a641aIvuy10azfNS+9r5OSTF3mqPgYqwYScKcyJewCmlseXa5ZSB7aWqajawrLbOaOwBrW7c3jB5+WimqejMylIC7loMRP46tBQQB/GVpfxoFRDsBWmcB91Lrf8fovGcT9XhnHVK3jsDdtjjxP+tVe//p0sy3HqSAOnfj8shlh9DUKuuGDRJUQUF3tNVAXTVM1e3DGUFEsP1xbFn9o/ikegByk+JbQUNPRKhH+yCoA/8xjldkIUgxT1gBfA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199021)(36840700001)(46966006)(40470700004)(40460700003)(2906002)(47076005)(36860700001)(426003)(7416002)(5660300002)(7636003)(356005)(82740400003)(82310400005)(36756003)(86362001)(40480700001)(54906003)(110136005)(186003)(26005)(478600001)(83380400001)(7696005)(6666004)(316002)(2616005)(8936002)(336012)(8676002)(41300700001)(70586007)(4326008)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:40.5724 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e047e666-40a5-4cc6-bc79-08db51077d0b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4208 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org With a nested translation setup, a stage-1 Context Descriptor table can be managed by a guest OS in the user space. So, the kernel driver should not assume that the guest OS will use a user space device driver that doesn't support TLBI_NH_VAA and TLBI_NH_ALL commands. Add them in the arm_smmu_cmdq_build_cmd(), to prepare for support of these two TLBI invalidation requests from the guest level. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 +++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 5fe7fed825d0..3902dd8cfcfa 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -272,8 +272,17 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) cmd[1] |= FIELD_PREP(CMDQ_CFGI_1_RANGE, 31); break; case CMDQ_OP_TLBI_NH_VA: - cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); + cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_ASID, ent->tlbi.asid); fallthrough; + case CMDQ_OP_TLBI_NH_VAA: + cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_NUM, ent->tlbi.num); + cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_SCALE, ent->tlbi.scale); + cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); + cmd[1] |= FIELD_PREP(CMDQ_TLBI_1_LEAF, ent->tlbi.leaf); + cmd[1] |= FIELD_PREP(CMDQ_TLBI_1_TTL, ent->tlbi.ttl); + cmd[1] |= FIELD_PREP(CMDQ_TLBI_1_TG, ent->tlbi.tg); + cmd[1] |= ent->tlbi.addr & CMDQ_TLBI_1_VA_MASK; + break; case CMDQ_OP_TLBI_EL2_VA: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_NUM, ent->tlbi.num); cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_SCALE, ent->tlbi.scale); @@ -295,6 +304,7 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) case CMDQ_OP_TLBI_NH_ASID: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_ASID, ent->tlbi.asid); fallthrough; + case CMDQ_OP_TLBI_NH_ALL: case CMDQ_OP_TLBI_S12_VMALL: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); break; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 9540926b4598..43c971af663c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -455,8 +455,10 @@ struct arm_smmu_cmdq_ent { }; } cfgi; + #define CMDQ_OP_TLBI_NH_ALL 0x10 #define CMDQ_OP_TLBI_NH_ASID 0x11 #define CMDQ_OP_TLBI_NH_VA 0x12 + #define CMDQ_OP_TLBI_NH_VAA 0x13 #define CMDQ_OP_TLBI_EL2_ALL 0x20 #define CMDQ_OP_TLBI_EL2_ASID 0x21 #define CMDQ_OP_TLBI_EL2_VA 0x22 From patchwork Wed May 10 03:33:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13236270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1148C7EE23 for ; Wed, 10 May 2023 03:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235796AbjEJDgR (ORCPT ); Tue, 9 May 2023 23:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235913AbjEJDff (ORCPT ); Tue, 9 May 2023 23:35:35 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC656593; Tue, 9 May 2023 20:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mdLQSOc/PKEiOTcDmtfJlW95E8pzf3k3trX4sTbps25QzS7dXN7E4DMzkdGASz4eultX3Q7b8KbyBDDWfiX2yX1yHra2MT/4ErsKjHM7SkbI2RvwApo7Te2gHv1cgy6Kx8wfo7aZhhaZeJ8S5z4B7pGGXwV8+A4ztJ3JW+cXCincRO4KbqFPwuJGXxWncsS5IOlJtpIOPFyK4x37vBDf3m4GNn6bqpMJPr5j4iEgwQJ+kaRPdwglqikN3mmvZBJYh4tRFgHkiThxSmAKO1ekmulaZUABJqh1sTIS+8zGsBE7Fjnq23hg6BYSq37sWrERea8hxS03LTqES3lrdTpQJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Sk58qbv9dLfH8MVN5qR9ZuRzKUxQ2e8g0y0e7qDp7X4=; b=MffbsOBm1cgyO1B29qvu82gEZ0inpxkToChKFEgqMbxYNq63bB94wB9nkJJAQQrQ3+iWAkZ+Ho2FSfjEauBtN7Ux/GSzbvZjsamEnEiTCB0utpqHbEjxpV0IwsRmHlRDxQ4+c+7SVbsSjBagE16YOOXRCMLWiNt9H0DqnEE9O+LQ2FIEAIQLk3Z7zxfy1sZNrUMF5FC+HSnTn9qhJicA6KHLUlWhh01JM0VppBiUISxQ9Gk2mrQ1nJyEPumg/x5wbur6HhjSebWFB83mUhW6uVEiCDvaBvjF2b0Hd2J1fM53/Pu8T5iO1yXDTGjYvtN67G1+39WWKbY3XBcO/5NAaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sk58qbv9dLfH8MVN5qR9ZuRzKUxQ2e8g0y0e7qDp7X4=; b=ObDzgKO8Ih91D1trajBTlgzLUB3wo9AMPqxZZLDdXU1KcjweqCOFsuUNr7oZhBprl9z3eI8UmTXezFu7B84Ven01Wjav2BcUImgeW92rOsP1Rvjb+3nmrxoVWEAKcMldqXDYWCVpdzi19feOvRWFHl1Fj5lwvMyasYH+qNivv7dlGC+6tCmeQhIOBYmdadyyUWOQHveWrOvKrEZwQ6VNuvh2KcOIE3cJPOIJ1oE3fY7o9v4oFCyPmlcSiHtvINTAyL0EAEpkVb+uLEnO2PanFqfe5U9zrSdy2Z6Tr3LiEgK6pFKawp5CmnqlYoKs10taZMTGqyB2YJ6YVMc8y8AZuA== Received: from MN2PR11CA0019.namprd11.prod.outlook.com (2603:10b6:208:23b::24) by DM6PR12MB5024.namprd12.prod.outlook.com (2603:10b6:5:20a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Wed, 10 May 2023 03:34:43 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::47) by MN2PR11CA0019.outlook.office365.com (2603:10b6:208:23b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Wed, 10 May 2023 03:34:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Wed, 10 May 2023 03:34:42 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 9 May 2023 20:34:29 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 9 May 2023 20:34:29 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 9 May 2023 20:34:28 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 17/17] iommu/arm-smmu-v3: Add arm_smmu_cache_invalidate_user Date: Tue, 9 May 2023 20:33:37 -0700 Message-ID: <6bacfc7213e9934f81bdc06a47bf58816f87e63b.1683688960.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|DM6PR12MB5024:EE_ X-MS-Office365-Filtering-Correlation-Id: 66d67722-64d8-4f0c-10d7-08db51077e44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z5EqzkAFqFmx+s2uh1V1n1NOC/qgzFJvOHBMx0lpyiMwNa5Y7WNU9TIlizm8+tzTaMiErLJJjdRv8PKipaOvzApBABO73mPye8emK9fen1Cw5R8AugnAozcDs8WdY5yIawKSPSV2yWH3tE17WhSTEJG5nuX4rsOmzDhWKV1At/Nr0J46Z3omQhUiJ2/uzdtTyXZHDAzGRPY220RoV7cNIrPUwah2+R5NEB61woe9xwCIPWLbjJikuGVjYj3Vf2TTVnS+WUNnWe9q6AuyZ7AlE/iGItcPN1g+zlwdoRKIGXWqeMzuCkbcWlblWPnxeh3gVLFcqCP2/Tn8xK0cFO5e+CBzBycR3HmBbFmXKNQVIbcrU5ecc6z1VqIKikUhBryTuqcPzhJ1YySNM536Y+pUBKCR+8g0qcvVuK8gjMMhswub5CiODrEhewJT2neI02/aZy3VuLEXqNXwD6FplbwNNo7ip83QCWObhT6tK9PtxguDdisAC98j7o0MSLHGbdjpg56cxqudvDhELOMdI/oktUp4gN7PRsdhH1Pdm5UmAoZWZ6zD1dLpH7noQD+uZ7/go5MB3mfcPMIfXuVWKuGxMozAgQGKJ4r1+FATpA/Vmu2mFf0O5VpXU+KtRsNYu3KxjG6pYJzjz1RJcBZLQLHmANW/QsJLLHSuEMOfFHOkN9xvWpUhDKJTHHcOdWnB9BEP58kk+cK8TKu3+mkKKD+wyA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(40470700004)(36840700001)(46966006)(26005)(7696005)(40480700001)(336012)(426003)(36860700001)(2616005)(36756003)(86362001)(356005)(82310400005)(186003)(40460700003)(82740400003)(47076005)(83380400001)(110136005)(41300700001)(54906003)(4326008)(2906002)(7636003)(5660300002)(8676002)(478600001)(8936002)(316002)(7416002)(70586007)(70206006)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 03:34:42.6193 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66d67722-64d8-4f0c-10d7-08db51077e44 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5024 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add arm_smmu_cache_invalidate_user() function for user space to invalidate TLB entries and Context Descriptors, since either an IO page table entrie or a Context Descriptor in the user space is still cached by the hardware. The input user_data is defined in struct iommu_hwpt_invalidate_arm_smmuv3, which contains the essential info of the command queue of the guest OS. It will be read by the host kernel to have a direct access to the guest queue to fetch all invalidation commands. Those commands should be also fixed at the SID and VMID fields by replacing with the correct physical values. Co-developed-by: Eric Auger Signed-off-by: Eric Auger Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 113 ++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 3902dd8cfcfa..124f63fe52e1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2994,10 +2994,123 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); } +static int arm_smmu_fix_user_cmd(struct arm_smmu_domain *smmu_domain, u64 *cmd) +{ + struct arm_smmu_stream *stream; + + switch (*cmd & CMDQ_0_OP) { + case CMDQ_OP_TLBI_NSNH_ALL: + *cmd &= ~CMDQ_0_OP; + *cmd |= CMDQ_OP_TLBI_NH_ALL; + fallthrough; + case CMDQ_OP_TLBI_NH_VA: + case CMDQ_OP_TLBI_NH_VAA: + case CMDQ_OP_TLBI_NH_ALL: + case CMDQ_OP_TLBI_NH_ASID: + *cmd &= ~CMDQ_TLBI_0_VMID; + *cmd |= FIELD_PREP(CMDQ_TLBI_0_VMID, + smmu_domain->s2->s2_cfg.vmid); + break; + case CMDQ_OP_ATC_INV: + case CMDQ_OP_CFGI_CD: + case CMDQ_OP_CFGI_CD_ALL: + xa_lock(&smmu_domain->smmu->streams_user); + stream = xa_load(&smmu_domain->smmu->streams_user, + FIELD_GET(CMDQ_CFGI_0_SID, *cmd)); + xa_unlock(&smmu_domain->smmu->streams_user); + if (!stream) + return -ENODEV; + *cmd &= ~CMDQ_CFGI_0_SID; + *cmd |= FIELD_PREP(CMDQ_CFGI_0_SID, stream->id); + break; + default: + return -EOPNOTSUPP; + } + pr_debug("Fixed user CMD: %016llx : %016llx\n", cmd[1], cmd[0]); + + return 0; +} + +static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, + void *user_data) +{ + const u32 cons_err = FIELD_PREP(CMDQ_CONS_ERR, CMDQ_ERR_CERROR_ILL_IDX); + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct iommu_hwpt_invalidate_arm_smmuv3 *inv = user_data; + struct arm_smmu_device *smmu = smmu_domain->smmu; + struct arm_smmu_queue q = { + .llq = { + .prod = inv->cmdq_prod, + .max_n_shift = inv->cmdq_log2size, + }, + .base = u64_to_user_ptr(inv->cmdq_uptr), + .ent_dwords = inv->cmdq_entry_size / sizeof(u64), + }; + unsigned int nents = 1 << q.llq.max_n_shift; + void __user *cons_uptr; + int ncmds, i = 0; + u32 prod, cons; + u64 *cmds; + int ret; + + if (!smmu || !smmu_domain->s2 || domain->type != IOMMU_DOMAIN_NESTED) + return -EINVAL; + if (q.ent_dwords != CMDQ_ENT_DWORDS) + return -EINVAL; + WARN_ON(q.llq.max_n_shift > smmu->cmdq.q.llq.max_n_shift); + + cons_uptr = u64_to_user_ptr(inv->cmdq_cons_uptr); + if (copy_from_user(&q.llq.cons, cons_uptr, sizeof(u32))) + return -EFAULT; + if (queue_empty(&q.llq)) + return -EINVAL; + + prod = Q_IDX(&q.llq, q.llq.prod); + cons = Q_IDX(&q.llq, q.llq.cons); + if (Q_WRP(&q.llq, q.llq.prod) == Q_WRP(&q.llq, q.llq.cons)) + ncmds = prod - cons; + else + ncmds = nents - cons + prod; + cmds = kcalloc(ncmds, inv->cmdq_entry_size, GFP_KERNEL); + if (!cmds) + return -ENOMEM; + + do { + u64 *cmd = &cmds[i * CMDQ_ENT_DWORDS]; + + ret = copy_from_user(cmd, Q_ENT(&q, q.llq.cons), + inv->cmdq_entry_size); + if (ret) { + ret = -EFAULT; + goto out_free_cmds; + } + + ret = arm_smmu_fix_user_cmd(smmu_domain, cmd); + if (ret && ret != -EOPNOTSUPP) { + q.llq.cons |= cons_err; + goto out_copy_cons; + } + if (!ret) + i++; + queue_inc_cons(&q.llq); + } while (!queue_empty(&q.llq)); + + ret = arm_smmu_cmdq_issue_cmdlist(smmu, cmds, i, true); +out_copy_cons: + if (copy_to_user(cons_uptr, &q.llq.cons, sizeof(u32))) + ret = -EFAULT; +out_free_cmds: + kfree(cmds); + return ret; +} + static const struct iommu_domain_ops arm_smmu_nested_domain_ops = { .attach_dev = arm_smmu_attach_dev, .free = arm_smmu_domain_free, .get_msi_mapping_domain = arm_smmu_get_msi_mapping_domain, + .cache_invalidate_user = arm_smmu_cache_invalidate_user, + .cache_invalidate_user_data_len = + sizeof(struct iommu_hwpt_invalidate_arm_smmuv3), }; /**