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 smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5D58C433EF for ; Wed, 11 May 2022 07:23:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7FF6841873; Wed, 11 May 2022 07:23:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nhnmcFWcIXLN; Wed, 11 May 2022 07:23:07 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id DDA27415CD; Wed, 11 May 2022 07:23:06 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B0ED6C0039; Wed, 11 May 2022 07:23:06 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 57E7EC002D for ; Wed, 11 May 2022 07:23:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 36FAF415CD for ; Wed, 11 May 2022 07:23:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sZ87fMptmITZ for ; Wed, 11 May 2022 07:23:04 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on20618.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8d::618]) by smtp4.osuosl.org (Postfix) with ESMTPS id 09D5D415A2 for ; Wed, 11 May 2022 07:23:03 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kcHynqrr6Md30hIUX9+SwZQUts8VpovkK75PTmmlBBtCom4UGwUfpZrTQrZQ1/Aby+gAKL0oaPh8ktyvL1vOMUopt4eEmnXyrCb31DzfyiYq2ru3AN5/aENoSR0l4qo0gGkIimy6abg1NewQpwFoL5Et3f4EfYVI3ygjWAKZ3i1FxIh31QeWH8LHIzbmPB61Fwq8lnZVgNG2Rsvmqh8LrZGZZ2juRRH5yDUDr3jFGojUkBxMIhPZ1ucx/1xew8+n7hJyCC/W5mClXVkoCiRFZGrw7L+fGHKr4e/7Gx1e/zAzfpTn7LaxkLOBYFaRi4MSQTnR6zsSYV+gy9rAbzYYcQ== 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=Lg7hFt5uKHUCo/JYrh700aNh3nIk1yc9Wf+muRT4hmQ=; b=WLDiDurDI2r9yF1Z923fQCZqnYnasTSV8xoYwxv108OwTLd5p4efEYqEQrv0HpSY4E4u2P48lvyCKOOABLzMp2U3RYOO7gvexG8X9TdqCda7Mc+GqAM12voNc9t4DExDtTcXjyy58MMt5bSQquFW+N89qngZalvX1Mf5YvgqNg8u4BmQB4PTpKvfiYuvBzVJ1vbRXUG3hdfZfRVg6whfOnHNXAmRUZa0OW9mVDVJLb0GMqCuqDQQWy38ynUzDYksI8bQGy6E6sCc7dMGboptMuMi2MqAHtdbguTwM6+KneZFFAjfjXHDq33Q95NWvuBSGiRr0w7vOpbfIQ/CuxOulQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.linux-foundation.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 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=Lg7hFt5uKHUCo/JYrh700aNh3nIk1yc9Wf+muRT4hmQ=; b=TB6N+bbdSuZvcSXuTyvd0TfDgW0mZGU6aHYNgIhz7cdPZa+YvSa/WpKZsbfhXw4b/Q4r/xoGd9Hxb2cG/IqdIlAfgisFnboOYwK/4arnc42qLo3aoj4AzVowy7kUuWs/+j/8zjZLEsW7vpk+zZCIxDqiT+6Sh1mnL3Yi5jZwxfk= Received: from DM5PR08CA0046.namprd08.prod.outlook.com (2603:10b6:4:60::35) by PH7PR12MB6561.namprd12.prod.outlook.com (2603:10b6:510:213::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.23; Wed, 11 May 2022 07:23:01 +0000 Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:4:60:cafe::a0) by DM5PR08CA0046.outlook.office365.com (2603:10b6:4:60::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.27 via Frontend Transport; Wed, 11 May 2022 07:23:00 +0000 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 (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; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT014.mail.protection.outlook.com (10.13.173.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5250.13 via Frontend Transport; Wed, 11 May 2022 07:23:00 +0000 Received: from kali.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.2375.24; Wed, 11 May 2022 02:22:58 -0500 To: Subject: [PATCH v3 03/35] iommu/amd: Introduce per PCI segment device table Date: Wed, 11 May 2022 12:51:09 +0530 Message-ID: <20220511072141.15485-4-vasant.hegde@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220511072141.15485-1-vasant.hegde@amd.com> References: <20220511072141.15485-1-vasant.hegde@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d85f24a1-a313-4315-b79d-08da331f1457 X-MS-TrafficTypeDiagnostic: PH7PR12MB6561:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aQeEXRMXRpPnWXErKxCCFacIKNmlOTdXZ5NjPNhnCEnd/tuMysYjClSzQ4s7r5DFRz7MCXvhktOoi7yuqnmGm8V91kaVMcb3oUUFxI12UWHfuuo3asudAWyIhJhaDdUhkKTFU1yYxlbJNc+ZvFHfEa5Y9GiJUzwUv+wBYOewziF7PtOvtMwYiJfXb7F3NMMrTq3VB0MyXhGap3MPKzf9+izL/8eIimoWTJI7NhYzrXRaBF+Go1Ozh732DFnH07YtrVZD/+wfbCHyTeFFaKeeQxA02DtN26Cxr8pKMFsooaGCRIlieT2EbM92P2aZR0OwxiTPfe5t3D8q0U7fsw/omEq5bXfTdB57vrH0dBZQ7LmEnBNyk3sjXR52JCWugAeNpiI+eyelwrqkndp0GCuRbArS4YnfNUvkPs6kWuNlVgClZzC6W2BWZXxsck2HI9qZ3eSVHnPkrEC5QS2HcOonmgfa5HZg1PjdjvkbWHf8Oan7Rv6ZueMJA0m2j9kNSNW228Nmtendp5HVwzwk+JSgndU/OSkc/rf0vPxaZaCN7xFK+abcn2S5/nxmg6ZbGfo1kzBmlyO0bM7WHYNwVtMqy8BLx3KEAduzQZKtfbRPz0nHokPUzrP2SUUPYSc/ZjI4i087/HaEJ99YIqyKUe5SWPKZTKfw3qozsGcp8pf3WSSiMw0chMYBcp7gJ5aVxwN9NKxSg5zUoQVw6HyUUg5lAQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(8936002)(81166007)(1076003)(36860700001)(5660300002)(16526019)(186003)(508600001)(2616005)(316002)(6916009)(36756003)(54906003)(40460700003)(2906002)(356005)(26005)(82310400005)(7696005)(83380400001)(47076005)(426003)(336012)(70206006)(70586007)(44832011)(4326008)(8676002)(6666004)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2022 07:23:00.3704 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d85f24a1-a313-4315-b79d-08da331f1457 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: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6561 Cc: Vasant Hegde X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vasant Hegde via iommu Reply-To: Vasant Hegde Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" From: Suravee Suthikulpanit Introduce per PCI segment device table. All IOMMUs within the segment will share this device table. This will replace global device table i.e. amd_iommu_dev_table. Also introduce helper function to get the device table for the given IOMMU. Co-developed-by: Vasant Hegde Signed-off-by: Vasant Hegde Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/amd_iommu_types.h | 10 ++++++++++ drivers/iommu/amd/init.c | 26 ++++++++++++++++++++++++-- drivers/iommu/amd/iommu.c | 12 ++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 1ab31074f5b3..885570cd0d77 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -128,4 +128,5 @@ static inline void amd_iommu_apply_ivrs_quirks(void) { } extern void amd_iommu_domain_set_pgtable(struct protection_domain *domain, u64 *root, int mode); +extern struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); #endif diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 7ec032afc1b2..a850d69b2849 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -540,6 +540,16 @@ struct amd_iommu_pci_seg { /* PCI segment number */ u16 id; + + /* + * device table virtual address + * + * Pointer to the per PCI segment device table. + * It is indexed by the PCI device id or the HT unit id and contains + * information about the domain the device belongs to as well as the + * page table root pointer. + */ + struct dev_table_entry *dev_table; }; /* diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 71be7ee4aa8b..9618bec97141 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -640,11 +640,29 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table) * * The following functions belong to the code path which parses the ACPI table * the second time. In this ACPI parsing iteration we allocate IOMMU specific - * data structures, initialize the device/alias/rlookup table and also - * basically initialize the hardware. + * data structures, initialize the per PCI segment device/alias/rlookup table + * and also basically initialize the hardware. * ****************************************************************************/ +/* Allocate per PCI segment device table */ +static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg) +{ + pci_seg->dev_table = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO | GFP_DMA32, + get_order(dev_table_size)); + if (!pci_seg->dev_table) + return -ENOMEM; + + return 0; +} + +static inline void free_dev_table(struct amd_iommu_pci_seg *pci_seg) +{ + free_pages((unsigned long)pci_seg->dev_table, + get_order(dev_table_size)); + pci_seg->dev_table = NULL; +} + /* * Allocates the command buffer. This buffer is per AMD IOMMU. We can * write commands to that buffer later and the IOMMU will execute them @@ -1469,6 +1487,9 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id) pci_seg->id = id; list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list); + if (alloc_dev_table(pci_seg)) + return NULL; + return pci_seg; } @@ -1490,6 +1511,7 @@ static void __init free_pci_segments(void) for_each_pci_segment_safe(pci_seg, next) { list_del(&pci_seg->list); + free_dev_table(pci_seg); kfree(pci_seg); } } diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index cf57ffcc8d54..54b8eb764530 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -134,6 +134,18 @@ static inline int get_device_id(struct device *dev) return devid; } +struct dev_table_entry *get_dev_table(struct amd_iommu *iommu) +{ + struct dev_table_entry *dev_table; + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; + + BUG_ON(pci_seg == NULL); + dev_table = pci_seg->dev_table; + BUG_ON(dev_table == NULL); + + return dev_table; +} + static struct protection_domain *to_pdomain(struct iommu_domain *dom) { return container_of(dom, struct protection_domain, domain); -- 2.27.0 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu