Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5835921rwb; Tue, 1 Aug 2023 08:31:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlEmL1cQHQ0XsAu+IWjSmL3FEvlqGBaUJkM64/mmhrH0ggnJCNjH8gLeSgM9kYuIDZzTqDzU X-Received: by 2002:aa7:9a8c:0:b0:686:5f73:4eac with SMTP id x12-20020aa79a8c000000b006865f734eacmr14186984pfi.13.1690903900319; Tue, 01 Aug 2023 08:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690903900; cv=none; d=google.com; s=arc-20160816; b=FP2915+jSXhy4cb9BA9RSXCDNMS3usghdqtQDtR07k8IRUTxAwGnm82FPo0LIdbVB9 gSeOOEdLG4BedfIFTqhNAgkJ4RcIwevvm3tSc8NPR7qij/MXs1ujnJZ376ORx9UgNwx6 E+3J4fY2WhKET8+sNaY62Qg1rJjYnpkGUJWT95CX981EFVDZeIE1HSGnMYsnpQHBqCUO qZEDKe73Q13srQL3FNKNv7HoSWeVyCtwEK88WNBtqZTL1J6Pjt5HDpituSh7JvcATdCg F5utOBHlha6z59MYqllek/MmmapV3h1OBOKWpNaR2F8IiZEi+uwL4g/TquQ6JH7fciXq 3yaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O8i0szRefbgJeKSL2o0qG6DrCbaDUp44uTnfIIYA8MY=; fh=i3gLtdu9xSzQPPVTj+9s6FBK2YcuZWkS7XUWqyPqS+g=; b=NUxLha9PAEkC3AhqnczA+HNcKbvxTI6OMCPaaOHSBxChHm/vV8bh7NKeQEtNOdIGyL byAB8NglTV3Czg+yaUw/FUnqlkelshEISeQsx49P8FzrqhBXOibzjIiOpO+gey08+4Tt TpemIR/D2riCXn0uelk82T+NjGWNA2pZVz2wLBW272/281IrXARIIVnvwPCKLh9657Fo 0Xg0nag7/arRc16eUiwQ8J2xCdx2ERcLQIKpgKM67Vccl7Ng3L57OFUNVT8djHA3QqUP YrgGHcFKbNGdvEHqtiAhDZmcKNNGGFZ+mRXBYl9cIaTM4u8xMYRd62Dl4Yq8IImqujas EiBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dqf88m/h"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca11-20020a056a00418b00b006871e685bc7si5454167pfb.2.2023.08.01.08.31.26; Tue, 01 Aug 2023 08:31: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dqf88m/h"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbjHAMuf (ORCPT + 99 others); Tue, 1 Aug 2023 08:50:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233801AbjHAMuP (ORCPT ); Tue, 1 Aug 2023 08:50:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 734801FCB for ; Tue, 1 Aug 2023 05:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690894160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O8i0szRefbgJeKSL2o0qG6DrCbaDUp44uTnfIIYA8MY=; b=dqf88m/hKiEH7Qp7VRNqaOgqpJJLS0Yy2467e+MQu5et00uAj7vxUt2Ft+m3vj4Yw+a+Ga n3T5ZM5UoFQ35EMYfxCfO5kHzduHhO/6lIzXkm36hGL5BjWE1e/txM/gdGOJTNn897bkQD 8IwC1fPPM1jxjhzX/1EWdteZioLyHDY= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-gTEMugfTOwCxAfHJNfIDeg-1; Tue, 01 Aug 2023 08:49:17 -0400 X-MC-Unique: gTEMugfTOwCxAfHJNfIDeg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C82C71C09A44; Tue, 1 Aug 2023 12:49:16 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECD06C585A1; Tue, 1 Aug 2023 12:49:11 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Linus Torvalds , liubo , Peter Xu , Matthew Wilcox , Hugh Dickins , Jason Gunthorpe , John Hubbard , Mel Gorman , Shuah Khan , Paolo Bonzini Subject: [PATCH v2 5/8] pgtable: improve pte_protnone() comment Date: Tue, 1 Aug 2023 14:48:41 +0200 Message-ID: <20230801124844.278698-6-david@redhat.com> In-Reply-To: <20230801124844.278698-1-david@redhat.com> References: <20230801124844.278698-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 Especially the "For PROT_NONE VMAs, the PTEs are not marked _PAGE_PROTNONE" is wrong: doing an mprotect(PROT_NONE) will end up marking all PTEs on x86 as _PAGE_PROTNONE, making pte_protnone() indicate "yes". So let's improve the comment, so it's easier to grasp which semantics pte_protnone() actually has. Signed-off-by: David Hildenbrand --- include/linux/pgtable.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index f34e0f2cb4d8..6064f454c8e3 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1333,12 +1333,16 @@ static inline int pud_trans_unstable(pud_t *pud) #ifndef CONFIG_NUMA_BALANCING /* - * Technically a PTE can be PROTNONE even when not doing NUMA balancing but - * the only case the kernel cares is for NUMA balancing and is only ever set - * when the VMA is accessible. For PROT_NONE VMAs, the PTEs are not marked - * _PAGE_PROTNONE so by default, implement the helper as "always no". It - * is the responsibility of the caller to distinguish between PROT_NONE - * protections and NUMA hinting fault protections. + * In an inaccessible (PROT_NONE) VMA, pte_protnone() may indicate "yes". It is + * perfectly valid to indicate "no" in that case, which is why our default + * implementation defaults to "always no". + * + * In an accessible VMA, however, pte_protnone() reliably indicates PROT_NONE + * page protection due to NUMA hinting. NUMA hinting faults only apply in + * accessible VMAs. + * + * So, to reliably identify PROT_NONE PTEs that require a NUMA hinting fault, + * looking at the VMA accessibility is sufficient. */ static inline int pte_protnone(pte_t pte) { -- 2.41.0