Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1134487pxb; Thu, 4 Mar 2021 04:20:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJy50QSz71bhzWT1vEMCnbnrKKMjzVVd7rEhrXnsyWmDf59WUGSVIhPccmdvH8/+Y2hawcBZ X-Received: by 2002:a17:907:2054:: with SMTP id pg20mr3897068ejb.213.1614860446160; Thu, 04 Mar 2021 04:20:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614860446; cv=none; d=google.com; s=arc-20160816; b=M1mdy06L9OY7oEn1zPK97EFGoW7uKKAuk4oSDxPEgWCnLFFbFXEfT9ue3vzg37l56h 6svOTBSqO+G6k7HWT61wKRrxqLK+bVm8NonU9E1JA6XlpW+SVsIFeLrTYxPaF07rZ7ur SeMOQluQFYmpp+ire//4UQ+/taERjITVqiMYhq+vJ/F9mJP0V7g9YLV3FJZ82w/5oByN nuvUtRaUODV4QWjK0YWxIJzC8xkMmN9xxvZC4ptR792btvJ775b3/lkVBdfhiVbNNUFe hpeXQFkE9kZTarihKndZNIKwbJkmSo7vr1lg5OsSvkVadqhhIrE9WzkulCAaZBkXh50P FF0A== 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 :message-id:date:subject:cc:to:from; bh=h9moC2CZ05I4rdFRaDmroZ9JpBUFqghE9NHA4V//DJ4=; b=bQjylJR/743AQSuoISpVD9vcjoFl7tQ6Adt7MiWFF7yAOI7SPIXqxMetCnGw2A+LEA aK8b7dIcnDfc7Ww3GC+51L7FUVErNv/pAqXz8LdWcnH9ZB16VfYzJqj/qsFU9RTbULmB YLT7cnUjFqtqA0Yh6MuidjfCoxzYzuYI2Qw25Op+y1PwqXsmLj13MEuzThfeoijTB11g dOkcWBlRhTzjnbNQGBa0mtIFLOVvwz15e8Lr55nNV8LWwBkVm/W4YOTw7iRNArM45lHs oyVBMt1wMFtDHVhcxnu7sR2sWSaudZkGp9wB8K4YEgNH4dqgmOz7+8vrQNk2lKDwWaec iTDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si2163403edy.138.2021.03.04.04.20.23; Thu, 04 Mar 2021 04:20:46 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1580889AbhCCSrB (ORCPT + 99 others); Wed, 3 Mar 2021 13:47:01 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:13427 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234043AbhCCRiL (ORCPT ); Wed, 3 Mar 2021 12:38:11 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DrLjx3KNMzjTqL; Thu, 4 Mar 2021 01:35:17 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.83.26) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Thu, 4 Mar 2021 01:36:29 +0800 From: Shameer Kolothum To: , CC: , , , , , Subject: [PATCH v3] iommu: Check dev->iommu in iommu_dev_xxx functions Date: Wed, 3 Mar 2021 17:36:11 +0000 Message-ID: <20210303173611.520-1-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.47.83.26] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v2 --> v3 -Removed iommu_ops from struct dev_iommu. v1 --> v2: -Added iommu_ops to struct dev_iommu based on the discussion with Robin. -Rebased against iommu-tree core branch. --- 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 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; } -- 2.17.1