From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA4E3C433DF for ; Fri, 15 May 2020 06:52:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 98830206F1 for ; Fri, 15 May 2020 06:52:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98830206F1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 80EE190000C; Fri, 15 May 2020 02:52:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BFEE8E0008; Fri, 15 May 2020 02:52:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 703B98E0005; Fri, 15 May 2020 02:52:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 555D88E0005 for ; Fri, 15 May 2020 02:52:43 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EEB9649961A for ; Fri, 15 May 2020 06:52:42 +0000 (UTC) X-FDA: 76818035364.13.goat68_51d8d9c6d2740 X-HE-Tag: goat68_51d8d9c6d2740 X-Filterd-Recvd-Size: 2908 Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 06:52:42 +0000 (UTC) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3E1FC151D066A462048B; Fri, 15 May 2020 14:52:30 +0800 (CST) Received: from [127.0.0.1] (10.166.215.55) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Fri, 15 May 2020 14:52:28 +0800 Subject: Re: [PATCH v2 07/10] block: use sectors_to_npage() and PAGE_SECTORS to clean up code To: Matthew Wilcox CC: Minchan Kim , Nitin Gupta , "Sergey Senozhatsky" , Jens Axboe , Coly Li , Kent Overstreet , Alasdair Kergon , Mike Snitzer , linux-block , "Andrew Morton" , linux-mm , dm-devel , Song Liu , linux-raid , linux-kernel References: <20200507075100.1779-1-thunder.leizhen@huawei.com> <20200507075100.1779-8-thunder.leizhen@huawei.com> <20200515041916.GE16070@bombadil.infradead.org> From: "Leizhen (ThunderTown)" Message-ID: Date: Fri, 15 May 2020 14:52:26 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20200515041916.GE16070@bombadil.infradead.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.166.215.55] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2020/5/15 12:19, Matthew Wilcox wrote: > On Thu, May 07, 2020 at 03:50:57PM +0800, Zhen Lei wrote: >> +++ b/block/blk-settings.c >> @@ -150,7 +150,7 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto >> unsigned int max_sectors; >> >> if ((max_hw_sectors << 9) < PAGE_SIZE) { >> - max_hw_sectors = 1 << (PAGE_SHIFT - 9); >> + max_hw_sectors = PAGE_SECTORS; > > Surely this should be: > > if (max_hw_sectors < PAGE_SECTORS) { > max_hw_sectors = PAGE_SECTORS; > > ... no? I've noticed this place before. "(max_hw_sectors << 9) < PAGE_SIZE" can also make sure that max_hw_sectors is not too large, that means (max_hw_sectors << 9) may overflow. > >> - page = read_mapping_page(mapping, >> - (pgoff_t)(n >> (PAGE_SHIFT - 9)), NULL); >> + page = read_mapping_page(mapping, (pgoff_t)sectors_to_npage(n), NULL); > > ... again, get the type right, and you won't need the cast. OK, I'll consider it. > > > . >