Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1620966pxp; Thu, 17 Mar 2022 12:55:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzE4Fyrf66EX9kjUmZ2HGlmg+ZWngSEBapZtRZI4RfYdjt8jHcPlfOm/kiFNwZLiNtRVXrj X-Received: by 2002:a17:902:f708:b0:153:839f:bf2c with SMTP id h8-20020a170902f70800b00153839fbf2cmr6413465plo.113.1647546929572; Thu, 17 Mar 2022 12:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546929; cv=none; d=google.com; s=arc-20160816; b=z4gPgZ5TjwALOE8uJwXF1oZ/p4wgckk0eDpfPnrHeIJt1VUMoCFxHK6Fgm7u0cJrZn q+ZonPvDYOASp6g6Xsnt5T9yrNTxvNsCrE/b9Je5dQROAW9gYpJc+w95YJommAbkuI7S E8kLHDevGx9vxrk/Yn0XYpx8i473KmJRxQhfQk2m3K3k5iXfUB+vrCIfbYFHgm0Y9mBG QCuGmbZt0IV5374xAb0akcnFxNi+9SRzCkpsu+dtLPpOGZpGBvqhH7pb/53sJhMA8EFW 67F5xlvizO5lqn/MFdEXthCWaHYzKjdH8ujGzxMz86NGMJtNEG+uP+/HWrYK3TLkeI1C ShkA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=kmSAVIxDhqRDk716IarmcZ84Nzu8AC36N67rDqNpvLM=; b=RSpJngO0psWMuuiiQW6N18Fp0UIrBzBmwrPq6D7MB+XFDwFwvSUaWtMnLULyn8zaTI KphGmg2ZwdviDAmGsH/TT7xFeGozJRe/5DtC1uuhb3lx75bECdgwGuZP4m27+nmDdFX+ nvuLOv8NephGaQXktH+80lqvDay21VHHA0m6pNaXrwMxbaHces4vcFAAg6A2/Kpsfcw9 jPFGuimjacK5Le8vQnTArmKwoQW93Ijw/FAU/pEpqBYEJYB2IhfkPTgYVILq/c3MpyeA RP7eza03RbF6j35Qo/9w+++I3wZaI/i9kbHfUowFbp6VvIgp5CuwSZtBOe0GSzHPQHBf GKPw== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d1-20020a056a0024c100b004f71cada491si6164273pfv.41.2022.03.17.12.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:55:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B0F125A4B3; Thu, 17 Mar 2022 12:49:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237753AbiCQTBc (ORCPT + 99 others); Thu, 17 Mar 2022 15:01:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233676AbiCQTBa (ORCPT ); Thu, 17 Mar 2022 15:01:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D23916BCF7 for ; Thu, 17 Mar 2022 12:00:14 -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 ED87D617B7 for ; Thu, 17 Mar 2022 19:00:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4176C340E9; Thu, 17 Mar 2022 19:00:08 +0000 (UTC) Date: Thu, 17 Mar 2022 19:00:04 +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=us-ascii Content-Disposition: inline In-Reply-To: <20220317141203.3646253-4-tongtiangen@huawei.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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); > +} There is another class of user mappings, execute-only, that have both PTE_USER and PTE_UXN cleared. So this logic should be: pte_valid(pte) && (pte_user(pte) || pte_user_exec(pte)) with pte_user() as: #define pte_user(pte) (!!(pte_val(pte) & PTE_USER)) Do we care about PROT_NONE mappings here? They have the valid bit cleared but pte_present() is true. > +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. Similar comment to the pte variant on execute-only and PROT_NONE mappings. -- Catalin