Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4619499pxj; Wed, 12 May 2021 09:22:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlCH3ZCtdiZBWv9qxNzZjL0C+CEPZzKTWNgAGXLDDCdiY5lU1BoC19JZY9EgovEo/25AYT X-Received: by 2002:a05:6402:354b:: with SMTP id f11mr45444127edd.139.1620836543801; Wed, 12 May 2021 09:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836543; cv=none; d=google.com; s=arc-20160816; b=Tq6mJAxeENEC6IjpJtJ1tVLkSAp3+YMZcKDnTSUMrG3wm6RcAhzngXCji0Y7mxLevV beN+FKHrEIwBaX8DzolN1hRHvSRbvJsRXwDQSC3htccxwDnul+yYKBOTFX4N4ME8aTg9 HPVNlbcL10iSZ6rkm1O0WJuShXpTVX6we3zcvXLOsGDfOpxj76D61cRxbkzgZjlHTbYH BCS8H6COk0HUyMBx/OSxHH2uzbNQjOJo5+nOKLVJkviCVKLh8WXWu/hsDs+VwrzlyvLA P3CqY/tPIsxCX92Z5xdG8B1XXiF4b1WaWx7G1MS4GSZqbky5UYzUJbreZGS4a1XSq9yU LYFQ== 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=/K7Ob9iI2SVkSYHn20edYJ3ZOrYYoTVBFCROLrY9jik=; b=QNxv4GEdFr8nnmK6FFxglRJ0fYHuooBs4TyBeGF0kW5Xwm6O0RWMlojenjL2AlH1Vz GgJY+W/W8hUFZlIht8Zxsg9/wDjLeRjGtdrivQUjCMHQg5hj8DatWtq02s0JmePMUvmd grHOw38ySD34ulH3XXY2Z3nk+rrtXZqmw+e+RWqFt6p8R5kIfwVRo6VeaZkrW8UThR0C EGooYw+S/ajCb4ge5vR1xVcIvn+hXod943kI0KGQuV0doblNSg7GbQCwbala/iZY3e/5 0E/Fp0gvXqDskSiS2sOt27TYgvoE0Yal5PDvKnSgBhk+inTwgFgTuu7GlbE5RZHLACWL xgfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fhupXbhu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 i5si176307eje.413.2021.05.12.09.21.59; Wed, 12 May 2021 09:22:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=fhupXbhu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S240162AbhELQRW (ORCPT + 99 others); Wed, 12 May 2021 12:17:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:50090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233627AbhELPdz (ORCPT ); Wed, 12 May 2021 11:33:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E19661987; Wed, 12 May 2021 15:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832634; bh=HDXkbyI3YlggLB0u4Elay3NlNk1nwAw4NVpE2KdDMxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fhupXbhu5+jUi9T0cC+RpOP8aUsblJjN/aoVHCU57Fv7I3ikKymU0p3dBDr7gROnp GeYFhKLWG4jEY8PskaDqNutM8F+8JxTIUjQsA4D1gOy07jvL1Fm6O2KEkgubPhI7ud RrdSSSpJHH9GVhk2PJubBn3xXSPcAhDgnxeD+7sc= 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.10 359/530] iommu: Check dev->iommu in iommu_dev_xxx functions Date: Wed, 12 May 2021 16:47:49 +0200 Message-Id: <20210512144831.584339022@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0d9adce6d812..9b8664d388af 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2872,10 +2872,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; } @@ -2888,10 +2890,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; } @@ -2899,10 +2903,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; } -- 2.30.2