Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.7 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796378388; b=ZIci6AxuUqG/tnDXAUiQwDeoS5ln0J4g4lV2PHnPK+pIgn03mU22LhePH6On6+YVgDpo 1mMdLB8ssoa0so5qKQpsIc1endVAShRw4xYEI6iP5FBtEtmU9xKz9EYe/YS0xCmmkRqad XOwblLlwtSR4q6BCeS7Ycei2nnx4YuHEZwNGCf0I6rKxj5/Cymi9MwEPMqZotnOjVtFa9 eXUwYNNbZf+Gv6zbKihhbrfkmP0iHDeBTl2SruJsfbz5MtDOmpgi3GrebCu8TrVEgKoRf c6q44CA9s2+SaQA9E5bQoAHEaBXaxExtVvRIoGEWWegvzquIlleFhpddJg7WuWr409w== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796378388; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=tEwxYYBszWW39wBUOplHjEW5G1VPhPeP58ff3oJqnLY=; b=unOuJ7sXhMDYLv4RwU2qqNjbjgeyacDeXBEL0SLbaLZvN4Jtc6P5pVcGzpo19TjKecJb Y/xRx+cwMNv0wqSoTfOxuG+uk37ICecs7/aUXUf5l6lfx9xFJy6fd3B0K7hqdeITnayVn mltqrEUNC/7P7B7Vb92EM/Kvv3BsKBKp3aHWEUY5Q8p5Ju9j3f9OK2bcPo2ZInT/M22Cb 7gBBS4fdv6np6nGGWE/HkF2yl8kzqWuVQ9UaAJiPw/LPKPmJz1XMHsvNeE23KenOR8kOt GvVDE4UssTYSa0Oi2jlxBfUpFRiSA620HnmNMINTJ0tYdz3645N0UMJb4nk1DcF2UQA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=pYXUDGCH; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.7 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012007.outbound.protection.outlook.com [40.93.195.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65122606A322 for ; Fri, 4 Dec 2026 09:59:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65122606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=pYXUDGCH ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=icxb88QVxHPY6r+sBQbuTuyQqyrPBHbqN1MWDh08vSPPfUq3n4VovYCHr/LhS7nTyfxF4VBNdYBoNLktprB9+qBtymehQtGeCuHsUcWox8P0YEIjJK6LBWfpHzHB6Y9J7QYGiFgQTFORhx8yjLu6nr9AlER2MMMcEvOkF1sFw4lpUAXYmB04QDTcoHHJBGV1AMnUj8/Ypehfnr6vaMSnQqHba1fbbi+xGqIV5j+zQEDOV/emD6/UqGEpQPXWuJFdyeBIjkfUs1mqbRf3xmku59nSDGYzT+Bowd48rftB29ldTIVp3BNXXtPtshipA6ipMFz2vV3LCIllAAPYthBUIA== 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=tEwxYYBszWW39wBUOplHjEW5G1VPhPeP58ff3oJqnLY=; b=Yu6Vns0FGeiznUqZkxWun5Q5RTeD4SABFclzzlfHs1+UDDuuVPd5oGwfgW4YO6QhoDHr1t1IrVrB2BeA5HBosQUkyhHV2CSBeFVZojfWI3U5zpCYWmY3HvrKwTBwKxiRakMkvruq1O8KhadUJxffca+FsXngRg1lhvdqwKY3zfjWpqKFHv/lw+NZ68AP7zQQRCVTa5Edh+cuPaVfExZ5/9FlrYURtSpERd6ybsvy3CViPdEWRBeKjD5NEDJgKQOZ4/hdyKVBHR+9xaMjgMToHLmDxm6EmyzM1rt9uat9kWRJES/sO6xvjG6DzFZtJYIUzXBTzXskcIXW+mmpgLT8oQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=8bytes.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=tEwxYYBszWW39wBUOplHjEW5G1VPhPeP58ff3oJqnLY=; b=pYXUDGCHwE+9zvmyRA8hLjc+SJpDnT58+9gJ398e/DtT7BfpqNbjqCfUWxoPCrgZSRu4Nkhe4+2z8MsByYTyS0Z/qcqiJRuuXE70olFItzn6Su+8BV2cm/hrEztN+j302f+4uWJBN6eSfxBLmfSksNCHjng3LH/MVL4HDV+bprg= Received: from CH0P223CA0004.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:116::14) by SN7PR12MB6743.namprd12.prod.outlook.com (2603:10b6:806:26d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.12; Fri, 4 Dec 2026 09:59:43 +0000 Received: from CH2PEPF00016D48.namprd02.prod.outlook.com (2603:10b6:610:116:cafe::8b) by CH0P223CA0004.outlook.office365.com (2603:10b6:610:116::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.13 via Frontend Transport; Fri, 4 Dec 2026 09:59:42 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF00016D48.mail.protection.outlook.com (10.167.244.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Fri, 4 Dec 2026 09:59:42 +0000 Received: from kali.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 03:59:41 -0600 From: Vasant Hegde To: CC: Subject: [PATCH 12/38] iommu/amd: Remove the shared INTCAPXT domain only after its IRQs are freed Date: Fri, 4 Dec 2026 09:56:10 +0000 Message-ID: <20261204095636.335222-13-vasant.hegde@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261204095636.335222-1-vasant.hegde@amd.com> References: <20261204095636.335222-1-vasant.hegde@amd.com> X-Mailing-List: iommu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00016D48:EE_|SN7PR12MB6743:EE_ X-MS-Office365-Filtering-Correlation-Id: f0bc67e5-e0a3-45b4-3c8a-08df51ed5188 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|82310400026|1800799024|376014|261102123227099003|10067099003|56012099006|261021123027099003|261021121427099003|261022105027099003|261026121527099003|261026140227099003|261028144727099003|261009223027099003|18002099003|22082099003|11063799006; X-Microsoft-Antispam-Message-Info: 0BRNrC75sWV+ch0jmY9tntybgQOKfvfT/+m2LODVC2aPElwM15AWdg5QdQAYuujFg79x9UUyz7evSLju1JOeYjCU3HHWWylWHEZ2ZwLmwPwXveU17xw8S0BHnoxe6OYOTojG+PEN08e+kiZkwL2qsoN1ygV6a+m1CNGvC5u9rFR/eVaKKFTv7txmHl6KJDbPv+TK0gOeDvEP5/OkpGK9HVqUynF0PWg2HqRlSjfvTNykIIY0/ECEmMsWTC9wXgGLJ5T8ymICgFF1713NuopCjiAbHtuls4jIdvUEVkT5LkhT67fc7Kx4bN+hpXnsbGotNSf4ecWjQ23+VySqt/yAljljmrd8RAZgiqFptn7VmQeMAiyoRVlLj0mU1OJaxcLsWNYgdAwtg8QQqV0Ey9W3x7H9eKHc5T/sylSWATZTbjwgLnFN36xrcGgV9fgMJkRfKFVxkE4Y6TDNVEy6TDJv10g/s14dulK1rhNYTcRuKmHvxYK26WtbWASw7oZ+hZaT+ZwFtgZ4jmqb5EFdRMp1WoW1RoWalaZD7+j/BDyNMiZwgHyov4HtTAzu7T4n+HCDJT60Cug17hdO3QrfPohjY9ZSPi5UGb4hg4zOAVKS46Pq2kZeZ8w84frWhxm1gNz0KaWWZevOwJOivqnau1p2XsF7hS7acLKYfnTpUdHfWFSp/uWLpaY1bKJKFnaia+SrNe8RhK6M3r97sIJaN28h6Q== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(82310400026)(1800799024)(376014)(261102123227099003)(10067099003)(56012099006)(261021123027099003)(261021121427099003)(261022105027099003)(261026121527099003)(261026140227099003)(261028144727099003)(261009223027099003)(18002099003)(22082099003)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WrGYxKgFu1DRFkeidjiNbfKTLK6VghRXWJQjJxws3e0bkIGx6QL6Mcji2kDOG/DDFaU8NtjVeWmPfU1xXQsWRQRze03QKeLsQ+DuNdBznuqOZzRU0Cy7eSMhuZrDOQWt7RqVZqZ5SZkZTbsz0kLgJOd2YinknMEilOfMHC/s4o4DhmYI+BbgGUPBublAvYVIiXm0/hr2pThATNACV4FhMBCGynO7VFWDH4KBw4ir3l6lkf2UkqA3TR4TJ4pzbOrAp9lqSvQ4dUptfB00iFKTjiNNgq8J7mQjH6ST3z3ES964lLgcI3Lbvwq38/MrNSyHdKBOXZQE1lNhyHdTzhA+0gsamwbk+KNHteMxEtR6HBiE23DpLN3UToXpagU/drUo6dHbTvpCApWl24SVezOeU0+qV5InQf5N/W9g7s2grsJ2Bmzo4tj0hhhnGeoHcGdx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 09:59:42.6334 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f0bc67e5-e0a3-45b4-3c8a-08df51ed5188 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00016D48.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6743 __iommu_setup_intcapxt() called irq_domain_remove() when allocation or request_threaded_irq() failed. That domain is shared by every IOMMU and by the event, PPR, and GA interrupts. Removing it while another IRQ is still mapped trips the warning, and iommu_irqdomain keeps pointing at the freed domain. Free only the IRQ whose request failed. Remember each requested IRQ and release it if a later interrupt fails or when the IOMMU is destroyed. Remove the domain, and clear iommu_irqdomain, once its last IRQ is gone. Signed-off-by: Vasant Hegde --- drivers/iommu/amd/amd_iommu_types.h | 3 ++ drivers/iommu/amd/init.c | 62 +++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 1c1b39a74233..51db65740e41 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -687,18 +687,21 @@ struct amd_iommu { /* Name for event log interrupt */ unsigned char evt_irq_name[16]; + int evt_irq; /* Base of the PPR log, if present */ u8 *ppr_log; /* Name for PPR log interrupt */ unsigned char ppr_irq_name[16]; + int ppr_irq; /* Base of the GA log, if present */ u8 *ga_log; /* Name for GA log interrupt */ unsigned char ga_irq_name[16]; + int ga_irq; /* Tail of the GA log, if present */ u8 *ga_log_tail; diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 0660604cf579..24bf65e35694 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1870,8 +1870,17 @@ static void __init unregister_iommus(void) } } +static void iommu_free_intcapxt_irq(struct amd_iommu *iommu, int *irq); + static void __init free_iommu_one(struct amd_iommu *iommu) { + /* + * Masking an INTCAPXT IRQ writes its MMIO register, so free the + * IRQs before unmapping the IOMMU registers. + */ + iommu_free_intcapxt_irq(iommu, &iommu->evt_irq); + iommu_free_intcapxt_irq(iommu, &iommu->ppr_irq); + iommu_free_intcapxt_irq(iommu, &iommu->ga_irq); free_iommu_buffers(iommu); amd_iommu_free_ppr_log(iommu); free_ga_log(iommu); @@ -2609,6 +2618,33 @@ static const struct irq_domain_ops intcapxt_domain_ops = { static struct irq_domain *iommu_irqdomain; +static int iommu_intcapxt_irqs; + +static void iommu_remove_intcapxt_domain(void) +{ + struct fwnode_handle *fn; + + if (!iommu_irqdomain || iommu_intcapxt_irqs) + return; + + fn = iommu_irqdomain->fwnode; + irq_domain_remove(iommu_irqdomain); + iommu_irqdomain = NULL; + /* irq_domain_remove() does not free an irqchip fwnode. */ + irq_domain_free_fwnode(fn); +} + +static void iommu_free_intcapxt_irq(struct amd_iommu *iommu, int *irq) +{ + if (!irq || *irq <= 0) + return; + + free_irq(*irq, iommu); + irq_domain_free_irqs(*irq, 1); + *irq = 0; + iommu_intcapxt_irqs--; + iommu_remove_intcapxt_domain(); +} static struct irq_domain *iommu_get_irqdomain(void) { @@ -2650,7 +2686,7 @@ static int __iommu_setup_intcapxt(struct amd_iommu *iommu, const char *devname, irq = irq_domain_alloc_irqs(domain, 1, node, &info); if (irq < 0) { - irq_domain_remove(domain); + iommu_remove_intcapxt_domain(); return irq; } @@ -2658,11 +2694,12 @@ static int __iommu_setup_intcapxt(struct amd_iommu *iommu, const char *devname, iommu); if (ret) { irq_domain_free_irqs(irq, 1); - irq_domain_remove(domain); + iommu_remove_intcapxt_domain(); return ret; } - return 0; + iommu_intcapxt_irqs++; + return irq; } static int iommu_setup_intcapxt(struct amd_iommu *iommu) @@ -2674,16 +2711,18 @@ static int iommu_setup_intcapxt(struct amd_iommu *iommu) ret = __iommu_setup_intcapxt(iommu, iommu->evt_irq_name, MMIO_INTCAPXT_EVT_OFFSET, amd_iommu_int_thread_evtlog); - if (ret) - return ret; + if (ret < 0) + goto err; + iommu->evt_irq = ret; snprintf(iommu->ppr_irq_name, sizeof(iommu->ppr_irq_name), "AMD-Vi%d-PPR", iommu->index); ret = __iommu_setup_intcapxt(iommu, iommu->ppr_irq_name, MMIO_INTCAPXT_PPR_OFFSET, amd_iommu_int_thread_pprlog); - if (ret) - return ret; + if (ret < 0) + goto err; + iommu->ppr_irq = ret; #ifdef CONFIG_IRQ_REMAP snprintf(iommu->ga_irq_name, sizeof(iommu->ga_irq_name), @@ -2691,8 +2730,17 @@ static int iommu_setup_intcapxt(struct amd_iommu *iommu) ret = __iommu_setup_intcapxt(iommu, iommu->ga_irq_name, MMIO_INTCAPXT_GALOG_OFFSET, amd_iommu_int_thread_galog); + if (ret < 0) + goto err; + iommu->ga_irq = ret; #endif + return 0; + +err: + iommu_free_intcapxt_irq(iommu, &iommu->ga_irq); + iommu_free_intcapxt_irq(iommu, &iommu->ppr_irq); + iommu_free_intcapxt_irq(iommu, &iommu->evt_irq); return ret; } -- 2.31.1