From patchwork Wed May 12 14:48:18 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: 435672 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5190763jao; Wed, 12 May 2021 14:08:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx44gXBxdnA4dhUsbtaIE23UOn1BncQnmTVKQ44vHbZsaXYHtlGUcGGy1PJ8WHKO1NCUW+G X-Received: by 2002:aa7:db94:: with SMTP id u20mr24256080edt.381.1620853737396; Wed, 12 May 2021 14:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620853737; cv=none; d=google.com; s=arc-20160816; b=vwbe2cDBNvkbvnhSsTbISjotO8U+VfDyahMM3GxMSviVOphrR+saoEemxcnQI3DIlW BP7kKD/hjF2MzWPZAut7uGDNqAA5tDOx09H6xoyELutVd9Y0lbH/zYU/+onO6DH4T8e5 pstvf8sI7q96OvolheRveNEzAITvegSGvFr0iliLdnVhg8Ez2iN/r6UZvL8M3P+zYInn B3gXw8tJiuynfvzsLytu/lKxAl97Ta26RfHHjgzmjf0eoMDSsgt7cLaQJZdtRtNwZNdm ULRW36X2HG1c6KXWsk3S6rTrERxgQkRzReMRkf3M2j1PlBuq53+jGSrMf9ROtHtgyDYT sxew== 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=pSrrNB+X9wPq18pdHdD5n8Cd4pZAH0RT9w6sENQuaOk=; b=HP45Wl82E3C2j2kxXl76Xk5/+DbKjcUgcXZ8zw/LWoknYTIh1jJaGVgVtwfWwXzC1N 0tWhsUs3uFloFY2NLCYKvVdBYvUAv5IQNAYc6GFP3utu30OvpqFJWiWpFPeNjvdOl5Ww +dGVQhSGigyOVKSYclELkRI94sBaxrNvRyJkeTmV18x3aeT7Qk1kiyDgUrgBZdTpo0/G eqJMHG7oX91lr/ykcPmR8/bPZpK2W3iLSCYeIQKLqhlres4hm28edL+ckenKJvSl14tS W3wj1i0wBZpNP1zHo5jAwawvKDrmIqQwI6RsjZydZ3x72rxi1BWQLagtGDgEQ3YAzfQl oyCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=13W2josP; 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 u19si859013ejx.176.2021.05.12.14.08.57; Wed, 12 May 2021 14:08:57 -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=13W2josP; 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 S238966AbhELQ51 (ORCPT + 12 others); Wed, 12 May 2021 12:57:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:60668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244040AbhELQm2 (ORCPT ); Wed, 12 May 2021 12:42:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F017A61D0A; Wed, 12 May 2021 16:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835793; bh=oYSkq20cqGf3TSJ6XuryktDSHljq7XAMF7O10/G1HMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=13W2josPENZwb314x6ozEOpIo/kacUJJ7XeLxyVFPGZ8hJ4kuZLaKqLcSN3qNZcoT GHBe2oXKX9MsEmdsEPQNiPcqFb2CfslzYdNoUwHN9m2BoQ2AehCN83sXLChKKHxxCd owWFPx9vN0MV5faeDtJkxtfmwnlkKYNni/uaSkiM= 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.12 452/677] iommu: Check dev->iommu in iommu_dev_xxx functions Date: Wed, 12 May 2021 16:48:18 +0200 Message-Id: <20210512144852.377040912@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@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 d0b0a15dba84..e10cfa99057c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2878,10 +2878,12 @@ EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids); */ 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; } @@ -2894,10 +2896,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; } @@ -2905,10 +2909,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; }