Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp255334imw; Fri, 15 Jul 2022 02:31:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sRagYTomj0gmbEStFomt9uccIawlPj8uW4NODOhTzlMAT1tfFbkb2DUU/Sq08I5U0sEli7 X-Received: by 2002:a17:906:c7c1:b0:711:d2e9:99d0 with SMTP id dc1-20020a170906c7c100b00711d2e999d0mr12839726ejb.639.1657877481133; Fri, 15 Jul 2022 02:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657877481; cv=none; d=google.com; s=arc-20160816; b=vKLX0LEBVFjKPmLTNLkfUbjiRPjjQxGcMYgaTSouHXT7wpOa1RxUNGKVCtC3HMPG+D a/FSuDxRiKNYET5xVPg76qJ1mARrtuljEzfe4xarXcEmNOHxChemsmIlVFwMyKWhhJmI wtXMChqkq558tSbkhqE8seYkn2RrG5GCH7AH8kZN346vEbQ/QXCXAI/pkQYEBRLAOCw+ vHMZnNavc6arcg/N9mDs8WYTUHjdpJxoOLYtBV9fY6LL6gYOZlgDxUvOgHfQFgPhFWSC n7WL9YRNHy7BQ6M5BAEkH2Lzah7nMbEDykXYGoTpD6CCs6MZvI8Mapi/Vt/yWMQ0S4nH Wgyw== 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=tuFF6yTd69Nr4xModXMUry0FfI0hK8wTxfwhUF8KhYY=; b=tKGzC43GqgzekG2c2O9vnCy7AKb7QY8cBz0ukOv8aomTHXmy8ndfJABtyTW+RXq0F0 cv01p7XIofa4x1Yrcc0fjpgOGImXHv/wMgN/W9s16Z7vK9XaBw6bUzDkbQLou0KC5oUR lc7tRmJn9i8cFnvxbjun8bzwIMg5RuIZ+o/ILfIc1cD83W8TNdkJpT5vkJ16q2jB87U7 YDTcoMSXJZc0KIvV/G+8KWPt1caLRQevfBb2LpYCWsyg/9wO2QNdh7qN2za0dxAZvpPd d37UwWPENrE1YKVshM04eCRk0iXF8z6+AgjbKt4Yp1fInZv1SZfHrDwZnGyVpwSjdM+f 106w== 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 hp35-20020a1709073e2300b00729c19c5106si5348618ejc.999.2022.07.15.02.30.55; Fri, 15 Jul 2022 02:31:21 -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 S232049AbiGOJ3N (ORCPT + 99 others); Fri, 15 Jul 2022 05:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233344AbiGOJ24 (ORCPT ); Fri, 15 Jul 2022 05:28:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8A81DE9F for ; Fri, 15 Jul 2022 02:28:54 -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 D74EB1474; Fri, 15 Jul 2022 02:28:54 -0700 (PDT) Received: from [10.57.86.139] (unknown [10.57.86.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A3A13F792; Fri, 15 Jul 2022 02:28:53 -0700 (PDT) Message-ID: <5d056fea-ee52-b7f8-a8c1-095f695ac805@arm.com> Date: Fri, 15 Jul 2022 10:28:48 +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: Joerg Roedel , Yang Yingliang 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> From: Robin Murphy In-Reply-To: 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_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-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? Robin. >> Fixes: ac9a5d522bb8 ("iommu/dma: Fix race condition during iova_domain initialization") >> Reported-by: Hulk Robot >> 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