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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 943BAC433F5 for ; Thu, 20 Jan 2022 11:09:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D28666B009E; Thu, 20 Jan 2022 06:09:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD8EA6B00A2; Thu, 20 Jan 2022 06:09:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA0226B00A4; Thu, 20 Jan 2022 06:09:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id AA36F6B009E for ; Thu, 20 Jan 2022 06:09:37 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5D21695CB3 for ; Thu, 20 Jan 2022 11:09:37 +0000 (UTC) X-FDA: 79050394794.19.6401B1D Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf22.hostedemail.com (Postfix) with ESMTP id E09CDC0008 for ; Thu, 20 Jan 2022 11:09:35 +0000 (UTC) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JffnP2sjDz1FCph; Thu, 20 Jan 2022 19:05:45 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 20 Jan 2022 19:09:31 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.21; Thu, 20 Jan 2022 19:09:30 +0800 Message-ID: Date: Thu, 20 Jan 2022 19:09:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v2 1/2] powerpc: Fix virt_addr_valid() check Content-Language: en-US To: Christophe Leroy , Nicholas Piggin , Andrew Morton , "Benjamin Herrenschmidt" , Kees Cook , Laura Abbott , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linuxppc-dev@lists.ozlabs.org" , Mark Rutland , Michael Ellerman , Paul Mackerras References: <20211225120621.13908-1-wangkefeng.wang@huawei.com> <20211225120621.13908-2-wangkefeng.wang@huawei.com> <09ed46a5-6df3-ffc0-8243-61612c06153a@huawei.com> <1641871726.fshx7g5r92.astroid@bobo.none> <8a24ef1d-1c93-416d-cfbe-e63aacfb25cc@huawei.com> <017744c1-1252-a25c-3dcc-057ee18d0769@csgroup.eu> From: Kefeng Wang In-Reply-To: <017744c1-1252-a25c-3dcc-057ee18d0769@csgroup.eu> Content-Type: text/plain; charset="UTF-8"; format=flowed X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggeme704-chm.china.huawei.com (10.1.199.100) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E09CDC0008 X-Stat-Signature: s5bmh871yruzq9cioh8736nairyf76o3 Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam08 X-HE-Tag: 1642676975-586638 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: On 2022/1/20 15:31, Christophe Leroy wrote: > > Le 19/01/2022 =C3=A0 02:15, Kefeng Wang a =C3=A9crit=C2=A0: >> On 2022/1/11 14:04, Christophe Leroy wrote: >>> Le 11/01/2022 =C3=A0 05:37, Nicholas Piggin a =C3=A9crit=C2=A0: >>>> Excerpts from Kefeng Wang's message of January 8, 2022 9:58 pm: >>>>> Hi PPC maintainers=EF=BC=8C ping.. >>>> Hmm. I might have confused myself about this. I'm going back and >>>> trying to work out what I was thinking when I suggested it. This >>>> works on 64e because vmalloc space is below the kernel linear map, >>>> right? >>>> >>>> On 64s it is the other way around and it is still possible to enable >>>> flatmem on 64s. Altough we might just not hit the problem there beca= use >>>> __pa() will not mask away the vmalloc offset for 64s so it will stil= l >>>> return something that's outside the pfn_valid range for flatmem. Tha= t's >>>> very subtle though. >>> That's the way it works on PPC32 at least, so for me it's not chockin= g >>> to have it work the same way on PPC64s. >>> >>> The main issue here is the way __pa() works. On PPC32 __pa =3D va - >>> PAGE_OFFSET, so it works correctly for any address. >>> On PPC64, __pa() works by masking out the 2 top bits instead of >>> substracting PAGE_OFFSET, so the test must add a verification that we >>> really have the 2 top bits set at first. This is what (addr >=3D >>> PAGE_OFFSET) does. Once this first test is done, we can perfectly rel= y >>> on pfn_valid() just like PPC32, I see absolutely no point in an >>> additionnal test checking the addr is below KERN_VIRT_START. >> >> Hi Christophe and Nicholas=EF=BC=8C for ppc32=EF=BC=8C I think we need= check the upper >> limit, > Why ? Have you experimented any problem at all on PPC32 with the way it > is done at the moment ? > > I don't think we have to change PPC32 at all unless we have a real > reason to do it. yes, I missed this commit in old kernel(lts5.10), you have fixed the=20 upper limit. commit 602946ec2f90d5bd965857753880db29d2d9a1e9 Author: Christophe Leroy Date:=C2=A0=C2=A0 Tue Oct 12 12:40:37 2021 +0200 =C2=A0=C2=A0=C2=A0 powerpc: Set max_mapnr correctly > >> eg,=C2=A0 addr >=3D PAGE_OFFSET && addr < high_memory > Isn't it exactly what pfn_valid() already do today ? > Why change that at all ? > > Christophe > >> arch/powerpc/mm/mem.c:=C2=A0 high_memory =3D (void *) __va(max_low_pfn= * >> PAGE_SIZE); >> >> for ppc32 max_low_pfn is the upper low memory pfn,=C2=A0 and For ppc64= , >> high_memory is >> >> the max memory pfn, it looks good too, correct me if I'm wrong, if the >> above check >> >> is ok, I will send a new v3,=C2=A0 thanks. >> >> >> >> >>> >>>> The checks added to __pa actually don't prevent vmalloc memory from >>>> being passed to it either on 64s, only a more basic test. >>> That's correct. It is the role of pfn_valid() to check that. >>> >>> Christophe >>> >>>> I think 64s wants (addr >=3D PAGE_OFFSET && addr < KERN_VIRT_START) = as >>>> the condition.=C2=A0 Could possibly add that check to __pa as well t= o >>>> catch vmalloc addresses. >>>> >>>> Thanks, >>>> Nick >>>> >>> >