Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2673876pxb; Thu, 10 Feb 2022 03:04:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwP18IDdBUykRalqPnJFQQtbYmbFK8WIJgZnJ0+v9FzG4zbU+6FkeDjATsSXcMLKTe8pKBz X-Received: by 2002:a17:90b:3ece:: with SMTP id rm14mr2204444pjb.220.1644491062120; Thu, 10 Feb 2022 03:04:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644491062; cv=none; d=google.com; s=arc-20160816; b=ut31W5kOwFhNaGvYmpM1Y734TAx21XEPPKf27WZeQHpHj3+QETq/mvp/yCulOyMF5Y F5qI17l1v2b4eiC3e1t9SzRE6XZtg0Y9yPLte9/OSgs1hJ7IemgXa6h5kPRrub+0SV3M DvT+UAGAqqKSpjl9Wc0bARfgDIklsbQAYWcQ0kw95f2JZEvmMpec00uJMlVfwCCzAq1J JEWfN1qbtA/Ojc43Fb3iyACZXsBqS4k+MFei0HoyLdgrHD/9ZOT5YIldohJwteBZNp1G 3KVMBdCA0ALCytEh6CRofCKECmAkocNLn0PEq6YJ8igmMokUzM+DcOGTNSq+deqObBAg tIQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=qvQtscv+QCCAwPNoKi5DiLptv++YW46bB1ZsZLtnGa4=; b=GQL7JLcSy8gxn4YMSfJets+zsID/YUo9B6srxb9JMWXDvmmzujorpAjgD8oNQTNQ9l uVU17L+dwCKkFCeT+LTikT28p7zoMOygNXxRfMre9Rr6fntP3LMubIPBNyYNQlVa8rAX pFlSa/T27GQhBW7JQ3yCYPBUJUfGxG4MR92qL6a21JIE4gNd8qCNX5sdm99+sYKyAUCQ IA2CjnUxmXqHR8kBHjAy8KOzzilajUWAFgI11P9lUPjTynBiIyVEo6sFHQh76OP4qHlY n5h0qWohwznadZvEQsUEyyfsj18lqPZYMKqKgws+crnRNLkpPLRSxUVkaReeavTFwZT+ Mn6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16si21369507pfg.76.2022.02.10.03.04.09; Thu, 10 Feb 2022 03:04:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239986AbiBJKnZ (ORCPT + 99 others); Thu, 10 Feb 2022 05:43:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239984AbiBJKnX (ORCPT ); Thu, 10 Feb 2022 05:43:23 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9B088FFC for ; Thu, 10 Feb 2022 02:43:24 -0800 (PST) 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 622D9ED1; Thu, 10 Feb 2022 02:43:24 -0800 (PST) Received: from [10.57.70.89] (unknown [10.57.70.89]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 845013F718; Thu, 10 Feb 2022 02:43:23 -0800 (PST) Message-ID: Date: Thu, 10 Feb 2022 10:43:17 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH] iommu: explicitly check for NULL in iommu_dma_get_resv_regions() Content-Language: en-GB To: Aleksandr Fedorov , Joerg Roedel , Will Deacon , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <5481021644415780@myt5-a5512e99e394.qloud-c.yandex.net> From: Robin Murphy In-Reply-To: <5481021644415780@myt5-a5512e99e394.qloud-c.yandex.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-02-09 14:09, Aleksandr Fedorov wrote: > iommu_dma_get_resv_regions() assumes that iommu_fwspec field for > corresponding device is set which is not always true. Since > iommu_dma_get_resv_regions() seems to be a future-proof generic API > that can be used by any iommu driver, add an explicit check for NULL. Except it's not a "generic" interface for drivers to call at random, it's a helper for retrieving common firmware-based information specifically for drivers already using the fwspec mechanism for common firmware bindings. If any driver calls this with a device *without* a valid fwnode, it deserves to crash because it's done something fundamentally wrong. I concur that it's not exactly obvious that "non-IOMMU-specific" means "based on common firmware bindings, thus implying fwspec". Robin. > Currently it can work by accident since compiler can eliminate > the 'iommu_fwspec' check altogether when CONFIG_ACPI_IORT=n, but > code elimination from optimizations is not reliable. > > Signed-off-by: Aleksandr Fedorov > --- > A compilation failure has been observed on a gcc-compatible compiler based on EDG. > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index d85d54f2b549..474b1b7211d7 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -382,10 +382,10 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) > */ > void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) > { > + struct iommu_fwspec *iommu_fwspec = dev_iommu_fwspec_get(dev); > > - if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) > + if (iommu_fwspec && !is_of_node(iommu_fwspec->iommu_fwnode)) > iort_iommu_msi_get_resv_regions(dev, list); > - > } > EXPORT_SYMBOL(iommu_dma_get_resv_regions); > > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu