Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1909827pxp; Mon, 21 Mar 2022 07:29:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRGt0p4hbjkYDhm93MYKJtzTflL9ZhDcW4Qhvlul5xTesh7KR2SRzURcx5aWnDPTO/k4Qw X-Received: by 2002:a17:907:3e99:b0:6df:7ad3:f66b with SMTP id hs25-20020a1709073e9900b006df7ad3f66bmr21481527ejc.230.1647872980109; Mon, 21 Mar 2022 07:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647872980; cv=none; d=google.com; s=arc-20160816; b=qsz+JYf8LSN0knOjtkZPyoZaJxjnxVkqvtq4sFex4muUYiXZdkFqQOp2viAuVjZt3f eMS1ZL0dJd+Jwe88nZ23Qr8HBFKtLzU1XbZVo62OnfsLCyS+aelOcmkH0ZBDqtsnlPvs 1SRuPnUn3Ht15iBvI7F3mdE5XzyUR+wX4MuU/ihxNzB8bwc7grV5yFPHtIAhcnQZQ9Nh fw8Ha8om+Oa/CjG3kyHN7wtgdc0935Pcl8v+ncAaPXD+2ytX9MWMN9ysFT1DymeS2NUk FCJe87ktxZRuDV7yJtDkiwGu5SUL65VHs5hKVU997PctHB6GEffIStwcKlJjg8/HWBpI ZvJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=abyJWT9h8rbaIDCx4MLJskFnsLCSwFI+Y4YARYOi2f4=; b=p+3asjzk661lqPmnWrfLpoPH320X2VUKKAr2znn/mnUmpJhEQOGbVO5e7wkPcQnyQP Se0sm06QRzqbf4JDI14ayBYIxNFeuULTXDDiutZ9YXMKD61UAwdybU2H0uH13vsUnxcZ q9ssKOeAMy2Rd6ZNNu3u8me+M4H18kAjazu2EXjTuvhIyo8LN29BLRFu3uM6h2B1KtTv 7sc4QK7gBF2ETH7uaJas2NK0cFKh+8VCrNx5l4Q4jdCcpyLu9jDTcLRSCvwwTODn65Z0 AHGgG1UJUFtOIiBmfjj54O3S7A1LyzOdJ3sQ1j7GRalzjhY/hlJIKnJLAvdQHnjWtzNs yN9w== ARC-Authentication-Results: i=1; mx.google.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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a17090616c900b006df76385dc9si6291428ejd.617.2022.03.21.07.29.13; Mon, 21 Mar 2022 07:29:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239522AbiCRRTp (ORCPT + 99 others); Fri, 18 Mar 2022 13:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236629AbiCRRTo (ORCPT ); Fri, 18 Mar 2022 13:19:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9512F25 for ; Fri, 18 Mar 2022 10:18:24 -0700 (PDT) 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 58D79619C6 for ; 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-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,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 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