From patchwork Wed May 12 14:47:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 435607 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5035674jao; Wed, 12 May 2021 10:31:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIbKUIU+eE2DSuwqrBSQyKuBJT8bYoJVKvMZus4jwv3Jj3A8GA77eXEu2WWh3MxdK/kxL+ X-Received: by 2002:a92:d48e:: with SMTP id p14mr2308568ilg.33.1620840675574; Wed, 12 May 2021 10:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620840675; cv=none; d=google.com; s=arc-20160816; b=rjZv44VDSshwhBMCAmOyDNVNrFejhW79c7RpUflKfRFUr8vg7y+P+aAA0r1uHqH3cy HCV/eOZaz8YHhYD44LuTEt7Qp43Wl/5d9KKrW5VTPGhs60L4Nwuwo5agPOaMIsDY1pz4 /tqH8J2JkjS4uoWsUQWWs+mJO67zKviwFSB7LqabU7GGPrfuWA2G+sRYyNf+VpVN95YW visbTY9SCivdnBxyHC8S0z7VVRsHdCP0dZ1TkWmA/XoqFbc1aLDP+gKM1GR9NnMRs0lH f+c74gRji6YrTM00Bp7v098JWrGA/Yz2jnlK9jIBO6xmKjd0p31Bb4xOfrsRU7jqHm4W qc/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lxI4wXZAClGCgaCJh4Y2t3houaGjNgf0Tbgd9UPpMy0=; b=rmpfQ+yncSy3+QFoBEvA1uyRlhIP70j6ewDv519Te44LuZy84kw3QgrOS05wppjyoe qQNqqv0iNh764tHLMD4skTa14wFDiVJ6eRptlEpAlzxTsty92fMYoeVegWzGa3hHQx8X Bb3BMJhc0abVsojF055VpsEluUsu0xDiNP6/fQCDBwTOv8evZMoVssYKC4ccnr4D3XV6 +jfbic1MOXQrVG3P+LG0IZ/tvrHq4I/beqEievi/us8c1tyJnkyK6tMUgx3uwQVwFyPh kw39CWRfThb+3gvPsg6oxuXfnyhlO1qI2qzrmu+Fj9bn+b9/pAb+h1lGtkpOlyIgYlho hqZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0tMuEpUb; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si330223ior.12.2021.05.12.10.31.15; Wed, 12 May 2021 10:31:15 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0tMuEpUb; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236261AbhELQUC (ORCPT + 12 others); Wed, 12 May 2021 12:20:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:49770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236925AbhELQMo (ORCPT ); Wed, 12 May 2021 12:12:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 54C9261444; Wed, 12 May 2021 15:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834085; bh=0z13vjHwTMx0WxQpUGOd3R7K+7q5IM0pG+0xqETNIlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0tMuEpUbpHHe7rNHd0GYuOjfTlXy8kk85wDbHw4t4mImZZL2pJKqlxP0dQRD1lOFx 9ZGeV5xEVmK4VOUDFpjaY/IWrOnC+C72510jgwLOXKIYSAAvwT0yfamQgaxHVhAmwi QXH+gH9yn/HKhEWwMfx9aFEMI6r7sFgzI382DeRw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shameer Kolothum , Robin Murphy , Joerg Roedel , Sasha Levin Subject: [PATCH 5.11 401/601] iommu: Check dev->iommu in iommu_dev_xxx functions Date: Wed, 12 May 2021 16:47:58 +0200 Message-Id: <20210512144841.015967162@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Shameer Kolothum [ Upstream commit b9abb19fa5fd2d8a4be61c6cd4b2a48aa1a17f9c ] The device iommu probe/attach might have failed leaving dev->iommu to NULL and device drivers may still invoke these functions resulting in a crash in iommu vendor driver code. Hence make sure we check that. Fixes: a3a195929d40 ("iommu: Add APIs for multiple domains per device") Signed-off-by: Shameer Kolothum Reviewed-by: Robin Murphy Link: https://lore.kernel.org/r/20210303173611.520-1-shameerali.kolothum.thodi@huawei.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/iommu.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) -- 2.30.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index fd5f59373fc6..0e0140454de8 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2889,10 +2889,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_has_feature); int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat) { - const struct iommu_ops *ops = dev->bus->iommu_ops; + if (dev->iommu && dev->iommu->iommu_dev) { + const struct iommu_ops *ops = dev->iommu->iommu_dev->ops; - if (ops && ops->dev_enable_feat) - return ops->dev_enable_feat(dev, feat); + if (ops->dev_enable_feat) + return ops->dev_enable_feat(dev, feat); + } return -ENODEV; } @@ -2905,10 +2907,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_enable_feature); */ int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat) { - const struct iommu_ops *ops = dev->bus->iommu_ops; + if (dev->iommu && dev->iommu->iommu_dev) { + const struct iommu_ops *ops = dev->iommu->iommu_dev->ops; - if (ops && ops->dev_disable_feat) - return ops->dev_disable_feat(dev, feat); + if (ops->dev_disable_feat) + return ops->dev_disable_feat(dev, feat); + } return -EBUSY; } @@ -2916,10 +2920,12 @@ EXPORT_SYMBOL_GPL(iommu_dev_disable_feature); bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat) { - const struct iommu_ops *ops = dev->bus->iommu_ops; + if (dev->iommu && dev->iommu->iommu_dev) { + const struct iommu_ops *ops = dev->iommu->iommu_dev->ops; - if (ops && ops->dev_feat_enabled) - return ops->dev_feat_enabled(dev, feat); + if (ops->dev_feat_enabled) + return ops->dev_feat_enabled(dev, feat); + } return false; }