Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3081147pxb; Fri, 12 Feb 2021 08:43:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxVr5EwgulHP4zq9h1eGcHX4UGHwlBXgr2mn/HWch4zsRZTFqjksgS4nlp7rkpB7pKcW0Q X-Received: by 2002:a05:6402:12d6:: with SMTP id k22mr4267264edx.368.1613148192046; Fri, 12 Feb 2021 08:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613148192; cv=none; d=google.com; s=arc-20160816; b=bCUPbk2rJFwcLI8g1b2f5CKNTnHxJ84vxuGNJTQ+2W6H4QeS7nRtz0D34UShmU34CE t0xZ6MIXq+eOKCedaknWUlzsxyEgk1W2jaMdjYoxJdGmJBp56FfvOWJ6a4oE/iTGTSat hRNFs2Fj3j4cz4K8ejSieb9B4+vIyatH0IQ3YCx7omTpr0i774zD9aMsCCbOG92/+E5H vi5CNcNHLeX1PiqaPppiWcbQQI6VI2pQFRsu1hUP/t3uqDhW6E+pCr0a7StJzowa3CQb Ad/TTKQdKCOZbIYGYatdtHnsEiw4+0UaRnm9FjMazJfY3vcc09gge4D1vIqJnM6m1Vgh QQEQ== 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=yOv9QSVdCnT8jSJaahRktyg3es1kMdp2GuXXS0z/bJg=; b=cOB8aZjJr+ZXdGdwDG6pnJLNu5BLXsjsowFHFA+jcMXoRpa/HO42Z0EXPPOoUGKuBr qUHf/LrzSblt58Vlmw1xTXwHqRak4yRAvScIbh13D+wgO2ZFuwkM7ZW+0zvnBvcui9J9 C9MM4kh4OpU6/uZGxiv1sc+ZmCrGiCi5E5y3tqiqoZn6PleTUNf1bkCyatHtu593AHGn vQ26lduYkvXfoLmw2t4M3rKKC9JlkQNSPLAOTiiYa/bw8Wd+zEUa2+Q8ZskE+aSOGfVl VGNANzqtmHhA4lEuCeA+lxj/kI2P8t8aw5Ra3g0izxOHFWU3aymL8VTRMsu5LMhiB9qQ A8Ag== 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 a11si7043278edn.318.2021.02.12.08.42.47; Fri, 12 Feb 2021 08:43:12 -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 S231263AbhBLQlq (ORCPT + 99 others); Fri, 12 Feb 2021 11:41:46 -0500 Received: from foss.arm.com ([217.140.110.172]:39678 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbhBLQj3 (ORCPT ); Fri, 12 Feb 2021 11:39:29 -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 111971063; Fri, 12 Feb 2021 08:38:41 -0800 (PST) Received: from [10.57.49.26] (unknown [10.57.49.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B16743F73B; Fri, 12 Feb 2021 08:38:39 -0800 (PST) Subject: Re: [PATCH v2] iommu: Check dev->iommu in iommu_dev_xxx functions To: Shameerali Kolothum Thodi , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" Cc: "joro@8bytes.org" , "jean-philippe@linaro.org" , "will@kernel.org" , "Zengtao (B)" , "linuxarm@openeuler.org" References: From: Robin Murphy Message-ID: Date: Fri, 12 Feb 2021 16:38:33 +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: 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-02-12 14:54, Shameerali Kolothum Thodi wrote: > Hi Robin/Joerg, > >> -----Original Message----- >> From: Shameer Kolothum [mailto:shameerali.kolothum.thodi@huawei.com] >> Sent: 01 February 2021 12:41 >> To: linux-kernel@vger.kernel.org; iommu@lists.linux-foundation.org >> Cc: joro@8bytes.org; robin.murphy@arm.com; jean-philippe@linaro.org; >> will@kernel.org; Zengtao (B) ; >> linuxarm@openeuler.org >> Subject: [Linuxarm] [PATCH v2] iommu: Check dev->iommu in iommu_dev_xxx >> functions >> >> 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. >> >> Also added iommu_ops to the "struct dev_iommu" and set it if the dev >> is successfully associated with an iommu. >> >> Fixes: a3a195929d40 ("iommu: Add APIs for multiple domains per device") >> Signed-off-by: Shameer Kolothum >> --- >> v1 --> v2: >> -Added iommu_ops to struct dev_iommu based on the discussion with Robin. >> -Rebased against iommu-tree core branch. > > A gentle ping on this... Is there a convincing justification for maintaining yet another copy of the ops pointer rather than simply dereferencing iommu_dev->ops at point of use? Robin. > Thanks, > Shameer > >> --- >> drivers/iommu/iommu.c | 19 +++++++------------ >> include/linux/iommu.h | 2 ++ >> 2 files changed, 9 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c >> index fd76e2f579fe..6023d0b7c542 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -217,6 +217,7 @@ static int __iommu_probe_device(struct device *dev, >> struct list_head *group_list >> } >> >> dev->iommu->iommu_dev = iommu_dev; >> + dev->iommu->ops = iommu_dev->ops; >> >> group = iommu_group_get_for_dev(dev); >> if (IS_ERR(group)) { >> @@ -2865,10 +2866,8 @@ 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 (ops && ops->dev_enable_feat) >> - return ops->dev_enable_feat(dev, feat); >> + if (dev->iommu && dev->iommu->ops->dev_enable_feat) >> + return dev->iommu->ops->dev_enable_feat(dev, feat); >> >> return -ENODEV; >> } >> @@ -2881,10 +2880,8 @@ >> 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 (ops && ops->dev_disable_feat) >> - return ops->dev_disable_feat(dev, feat); >> + if (dev->iommu && dev->iommu->ops->dev_disable_feat) >> + return dev->iommu->ops->dev_disable_feat(dev, feat); >> >> return -EBUSY; >> } >> @@ -2892,10 +2889,8 @@ >> 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 (ops && ops->dev_feat_enabled) >> - return ops->dev_feat_enabled(dev, feat); >> + if (dev->iommu && dev->iommu->ops->dev_feat_enabled) >> + return dev->iommu->ops->dev_feat_enabled(dev, feat); >> >> return false; >> } >> diff --git a/include/linux/iommu.h b/include/linux/iommu.h >> index 524ffc2ff64f..ff0c76bdfb67 100644 >> --- a/include/linux/iommu.h >> +++ b/include/linux/iommu.h >> @@ -354,6 +354,7 @@ struct iommu_fault_param { >> * @fault_param: IOMMU detected device fault reporting data >> * @fwspec: IOMMU fwspec data >> * @iommu_dev: IOMMU device this device is linked to >> + * @ops: iommu-ops for talking to the iommu_dev >> * @priv: IOMMU Driver private data >> * >> * TODO: migrate other per device data pointers under iommu_dev_data, >> e.g. >> @@ -364,6 +365,7 @@ struct dev_iommu { >> struct iommu_fault_param *fault_param; >> struct iommu_fwspec *fwspec; >> struct iommu_device *iommu_dev; >> + const struct iommu_ops *ops; >> void *priv; >> }; >> >> -- >> 2.17.1 >> _______________________________________________ >> Linuxarm mailing list -- linuxarm@openeuler.org >> To unsubscribe send an email to linuxarm-leave@openeuler.org