From patchwork Wed Jul 22 09:05:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 11677789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93BCD13B1 for ; Wed, 22 Jul 2020 08:54:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F7792084D for ; Wed, 22 Jul 2020 08:54:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F7792084D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8821A6B0003; Wed, 22 Jul 2020 04:54:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 832AC6B0005; Wed, 22 Jul 2020 04:54:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 748456B0006; Wed, 22 Jul 2020 04:54:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 5C5A96B0003 for ; Wed, 22 Jul 2020 04:54:13 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0CCA11827E91F for ; Wed, 22 Jul 2020 08:54:13 +0000 (UTC) X-FDA: 77065099986.18.verse42_1e0ff4126f34 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 322DC1A2F21B7 for ; Wed, 22 Jul 2020 08:53:46 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,qiang.zhang@windriver.com,,RULES_HIT:30054,0,RBL:147.11.146.13:@windriver.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04ygkir68wpe3936ybxf8spehzcahycmd43hwnt78mtnbnd1n8o1xzch7ppoery.m351464q3oqskcxgrmidpyqs71bkk35yk5bgtangqk7mp8j3kp8cmdqfunnx74b.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: verse42_1e0ff4126f34 X-Filterd-Recvd-Size: 2601 Received: from mail1.windriver.com (mail1.windriver.com [147.11.146.13]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Jul 2020 08:53:44 +0000 (UTC) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.2) with ESMTPS id 06M8rcie010699 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 22 Jul 2020 01:53:38 -0700 (PDT) Received: from pek-lpg-core1-vm1.wrs.com (128.224.156.106) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.487.0; Wed, 22 Jul 2020 01:53:37 -0700 From: To: CC: , Subject: [PATCH] mm/dmapool.c: add lock protect in dma_pool_destroy Date: Wed, 22 Jul 2020 17:05:16 +0800 Message-ID: <20200722090516.28829-1-qiang.zhang@windriver.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 322DC1A2F21B7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Zhang Qiang When traversing "pool->page" linked list, to prevent possible other path operations this list, causing it to be destroyed, we should add lock protect for this list in dma_pool_destroy func. Signed-off-by: Zhang Qiang --- mm/dmapool.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/dmapool.c b/mm/dmapool.c index f9fb9bbd733e..f7375b25af6c 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -267,6 +267,9 @@ static void pool_free_page(struct dma_pool *pool, struct dma_page *page) void dma_pool_destroy(struct dma_pool *pool) { bool empty = false; + LIST_HEAD(discard); + struct dma_page *page,*h; + unsigned long flags; if (unlikely(!pool)) return; @@ -281,8 +284,8 @@ void dma_pool_destroy(struct dma_pool *pool) device_remove_file(pool->dev, &dev_attr_pools); mutex_unlock(&pools_reg_lock); + spin_lock_irqsave(&pool->lock, flags); while (!list_empty(&pool->page_list)) { - struct dma_page *page; page = list_entry(pool->page_list.next, struct dma_page, page_list); if (is_page_busy(page)) { @@ -297,8 +300,12 @@ void dma_pool_destroy(struct dma_pool *pool) list_del(&page->page_list); kfree(page); } else - pool_free_page(pool, page); + list_move(&page->page_list, &discard); } + spin_unlock_irqrestore(&pool->lock, flags); + + list_for_each_entry_safe(page, h, &discard, page_list) + pool_free_page(pool, page); kfree(pool); }