From nobody Sun Nov 24 05:20:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1726497166; cv=pass; d=zohomail.com; s=zohoarc; b=U2mP9/cWFtLGgrwTMdQMsNogpIxslFZ2SCNl6WMWXyXsdDrmaL5QtC9wl8wV0SmS7lACkjNmx5j2xnzyzKnYnbDgIs2QcEPEwNP925+4Dl2PmXdDzywlzbXclxhE6hAKk3h3GkNZVtnqdqqROt+LJ1sBcUcWWJZax+RzDHzYfao= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726497166; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=x5ubfCtBc+j644eI27xuiuImRuefsEjP+rSV1R2oN/M=; b=XNr4hptifBAlamPE42uTHzQzjwql1Or8NgEDTdYcY/TTliFa9N8auAg/PkjHFFGVQVRXB/qQDDPSiX2lBEQjSIc1+gcAmX7fh6P7ft0KeBVgQdJm0q2EeCe5RIG9DKlPayLtcc8FKGNNU+7K8uNu2YJy5RhofcXA1txIMr1bVXs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726497166437920.6898010911124; Mon, 16 Sep 2024 07:32:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqClq-0002u5-3X; Mon, 16 Sep 2024 10:32:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqClj-0002qc-UM for qemu-devel@nongnu.org; Mon, 16 Sep 2024 10:31:59 -0400 Received: from mail-dm6nam10on20607.outbound.protection.outlook.com ([2a01:111:f400:7e88::607] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqClh-0008Qy-1S for qemu-devel@nongnu.org; Mon, 16 Sep 2024 10:31:59 -0400 Received: from MW4PR04CA0215.namprd04.prod.outlook.com (2603:10b6:303:87::10) by BY5PR12MB4162.namprd12.prod.outlook.com (2603:10b6:a03:201::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Mon, 16 Sep 2024 14:31:51 +0000 Received: from SJ5PEPF00000208.namprd05.prod.outlook.com (2603:10b6:303:87:cafe::9f) by MW4PR04CA0215.outlook.office365.com (2603:10b6:303:87::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Mon, 16 Sep 2024 14:31:51 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ5PEPF00000208.mail.protection.outlook.com (10.167.244.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 14:31:51 +0000 Received: from volcano-ed17host-rhel.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 16 Sep 2024 09:31:50 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Hv8vVSIhSL09Po1MiXNv0nOqKuXxeUcdNqJpU+JpC64iXvdAMgvBZ8PSdaHjuzn/sBprSbObJTwpW9e7VOg8czD9ZjuZ8dkSXpV/gwWiZmQfhum2SrFMIDCAuLbN9/UIvApzxCd0VhnIqwZI1v+zhdqh6KuhJm4zLD/MYfKHW0AVxvGrm9/h+CoHgvY8xvfySqnqfjERiqlLVv4Rp5uNu23VPcsJRLzldFjcH5FRefdUYpcDMbapTZ+OdJVU31nXSPo10OgRCzuG9TvEVMT5p6JQEVWmJTiyXOsWTeKlmU3gdOvP5qQgxZIAXJcUJdiOP+Qa+wboU5Rmpo18hBmFlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=x5ubfCtBc+j644eI27xuiuImRuefsEjP+rSV1R2oN/M=; b=PVrV2ZU0lnN9zveARyksMXZc8eZaapzcBKUWMRj2JPYwjU5xy4YoTRWhOB3hSR/X2PFe655EE5F8scx7H++ATir6whlANBsG1MiWg3MLVntrVpeuB9clq9vl5kU5qDG1931kB8P+7IvqAeQbW3/+d0yojYpv4O6rhtEr3M34BAnrCnAcF7acpHlwC5h/2HTZN2q8hb/fWhrJuMBhCE1NkLC0sjyQZT27IX4OaGZxJ8ERqvmslv87anS1cXTWACmZrOJuFVHKBY86DeVEPSPULgvGbweYhnz2HWvvoVk3BdV4fHPjkvPwoAp182qFARw+JAo++coW+1O7MV/5yBf5QA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x5ubfCtBc+j644eI27xuiuImRuefsEjP+rSV1R2oN/M=; b=MhSyIC9ylG1fu5Lwsm2migPotOVSRIh5g+OpcWxCymq+ZnLTqM9R3QmqgoksqXgO7LinGPyxhTAswYNeg82FRpz4VLUZfQPX/j8bldeC9cZrae4+DG16zNjfuRb3eNzWzwZeq9W+ap59F/DDf9cXHC77ptMWlDy12apgXJXafSY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Santosh Shukla To: CC: , , , , , , Subject: [PATCH v2 2/5] amd_iommu: Add support for pass though mode Date: Mon, 16 Sep 2024 09:31:13 -0500 Message-ID: <20240916143116.169693-3-santosh.shukla@amd.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240916143116.169693-1-santosh.shukla@amd.com> References: <20240916143116.169693-1-santosh.shukla@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF00000208:EE_|BY5PR12MB4162:EE_ X-MS-Office365-Filtering-Correlation-Id: d79eee10-8ca6-47bd-3cc1-08dcd65c4e0a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Yp6+7n1pPD8hsmrrr6mlUVJ/vCgVwBmcTPsuAx5SEU4UMcWVIGYYM9ADGtNx?= =?us-ascii?Q?u6QQyWmq6VQT0SxRb6OeT3WbVf5zh91qEjyQgthXjypiiac9j7wVOhMjLRBw?= =?us-ascii?Q?e/Pay0hbxjo8tro2umGwYQMup9S6eziXvKQKsQxk7paCaQz0Xp5u6t2iYwem?= =?us-ascii?Q?mvXzjsYIIk2S/SKuUUdqbR7HI75xRPOiwt88+60MxhZ68vFpERrruWGz/PAi?= =?us-ascii?Q?LAtZ3DG4lUSdcCjlH+/69zkRI3mA71tebbHjX/PQPKuSFCmI21EiM82rQxNr?= =?us-ascii?Q?pbu3ceHId08vr1L9l5wsjmXmHrWDaDTt+vNa8QqoiwgYje+DbJ7gSw1xuxkB?= =?us-ascii?Q?y/tMCbHY7r4o8AICUmpaqwGg6aNo/gGkeV0HxbRLq3Urc5HowiIi/K5TCPND?= =?us-ascii?Q?1huHclH18fdB5nReYfe9i2fXgED4oo0XJbAzazrWVcSZ6S8sPHqCVF4ipSBP?= =?us-ascii?Q?HBY60LNA3XscaLoTFgzfLsE/zXBFzv+ViQl6cUH9YFa2jx68SywBheJrDva/?= =?us-ascii?Q?QAtRxek2KjPoxYBoqVkl/0Ago+0g0QofVHEbgTdfndNL/quG+NJdzGx8KYRY?= =?us-ascii?Q?31duEq8eLWrSCep2vrJisYZt9CrNOYf+QqrR8oqHWIGPOVx/RwPSiJMkp+3b?= =?us-ascii?Q?5gGAg4s8KD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d.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 14:31:51.2990 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d79eee10-8ca6-47bd-3cc1-08dcd65c4e0a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF00000208.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4162 Received-SPF: permerror client-ip=2a01:111:f400:7e88::607; envelope-from=Santosh.Shukla@amd.com; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1726497168230116600 Content-Type: text/plain; charset="utf-8" From: Suravee Suthikulpanit Introduce 'nodma' shared memory region to support PT mode so that for each device, we only create an alias to shared memory region when DMA-remapping is disabled. Signed-off-by: Suravee Suthikulpanit Signed-off-by: Santosh Shukla --- hw/i386/amd_iommu.c | 49 ++++++++++++++++++++++++++++++++++++--------- hw/i386/amd_iommu.h | 2 ++ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index abb64ea507be..c5f5103f4911 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -60,8 +60,9 @@ struct AMDVIAddressSpace { uint8_t bus_num; /* bus number */ uint8_t devfn; /* device function */ AMDVIState *iommu_state; /* AMDVI - one per machine */ - MemoryRegion root; /* AMDVI Root memory map region */ + MemoryRegion root; /* AMDVI Root memory map region */ IOMMUMemoryRegion iommu; /* Device's address translation region */ + MemoryRegion iommu_nodma; /* Alias of shared nodma memory region */ MemoryRegion iommu_ir; /* Device's interrupt remapping region */ AddressSpace as; /* device's corresponding address space */ }; @@ -1412,6 +1413,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus= , void *opaque, int devfn) AMDVIState *s =3D opaque; AMDVIAddressSpace **iommu_as, *amdvi_dev_as; int bus_num =3D pci_bus_num(bus); + X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); =20 iommu_as =3D s->address_spaces[bus_num]; =20 @@ -1436,13 +1438,13 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *b= us, void *opaque, int devfn) * Memory region relationships looks like (Address range shows * only lower 32 bits to make it short in length...): * - * |-----------------+-------------------+----------| - * | Name | Address range | Priority | - * |-----------------+-------------------+----------+ - * | amdvi_root | 00000000-ffffffff | 0 | - * | amdvi_iommu | 00000000-ffffffff | 1 | - * | amdvi_iommu_ir | fee00000-feefffff | 64 | - * |-----------------+-------------------+----------| + * |--------------------+-------------------+----------| + * | Name | Address range | Priority | + * |--------------------+-------------------+----------+ + * | amdvi-root | 00000000-ffffffff | 0 | + * | amdvi-iommu_nodma | 00000000-ffffffff | 0 | + * | amdvi-iommu_ir | fee00000-feefffff | 64 | + * |--------------------+-------------------+----------| */ memory_region_init_iommu(&amdvi_dev_as->iommu, sizeof(amdvi_dev_as->iommu), @@ -1461,7 +1463,25 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bu= s, void *opaque, int devfn) 64); memory_region_add_subregion_overlap(&amdvi_dev_as->root, 0, MEMORY_REGION(&amdvi_dev_as->i= ommu), - 1); + 0); + + /* Build the DMA Disabled alias to shared memory */ + memory_region_init_alias(&amdvi_dev_as->iommu_nodma, OBJECT(s), + "amdvi-sys", &s->mr_sys, 0, + memory_region_size(&s->mr_sys)); + memory_region_add_subregion_overlap(&amdvi_dev_as->root, 0, + &amdvi_dev_as->iommu_nodma, + 0); + + if (!x86_iommu->pt_supported) { + memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, false); + memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as->iommu), + true); + } else { + memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as->iommu), + false); + memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, true); + } } return &iommu_as[devfn]->as; } @@ -1602,6 +1622,17 @@ static void amdvi_sysbus_realize(DeviceState *dev, E= rror **errp) "amdvi-mmio", AMDVI_MMIO_SIZE); memory_region_add_subregion(get_system_memory(), AMDVI_BASE_ADDR, &s->mr_mmio); + + /* Create the share memory regions by all devices */ + memory_region_init(&s->mr_sys, OBJECT(s), "amdvi-sys", UINT64_MAX); + + /* set up the DMA disabled memory region */ + memory_region_init_alias(&s->mr_nodma, OBJECT(s), + "amdvi-nodma", get_system_memory(), 0, + memory_region_size(get_system_memory())); + memory_region_add_subregion_overlap(&s->mr_sys, 0, + &s->mr_nodma, 0); + pci_setup_iommu(bus, &amdvi_iommu_ops, s); amdvi_init(s); } diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index e5c2ae94f243..be417e51c4dc 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -354,6 +354,8 @@ struct AMDVIState { uint32_t pprlog_tail; /* ppr log tail */ =20 MemoryRegion mr_mmio; /* MMIO region */ + MemoryRegion mr_sys; + MemoryRegion mr_nodma; uint8_t mmior[AMDVI_MMIO_SIZE]; /* read/write MMIO */ uint8_t w1cmask[AMDVI_MMIO_SIZE]; /* read/write 1 clear mask */ uint8_t romask[AMDVI_MMIO_SIZE]; /* MMIO read/only mask */ --=20 2.43.5