Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4240635pxb; Tue, 26 Jan 2021 16:46:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjTJJsZNV1GNG1xmNyK6HMFQiWQHIoAlxdHAUOYS963L1hQAb6yKVDxXrU3JqRzfyj/nwl X-Received: by 2002:a17:906:3bc2:: with SMTP id v2mr5061214ejf.291.1611708366724; Tue, 26 Jan 2021 16:46:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611708366; cv=none; d=google.com; s=arc-20160816; b=HAGFES+EtaJXsG3KyaWbFAyPMnH9stb5M065WtlhYmRcW9oUil/G5GFsLlGnjrD216 eF8tg2F38YDZwgRlP3Ee3u6L1TAu+keZbLHeBp+CNOqZyD0sjdSpqs3tTxjtmAL+UDsQ 4BgGR4RPBKdk6YQVCVQNi94hngZR4k9cnPhWGsoah2J2igGY8admK8aamysIkwExESLv BwnU2gVNRFnpcSJZk99cN49EyYK186XrPh/viPNKRq8PAIJJD4dwTKbWqZ8j1qxK3HFh reizGBVPh9OsWHMTgxnJQP6lb5+eecF6udkgiWrPtAtTmbgJH2iFB1V7eDs0G+0CY3rK yFBQ== 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=KVer87+/yq3PCjwxR72ebKZbOdakKNN4S6K5qT9PAi0=; b=DsB0Ap5EYQb3TMgztqQweIXLhkafRhc3cFBU/w/bwwOC4Np5L2q0cufaYcHc5LJTZo RdUZyLPGCcz8vjGziRooKoicTMYKtiJL+b0HSzrjAITlf+8xZZhbdvJNylLIu0Ri/cR0 +9IQZ4Zxe88scfTZePYDn9wIIhg9+23UB+7JhWEbQT8Qa5GCKGzyEQuIG/uoTbhpQujP 4uhipfBL7n4S6lAeJn75eqhGj5MLVP4JGuzvekuDa0SOTcqlMnbaP1EF3dLlg0lzcBHs EgzyPSKdLq8otTDxVIbcMFAsRIEnujrHOLD42H1Lq1UeDdt1gGWBmXUyd+GWNcqacoYx Iomg== 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 gb36si118780ejc.470.2021.01.26.16.45.42; Tue, 26 Jan 2021 16:46:06 -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 S2404343AbhA0AcC (ORCPT + 99 others); Tue, 26 Jan 2021 19:32:02 -0500 Received: from foss.arm.com ([217.140.110.172]:49436 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387609AbhAZRZj (ORCPT ); Tue, 26 Jan 2021 12:25:39 -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 53A0331B; Tue, 26 Jan 2021 09:24:52 -0800 (PST) Received: from [10.57.43.46] (unknown [10.57.43.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 207543F66E; Tue, 26 Jan 2021 09:24:51 -0800 (PST) Subject: Re: [PATCH] iommu: Check dev->iommu in iommu_dev_xxx functions 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)" References: <20210126130629.8928-1-shameerali.kolothum.thodi@huawei.com> <20210126135039.000039a0@arm.com> <8654e506fa26443f8f4413ec8fd96bf7@huawei.com> From: Robin Murphy Message-ID: <5828b2f9-e1d3-fd96-ebf3-2a38c903c9c3@arm.com> Date: Tue, 26 Jan 2021 17:24:45 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <8654e506fa26443f8f4413ec8fd96bf7@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-01-26 16:40, Shameerali Kolothum Thodi wrote: > 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. Bleh, I was thinking that dev->iommu pointed directly to a struct iommu_device there, sorry. There are too many things and not enough distinct names for the things. But yeah, basically that if the device's "I am associated with an IOMMU" data is set, then by construction it must lead to a set of ops which are definitely valid. Conceptually it's cleaner than combining two different data sources (the per-device info plus the bus ops which may or may not be relevant to a given device), even if cosmetically we have to juggle through practically every possible permutation of the names "iommu" and "device" to get there :/ Robin.