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 X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27DB6C433DB for ; Thu, 11 Mar 2021 14:26:58 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 937D264FB3 for ; Thu, 11 Mar 2021 14:26:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 937D264FB3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2B271431D6; Thu, 11 Mar 2021 14:26:57 +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 HuIRoRPk6Dji; Thu, 11 Mar 2021 14:26:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id CE85642FB1; Thu, 11 Mar 2021 14:26:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id AAF2CC000C; Thu, 11 Mar 2021 14:26:55 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id E7289C000A for ; Thu, 11 Mar 2021 14:26:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D5FDB42FC0 for ; Thu, 11 Mar 2021 14:26:52 +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 TCMhpsdi_u0Q for ; Thu, 11 Mar 2021 14:26:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20616.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eab::616]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4DB9D42FB1 for ; Thu, 11 Mar 2021 14:26:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H17Dpe6lbymaw7NLcpRcikZLg/eQOU7tt4aaZfdFt2I/0fCGqGqujIarTOFHauT17Yy9WTfGuquYgOoMzYxqykzH/ejFH2g0NyIQUHdLnLqfqTVFVy0MfnItuhFi62DN1OnPD3CAzLgT0/CYz6hp/pMhEgjqpylnUxwsXz2izEvqQJhDAUwMtrvWH9LbKchDE1dlXzO/o1IKd4cAemisANPa9Lcu4Q9Mjp7/3dvHhxU3Vwm2DFcU8ATSvrFVbYzFeuNwtY+JIMWJHK2OhE3LnLgkujkscZmowa+5zAmD4Gnkjz7bRlzVbb3qoKOPxcKqGsaT4U3r3onNwzsPjT+RNA== 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-SenderADCheck; bh=jmDjuCzIsugNRfIx1Sf3yWR/Hc6g3YUsdLtFcbWUFBg=; b=bqsRL0xMF9C2ZO7flIyk73A60zraesrf5s0ZHvx/QzNh+SH1vebBam6Ftpu4250r8WipE1IiMq1Pqo2ZVZERTAgoxVs2bbEVVg1bPPsyD02yNLWzAPDUIwwwdQOff3wC5ygC28Pf9PcnVgYo4V5c7n5gOakQNvp670Ior3BkVrsM/bJ5fb2G2dCSHYqofig4WU3EhMH6kiCNU8DyFtBCNrJl7Np/+VTuN/p76NqXECJQ2sb11cHF13rKBJ58syrmOG0iVOEAThj14oqXHU/b8JMcjUNTxplWCXs4On3QidrW72KbZ9Ekat+nWULAmF5zYuqIYZ00WC1sXrfqLyGKmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=jmDjuCzIsugNRfIx1Sf3yWR/Hc6g3YUsdLtFcbWUFBg=; b=Cc1jrbkTWxarjCYhNmDL7sLuCAViInrdE5nEvp9h3lfhQpo7nyceYcHr7d8zmQJpkOttTVTHNXuzOX3tJb5pTEYhHNZNPZDEPpBlOgnm9iRrCGe9jekM2QXfIX26iII4VfagXc24Z3Y0LJVLl14pXS1upUMwL/7R/strjlPhZbE= Authentication-Results: lists.linux-foundation.org; dkim=none (message not signed) header.d=none;lists.linux-foundation.org; dmarc=none action=none header.from=amd.com; Received: from MWHPR12MB1248.namprd12.prod.outlook.com (2603:10b6:300:12::21) by MWHPR12MB1520.namprd12.prod.outlook.com (2603:10b6:301:f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.27; Thu, 11 Mar 2021 14:26:49 +0000 Received: from MWHPR12MB1248.namprd12.prod.outlook.com ([fe80::5094:3a69:806f:8a28]) by MWHPR12MB1248.namprd12.prod.outlook.com ([fe80::5094:3a69:806f:8a28%5]) with mapi id 15.20.3912.028; Thu, 11 Mar 2021 14:26:48 +0000 From: Huang Rui To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] iommu/amd: Fix iommu remap panic while amd_iommu is set to disable Date: Thu, 11 Mar 2021 22:28:07 +0800 Message-Id: <20210311142807.705080-1-ray.huang@amd.com> X-Mailer: git-send-email 2.25.1 X-Originating-IP: [58.247.170.245] X-ClientProxiedBy: HKAPR04CA0001.apcprd04.prod.outlook.com (2603:1096:203:d0::11) To MWHPR12MB1248.namprd12.prod.outlook.com (2603:10b6:300:12::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from hr-amd.amd.com (58.247.170.245) by HKAPR04CA0001.apcprd04.prod.outlook.com (2603:1096:203:d0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Thu, 11 Mar 2021 14:26:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ff5fc478-81ce-4a4c-af3f-08d8e499b498 X-MS-TrafficTypeDiagnostic: MWHPR12MB1520: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j8BKgy7+IbUXj6SCKlLhEf0e8B5GvbfM+PbgIPBXDGV6f7uxHTPavGVlH/cGi54SBrh2IZYpTbh/S7RzLW9cGq6oSjc/U0iPofOLzsRAyIHa0iLnHAw0WyefgIctnFP9c8S4dGX7W9xhRrK5K/beT6v1GqjjH629YQnlsrSWn8q7ck0K/daR5NGJtWAYuSRPuF2qU5oozm+Puu1zllGzzZwrRht7kiqwV8H5Rj3QJRePiIBJ4yFjdLTU4TCbxoxFx3/ReVuRa4LUyyFWFrcj1HdGLFESzt6VdkltTM7aKZzVyT5ohfwkag+f0ptcuwcAv5j437V3pmRD+Vyqg9nQ+ZPe8PlmMBnaTeHNHRtlF3ROZuV8NLJW8Gph0MiSUffdCMitM5T0M6PyH5FrXn/uNnLsPyGi3phlRJu5VU0BmIzEzRlifV3voaabTh1IUNFAwqLQWNJBQUL11nDeyl9TWQN41b4yNuPWn+w3wxSoNoSLQO3HNERqfC9FvMjh5E8Rq0knjIzCxr27Sn9pMeuJhA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR12MB1248.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(366004)(39860400002)(346002)(376002)(6486002)(36756003)(186003)(26005)(4326008)(6666004)(66946007)(66556008)(86362001)(5660300002)(66476007)(52116002)(16526019)(8936002)(7696005)(2616005)(1076003)(478600001)(54906003)(8676002)(956004)(316002)(83380400001)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?gaDSLNCwHtiPA6bKfnSha2XPCuaP7vE01tG5Yf8NUSDzspCZrTYWPjEo60WM?= =?us-ascii?Q?NM0acvV+ObIP2Jo1dN4JOwmGz5knzmGqLLLrgNTAC6H4DygmgRLX6P6vnTdV?= =?us-ascii?Q?IJeGIvUFo3dg3Sb+7fLLmEpruILW0KB9mwi1+MqvbfH3ftyUO+flhN0ox3MP?= =?us-ascii?Q?FpbQLr6FqQcMmLcMqs/2qR6HrUp2nnbE5cXtlQRpoN/pGZwvHcC6KOFUg+Yq?= =?us-ascii?Q?mGYucxgXRlTS9YgcBeDq7V6TW95Eb7YMaX0WbPuujZ1lJxiQhwCpuvOJVEg+?= =?us-ascii?Q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976ipxth5dICw?= =?us-ascii?Q?5w8+FKdMcAbV3yF/YA/4h1gB6rsvX+SJQQSCRk+ufHdsTj51O/3+qTmI7KH3?= =?us-ascii?Q?Wm53CiiNCp2RS0XnH2v9ZLRcFXsfzg+ub5m2FHZACJzfGm0vdbQdysReT/mg?= =?us-ascii?Q?5mPfOvtUwiNifmgdEkBc9UDe?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff5fc478-81ce-4a4c-af3f-08d8e499b498 X-MS-Exchange-CrossTenant-AuthSource: MWHPR12MB1248.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2021 14:26:48.8297 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CGnSYP/2ItX7MOd3FLqzwF+W1PWRUfe6BN4bUrdNS5aG5w6sQl2gvwXlObiTkbygk1ADU70NiZEPgTKY7WNIfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1520 Cc: Joerg Roedel , Xiaojian Du , stable@vger.kernel.org, Huang Rui , Alex Deucher 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" While amd_iommu is set to disable in cmd line, it will free the iommu resources. Then the pages of rlookup table is freed as well. If that, we have to check rlookup table in irq_remapping_select(), otherwise, it will trigger a kernel panic below. [ 2.245855] BUG: kernel NULL pointer dereference, address: 0000000000000500 [ 2.252861] #PF: supervisor read access in kernel mode [ 2.258053] #PF: error_code(0x0000) - not-present page [ 2.263247] PGD 0 P4D 0 [ 2.265844] Oops: 0000 [#1] SMP NOPTI [ 2.269570] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.11.0-custom #1 [ 2.276150] Hardware name: AMD Chachani-VN/Chachani-VN, BIOS VCH162755N.FD 03/04/2021 [ 2.284085] RIP: 0010:irq_remapping_select+0x5c/0xb0 [ 2.289107] Code: 4b 0c 48 3d 70 7c c8 8f 75 0d eb 35 48 8b 00 48 3d 70 7c c8 8f 74 2a 0f b6 50 10 39 d1 75 ed 0f b7 40 12 48 8b 15 f4 8a 3b 02 <48> 8b 14 c2 48 85 d2 74 0e b8 01 00 00 00 4c 3b a2 90 04 00 00 74 [ 2.307999] RSP: 0000:ffffffff8f403d40 EFLAGS: 00010246 [ 2.313285] RAX: 00000000000000a0 RBX: ffffffff8f403d98 RCX: 0000000000000021 [ 2.320471] RDX: 0000000000000000 RSI: 000000000000000a RDI: ffff8cbb4006118a [ 2.327658] RBP: ffffffff8f403d50 R08: 0000000000000021 R09: 0000000000000002 [ 2.334838] R10: 000000000000000a R11: f000000000000000 R12: ffff8cbb401bfe40 [ 2.342022] R13: 0000000000000000 R14: ffff8cbb401be900 R15: 0000000000000000 [ 2.349210] FS: 0000000000000000(0000) GS:ffff8cbd73e00000(0000) knlGS:0000000000000000 [ 2.357399] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 2.363198] CR2: 0000000000000500 CR3: 00000002dae0a000 CR4: 00000000000406b0 [ 2.370382] Call Trace: [ 2.372897] irq_find_matching_fwspec+0x48/0xd0 [ 2.377489] mp_irqdomain_create+0x7c/0x180 [ 2.381736] ? __raw_callee_save___native_queued_spin_unlock+0x15/0x23 [ 2.388320] setup_IO_APIC+0x81/0x875 [ 2.392048] ? clear_IO_APIC_pin+0xd6/0x130 [ 2.396294] ? clear_IO_APIC+0x39/0x60 [ 2.400103] apic_intr_mode_init+0x107/0x10a [ 2.404432] x86_late_time_init+0x24/0x35 [ 2.408507] start_kernel+0x509/0x5c7 [ 2.412230] x86_64_start_reservations+0x24/0x26 [ 2.416911] x86_64_start_kernel+0x75/0x79 [ 2.421068] secondary_startup_64_no_verify+0xb0/0xbb Fixes: a1a785b572425 ("iommu/amd: Implement select() method on remapping irqdomain") Tested-by: Xiaojian Du Signed-off-by: Huang Rui Cc: Joerg Roedel Cc: Suravee Suthikulpanit Cc: Alex Deucher Cc: stable@vger.kernel.org --- drivers/iommu/amd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index f0adbc48fd17..a08e885403b7 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -3862,7 +3862,7 @@ static int irq_remapping_select(struct irq_domain *d, struct irq_fwspec *fwspec, else if (x86_fwspec_is_hpet(fwspec)) devid = get_hpet_devid(fwspec->param[0]); - if (devid < 0) + if (devid < 0 || !amd_iommu_rlookup_table) return 0; iommu = amd_iommu_rlookup_table[devid]; -- 2.25.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu