Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2420810imi; Sun, 24 Jul 2022 19:45:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v15U/2y5ZlJ8PEasbOxF3Krnt/lsJmt8qPnrE5SoiIKu89eyI4VzUrqD8sXklvg5iFcs0S X-Received: by 2002:a17:906:84f0:b0:72b:5cf4:465d with SMTP id zp16-20020a17090684f000b0072b5cf4465dmr8558901ejb.705.1658717125442; Sun, 24 Jul 2022 19:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658717125; cv=none; d=google.com; s=arc-20160816; b=pt0Ui3/bqsShjqmU5VbyC+vaDwq3S2yhRKV6AjEVm0XLfDSNlrBcAjt8W7/WGANch4 JwI2DQlopgINpozKmRU4TBOAjwsTyI7EqE5Rh3bjwpg36AQAhixx/rAC6znO//UbOEqy N9gpiUQqsthI0wsHxZpFNyopWX8Vs4ULCWNc9qhQH3J/EqDg33zps7UrxrAVqMYNoTjk vX/1bpb/cNloX/b4QBAtpgVaTUO08aukggmjxQgR3Qx5SuEEd5REx2hFeseiBdlWPG+h P6DRlMH7bEANdWaLkEqikGaTdsGJ4bx14dlU7hBvdNtNKcrZdm1IuH16V5uXzaYPNasv Hz9Q== 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 :message-id:date:subject:cc:to:from; bh=178JYpYrmHXS5FPj5ssjGTwMrBBfNRDtsn3Pi9NJdnc=; b=Mz/ZxR1fANOuln3sOVU4gBXj4hr8AyI/My8cqQibKq8xEKqrqRiaNaF4tugylSqC4/ CT1pW4RXPhPumfV9o0420eHCNk3z9OlLfJE17lNSA4ON+EAWLZ4IorFLqnvY3M+cQn7W VOSCj2eW3z9X7Tf6OhsMYEaqIR5ovcVodAW9z/WIVSGU36I/2iB64JBZo4p5CK/Hs9lv hZLEP769RzGu1vkSxWAdSdd5++XolPEDEg0+YVsEi+cNUl8kA+A85PpNHQcMl6G7Hafk mcpPUhaSqL8WIlhaPjx7TDarz6OsntmeyXBR0o2+JUE1ES4TOje61+gXGrWOEyM2Rt10 uFtQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020aa7d2c2000000b0043a71bf3999si11003971edr.57.2022.07.24.19.45.00; Sun, 24 Jul 2022 19:45:25 -0700 (PDT) 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 S232955AbiGYCjJ (ORCPT + 99 others); Sun, 24 Jul 2022 22:39:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbiGYCjG (ORCPT ); Sun, 24 Jul 2022 22:39:06 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16159DF87; Sun, 24 Jul 2022 19:39:06 -0700 (PDT) Received: from canpemm500008.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lrkh30rRszkXD4; Mon, 25 Jul 2022 10:36:35 +0800 (CST) Received: from localhost.huawei.com (10.175.124.27) by canpemm500008.china.huawei.com (7.192.105.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 25 Jul 2022 10:39:04 +0800 From: Li Jinlin To: , , , , CC: , , , , Subject: [PATCH] fsdax: Fix infinite loop in dax_iomap_rw() Date: Mon, 25 Jul 2022 11:20:50 +0800 Message-ID: <20220725032050.3873372-1-lijinlin3@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500008.china.huawei.com (7.192.105.151) 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 I got an infinite loop and a WARNING report when executing a tail command in virtiofs. WARNING: CPU: 10 PID: 964 at fs/iomap/iter.c:34 iomap_iter+0x3a2/0x3d0 Modules linked in: CPU: 10 PID: 964 Comm: tail Not tainted 5.19.0-rc7 Call Trace: dax_iomap_rw+0xea/0x620 ? __this_cpu_preempt_check+0x13/0x20 fuse_dax_read_iter+0x47/0x80 fuse_file_read_iter+0xae/0xd0 new_sync_read+0xfe/0x180 ? 0xffffffff81000000 vfs_read+0x14d/0x1a0 ksys_read+0x6d/0xf0 __x64_sys_read+0x1a/0x20 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd The tail command will call read() with a count of 0. In this case, iomap_iter() will report this WARNING, and always return 1 which casuing the infinite loop in dax_iomap_rw(). Fixing by checking count whether is 0 in dax_iomap_rw(). Fixes: ca289e0b95af ("fsdax: switch dax_iomap_rw to use iomap_iter") Signed-off-by: Li Jinlin --- fs/dax.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/dax.c b/fs/dax.c index 4155a6107fa1..7ab248ed21aa 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1241,6 +1241,9 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, loff_t done = 0; int ret; + if (!iomi.len) + return 0; + if (iov_iter_rw(iter) == WRITE) { lockdep_assert_held_write(&iomi.inode->i_rwsem); iomi.flags |= IOMAP_WRITE; -- 2.30.2