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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 7471EC2D0DB for ; Tue, 28 Jan 2020 14:21:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D49724686 for ; Tue, 28 Jan 2020 14:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221287; bh=7m3fKvPOw1TUuYme9LEnc0AE6Udzj0eu0sWT5cbzFnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wB9/KyFshlJC2EJMCW8oYNec6m2HpU3CZ+gtKwaq1g8APHPUUTJGsj4aoDzaMNCZd m9B7f8xSm2GR+x5gC7nncQ21+OhP4ie1khcX8SG8GpPk+4GMXs2DLQjLpGYD3iUGmF 1mMMKIgXhdFX+qgeUkt7qTmCnYeYJUtOWnuQeDZ0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731086AbgA1OV0 (ORCPT ); Tue, 28 Jan 2020 09:21:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:46714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731272AbgA1OVY (ORCPT ); Tue, 28 Jan 2020 09:21:24 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3EC024691; Tue, 28 Jan 2020 14:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221283; bh=7m3fKvPOw1TUuYme9LEnc0AE6Udzj0eu0sWT5cbzFnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bxw55WSTY/ero4tn2D2hhlw0TDFljBuSXwzpWTnePOYuAflbZNazmfOOGXK8w5ORO wIxxQESp8k2aws0NpPrQjUYAT+oYAwstgAQ3G3uQK9eNVOCA7ZyVaIbCEzXHmeoY6/ oLi+fb6wWkQv435vF5Eyx9Baz+08V2REJ7MRFYP0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kevin Mitchell , Joerg Roedel , Sasha Levin Subject: [PATCH 4.9 163/271] iommu/amd: Make iommu_disable safer Date: Tue, 28 Jan 2020 15:05:12 +0100 Message-Id: <20200128135904.718482747@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 9bb8d64b6f947..c113e46fdc3ab 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -383,6 +383,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