Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4228601pxb; Tue, 26 Jan 2021 16:21:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuqc31/SbJTYqcjfOOH75tyFHND6LNBuXPFTBCewlq0h5XdIsIJ6Y2q77IIBZaEx75hIuo X-Received: by 2002:a17:906:33c5:: with SMTP id w5mr5127558eja.319.1611706919276; Tue, 26 Jan 2021 16:21:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611706919; cv=none; d=google.com; s=arc-20160816; b=D/ZskbG4Yq4CnYVP7GH+WfWc2l6QoV0pqVu3GqWhEcqk9ZBqmXWIqwAWmk+qLzczw5 1V8pGEjpeQDZBGtUT7Jx87K2hElpC/7AammOXPvrZmdIUYZF0MUWHuJRFXJASIVPVsAl UdwsqoZIk/yKzuiLtC/lCR26VLSssq3VkU7ucrlfgdvPZ01w6BYj0g4np//Og3GnLU5h 2mWKBccF7nQL9ePj91DjNDLP253AyeY6N2OzXp/24il39D81/7XhnYxxpvIbI/muioJs piBMP7tegX+oEVb+m6Jr5abbEooizM1zYZiNXqPvc//g5SH8no+dbPuSPOn+ISVCLY6a oHuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=nZAoV9/3sBySo3ut+qUxSFvcrDoT8YarjhVsG9TswGk=; b=a42+ro1oQ7fB9m2hy/gfou+Qa0f+e6wAl16DJ1PYtbGQCq2yd1+lmr3WSW8U5MLDN6 eNVtrDmeFfLnxYLP2nJDRBFGrBFE+HgTp0o879spjHTV11BMpPqOrugxJY/PyJt5pv/U pwamN/r9Dm2o0SC339quGOG62teSAGaZn2XS9UVU6Yl3tGg+LIoDo7Iune7tthoQXCbj xDMOwRtieH3LabXhiD3juU43ilV/4iLFjuMCPDyyQ1A/G7Nya+EvLSS8FeBjFknkNUoN gJY3+BThNdeGJLKi3HhmYG8Hmbb+Gek2QD0aKUy7Ho/IyGmoGO7KCXJMtR2nJWEDgD2I ukmA== 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 k18si52913eds.608.2021.01.26.16.21.35; Tue, 26 Jan 2021 16:21:59 -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 S2388777AbhAZX0M convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Jan 2021 18:26:12 -0500 Received: from szxga03-in.huawei.com ([45.249.212.189]:2878 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389172AbhAZQ6v (ORCPT ); Tue, 26 Jan 2021 11:58:51 -0500 Received: from DGGEMM403-HUB.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4DQC9x6499z5JF7; Wed, 27 Jan 2021 00:39:17 +0800 (CST) Received: from dggemm753-chm.china.huawei.com (10.1.198.59) by DGGEMM403-HUB.china.huawei.com (10.3.20.211) with Microsoft SMTP Server (TLS) id 14.3.498.0; Wed, 27 Jan 2021 00:40:48 +0800 Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggemm753-chm.china.huawei.com (10.1.198.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Wed, 27 Jan 2021 00:40:47 +0800 Received: from lhreml710-chm.china.huawei.com ([169.254.81.184]) by lhreml710-chm.china.huawei.com ([169.254.81.184]) with mapi id 15.01.2106.006; Tue, 26 Jan 2021 16:40:45 +0000 From: Shameerali Kolothum Thodi To: Robin Murphy CC: "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "jean-philippe@linaro.org" , "will@kernel.org" , "linuxarm@openeuler.org" , "Zengtao (B)" Subject: RE: [PATCH] iommu: Check dev->iommu in iommu_dev_xxx functions Thread-Topic: [PATCH] iommu: Check dev->iommu in iommu_dev_xxx functions Thread-Index: AQHW8+RNdZVLOLYLIk+ZoY3uV2Gpc6o57K4AgAAuUAA= Date: Tue, 26 Jan 2021 16:40:45 +0000 Message-ID: <8654e506fa26443f8f4413ec8fd96bf7@huawei.com> References: <20210126130629.8928-1-shameerali.kolothum.thodi@huawei.com> <20210126135039.000039a0@arm.com> In-Reply-To: <20210126135039.000039a0@arm.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.47.82.74] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Robin, > -----Original Message----- > From: Robin Murphy [mailto:robin.murphy@arm.com] > Sent: 26 January 2021 13:51 > To: Shameerali Kolothum Thodi > Cc: linux-kernel@vger.kernel.org; iommu@lists.linux-foundation.org; > jean-philippe@linaro.org; will@kernel.org; linuxarm@openeuler.org; Zengtao > (B) > Subject: Re: [PATCH] iommu: Check dev->iommu in iommu_dev_xxx functions > > On Tue, 26 Jan 2021 13:06:29 +0000 > 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 a > > crash in iommu vendor driver code. Hence make?sure we check that. > > > > Signed-off-by: Shameer Kolothum > > --- > > drivers/iommu/iommu.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index > > ffeebda8d6de..cb68153c5cc0 100644 > > --- a/drivers/iommu/iommu.c > > +++ b/drivers/iommu/iommu.c > > @@ -2867,7 +2867,7 @@ bool iommu_dev_has_feature(struct device *dev, > > enum iommu_dev_features feat) { > > const struct iommu_ops *ops = dev->bus->iommu_ops; > > > > - if (ops && ops->dev_has_feat) > > + if (dev->iommu && ops && ops->dev_has_feat) > > return ops->dev_has_feat(dev, feat); > > Might make sense to make these more self-contained, e.g.: > > if (dev->iommu && dev->iommu->ops->foo) > dev->iommu->ops->foo() Right. Does that mean adding ops to "struct dev_iommu" or retrieve ops like below, if (dev->iommu && dev->iommu->iommu_dev->ops->foo) dev->iommu->iommu_dev->ops->foo() Sorry, not clear to me. Thanks, Shameer