From mboxrd@z Thu Jan 1 00:00:00 1970 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 smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 303F6C433EF for ; Fri, 11 Mar 2022 09:52:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D92F840906; Fri, 11 Mar 2022 09:52:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r2XtNLbYf_H4; Fri, 11 Mar 2022 09:52:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4D078408D9; Fri, 11 Mar 2022 09:52:24 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 23543C0012; Fri, 11 Mar 2022 09:52:24 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0DB59C000B for ; Fri, 11 Mar 2022 09:52:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id F1002611EA for ; Fri, 11 Mar 2022 09:52:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=amd.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AUtMuX_N2T9B for ; Fri, 11 Mar 2022 09:52:22 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5a::601]) by smtp3.osuosl.org (Postfix) with ESMTPS id 2A906611D9 for ; Fri, 11 Mar 2022 09:52:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WIVTXCJ+i7fNcB83Up1D/D4OK1MBb0UENYRzDqP3oqtR2ZWnNdc/fR9ibGKQq+pkOn/5HE13f1zXynnmbdhe18De1KjVSRQuh54IEXXgUK+jHQcBHQJPU3fXUwx+7wka3tWPz58NovBAKrL6IeTAIv/qBZiV7fABmL64Yl+4oeSaphQIG/Tni/RFNAZEyVy7NXooWO6MpDN60Ntwwf2bkJK37DufHaFdfV8f1NyDp2UFlHzyjzL47UGXSazfQAsL4EvUKX13j6l08J6pV1RuEgs2XGgyeqzcYqTYCE4Ed2Mtzz6DG8vApa64GiVXZSQK1Esbix9oGYoS8gH6Kq6g1g== 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=xjBdvbdLIp3UkEJNIAG5Bv6z01dq2lbHXXk2tkpZ+T4=; b=RHEqre/S2s+snwPN51Nazwu+qObQ7f31L7bSXtihz/mz40Es57lZWDbgmmzJ5J6CraZN6t7lw6soWf7R+mNtRJJDQ3IxGXB7Td/s9rP5AwGRbdACgOlzaD7xXt9NNe+ZDTQdHy25eo3wqDNkBN5FDhb8Tw8YckMEm99kId9zgI5BdqWRUz4YEtitZuZsescNBt7Fs+CyLD2v9LUTPs8uci9HpDSn0QH0Gsm+2bACP4ZQT21R4IiZQodpUqOUPUurWNrD50JoR+DeoB5ke6VHpQYLYx5CJpU1ZlReNHejfPyrU7StQU3KMZSljyYn48G6hqS/eznPJh9tglVwOOH4gQ== 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=xjBdvbdLIp3UkEJNIAG5Bv6z01dq2lbHXXk2tkpZ+T4=; b=KqlwpMbPHiiYp8ty37eaDGK1+Cr/PnX2TZWJKaR3RgsYs7aJycX5x+P9NvqxsTpxHfUwqFAZ9xEn8DK6dlGk5ihk86ZWhIrF5uEwJUgTBQRGCkpFXAtseDdNILZexqf/iSmwu7u4Q6ejEHpgG5B5T8wcBarvHlnMu5sh6DMeNW4= Received: from BN8PR16CA0021.namprd16.prod.outlook.com (2603:10b6:408:4c::34) by BN9PR12MB5322.namprd12.prod.outlook.com (2603:10b6:408:103::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 09:52:19 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:408:4c:cafe::fd) by BN8PR16CA0021.outlook.office365.com (2603:10b6:408:4c::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.24 via Frontend Transport; Fri, 11 Mar 2022 09:52:19 +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 BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 09:52:18 +0000 Received: from kali.amdval.net (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; Fri, 11 Mar 2022 03:52:10 -0600 To: , Subject: [RFC PATCH 10/36] iommu/amd: Introduce per PCI segment device table size Date: Fri, 11 Mar 2022 15:18:28 +0530 Message-ID: <20220311094854.31595-11-vasant.hegde@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311094854.31595-1-vasant.hegde@amd.com> References: <20220311094854.31595-1-vasant.hegde@amd.com> MIME-Version: 1.0 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-Office365-Filtering-Correlation-Id: 316f2a68-d6f5-48f8-1211-08da0344d4d9 X-MS-TrafficTypeDiagnostic: BN9PR12MB5322: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: 11r6t/vhOH7WsR37EmybtVQr/9nj0MIQHtyym4Z/KUjY5+vlXLfcCsdtyEs7+x5UIPmIjEXvwp4aCWO0Ghqg8x+vLah9Cgh+mKJbbkdFdceTopPyjyEDLwoYSTQxhay+Rjl9ZCRJ1MD+6Y7ttsIOvHwS4MTXZuhFx3u6cwoO8vtMKZHr73xgNQn//ctek6v3LA0ABoy37VY/L3OjKim9bBg2Cv3+qK1O0fFF7wnVEeaYZlKQP0QfTjxi44xjoKfTRs/I5qTzZTLL7YYsCXT4ipaGtgmmA4kb62C81iqdVRts5xQvFtrsabNdSZKBXDx5nq8b1RgvUWF7uBAaByxV6ukO4lI15QrA5DpYX3sYtWG127iPntQoNFcoKqKc5LQjOzBy5Jt8LA65FSKEF/TS1eCr5Lv6Z9bC7PqNxq7Gj6lpFTVC7HZsSwXDdEkOCNU6TyVyYaq9XZgB39UXzQY9DYHAHIoj4IqJkqdSEdAlFG21ai6GLpaGyODEMWyIEilzwrjlVhxpeMd/TAadATyDI5PmjAyYWgkKFXfSud7J/3eMA75UU7vmbZDNvV3rpqjGKnXL2gUaTbGlOgRUG5xlbf5ns3Nb/DiDE8/opnXckPA4sWRrppn059aWMbTmCz4yybHzkJ4SrH+RN04wBcwA8ojcFhekcqZh5nh8W84rIl+It+v5vyqKKXooL4CFn+dRKmyomTbwkm92YnkfNUATGQ== 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)(46966006)(40470700004)(36840700001)(508600001)(86362001)(83380400001)(40460700003)(1076003)(426003)(2616005)(16526019)(2906002)(6666004)(47076005)(336012)(4326008)(186003)(81166007)(5660300002)(44832011)(70206006)(70586007)(8676002)(54906003)(36860700001)(110136005)(356005)(316002)(8936002)(82310400004)(36756003)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 09:52:18.9376 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 316f2a68-d6f5-48f8-1211-08da0344d4d9 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: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5322 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" With multiple pci segment support, number of BDF supported by each segment may differ. Hence introduce per segment device table size which depends on last_bdf. This will replace global "device_table_size" variable. Co-developed-by: Suravee Suthikulpanit Signed-off-by: Suravee Suthikulpanit Signed-off-by: Vasant Hegde --- drivers/iommu/amd/amd_iommu_types.h | 3 +++ drivers/iommu/amd/init.c | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index ba837ecd46f2..b5b0c23eacf2 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -547,6 +547,9 @@ struct amd_iommu_pci_seg { /* Largest PCI device id we expect translation requests for */ u16 last_bdf; + /* Size of the device table */ + u32 dev_table_size; + /* * device table virtual address * diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 71f39551a83a..f8da686182b5 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -414,6 +414,7 @@ static void iommu_set_cwwb_range(struct amd_iommu *iommu) static void iommu_set_device_table(struct amd_iommu *iommu) { u64 entry; + u32 dev_table_size = iommu->pci_seg->dev_table_size; BUG_ON(iommu->mmio_base == NULL); @@ -651,7 +652,7 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table, u16 pci_ 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)); + get_order(pci_seg->dev_table_size)); if (!pci_seg->dev_table) return -ENOMEM; @@ -661,7 +662,7 @@ static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg) 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)); + get_order(pci_seg->dev_table_size)); pci_seg->dev_table = NULL; } @@ -1034,7 +1035,7 @@ static bool __copy_device_table(struct amd_iommu *iommu) entry = (((u64) hi) << 32) + lo; old_devtb_size = ((entry & ~PAGE_MASK) + 1) << 12; - if (old_devtb_size != dev_table_size) { + if (old_devtb_size != pci_seg->dev_table_size) { pr_err("The device table size of IOMMU:%d is not expected!\n", iommu->index); return false; @@ -1053,15 +1054,15 @@ static bool __copy_device_table(struct amd_iommu *iommu) } old_devtb = (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT) && is_kdump_kernel()) ? (__force void *)ioremap_encrypted(old_devtb_phys, - dev_table_size) - : memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB); + pci_seg->dev_table_size) + : memremap(old_devtb_phys, pci_seg->dev_table_size, MEMREMAP_WB); if (!old_devtb) return false; gfp_flag = GFP_KERNEL | __GFP_ZERO | GFP_DMA32; pci_seg->old_dev_tbl_cpy = (void *)__get_free_pages(gfp_flag, - get_order(dev_table_size)); + get_order(pci_seg->dev_table_size)); if (pci_seg->old_dev_tbl_cpy == NULL) { pr_err("Failed to allocate memory for copying old device table!\n"); memunmap(old_devtb); @@ -1580,6 +1581,7 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf; DUMP_printk("PCI segment : 0x%0x, last bdf : 0x%04x\n", id, last_bdf); + pci_seg->dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE); pci_seg->id = id; init_llist_head(&pci_seg->dev_data_list); @@ -2675,7 +2677,7 @@ static void early_enable_iommus(void) for_each_pci_segment(pci_seg) { if (pci_seg->old_dev_tbl_cpy != NULL) { free_pages((unsigned long)pci_seg->old_dev_tbl_cpy, - get_order(dev_table_size)); + get_order(pci_seg->dev_table_size)); pci_seg->old_dev_tbl_cpy = NULL; } } @@ -2689,7 +2691,7 @@ static void early_enable_iommus(void) for_each_pci_segment(pci_seg) { free_pages((unsigned long)pci_seg->dev_table, - get_order(dev_table_size)); + get_order(pci_seg->dev_table_size)); pci_seg->dev_table = pci_seg->old_dev_tbl_cpy; } -- 2.27.0 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu