Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2523319pxb; Tue, 9 Mar 2021 04:54:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjab+yu2hKG8GAsEWAcRJlk4ukxFz8UB8z6PytOkYXlZTxN4snMxmAWApJnKeQF6JQujz8 X-Received: by 2002:a17:906:7015:: with SMTP id n21mr20175494ejj.391.1615294486722; Tue, 09 Mar 2021 04:54:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615294486; cv=none; d=google.com; s=arc-20160816; b=IJoDYolZ34EY1iIs8I1fkrorZivo89DqHA8Jn5Cas4hd7KOoXj3q/6XezKgdN6+Jj8 5wS3FtCIJL7b1LhTdYbOTUr90wuambtyPQRenyNLJknhYcD+R14slCZBs6e0a5tUKOr4 sfMKfFQpGyef7MeBfhDUpdpLBPD0U+j/fL2HB1nQAUQn2r6XrsanqIytpkMpoNe3geD/ dUKbjW/pLB1WpaC5vxj/fSio+6U8ba9RvQPD21mZaNkIpKKlXQNW9P92X1qWwukjGhbT VutQgS1AOJ4gRR8HqrOGD7N5zyu+FDbWVsmcHoMeH3vy6K+Qch59LjlNcyeKDI7voduC zkZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=BY10+CDgFZph2pClLpEHnjRUsVo5Obt7zN09AEDyA8g=; b=cysfJPcAKDwYJKhk112sEeRst1l30yu0aMuNt089PVHSj8sbFyPh3yfntFJxcXRwGU bnWShQlI6CQF2pslJh6yzWEboHRByCFLnNErWkVd9/KWLB6N9gvQ5x5fMaT4I1CvqMED rdfYCACCQGZXhIrd7QJjzHUIUGi3klvYaZNrC76f5DFDyzm+LLwP7C4vHXotV5c+ogvX 6H/eglnnblVG3yK/b562TETMzNEr0qObqqD3HkFsN+udvx4UOTCBONpOjGhYxNneTLLh /eOhokLKtf1IApyAua21vIUv+mkl3pOfqSXFFRDx1wAXRgP8EdiW2oSC1Mxg2DtDLF5r 0aqA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y1si4589136edp.405.2021.03.09.04.54.22; Tue, 09 Mar 2021 04:54: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbhCIMvG (ORCPT + 99 others); Tue, 9 Mar 2021 07:51:06 -0500 Received: from foss.arm.com ([217.140.110.172]:52576 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbhCIMug (ORCPT ); Tue, 9 Mar 2021 07:50:36 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 092291042; Tue, 9 Mar 2021 04:50:36 -0800 (PST) Received: from [10.57.55.135] (unknown [10.57.55.135]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C1F493F70D; Tue, 9 Mar 2021 04:50:34 -0800 (PST) Subject: Re: [PATCH v3] iommu: Check dev->iommu in iommu_dev_xxx functions To: Shameer Kolothum , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: joro@8bytes.org, jean-philippe@linaro.org, will@kernel.org, prime.zeng@hisilicon.com, linuxarm@openeuler.org References: <20210303173611.520-1-shameerali.kolothum.thodi@huawei.com> From: Robin Murphy Message-ID: Date: Tue, 9 Mar 2021 12:50:29 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210303173611.520-1-shameerali.kolothum.thodi@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-03-03 17:36, Shameer Kolothum wrote: > 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. Reviewed-by: Robin Murphy > 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; > } >