Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34875459rwd; Sun, 9 Jul 2023 22:29:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlHoCeIX2Xx+rV+xKf9IKXTHtSG9rcTb0K3zhcIo7g8r0gK6tphfK9Il3H6IT+qcm3u3F7NT X-Received: by 2002:a05:6402:1646:b0:51d:e1d7:319d with SMTP id s6-20020a056402164600b0051de1d7319dmr10434592edx.37.1688966990496; Sun, 09 Jul 2023 22:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688966990; cv=none; d=google.com; s=arc-20160816; b=gG7K7oK69OWKtApzRtLP46VDhPr8sJjhIxP61nBfglgb34snWAkBaJpemg7X9kztDa MYUkBv9PFTc1juLmnMNJtZA5LMaqAOk6XlQaHBxdrcwtT9PyES21mhXBwdaNvSMUYEKA IXbJdtvYOoB0zSLyoG3kj97dh7jg584x/ubDuAttd5nt7dyeMZRRXLH4hevSM/dqotXl JyBTxhJl3V61tDJhdMAFSspFy9imKbmGxA7Fzssk8KSXeX1vAYKcA5XCDacClY7Vg7Oc TfzkoWY97foTwAA5HfO8rNA+mjrDAYq4uT4P7yMOyEd5M2sQj2FjC/ghCdDRyaPAWKSt v8tQ== 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:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=d+Dn/LNlRa7GiQ7qICcEKxlZe1gN3rVe4B4dK1mNZkc=; fh=0wRzg3VwHWGTaaUtCHOfMq1+lvu/gO83CsuQxr1u8K0=; b=VkokC+hBNjLwi/uFq7IQznEBcYsIaHyYJTsDn0iKR7aMglbLFVSCMaL1rjOo6eyNL2 t+NcxwSbvbMF867s44/D+6M5CRE3gYRL/IPPQPDcahD/OQ/XR61B7wwXF5VCZOynM0R6 OaEm8PfJpNbcUdIcvwa2XrwAbgqANrYw/rneAslfdCBY8kEDtmOHK390cmR+YE+ug5QS N2FsIdwuve6E57PR3zVe0SnOQgHfCaQgWXKDbyCjHJ+rc5sbEc9JRGA5Xxxyq9xsAWte Tg6xSrDVHHGbI5hiz1wmqXbIEOZ/JgsND7z1H6kha9OQOFkY0jS52EwtVmferblh1Wbj 2nyQ== 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=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020aa7d989000000b0051e52b91239si5094763eds.666.2023.07.09.22.29.27; Sun, 09 Jul 2023 22:29:50 -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=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbjGJFDG (ORCPT + 99 others); Mon, 10 Jul 2023 01:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbjGJFDF (ORCPT ); Mon, 10 Jul 2023 01:03:05 -0400 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE0D120 for ; Sun, 9 Jul 2023 22:03:02 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Vmy4O50_1688965378; Received: from 30.97.48.247(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Vmy4O50_1688965378) by smtp.aliyun-inc.com; Mon, 10 Jul 2023 13:02:59 +0800 Message-ID: <1a107593-e411-70a0-b6b8-3c34a9036ff3@linux.alibaba.com> Date: Mon, 10 Jul 2023 13:02:58 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] erofs: fix two loop issues when read page beyond EOF To: Chunhai Guo , "xiang@kernel.org" , "chao@kernel.org" Cc: "huyue2@coolpad.com" , "jefflexu@linux.alibaba.com" , "linux-erofs@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" References: <20230708062432.67344-1-guochunhai@vivo.com> <97875049-8df9-e041-61ca-d90723ba6e82@linux.alibaba.com> From: Gao Xiang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 On 2023/7/10 12:35, Chunhai Guo wrote: > > > On 2023/7/10 11:37, Gao Xiang wrote: >> >> >> On 2023/7/10 11:32, Chunhai Guo wrote: >>> Hi Xiang, >>> >>> On 2023/7/8 17:00, Gao Xiang wrote: >>>> Hi Chunhai, >>>> >>>> On 2023/7/8 14:24, Chunhai Guo wrote: >>>>> When z_erofs_read_folio() reads a page with an offset far beyond EOF, two >>>>> issues may occur: >>>>> - z_erofs_pcluster_readmore() may take a long time to loop when the offset >>>>>      is big enough, which is unnecessary. >>>>>        - For example, it will loop 4691368 times and take about 27 seconds >>>>>          with following case. >>>>>            - offset = 19217289215 >>>>>            - inode_size = 1442672 >>>>> - z_erofs_do_read_page() may loop infinitely due to the inappropriate >>>>>      truncation in the below statement. Since the offset is 64 bits and >>>>> min_t() truncates the result to 32 bits. The solution is to replace >>>>> unsigned int with another 64-bit type, such as erofs_off_t. >>>>>        cur = end - min_t(unsigned int, offset + end - map->m_la, end); >>>>>        - For example: >>>>>            - offset = 0x400160000 >>>>>            - end = 0x370 >>>>>            - map->m_la = 0x160370 >>>>>            - offset + end - map->m_la = 0x400000000 >>>>>            - offset + end - map->m_la = 0x00000000 (truncated as unsigned int) >>>> >>>> Thanks for the catch! >>>> >>>> Could you split these two into two patches? >>>> >>>> how about using: >>>> cur = end - min_t(erofs_off_t, offend + end - map->m_la, end) >>>> for this? >>>> >>>> since cur and end are all [0, PAGE_SIZE - 1] for now, and >>>> folio_size() later. >>> >>> OK. I will split the patch. >>> >>> Sorry that I can not understand what is 'offend' refer to and what do you mean. Could you please describe it more clearly? >> >> Sorry, there is a typo here, I meant 'offset'. >> >> `cur` and `end` both are not exceed 4096 if your page_size >> is 4096. >> >> Does >> cur = end - min_t(erofs_off_t, offset + end - map->m_la, end) >> >> fix your issue? > > Yes. I think this will fix this issue. Do you mean the below change is unncessary? > >>>> -    unsigned int cur, end, spiltted; > >>>> +    erofs_off_t cur, end; > >>>> +    unsigned int spiltted; Yes, please help send a fix for this! Thanks, Gao Xiang