Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3321130ybz; Sun, 19 Apr 2020 23:57:50 -0700 (PDT) X-Google-Smtp-Source: APiQypIEptom9iAUUAAHVZsQhCgjbxl3OcSjt28rYgVAZK32ZjFslVe0bFrjK+SmuXmuTqUeXKsi X-Received: by 2002:a17:906:7f13:: with SMTP id d19mr14765169ejr.57.1587365869833; Sun, 19 Apr 2020 23:57:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587365869; cv=none; d=google.com; s=arc-20160816; b=SuUl/B8O/RNYudkQBI2zJObHCF1K6XSUMMycep6Z+uWbTqOjh1+1+EKG7HP/bKsnWN hWhCPe8aw+uObIPOCLylGoKBDJJs7gmyYFszjRydsjN8jaMcAtbaBcUhq/2fsqGw1TF0 AxOV9dAAiZv5LQtSUvS8fHUvG62BYC8mtud4Ru9B+8wC0E7r+CTouuPIjgucekXLXPfi +KkKLOHYGsdrYcMaJR9smgo1JmLXi8G55mk0Q8FG7FAzkdB1uiiGGnWn8ckdVCCkQciI FaqrcQoS0Mnd9/aqZ8XwxVVPjWf4T4pntiqgiC9TlUBqZfhjGuAbSD6NOURrATnjeFwk pj4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=pQU7OWshGu3ITeZ9V4rZkrIPTnuqgBltzkhEt3izYYs=; b=FGFjHtPyU0gZcaXAOQYnAQh1/XzjBzrHMvPAQB8fKfJAY56Ddw4f5MD6fQLeakyriU e8Vu4QflAg8tNVBSmkyv/9WZHkGmY477U7Qiq5RAHDcXq3jnjwwqZqJ7DjBHOqwAEjIh dJtBWZU+eJZjtaIrxR0S28F7QAOdBJLhfR7vjfBrzMnQCz5NPmUHL81BMADDvLWBPjDn 6LLRFyHjboHl3rHqERJf+I+11qjMFCGaw7P64BqGr4q1IHtaOZDFUFccDYqzi4xz4zfw B9dw/VRvQdYMHHzoBCEKk5vrh5evxEeLI1tXWiDGi8osHfbebICJd7ZfI9VA8N1o6iuC cXgg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si29210edb.416.2020.04.19.23.57.27; Sun, 19 Apr 2020 23:57:49 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726063AbgDTGzw (ORCPT + 99 others); Mon, 20 Apr 2020 02:55:52 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:45398 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725815AbgDTGzv (ORCPT ); Mon, 20 Apr 2020 02:55:51 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id BCF396C3F37183F6F41D; Mon, 20 Apr 2020 14:55:49 +0800 (CST) Received: from [127.0.0.1] (10.166.215.235) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Mon, 20 Apr 2020 14:55:39 +0800 Subject: Re: bcache: unlock new_nodes[i]->write_lock in btree_gc_coalesce From: Zhiqiang Liu To: , , , CC: "wubo (T)" , Mingfangsen , Yanxiaodan , linfeilong References: Message-ID: Date: Mon, 20 Apr 2020 14:55:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.166.215.235] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org friendly ping... On 2020/4/15 19:42, Zhiqiang Liu wrote: > From: Zhiqiang Liu > > coccicheck reports: > drivers/md//bcache/btree.c:1538:1-7: preceding lock on line 1417 > > After obtaining new_nodes[i]->write_lock, we may go to out_nocoalesce > tag without releasing lock. Here, we add a new tag > 'out_unlock_nocoalesce' before out_nocoalesce tag to release > new_nodes[i]->write_lock. > > Fixes: 2a285686c1 ("bcache: btree locking rework") > Signed-off-by: Zhiqiang Liu > --- > drivers/md/bcache/btree.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c > index fa872df4e770..cad8b0b97e33 100644 > --- a/drivers/md/bcache/btree.c > +++ b/drivers/md/bcache/btree.c > @@ -1447,7 +1447,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, > if (__set_blocks(n1, n1->keys + n2->keys, > block_bytes(b->c)) > > btree_blocks(new_nodes[i])) > - goto out_nocoalesce; > + goto out_unlock_nocoalesce; > > keys = n2->keys; > /* Take the key of the node we're getting rid of */ > @@ -1476,7 +1476,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, > > if (__bch_keylist_realloc(&keylist, > bkey_u64s(&new_nodes[i]->key))) > - goto out_nocoalesce; > + goto out_unlock_nocoalesce; > > bch_btree_node_write(new_nodes[i], &cl); > bch_keylist_add(&keylist, &new_nodes[i]->key); > @@ -1522,6 +1522,10 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, > /* Invalidated our iterator */ > return -EINTR; > > +out_unlock_nocoalesce: > + for (i = 0; i < nodes; i++) > + mutex_unlock(&new_nodes[i]->write_lock); > + > out_nocoalesce: > closure_sync(&cl); >