Message ID | TYCP286MB2323D71DEC1D008BEA6F7ABBCA399@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp54337dyb; Wed, 2 Nov 2022 09:02:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Ne8dvFQMFvR+HGieTaJCd8GwkNWK9SZL2Mac1fmHmPF0+da2ALlhR2AyfbwcMo0ycWlbo X-Received: by 2002:a17:906:dac9:b0:780:ab6f:591f with SMTP id xi9-20020a170906dac900b00780ab6f591fmr24591539ejb.77.1667404926778; Wed, 02 Nov 2022 09:02:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667404926; cv=pass; d=google.com; s=arc-20160816; b=wBWSEQ3BzOarpkuVED8dR6vTx9ewD55OJahFEvMK2d5HvevMhVr/a3VmDg4Ytm/kfG UwKXvud+LzlWvX0cN31ZpYZ75v+zntPT0f7jbCrRQ/OIE7ML95zqxzqMYRpfQoY8EokK ERx+SDnljPi2VbEyNxwBCFum6tR7o3sqTxjLk3q4LhSeDY6UAYiku0uGY/zYLeVsFijp GEoIFpdMqeU0AZOOAtJFbwMesyKmaMvGPX0pY2nqxy8R+FEcfMsIe4ER3A2L41mJzYEX +/MaXt5TzgHIn1QHaOp6gjsvcGQ585CygK6Hzjl/7ZQFsJRd4mHFRdx6SsC8fnx5KLjV Ir+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=/xQxRB+vXWAaN6lf7I9+zqAqmt3lidWLUa0xSH7X+hw=; b=hfgt+ZiH1vVHDReAwX3q4XKzhQ5pKqRgJyGz5cd3ljqn8BVinmxROpGwN38iijtcpM IjoNXtZH9i6RnytBB/X68ykxBEqb4X/lFBTYQbDVC1FOdcLJbE3VLIRxKs1F8CANjtJz SLZEuPSU36XU3IiCDHKlD9D5K0xudxEQVft5ncLfH1lp/JLrAav5kdxaMeAsK0shIhfF aWvNqVpv5FX/VEDH2vnzArtBfWxptxg2kYfYimn0zgw2DgmE3SknMtL5/h9DSJvHewdx YYsfMHFsHavl7r+DM+a+gG+/V8MEaXhCykfPU5zxsMIQ1hwYH6Jzv7hu/5+O3o42bn8i ntrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=YWpC3q2U; arc=pass (i=1); 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd8-20020a1709069b8800b007ae10525563si135646ejc.991.2022.11.02.09.01.31; Wed, 02 Nov 2022 09:02:06 -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; dkim=pass header.i=@outlook.com header.s=selector1 header.b=YWpC3q2U; arc=pass (i=1); 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230242AbiKBP7M (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Wed, 2 Nov 2022 11:59:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbiKBP6u (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Nov 2022 11:58:50 -0400 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2017.outbound.protection.outlook.com [40.92.99.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E542BB0A; Wed, 2 Nov 2022 08:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D8zx23gSFiKXhU9W7qBQf44Tj0qxEZXpqPzqHhky0l4wCoHzvH44jaUy67zRohyCV3LHUZvc3zxTnmQzzf77PJjPnpuSdSlD4W9j/8ivpQU7bKGYiVySh9ypB6+7ZTtJuSp35ngSnLLIQUOvpGiLh9z4JmVme3vsrEB7w4v7SnFBn8zdjDIMyb2uN56va8TKA/lGbnd8xbdQHVUMBec/kjAWDT8p1fNXUUjHCu6w7v4UFAfgVEHWXrmvXzowy4syMkzZZkCA7J+bTQOGcqtxD4qzDswTPmCVmrJGq5hNDY/KUqzA4JW2Rznor1vhIdmk/w3bOmRGn6uh3I9Ca9tNCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/xQxRB+vXWAaN6lf7I9+zqAqmt3lidWLUa0xSH7X+hw=; b=kJIaBC99mT7RxyQu5XkVZoPPxjvkIikZMOkPCGsVf3Tstvm08VUGtgalp5WcNmXFdrSeP5i8EnhV1gQlR57+qdCCiDrcfV2n97qzvnu8VtLpLNauvGtqoFhIAqy2yrEUUDkGxB9apRO2Pc+qhxYlsXXQZe9Qb51cwd9G8JcB+YxLJEwiDIX3ttT0cjNXzZ1mRyFgjpU6GreKwSiQIstw1fjL7ZPppjsXjmlCNtbS3WIIMvye3Skckk108MTfi0+W6VtKgsDXr6JCqy3r9cu9F4vgODlqq3qB47indn2eNX/NqOYLtSfpKZ5mhin1DnJolBeqwmBpU7BYIYA0cohQoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/xQxRB+vXWAaN6lf7I9+zqAqmt3lidWLUa0xSH7X+hw=; b=YWpC3q2UCJljzO5os7oRs2r1qTqlhvWxP9WKS/Icy5RVAL/T4cVID/nsnUdvD9jIxTlx66D4LOGMCKfGFt7rHMy4LKvJ1YVBPA8HieAJVq/Usuf3WrdSkZI4ElpxnnmQSyn5NXIty44Un3ihQev+El4NKh5O/fyzvrKNwu7irdyWTRzQnE8mAqmYZBFLdXOt/pC/wQdiss/pD78C2WjjA6bfWqjk51PTpViflsU/FlUCXxr3hd0TPZXHYqPAcQub0ATjm7YjwADjSdxsmU8+Wcvg/TsOFGOTiR4Kjg6UOPfc8V0jcvvSpkGYw0O9zCx6vJnokPReil2Jl0vOEu1ULQ== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OS3P286MB2422.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Wed, 2 Nov 2022 15:58:42 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5%9]) with mapi id 15.20.5791.022; Wed, 2 Nov 2022 15:58:42 +0000 From: Dawei Li <set_pte_at@outlook.com> To: sumit.semwal@linaro.org, christian.koenig@amd.com Cc: benjamin.gaignard@collabora.com, labbott@redhat.com, Brian.Starkey@arm.com, jstultz@google.com, afd@ti.com, sspatil@android.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, Dawei Li <set_pte_at@outlook.com> Subject: [PATCH v3] dma-buf: fix racing conflict of dma_heap_add() Date: Wed, 2 Nov 2022 23:58:23 +0800 Message-ID: <TYCP286MB2323D71DEC1D008BEA6F7ABBCA399@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [Hb13McbHy8iya2slT4EkVubLNUyTNzO/] X-ClientProxiedBy: SGAP274CA0006.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::18) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221102155823.406044-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OS3P286MB2422:EE_ X-MS-Office365-Filtering-Correlation-Id: 52dd0f8a-61d7-4684-9574-08dabceb1d59 X-MS-Exchange-SLBlob-MailProps: ZLYX9kf+sFZrWcqlYuxsQ4SinJ0dkCiqXcsavXO7jaSL3FwrSbAMOCLBPddQdbgOgPvnX69oxlNgKJ13hRvJznrLWDHsVacx/W3igzW+0IarXyvR90JSYQOssUT4M9UQ9pn45aEYld6rL6Z7thebJwH4CTCPdVsI8sOSlhCLLx7EkaIJV1CVvk3qPXrGFGxqhyQH70hgYXtXNCAx/ZbqE5GzvwcM23aX2CfS34ueYVW06gNOy/1Xk5AqIc3hemdUfECHrkBoNspWEhHy6blrgUjbi/a5dJxqgIqGIjTRktm9zTFXH13YIGDwLThb+rxl3jSzeeYOqJxZkp2wZ9X3tF5CKL1a4K792NeH0deN+nHJ+Vmc6ZFZmzb/ccXfZdTwEAjUKbBd9KW7MQx6apt2OKbaD4juwuREzkziQs2SWcr6he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f/OyYiJXKyVr3Jr98WZGxMRMHhmytiNjNPKxFH1MsElspo05o1ng2bB5kh3F5lUFU1KlivwVX1ObOVLufGwKcIVWLOs18sRMx7D2S/MPq4ItzhvGwY/WQZ+u3cf7s5p0Fr7opWXBYPDxSm2CXvMD3VSi3aqTWAM5SH+R0f2aCHY0n/3bxmF96+GuAIuXYNyfFUp4eSjb5QR1Y/dMe/ZOzwpSbPfej/KURGStKVnUzRCuelRFKRH/O5wZNsUUCSU4SHy4Z0XpToj6WYx10poST0xChP4VxIt/pIXWU9VyYqNfuCedUFdBPByMplf8LyG/5vG4RVWgsT/dJYaA20Q0zAx8y3Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52dd0f8a-61d7-4684-9574-08dabceb1d59 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2022 15:58:42.4905 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB2422 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748400788691599565?= X-GMAIL-MSGID: =?utf-8?q?1748400788691599565?= |
Series |
[v3] dma-buf: fix racing conflict of dma_heap_add()
|
|
Commit Message
Dawei Li
Nov. 2, 2022, 3:58 p.m. UTC
Racing conflict could be:
task A task B
list_for_each_entry
strcmp(h->name))
list_for_each_entry
strcmp(h->name)
kzalloc kzalloc
...... .....
device_create device_create
list_add
list_add
The root cause is that task B has no idea about the fact someone
else(A) has inserted heap with same name when it calls list_add,
so a potential collision occurs.
v1: https://lore.kernel.org/all/TYCP286MB2323950197F60FC3473123B7CA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM/
v1->v2: Narrow down locking scope, check the existence of heap before
insertion, as suggested by Andrew Davis.
v2->v3: Remove double checking.
Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework")
base-commit: 447fb14bf07905b880c9ed1ea92c53d6dd0649d7
Signed-off-by: Dawei Li <set_pte_at@outlook.com>
---
drivers/dma-buf/dma-heap.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
Comments
On Wed, Nov 2, 2022 at 8:59 AM Dawei Li <set_pte_at@outlook.com> wrote: > > Racing conflict could be: > task A task B > list_for_each_entry > strcmp(h->name)) > list_for_each_entry > strcmp(h->name) > kzalloc kzalloc > ...... ..... > device_create device_create > list_add > list_add > > The root cause is that task B has no idea about the fact someone > else(A) has inserted heap with same name when it calls list_add, > so a potential collision occurs. > > v1: https://lore.kernel.org/all/TYCP286MB2323950197F60FC3473123B7CA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM/ > > v1->v2: Narrow down locking scope, check the existence of heap before > insertion, as suggested by Andrew Davis. > > v2->v3: Remove double checking. > > Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework") > > base-commit: 447fb14bf07905b880c9ed1ea92c53d6dd0649d7 > > Signed-off-by: Dawei Li <set_pte_at@outlook.com> > --- > drivers/dma-buf/dma-heap.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) > > diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c > index 8f5848aa144f..7a25e98259ea 100644 > --- a/drivers/dma-buf/dma-heap.c > +++ b/drivers/dma-buf/dma-heap.c > @@ -233,18 +233,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > return ERR_PTR(-EINVAL); > } > > - /* check the name is unique */ > - mutex_lock(&heap_list_lock); > - list_for_each_entry(h, &heap_list, list) { > - if (!strcmp(h->name, exp_info->name)) { > - mutex_unlock(&heap_list_lock); > - pr_err("dma_heap: Already registered heap named %s\n", > - exp_info->name); > - return ERR_PTR(-EINVAL); > - } > - } > - mutex_unlock(&heap_list_lock); > - > heap = kzalloc(sizeof(*heap), GFP_KERNEL); > if (!heap) > return ERR_PTR(-ENOMEM); > @@ -283,13 +271,26 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > err_ret = ERR_CAST(dev_ret); > goto err2; > } > - /* Add heap to the list */ > + > mutex_lock(&heap_list_lock); > + /* check the name is unique */ > + list_for_each_entry(h, &heap_list, list) { > + if (!strcmp(h->name, exp_info->name)) { > + mutex_unlock(&heap_list_lock); > + pr_err("dma_heap: Already registered heap named %s\n", > + exp_info->name); > + err_ret = ERR_PTR(-EINVAL); > + goto err3; > + } > + } > + > + /* Add heap to the list */ > list_add(&heap->list, &heap_list); > mutex_unlock(&heap_list_lock); > > return heap; > - > +err3: > + device_destroy(dma_heap_class, heap->heap_devt); > err2: > cdev_del(&heap->heap_cdev); > err1: > -- > 2.25.1 > Reviewed-by: T.J. Mercier <tjmercier@google.com> Thanks!
On 11/2/22 10:58 AM, Dawei Li wrote: > Racing conflict could be: > task A task B > list_for_each_entry > strcmp(h->name)) > list_for_each_entry > strcmp(h->name) > kzalloc kzalloc > ...... ..... > device_create device_create > list_add > list_add > > The root cause is that task B has no idea about the fact someone > else(A) has inserted heap with same name when it calls list_add, > so a potential collision occurs. > > v1: https://lore.kernel.org/all/TYCP286MB2323950197F60FC3473123B7CA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM/ > > v1->v2: Narrow down locking scope, check the existence of heap before > insertion, as suggested by Andrew Davis. > > v2->v3: Remove double checking. The above version info should be in a cover letter or below the --- line so it doesn't end up in the commit message in tree. > > Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework") > > base-commit: 447fb14bf07905b880c9ed1ea92c53d6dd0649d7 > Same as above, plus this is an odd base, maybe just use "v6.1-rc2". > Signed-off-by: Dawei Li <set_pte_at@outlook.com> > --- > drivers/dma-buf/dma-heap.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) > > diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c > index 8f5848aa144f..7a25e98259ea 100644 > --- a/drivers/dma-buf/dma-heap.c > +++ b/drivers/dma-buf/dma-heap.c > @@ -233,18 +233,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > return ERR_PTR(-EINVAL); > } > > - /* check the name is unique */ > - mutex_lock(&heap_list_lock); > - list_for_each_entry(h, &heap_list, list) { > - if (!strcmp(h->name, exp_info->name)) { > - mutex_unlock(&heap_list_lock); > - pr_err("dma_heap: Already registered heap named %s\n", > - exp_info->name); > - return ERR_PTR(-EINVAL); > - } > - } > - mutex_unlock(&heap_list_lock); > - > heap = kzalloc(sizeof(*heap), GFP_KERNEL); > if (!heap) > return ERR_PTR(-ENOMEM); > @@ -283,13 +271,26 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > err_ret = ERR_CAST(dev_ret); > goto err2; > } > - /* Add heap to the list */ > + > mutex_lock(&heap_list_lock); > + /* check the name is unique */ > + list_for_each_entry(h, &heap_list, list) { > + if (!strcmp(h->name, exp_info->name)) { > + mutex_unlock(&heap_list_lock); > + pr_err("dma_heap: Already registered heap named %s\n", > + exp_info->name); > + err_ret = ERR_PTR(-EINVAL); > + goto err3; > + } > + } > + > + /* Add heap to the list */ > list_add(&heap->list, &heap_list); > mutex_unlock(&heap_list_lock); > > return heap; > - Would like to keep this new line after the return statement. Andrew > +err3: > + device_destroy(dma_heap_class, heap->heap_devt); > err2: > cdev_del(&heap->heap_cdev); > err1:
diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 8f5848aa144f..7a25e98259ea 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -233,18 +233,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) return ERR_PTR(-EINVAL); } - /* check the name is unique */ - mutex_lock(&heap_list_lock); - list_for_each_entry(h, &heap_list, list) { - if (!strcmp(h->name, exp_info->name)) { - mutex_unlock(&heap_list_lock); - pr_err("dma_heap: Already registered heap named %s\n", - exp_info->name); - return ERR_PTR(-EINVAL); - } - } - mutex_unlock(&heap_list_lock); - heap = kzalloc(sizeof(*heap), GFP_KERNEL); if (!heap) return ERR_PTR(-ENOMEM); @@ -283,13 +271,26 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) err_ret = ERR_CAST(dev_ret); goto err2; } - /* Add heap to the list */ + mutex_lock(&heap_list_lock); + /* check the name is unique */ + list_for_each_entry(h, &heap_list, list) { + if (!strcmp(h->name, exp_info->name)) { + mutex_unlock(&heap_list_lock); + pr_err("dma_heap: Already registered heap named %s\n", + exp_info->name); + err_ret = ERR_PTR(-EINVAL); + goto err3; + } + } + + /* Add heap to the list */ list_add(&heap->list, &heap_list); mutex_unlock(&heap_list_lock); return heap; - +err3: + device_destroy(dma_heap_class, heap->heap_devt); err2: cdev_del(&heap->heap_cdev); err1: