Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35128024rwd; Mon, 10 Jul 2023 03:02:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlHn86pelYJadkKsYjheBraFlUchhEtc/UdqZYQvWAmmrG97DTHabseRcoh0gGEitegsnwEf X-Received: by 2002:a2e:8e89:0:b0:2b5:828c:bfc7 with SMTP id z9-20020a2e8e89000000b002b5828cbfc7mr9032692ljk.19.1688983363618; Mon, 10 Jul 2023 03:02:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688983363; cv=pass; d=google.com; s=arc-20160816; b=IkGNuA36LjrjSI8RBLdeWRGG0kZgPmNj8AfvbP/dJdjTwcnFOqxCMrE7qqmpE07jzr 6d+8cmxm2X+tTQeD4LSPzMty7vpiK/SCjoYux5MlOhIIMpKc5DB7cgUTlRsfvQQ3Swgf r5wHiovKUWf0HhGTa9UlJPxgIRPUcw+KvbVfIwoQmupmT8e/8sswyxG32jO/OeQKwKGZ xen+AizSxJSuTeAtKDg1KU+A7GEdvSOfr0Xo2tww0UBBCx6phENFYsYHRkFeCW7N7m/h cGwOmx2L/D1dX2dP6CdM4Vevo+Nhz7tIOJvYo2VBg3ezfwhsz1bFcYULHJptaV2HpnrH do7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:subject:user-agent:date :message-id:dkim-signature; bh=jc5VbaQwUAskmlbLCG9X0yrIpMat+oHNiyMTIckJ+Oo=; fh=vyMtYBMVBz3Xf7jpbK1JXUTwZB5PvoNNMqKaHMXmYrY=; b=pklMd1/ZmWQX0P7BiUPBf8eyrh+R/g+6QSbLFN0kIbWrzGs8OO8KZD9cBFv1PzE+O/ JwUYcN0ab8/VwXkhI79AL3URKrz/F15ql3XZpRu2ZUrVDv4Ir3klSvjJxw3rer9GxV4o ufhLkelcuJz6k36gHsZG71S84CyhcB59zXrG64vkyl5uQWv+np36y+6aqzE3w0DHgNb3 zmWQTvtubwvPuZ1uNPEfSJByrBScvG5SjnjdnHGdlOa1OoJ7kvMXF/Ysdv5XHPYb1XHH aKj7P55V/SHpRAzeWQ1Y9joaUK87CqgcS1FqvzqCdouYRnlIGy1OrSn/UCMEg0xmoMNu noDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=AtDkIdXB; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb6-20020a170906b88600b0099309c64f17si7892656ejb.146.2023.07.10.03.02.19; Mon, 10 Jul 2023 03:02:43 -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; dkim=pass header.i=@vivo.com header.s=selector2 header.b=AtDkIdXB; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbjGJJlW (ORCPT + 99 others); Mon, 10 Jul 2023 05:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232906AbjGJJkB (ORCPT ); Mon, 10 Jul 2023 05:40:01 -0400 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2115.outbound.protection.outlook.com [40.107.215.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E6D41FD7 for ; Mon, 10 Jul 2023 02:37:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hHSGHvBk1ZSesdTEy4idLSv8Oz2VJtfLAswLlRsi0SCX35gz8/IQRi/Xpq3dxfB8IzLHzIjh6Bq2xlTT21EI/hoZajgXFgIpGKT56C58sxHmhrzovY59RGWdDpnlL1uePD9qBYXuiRDmpM+Z9AgIOiWBDM3pMpLwb1xpdOFKs/Rhv3G9OQnx1ULw6CFxGwYNBc20btM1SfP/IBAI9GT0IdNXuUnGd5rnJ7KD8h6xDFTjLuZDobn3luyUh0DDrDU7YEeMSLf6Hj92ImvlDQRWITTfuR6kDRtWbw6wr7ot2xQy+b1Yzmn2K0jm30xnnY8U5D3Tqr5jV3wMaxj5aq61qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jc5VbaQwUAskmlbLCG9X0yrIpMat+oHNiyMTIckJ+Oo=; b=NECZ9ezjR8kx1D00K8yoOCZbjkg1xS7FigWGThoP/Akl9OmDzj/ggEWapwte075mqPG2+BkidNWRRlvPqt/8gxp8uQ+tbHGHy0PtsbofGhAKc9EmGXLulXAzEy8O4hD5ffqyGNwcnqC7HRoBIGdX62iM5WXhNAue1pu0GTuKCwaD8hk8CXBJRrW6Uiftv/x+1tLBc6Jui3rO8i6RMV/OQkWwjyry877mDLrVqP/zDF7AWafFl/xVjs5jwMpGt41t/DKtQ9MkIG9nlQ9tW8tbIwkwhGYAtJHHER8hicXWJrZ38YsLx0TorfvF03wJHDtGT5VQpno3bFtfX2QV0nTIrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jc5VbaQwUAskmlbLCG9X0yrIpMat+oHNiyMTIckJ+Oo=; b=AtDkIdXBPRaNoLgR79llbvH6jHRX5uOtPYm63j1jc0zZYml6Rqozys9uAtRI76S4j1pbL6NI5tM9PEE5TgI8ho02XwImgi+UmFtUdMm5XfXwR576KdBOSE/FfUnnkTOu2+wdg3vNXZ1gh6YpiJPLLiwf2iMwW2fVV4BwC8u+/H29wywaEoYO0m/friEVe1Gs88Xuo8Rb/ygsZW9TpRQ9jJ2rhRNVsWgHavkMcIPJyRZfLlEJFQnXdmhqZdaFVR93cjwGgHjoCPgiFwt+6lD59e/B7Iu785pf7hsa6hvcd/mcP4p1jzO4PWIIU6QoclzwQlrToNy2tYGTySlbqROZRA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SG2PR06MB3338.apcprd06.prod.outlook.com (2603:1096:4:97::23) by PUZPR06MB5555.apcprd06.prod.outlook.com (2603:1096:301:eb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30; Mon, 10 Jul 2023 09:37:32 +0000 Received: from SG2PR06MB3338.apcprd06.prod.outlook.com ([fe80::a05b:2f8b:fba5:50fb]) by SG2PR06MB3338.apcprd06.prod.outlook.com ([fe80::a05b:2f8b:fba5:50fb%7]) with mapi id 15.20.6565.028; Mon, 10 Jul 2023 09:37:32 +0000 Message-ID: Date: Mon, 10 Jul 2023 17:37:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: [PATCH] erofs: fix two loop issues when read page beyond EOF To: Gao Xiang , "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> <1a107593-e411-70a0-b6b8-3c34a9036ff3@linux.alibaba.com> From: Chunhai Guo In-Reply-To: <1a107593-e411-70a0-b6b8-3c34a9036ff3@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SI2PR04CA0013.apcprd04.prod.outlook.com (2603:1096:4:197::6) To SG2PR06MB3338.apcprd06.prod.outlook.com (2603:1096:4:97::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3338:EE_|PUZPR06MB5555:EE_ X-MS-Office365-Filtering-Correlation-Id: 0204bb1b-1d97-4b6a-ab3f-08db8129491d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NF8fjbBGpGe/1r7N37smSa3VgG79q1K/U24ZPSTQyD1nHawFPVkHvw0BOf+zygX7lhBbd8BqAWafwCYllILozKsTt4DL9XMa2/8ORV5beGeyJnl+IAl04SgC3H20DaQ8q5Pm0WSqepu9CcyMNDZDecvRu1zAsG09muMdnyc2Vz9iH+JO5/ssRq0s83LJNRbeBozAPiBuA+cSmsrhVv+qnhfQ2DVYvvQfvyT0MU1+riwmdmZHnKkBevH7fyhKNRZ4mBGyoVbuRYS4H5K2YmDv0gDV2l9Iy3bmIAwhsHnQEDmttJpdy0WcySA0lE4e1cyKExkEJcq07s5PxjAS5wJqdZI3RAkxpBsRfj5XUM0ZbosnXESgX7dZd+zOwhGF4DZaSEYp9d52LB4B0sMP1luA9J377ldwTV68N0gPACjVnrqToUDSGt8vzZBteUftB+ZK1E/bh9eRiXrqivJI2PfKazdexV8wJl7ztjEVjmPrv/MYo22nBZqnN8J0Rzgp5pNkzL5lxH7lx76GX+8Jn2PKpUKOWE960ZI4D4DwtufVtzwSKT1VT79wGpkWpkedufrFSCmjvz2KmuxIeA+tuVmLrlnohcZbcXYa7UCzbrBFu5PTvFRkUd17kAbvCFoObWQxH3QUGx/xuXgH/sSVu+ckFQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SG2PR06MB3338.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(366004)(396003)(39860400002)(346002)(376002)(451199021)(36756003)(86362001)(31696002)(38100700002)(478600001)(110136005)(6666004)(54906003)(6486002)(6512007)(8676002)(8936002)(5660300002)(2906002)(316002)(4326008)(66946007)(66556008)(66476007)(31686004)(41300700001)(2616005)(26005)(53546011)(6506007)(186003)(83380400001)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cGhNNTBOd0liMUtFTWF1L3FZdkFSQ0phUVNlWVZyVS9Ea2c1b2xlVUpQdVZZ?= =?utf-8?B?WGhZSCtQeVFPZGxrMTZlclR3akdWZXRPWFZ1bERWb0pIdVpManNZMnZRRzJC?= =?utf-8?B?T3NqQXN0b3B3VGh0QldLMzl0eHBCNlFRcHJyMVBFR0hiRUI2aXl1bCtqbmlB?= =?utf-8?B?VHR0em1xeWF6UVFQSWRqNDZadUpPOU1jdWVLWmluaXBBTHBvRVNiV2JWaVcr?= =?utf-8?B?M0RtN3o2bzgvYmFYTCt0NnR0WENJdkxyV1k1YTNveTFWTUtJdDRLd0IzeTBm?= =?utf-8?B?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c1N5QzRzOEVzMElTdVl4UG1NZnd4c3U0?= =?utf-8?Q?nICPdtaT5iRFqqkfOew+0E6uX?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0204bb1b-1d97-4b6a-ab3f-08db8129491d X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3338.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2023 09:37:32.4511 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Gn+bCT4hyz2+ixwAn5DrgD+M3EoX4jUnKA8E8WJN+G8CuyrMSvvJHjr0OBt5ouoINVKWlhsC4cfwgAAsttuzbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB5555 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 13:02, Gao Xiang wrote: > > > 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 > Got it. I have sent the patch. Please have a check. Thanks, Guo Chunhai