Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1124288pxb; Sun, 12 Sep 2021 08:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6oWNhMV331T3471Iyoh8KdaYQA/cWex5MZl/HOP0WsT3cfrqij2l0UBeUYEAM+FQ2u7Ub X-Received: by 2002:a05:6e02:1d1a:: with SMTP id i26mr4970541ila.96.1631461096755; Sun, 12 Sep 2021 08:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631461096; cv=none; d=google.com; s=arc-20160816; b=dl6bOu50F7Uh/nbRMd7/Z4POB1t/RoxxyzKtbVnXbhcmivjJTc7NlyRF11xHrFCIEj yd+wcGazjjxoRKw5isnRMEd1cvvkayyFZwxvR2OaTAHuaFx7L5popVJo5+tQ53zPz1yv YEdoqk1YZh7vIyBhOHW24es0+wH6nsUjM8O0vUVSdEwwNMcEzw/+G3iM489YiQ/RaCis ZbWa0fm/wkNsz7kzslm8RUL0azBXquyzybwrQO5AGajxfkgprlcddh9aYeRAAjCK/5qM uwmHhd72OXeZ3J3/inAz09eZbCLhXweUuDDkqD8A53tgcl8zWCb5Db/7LXHJ0vP+Bt36 yhvA== 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 :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=s4JWKojITaGWbA83l85/jE3q6ibvlgj7DmdWTiAbF7c=; b=iDfGfOPgRPjz7JppZM+ehMAKCvAwHoAvwGdtH5JDkgwE+ahZ9TeAlirGotbxRxh+GN uRFRLxsZDrfRuzNZR2T1t0BdT7FLXab04P26p+jXxciEPAlPGNKsK7ifs5Aqm3ellx1J 3BVWShkHoxJZJ5/Twb08ffn+i91xKnArBDK+96B/FA+gytUy1hj5h+LEqj79Q2mLyP/m Qj7fhL4h6UHeBg0uWJIRR4oj6I4q52kK1d8Gm8HEn2HZcEfvSYEiVFsJDqeh/JGjgpkY uVu8+Uiur3+/yl5hvTVZrTxgaWEAlWiRpTcwsufDSBiQSTBYfNWjVBxHZqSulcnB0UGa ALdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j18si4352877ilc.159.2021.09.12.08.38.05; Sun, 12 Sep 2021 08:38:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235822AbhILPhT (ORCPT + 99 others); Sun, 12 Sep 2021 11:37:19 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:59804 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbhILPhS (ORCPT ); Sun, 12 Sep 2021 11:37:18 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=haoxu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Uo4H.DJ_1631460961; Received: from 30.30.116.57(mailfrom:haoxu@linux.alibaba.com fp:SMTPD_---0Uo4H.DJ_1631460961) by smtp.aliyun-inc.com(127.0.0.1); Sun, 12 Sep 2021 23:36:02 +0800 Subject: Re: [PATCH -next] io-wq: Remove duplicate code in io_workqueue_create() To: Bixuan Cui , linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Cc: axboe@kernel.dk, asml.silence@gmail.com, Joseph Qi References: <20210911085847.34849-1-cuibixuan@huawei.com> From: Hao Xu Message-ID: <49d9bb13-a7b3-48b5-20ef-d3b72052f92b@linux.alibaba.com> Date: Sun, 12 Sep 2021 23:36:01 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210911085847.34849-1-cuibixuan@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/9/11 下午4:58, Bixuan Cui 写道: > While task_work_add() in io_workqueue_create() is true, > then duplicate code is executed: > > -> clear_bit_unlock(0, &worker->create_state); > -> io_worker_release(worker); > -> atomic_dec(&acct->nr_running); > -> io_worker_ref_put(wq); > -> return false; > > -> clear_bit_unlock(0, &worker->create_state); // back to io_workqueue_create() > -> io_worker_release(worker); > -> kfree(worker); > > The io_worker_release() and clear_bit_unlock() are executed twice. > > Fixes: 3146cba99aa2 ("io-wq: make worker creation resilient against signals") > Signed-off-by: Bixuan Cui > --- > fs/io-wq.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/fs/io-wq.c b/fs/io-wq.c > index 6c55362c1f99..95d0eaed7c00 100644 > --- a/fs/io-wq.c > +++ b/fs/io-wq.c > @@ -329,8 +329,10 @@ static bool io_queue_worker_create(struct io_worker *worker, > > init_task_work(&worker->create_work, func); > worker->create_index = acct->index; > - if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) > + if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) { > + clear_bit_unlock(0, &worker->create_state); > return true; > + } > clear_bit_unlock(0, &worker->create_state); > fail_release: > io_worker_release(worker); > @@ -723,11 +725,8 @@ static void io_workqueue_create(struct work_struct *work) > struct io_worker *worker = container_of(work, struct io_worker, work); > struct io_wqe_acct *acct = io_wqe_get_acct(worker); > > - if (!io_queue_worker_create(worker, acct, create_worker_cont)) { > - clear_bit_unlock(0, &worker->create_state); > - io_worker_release(worker); > + if (!io_queue_worker_create(worker, acct, create_worker_cont)) > kfree(worker); > - } > } > > static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) > AFAIK, this looks reasonable for me.