Message ID | 20230209194825.511043-8-shikemeng@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp289298wrn; Thu, 9 Feb 2023 03:58:49 -0800 (PST) X-Google-Smtp-Source: AK7set9pmJps63Y+OLo4iPG8TwYgqeikFI0n+jk0QassKqDfBNMUi1JeeCetlZq6/U+AeyoRr8u4 X-Received: by 2002:a17:90b:1b01:b0:231:405:3365 with SMTP id nu1-20020a17090b1b0100b0023104053365mr8154700pjb.20.1675943929233; Thu, 09 Feb 2023 03:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675943929; cv=none; d=google.com; s=arc-20160816; b=z9vwvIacBUj+pNA/U20fpFI/XhXbcppNKt7MJV11UsTcutsTQ6I8JczNVJ2PuB8h8O XgWp0ryc0JS9PwgqQdqTs4jilXOKgN/44e9CEb4GqW0AZLVDlacFVuoa6bdxPbD5aVHp u77jGmr1ga08X9YNukZ65co5J6cXUsj6yXfwPZmQnUtDwvH3SVysgjD/iMVGwFRzuUNt ybWAfolxbQ3PUKXo6I2sUFAPjZRx0NYQvaghV7TSqVIgAwbotfIeJ9z775+3hfHUG1Dl /qW43wpPx67Kxi5Y57zHNL4ZABhpiopMS31UHcKv5DDS70/u82x+1LUR1OLOrNCE9xQ9 VTYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=MwUe1WzShvA7mknTw4d6CO6EXB5zXpRiWPfYUVeZuWE=; b=kZSHnUkBvHh8pheovGtMaFtjFQh1NJUX7ZhZqrJyEb7gEUrr9KPxVUMRyaE2aCCBd6 qRydJU5pHfNSzs7iHG3WUAeBnNcpc2WswoBSt8VCjbRxnjs7ShtyijXrmqiqLncsvcv0 zgLhLT5+yg/BluPMWU7P5i/l59MjMyFKpkY4ZssAXwsWafS0Ox0ROvvbcJbrT65sRGyT 0XM/XwXx/LblyKz0/o+kTOAVRtitlAJRPl+DaX9+nz6EcQnAxxXDTIhpUQqYUDnInyEc 4pL33KqJh8VDgfBscpV4WBuUOz5n9qULogboBxJws1an6qZ6eW+wcMYofBCXHgNItHqS Vmfw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14-20020a63b70e000000b004dc05ba4699si1649290pgf.417.2023.02.09.03.58.30; Thu, 09 Feb 2023 03:58:49 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbjBIL5V (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Thu, 9 Feb 2023 06:57:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbjBIL4M (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Feb 2023 06:56:12 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86C5B5C488; Thu, 9 Feb 2023 03:46:30 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4PCFSd6933z4f3m7P; Thu, 9 Feb 2023 19:46:25 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgAn3rEQ3eRjgb0tDQ--.53508S9; Thu, 09 Feb 2023 19:46:27 +0800 (CST) From: Kemeng Shi <shikemeng@huaweicloud.com> To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/21] ext4: protect pa->pa_free in ext4_discard_allocated_blocks Date: Fri, 10 Feb 2023 03:48:11 +0800 Message-Id: <20230209194825.511043-8-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230209194825.511043-1-shikemeng@huaweicloud.com> References: <20230209194825.511043-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgAn3rEQ3eRjgb0tDQ--.53508S9 X-Coremail-Antispam: 1UD129KBjvdXoW7Gr1UGF18KFyDJryxXF47Arb_yoW3ArXEka 48AF4xJFWrJa4S93W8tay0qr4rKF4Syr4UWFWrtr43ua1rXF4fG3WDXr1rJrZxWa12y3y7 C3sY9ryUGanagjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbS8YFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r126s0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC 64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM2 8EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq 3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jstxDUUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, 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: <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?1757354581560164063?= X-GMAIL-MSGID: =?utf-8?q?1757354581560164063?= |
Series |
Some bugfix and cleanup to mballoc
|
|
Commit Message
Kemeng Shi
Feb. 9, 2023, 7:48 p.m. UTC
If ext4_mb_mark_diskspace_used fails in ext4_mb_new_blocks, we may
discard pa already in list. Protect pa with pa_lock to avoid race.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/ext4/mballoc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Fri, Feb 10, 2023 at 03:48:11AM +0800, Kemeng Shi wrote: > If ext4_mb_mark_diskspace_used fails in ext4_mb_new_blocks, we may > discard pa already in list. Protect pa with pa_lock to avoid race. > > Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> > --- > fs/ext4/mballoc.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c > index 433337ac8da2..4e1caac74b44 100644 > --- a/fs/ext4/mballoc.c > +++ b/fs/ext4/mballoc.c > @@ -4263,8 +4263,11 @@ static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac) > ext4_mb_unload_buddy(&e4b); > return; > } > - if (pa->pa_type == MB_INODE_PA) > + if (pa->pa_type == MB_INODE_PA) { > + spin_lock(&pa->pa_lock); > pa->pa_free += ac->ac_b_ex.fe_len; > + spin_unlock(&pa->pa_lock); > + } > } > > /* > -- > 2.30.0 > Looks correct. Feel free to add: Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 433337ac8da2..4e1caac74b44 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4263,8 +4263,11 @@ static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac) ext4_mb_unload_buddy(&e4b); return; } - if (pa->pa_type == MB_INODE_PA) + if (pa->pa_type == MB_INODE_PA) { + spin_lock(&pa->pa_lock); pa->pa_free += ac->ac_b_ex.fe_len; + spin_unlock(&pa->pa_lock); + } } /*