Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2146311imn; Mon, 1 Aug 2022 12:56:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR4mNJlxH0XdI6v3+tXg6B/lgB53rVLAA1JbZ18+OjzxaMCugqtjYW0laWgJaPW+2wC5Ecr7 X-Received: by 2002:a17:906:9bc4:b0:730:9edc:40b2 with SMTP id de4-20020a1709069bc400b007309edc40b2mr211335ejc.155.1659383779915; Mon, 01 Aug 2022 12:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659383779; cv=none; d=google.com; s=arc-20160816; b=EP7L9+SKPtYMszTdUae+X2DfELwmrf68a3JtUEEpV2cAgsAFB7pEwm61bZFfYwYUeb a6lkzzdok1QVL8MYqrYRxEkTkRq1Cj8FWIR/dRSEjwC18RVMeq6MS13H/k/uyWrAJBkU NOanrXudAbkFug6+S4SjN0lc1xMZ9wQtlU9AqWYIg+uN7+IRgmtIy2c9TyoAGgjhsCss 0Rqkt2CaWJ5kfMSJAzH9koHHzg3FgIUWEw7SycqzsyIvtJKLxV7OFOJbQA2s5u7AEszn bFAEJg5PFfZ5uyHa8lCr4YgkM+Mpq3QgcfzsDC5DgXK9HX0AW9xjaJUza2rzIhdztG6Y pCHw== 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:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=6LXVXGknuYKIJLxM0pf9WB5b2vTD674hYJNFjAmm0Ac=; b=SOJYDuzaTemcNLezuQJTAvrJnrOWDuKChWv8hB0wS1E1z8/gYMZPIV/yM+0NH3Oewm btevihrGl1+B3eqX+TFHl0jOKLIIN7u6pI3AzQOwexMmupmkedHKAd+FjExMnKYro/zS ZsDEZDqOB533r9E1+QlPLRBlypKS/So61KO0eb9bgO6He5xkJ7AzdKsmx7UUQtt3tKRt 1L7rplVTAhN7ruul5Rfilx8iJpSF+r3DwAIGviwMtehHu3VPQ34hRHipohMQ20btKg0i FyfL2q8V+Sc7VYp3dA/8AvFQmf5oyoSko63aBoko4MW6pOio9vkDO+2Ti04kauT1QYar IKuA== 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 hv13-20020a17090760cd00b007308bd44018si3731204ejc.550.2022.08.01.12.55.55; Mon, 01 Aug 2022 12:56:19 -0700 (PDT) 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 S235076AbiHATsr (ORCPT + 99 others); Mon, 1 Aug 2022 15:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235052AbiHATsn (ORCPT ); Mon, 1 Aug 2022 15:48:43 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54B182F64E for ; Mon, 1 Aug 2022 12:48:40 -0700 (PDT) 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 9D5D2139F; Mon, 1 Aug 2022 12:48:40 -0700 (PDT) Received: from [10.57.10.23] (unknown [10.57.10.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C76103F67D; Mon, 1 Aug 2022 12:48:38 -0700 (PDT) Message-ID: Date: Mon, 1 Aug 2022 20:48:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH -next] iommu/dma: Fix missing mutex_init() in iommu_get_msi_cookie() Content-Language: en-GB To: Yang Yingliang , Joerg Roedel Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, iommu@lists.linux-foundation.org, will@kernel.org, yf.wang@mediatek.com References: <20220627085533.1469141-1-yangyingliang@huawei.com> <5d056fea-ee52-b7f8-a8c1-095f695ac805@arm.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE 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-07-18 07:42, Yang Yingliang wrote: > Hi, > > On 2022/7/15 17:28, Robin Murphy wrote: >> On 2022-07-15 08:49, Joerg Roedel wrote: >>> Adding Robin. >>> >>> On Mon, Jun 27, 2022 at 04:55:33PM +0800, Yang Yingliang wrote: >>>> cookie_alloc() is called by iommu_get_dma_cookie() and >>>> iommu_get_msi_cookie(), >>>> but the mutex is only initialized in iommu_get_dma_cookie(), move >>>> mutex_init() >>>> into cookie_alloc() to make sure the mutex will be initialized. >> >> The mutex is only used in iommu_dma_init_domain(), which is only >> called by iommu_setup_dma_ops() for IOMMU_DOMAIN_DMA domains. How is >> there a problem here? > It's no problem now, but I thinks it's better to initialize the 'mutex' > in cookie_alloc() to make code stronger. Stronger against what, though? The sole reason this mutex exists at all is as a temporary measure to protect the IOVA domain from concurrent initialisation - I suppose in hindsight it might have made sense to define it inside the union, but I don't see much point in churning that now. I'd rather spend the time on continuing to get the iommu_probe_device() path sorted out so that we don't have the whole problematic driver-probe-time-replay mess in the first place and this mutex can be reverted ASAP. >>>> Fixes: ac9a5d522bb8 ("iommu/dma: Fix race condition during >>>> iova_domain initialization") >>>> Reported-by: Hulk Robot Please teach your robot to care about things that actually matter. All it's "reporting" here is that it isn't clever enough to follow control flow across multiple compilation units, otherwise it should have seen the matching iommu_is_dma_domain() checks between __iommu_domain_alloc() and iommu_setup_dma_ops(). Having to explain this is not a good use of the kernel community's time and effort. Thanks, Robin. >>>> Signed-off-by: Yang Yingliang >>>> --- >>>>   drivers/iommu/dma-iommu.c | 2 +- >>>>   1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c >>>> index 1910f4f1612b..e29157380c48 100644 >>>> --- a/drivers/iommu/dma-iommu.c >>>> +++ b/drivers/iommu/dma-iommu.c >>>> @@ -294,6 +294,7 @@ static struct iommu_dma_cookie >>>> *cookie_alloc(enum iommu_dma_cookie_type type) >>>>       if (cookie) { >>>>           INIT_LIST_HEAD(&cookie->msi_page_list); >>>>           cookie->type = type; >>>> +        mutex_init(&cookie->mutex); >>>>       } >>>>       return cookie; >>>>   } >>>> @@ -311,7 +312,6 @@ int iommu_get_dma_cookie(struct iommu_domain >>>> *domain) >>>>       if (!domain->iova_cookie) >>>>           return -ENOMEM; >>>>   -    mutex_init(&domain->iova_cookie->mutex); >>>>       return 0; >>>>   } >>>>   -- >>>> 2.25.1 >> .