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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 198C5C1B08C for ; Thu, 15 Jul 2021 12:45:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 948C860FED for ; Thu, 15 Jul 2021 12:45:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 948C860FED Authentication-Results: mail.kernel.org; dmarc=fail (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 CA6948D00B9; Thu, 15 Jul 2021 08:45:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C579F8D0065; Thu, 15 Jul 2021 08:45:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF7CE8D00B9; Thu, 15 Jul 2021 08:45:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 86CDF8D0065 for ; Thu, 15 Jul 2021 08:45:07 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5374A184B956F for ; Thu, 15 Jul 2021 12:45:06 +0000 (UTC) X-FDA: 78364792212.14.1B0E269 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id 64F4AE008BF1 for ; Thu, 15 Jul 2021 12:45:03 +0000 (UTC) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GQYsL4bDXzbcyL; Thu, 15 Jul 2021 20:41:42 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 15 Jul 2021 20:45:00 +0800 Received: from [10.174.179.191] (10.174.179.191) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 15 Jul 2021 20:45:00 +0800 Subject: Re: [PATCH] mm/vmalloc: fix wrong behavior in vread To: Uladzislau Rezki CC: , , , , , , Hulk Robot References: <20210714015959.3204871-1-chenwandun@huawei.com> <20210715105813.GA1879@pc638.lan> From: Chen Wandun Message-ID: <8ece1d71-5b0d-331a-a170-0d5e8cdbedae@huawei.com> Date: Thu, 15 Jul 2021 20:44:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210715105813.GA1879@pc638.lan> Content-Type: text/plain; charset="UTF-8"; format=flowed X-Originating-IP: [10.174.179.191] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 64F4AE008BF1 X-Stat-Signature: abbaxzrffgi7squsndjgmifxb614bywg Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf30.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=chenwandun@huawei.com X-HE-Tag: 1626353103-593481 Content-Transfer-Encoding: quoted-printable 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: =E5=9C=A8 2021/7/15 18:58, Uladzislau Rezki =E5=86=99=E9=81=93: > On Wed, Jul 14, 2021 at 09:59:59AM +0800, Chen Wandun wrote: >> commit f608788cd2d6 ("mm/vmalloc: use rb_tree instead of list for vrea= d() >> lookups") use rb_tree instread of list to speed up lookup, but functio= n >> __find_vmap_area is try to find a vmap_area that include target addres= s, >> if target address is smaller than the leftmost node in vmap_area_root, >> it will return NULL, then vread will read nothing. This behavior is >> different from the primitive semantics. >> >> The correct way is find the first vmap_are that bigger than target add= r, >> that is what function find_vmap_area_exceed_addr does. >> >> Fixes: f608788cd2d6 ("mm/vmalloc: use rb_tree instead of list for vrea= d() lookups") >> Reported-by: Hulk Robot >> Signed-off-by: Chen Wandun >> --- >> mm/vmalloc.c | 29 ++++++++++++++++++++++++++++- >> 1 file changed, 28 insertions(+), 1 deletion(-) >> >> diff --git a/mm/vmalloc.c b/mm/vmalloc.c >> index d5cd52805149..47c3a551b6dc 100644 >> --- a/mm/vmalloc.c >> +++ b/mm/vmalloc.c >> @@ -787,6 +787,28 @@ unsigned long vmalloc_nr_pages(void) >> return atomic_long_read(&nr_vmalloc_pages); >> } >> =20 >> +static struct vmap_area *find_vmap_area_exceed_addr(unsigned long add= r) >> +{ >> + struct vmap_area *va =3D NULL; >> + struct rb_node *n =3D vmap_area_root.rb_node; >> + >> + while (n) { >> + struct vmap_area *tmp; >> + >> + tmp =3D rb_entry(n, struct vmap_area, rb_node); >> + if (tmp->va_end > addr) { >> + va =3D tmp; >> + if (tmp->va_start <=3D addr) >> + break; >> + >> + n =3D n->rb_left; >> + } else >> + n =3D n->rb_right; >> + } >> + >> + return va; >> +} >> + > Can we combine pvm_find_va_enclose_addr() with your new function > making it as one function? The aim is to reduce copy-paste and > not create such new "find" functions. > > The pvm_find_va_enclose_addr() seems does the same but only in > reverse order. So something like: > > find_vmap_area_exceed_addr(bool reverse) I dig into the two function, and found the lookup logic is some big diffe= rence between them. pvm_find_va_enclose_addr is to find the highest vmap_area whose va_start = is little than target address. find_vmap_area_exceed_addr is to find the lowest vmap_area whose va_end t= hat bigger than target address. Two function maybe more clear. But some refactor work can be done to make the code more readable and mor= e common to use, I'm trying it. Thanks for your suggestion. Wandun > > Thanks! > > -- > Vlad Rezki > .