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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 B5800C33CAF for ; Thu, 16 Jan 2020 18:20:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E35C2176D for ; Thu, 16 Jan 2020 18:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579198827; bh=QTWwA5ZX57t85mu8XhxifcF7+aHq2EqsBzcSV9TS4WU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2VQC/7Uvj74aIRQ4ZVL9fJx3Yhzvau2J9BUdM4HKhxCKQQIgGIP1RGRN1hXUTB4U5 JXe8gP7uUeqA0C4LBaUwTgV250qgbLZIFGV5CppAKBUQPhQA7mM8B43I6XY4ubQBK7 eNog30zSbzzCbrXOPJ1OlEckd7aNxdnTxebf4s0Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395499AbgAPSUW (ORCPT ); Thu, 16 Jan 2020 13:20:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404131AbgAPR2M (ORCPT ); Thu, 16 Jan 2020 12:28:12 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 54F5F246F2; Thu, 16 Jan 2020 17:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579195692; bh=QTWwA5ZX57t85mu8XhxifcF7+aHq2EqsBzcSV9TS4WU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1+Lug0EZbYsaUgfYCZUyBT2t90ydGoYqXQy03Qm4NLLsBcNqntyMP5soB+gLlzbvO 8Vskt9ctW0pas7+RX8c80adZDJW/r/5GpcBAToqhRTg0E9LN2Y7Y5Ad04bk7H6ilyR ECN7m7p8irNDWNP/fqEE1Xx5E+SS8RxoTQTKuEfg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kevin Mitchell , Joerg Roedel , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.14 242/371] iommu/amd: Make iommu_disable safer Date: Thu, 16 Jan 2020 12:21:54 -0500 Message-Id: <20200116172403.18149-185-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116172403.18149-1-sashal@kernel.org> References: <20200116172403.18149-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Mitchell [ Upstream commit 3ddbe913e55516d3e2165d43d4d5570761769878 ] Make it safe to call iommu_disable during early init error conditions before mmio_base is set, but after the struct amd_iommu has been added to the amd_iommu_list. For example, this happens if firmware fails to fill in mmio_phys in the ACPI table leading to a NULL pointer dereference in iommu_feature_disable. Fixes: 2c0ae1720c09c ('iommu/amd: Convert iommu initialization to state machine') Signed-off-by: Kevin Mitchell Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd_iommu_init.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 6a3cf4d0bd5e..4d2920988d60 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -420,6 +420,9 @@ static void iommu_enable(struct amd_iommu *iommu) static void iommu_disable(struct amd_iommu *iommu) { + if (!iommu->mmio_base) + return; + /* Disable command buffer */ iommu_feature_disable(iommu, CONTROL_CMDBUF_EN); -- 2.20.1