mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Chunhai Guo <guochunhai@vivo.com>,
	"xiang@kernel.org" <xiang@kernel.org>,
	"chao@kernel.org" <chao@kernel.org>
Cc: "huyue2@coolpad.com" <huyue2@coolpad.com>,
	"jefflexu@linux.alibaba.com" <jefflexu@linux.alibaba.com>,
	"linux-erofs@lists.ozlabs.org" <linux-erofs@lists.ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] erofs: fix two loop issues when read page beyond EOF
Date: Mon, 10 Jul 2023 13:02:58 +0800	[thread overview]
Message-ID: <1a107593-e411-70a0-b6b8-3c34a9036ff3@linux.alibaba.com> (raw)
In-Reply-To: <ac05d6e3-79b4-a470-2a30-8c809c277209@vivo.com>



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


  reply	other threads:[~2023-07-10  5:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-08  6:24 Chunhai Guo
2023-07-08  9:00 ` Gao Xiang
2023-07-10  3:32   ` Chunhai Guo
2023-07-10  3:37     ` Gao Xiang
2023-07-10  4:35       ` Chunhai Guo
2023-07-10  5:02         ` Gao Xiang [this message]
2023-07-10  9:37           ` Chunhai Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a107593-e411-70a0-b6b8-3c34a9036ff3@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=guochunhai@vivo.com \
    --cc=huyue2@coolpad.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®