From patchwork Mon Feb 6 09:55:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 53086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2123039wrn; Mon, 6 Feb 2023 00:48:06 -0800 (PST) X-Google-Smtp-Source: AK7set8a0YX3xmhM1jJXQburqy2Z07Hz/uCt+WnDbOT5gZ8GCBbTgNlsOrsvvTIko8ZJKxYPM/Pb X-Received: by 2002:a17:902:f2d2:b0:199:15d6:48a6 with SMTP id h18-20020a170902f2d200b0019915d648a6mr2672359plc.55.1675673285964; Mon, 06 Feb 2023 00:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675673285; cv=none; d=google.com; s=arc-20160816; b=ICUylgDkMDaviGQq+SDi8yCkV7vyE4Az7PenTI+fgJok2X7H5q2EmeGLT+8TqUPY1A 4Mg9vC1spbPLappEsdU4Z0qCuElbIDMyC5VEHstBhz5LFunAqRVGBI+VYer02THko5dD QCgtfPOqN6+v7s4h2Wt7ifbCJAT4osYR1amIXsKfUDCvgbzMnL9a7hN58HN2hk2V088J C7lSJiqxiYUla1KeAqZj9oRtiMYp8NeFjgkPwCICJMNXEYMWxy4xvoub15CU0kei8nlT cq4p4+3Lx3HGymi/ewWnAOfWgoQdPmQZAKzjOSv4QJCQxGchrsLyWhsO0YyooZ7mP0+L hZ4w== 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=iDSgNqoI8iIveS7HH5zRSNXVaima4Lr4yDwxhMA8xi0=; b=JCarBX6U7UJSMr5sFaNyxQ57WWfxUwkzTXWG5txJpShCP9FWygtFzKXKM6n/GQAVsS tAm2DUMwRLEPGy16dU1JXkJVqCxMxTov7hHz0Pjel7IKJgnMWZoQajpS8CYWnb97wcsh p6C2WI5cHska5jHeGlJH3A9Eg2OdNabE+8dxrARnlNVEybmQ5KEM9613z6xv0Q1yhLg/ BX5R2RmV3ojFFyWc8ytv7g/NAEEKk79kCjkbYy9TWLk7I4Qxk7X7m3CuDhXBnv4z2Uip pCihaVLg8wz4Hik15QsztsXx6W9m/vqJ4094LbaaLJ3GkxIiKB08szV9F1G4oDYedK2m OfIw== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a170902e84200b00198f5dab2besi7724033plg.517.2023.02.06.00.47.53; Mon, 06 Feb 2023 00:48:05 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbjBFIrN (ORCPT + 99 others); Mon, 6 Feb 2023 03:47:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjBFIrI (ORCPT ); Mon, 6 Feb 2023 03:47:08 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8B8C113E9 for ; Mon, 6 Feb 2023 00:46:57 -0800 (PST) Received: from kwepemm600015.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4P9KZQ1SMJznW2X; Mon, 6 Feb 2023 16:44:46 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 6 Feb 2023 16:46:50 +0800 From: ChenXiaoSong To: , CC: , , Subject: [PATCH 1/2] gfs2: factor out __gfs2_ail1_empty() and gfs2_ail1_withdraw() Date: Mon, 6 Feb 2023 17:55:42 +0800 Message-ID: <20230206095543.539186-2-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230206095543.539186-1-chenxiaosong2@huawei.com> References: <20230206095543.539186-1-chenxiaosong2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757070791453116264?= X-GMAIL-MSGID: =?utf-8?q?1757070791453116264?= Factor out __gfs2_ail1_empty() and gfs2_ail1_withdraw() from gfs2_ail1_empty(). No functional change. Signed-off-by: ChenXiaoSong --- fs/gfs2/log.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 61323deb80bc..c62c914702ba 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -347,15 +347,7 @@ static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr, return active_count; } -/** - * gfs2_ail1_empty - Try to empty the ail1 lists - * @sdp: The superblock - * @max_revokes: If non-zero, add revokes where appropriate - * - * Tries to empty the ail1 lists, starting with the oldest first - */ - -static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) +static int __gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) { struct gfs2_trans *tr, *s; int oldest_tr = 1; @@ -372,10 +364,31 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) ret = list_empty(&sdp->sd_ail1_list); spin_unlock(&sdp->sd_ail_lock); + return ret; +} + +static void gfs2_ail1_withdraw(struct gfs2_sbd *sdp) +{ if (test_bit(SDF_WITHDRAWING, &sdp->sd_flags)) { gfs2_lm(sdp, "fatal: I/O error(s)\n"); gfs2_withdraw(sdp); } +} + +/** + * gfs2_ail1_empty - Try to empty the ail1 lists + * @sdp: The superblock + * @max_revokes: If non-zero, add revokes where appropriate + * + * Tries to empty the ail1 lists, starting with the oldest first + */ + +static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) +{ + int ret; + + ret = __gfs2_ail1_empty(sdp, max_revokes); + gfs2_ail1_withdraw(sdp); return ret; } From patchwork Mon Feb 6 09:55:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 53085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2122978wrn; Mon, 6 Feb 2023 00:47:56 -0800 (PST) X-Google-Smtp-Source: AK7set8NUwyxSo6mnwbvdZ6kHACJxwymCe2wOyMhNGDqG2A9TBDTGiDKtjdYhSclb9WrUeRQNCbb X-Received: by 2002:a17:902:ce84:b0:196:7128:f803 with SMTP id f4-20020a170902ce8400b001967128f803mr24825263plg.23.1675673276356; Mon, 06 Feb 2023 00:47:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675673276; cv=none; d=google.com; s=arc-20160816; b=orCqBhW1cY2yXjfCxNXL+malz/ItRn3GJ2Zzhpi0QtjYhBJvzJKqSwfHpyJPEjd5WS xg+KTngEhHwO3qVU01qWADIkhi9onEn+x7iVv6LCxfjqsNavlFesCn11Iqj44S5jK++T mvBxyeXnPR/kLKp1MsmJ+cv/3PSltnM9hPY2J1jnn59szI3OgSUJWL3yDVmM8/PD5qVN 17YcI34cKvZBm2B0lJc/jNTOe/8dQjQpXuFmUaCeueAa/TBnVnCJgZb2MDYjihKyKrIA J6Rbhzh2PBJc/Lwkx3tCzAAW0xHIkXc2/YfG/AAuDeNweyY8aZXs6FIo3sU7lo3mhiBl XQrw== 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=n0gj0qkU0xM14BNG7mMic6Nx08v1Ez32FJBlFByFnok=; b=pnqOChdP8TEK/czwUx/hM/ZJ/N1iBUcPTL3f1sMpfEPxmG9kosr002WxUuOunjhaV0 LJIebBNQMhsNv97sNmiFNZANFqdn1Wq9nzc5Pc9/wuZ6qrJjVPx640ODSxMNdneaWEXO 1KXFBfzLXgPc0fjeZNW/ehyBnksYSJig/7daZMUfPYf+qsnqb71TEzbj77uwKemV5XM8 hLj3xNQ9soj60tA2x1kMYewFzzITacFSnRGlatDcEITICYHnSSCYRk6L6KODsghqdVYO X3PZcG53CPq4Y723MTYE0iy+MceYMTNdQHregDRE3VwbA+QgXc40sU6q+QXCbgeF3xqm dESg== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a170902a60600b001990aae7572si3691086plq.294.2023.02.06.00.47.20; Mon, 06 Feb 2023 00:47:56 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229605AbjBFIrK (ORCPT + 99 others); Mon, 6 Feb 2023 03:47:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjBFIrI (ORCPT ); Mon, 6 Feb 2023 03:47:08 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEA3311178 for ; Mon, 6 Feb 2023 00:46:57 -0800 (PST) Received: from kwepemm600015.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4P9KZQ2YnGznW3B; Mon, 6 Feb 2023 16:44:46 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 6 Feb 2023 16:46:51 +0800 From: ChenXiaoSong To: , CC: , , Subject: [PATCH 2/2] gfs2: fix sleep from invalid context bug in gfs2_glock_wait() Date: Mon, 6 Feb 2023 17:55:43 +0800 Message-ID: <20230206095543.539186-3-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230206095543.539186-1-chenxiaosong2@huawei.com> References: <20230206095543.539186-1-chenxiaosong2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757070781385828057?= X-GMAIL-MSGID: =?utf-8?q?1757070781385828057?= Syzkaller reported BUG as follows: BUG: sleeping function called from invalid context at fs/gfs2/glock.c:1316 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1b1/0x290 lib/dump_stack.c:106 __might_resched+0x4e9/0x6b0 kernel/sched/core.c:10036 gfs2_glock_wait+0x52/0x2a0 fs/gfs2/glock.c:1316 gfs2_glock_nq_init fs/gfs2/glock.h:262 [inline] gfs2_freeze_lock+0x5f/0xc0 fs/gfs2/util.c:107 signal_our_withdraw fs/gfs2/util.c:160 [inline] gfs2_withdraw+0x5cc/0x1540 fs/gfs2/util.c:351 gfs2_ail1_empty+0x8c9/0x950 fs/gfs2/log.c:368 gfs2_flush_revokes+0x59/0x80 fs/gfs2/log.c:806 revoke_lo_before_commit+0x2b/0xcf0 fs/gfs2/lops.c:869 lops_before_commit fs/gfs2/lops.h:40 [inline] gfs2_log_flush+0xc8e/0x26a0 fs/gfs2/log.c:1093 do_sync+0xa3c/0xc80 fs/gfs2/quota.c:975 gfs2_quota_sync+0x3da/0x8b0 fs/gfs2/quota.c:1318 gfs2_sync_fs+0x49/0xb0 fs/gfs2/super.c:650 sync_filesystem+0xe8/0x220 fs/sync.c:56 generic_shutdown_super+0x6b/0x310 fs/super.c:474 kill_block_super+0x79/0xd0 fs/super.c:1386 deactivate_locked_super+0xa7/0xf0 fs/super.c:332 cleanup_mnt+0x494/0x520 fs/namespace.c:1291 task_work_run+0x243/0x300 kernel/task_work.c:179 exit_task_work include/linux/task_work.h:38 [inline] do_exit+0x644/0x2150 kernel/exit.c:867 do_group_exit+0x1fd/0x2b0 kernel/exit.c:1012 __do_sys_exit_group kernel/exit.c:1023 [inline] __se_sys_exit_group kernel/exit.c:1021 [inline] __x64_sys_exit_group+0x3b/0x40 kernel/exit.c:1021 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Fix this by calling gfs2_withdraw() outside of the spinlock context. Link: https://syzkaller.appspot.com/bug?id=7bd882c47078df844b5a82550559d69482d5c3c1 Signed-off-by: ChenXiaoSong --- fs/gfs2/log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index c62c914702ba..945540c0a3cf 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -825,8 +825,10 @@ void gfs2_flush_revokes(struct gfs2_sbd *sdp) unsigned int max_revokes = atomic_read(&sdp->sd_log_revokes_available); gfs2_log_lock(sdp); - gfs2_ail1_empty(sdp, max_revokes); + __gfs2_ail1_empty(sdp, max_revokes); gfs2_log_unlock(sdp); + + gfs2_ail1_withdraw(sdp); } /**