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 04121C433F5 for ; Fri, 18 Mar 2022 17:18:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FCE68D0002; Fri, 18 Mar 2022 13:18:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D2188D0001; Fri, 18 Mar 2022 13:18:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 399498D0002; Fri, 18 Mar 2022 13:18:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 2B1268D0001 for ; Fri, 18 Mar 2022 13:18:26 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D50FC6040B for ; Fri, 18 Mar 2022 17:18:25 +0000 (UTC) X-FDA: 79258165770.13.F1D5C1C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 457C14001E for ; Fri, 18 Mar 2022 17:18:25 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 54A7D619B6; Fri, 18 Mar 2022 17:18:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80BEDC340E8; Fri, 18 Mar 2022 17:18:20 +0000 (UTC) Date: Fri, 18 Mar 2022 17:18:16 +0000 From: Catalin Marinas To: Tong Tiangen Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Pasha Tatashin , Andrew Morton , Will Deacon , Paul Walmsley , Palmer Dabbelt , Palmer Dabbelt , Albert Ou , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH -next 3/4] arm64: mm: add support for page table check Message-ID: References: <20220317141203.3646253-1-tongtiangen@huawei.com> <20220317141203.3646253-4-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 457C14001E X-Stat-Signature: 1wxp6wkxnjdygteohtesjxyshsxbqdr3 Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf01.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Rspam-User: X-HE-Tag: 1647623905-702153 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 Fri, Mar 18, 2022 at 11:58:22AM +0800, Tong Tiangen wrote: > 在 2022/3/18 3:00, Catalin Marinas 写道: > > On Thu, Mar 17, 2022 at 02:12:02PM +0000, Tong Tiangen wrote: > > > @@ -628,6 +647,25 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) > > > #define pud_leaf(pud) pud_sect(pud) > > > #define pud_valid(pud) pte_valid(pud_pte(pud)) > > > +#ifdef CONFIG_PAGE_TABLE_CHECK > > > +static inline bool pte_user_accessible_page(pte_t pte) > > > +{ > > > + return (pte_val(pte) & PTE_VALID) && (pte_val(pte) & PTE_USER); > > > +} [...] > > Do we care about PROT_NONE mappings here? They have the valid bit > > cleared but pte_present() is true. > > > > PTC will not check this special type(PROT_NONE) of page. PROT_NONE is just a permission but since we don't have independent read and write bits in the pte, we implement it as an invalid pte (bit 0 cleared). The other content of the pte is fine, so pte_pfn() should still work. PTC could as well check this, I don't think it hurts. > > > +static inline bool pmd_user_accessible_page(pmd_t pmd) > > > +{ > > > + return pmd_leaf(pmd) && (pmd_val(pmd) & PTE_VALID) && > > > + (pmd_val(pmd) & PTE_USER); > > > +} > > > > pmd_leaf() implies valid, so you can skip it if that's the aim. > > PTC only checks whether the memory block corresponding to the pmd_leaf type > can access, for !pmd_leaf, PTC checks at the pte level. So i think this is > necessary. My point is that the (pmd_val(pmd) & PTE_VALID) check is superfluous since that's covered by pmd_leaf() already. -- Catalin