Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2481501rwo; Thu, 3 Aug 2023 09:59:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlF00UaO8S9KKTOVOGNM6jeNW8wF3Qs/x2IYK1gBFcTJaHd0E6VDoDfuPVhs90/vHySSIrAp X-Received: by 2002:a17:90a:6be6:b0:268:36a2:bd0 with SMTP id w93-20020a17090a6be600b0026836a20bd0mr16907930pjj.8.1691081999521; Thu, 03 Aug 2023 09:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691081999; cv=none; d=google.com; s=arc-20160816; b=YQWuvLklRE3ngdqS1Zj8DYDv84dZA9HvDz7c6O7dyYpYvyX79kHzkj4jnkjDCUiQrI 02ckgWWAAtXxtptgEEtldegnchFm5kR1fFruVgPnK9doku0VOWRucjRNovNekXIF1vkD orrsfZkoA718bBIgqbIwofVDssfqm7qJRDMIEYgCMH+nkPrJQzy1eJyykDWt/8+6xJvC 6mD+WRp1yn5cLOtQn4UiATxTSFFK2q3P58YGhGK9A9Kqmz6XfYKCzbDuaTIlJU64pBDW t39yzc3EvfK2o0zpL2Epn04SSzm0dguYbrjJ9YQahKEGbycJjQy0rUoNS8GMQ2Z4WkHU +CVw== 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=ymf0b+2Kqr9mLIxdkVxybggSGs/fK9hNLVEJOY2Qbdo=; fh=7gHKz8hUXog+nH8+rwpQvaH3+lNm2h8Xml5IfBzuWtM=; b=Eec4Of+7e1HnFwhK1hoYK26Flr2EtiaL33xnENFIQM42c9YomdfkuJaoY5TnM7gP09 uN7VDXZu8xg1r/syMZ9hkHvEtpGzn221KHpjKy5vFO4F/eA6x6i5votAJHS/oteihte5 JURqjoJ1HEKGAUL3mQtQ9bGt50KUmq9KHtX32+iERGiO/v9PED+Dd9SJJQoHF+G2yIhH KfOUdDd/Kyh4v+Qbx9tK5jX10rPFGCWiCCHXWv0VT/F2YeAYh0jSWaB/mwxzuZ4Rn/CX vAAqbPu6lQQMWPFL9Ckpp8RXKkgHbZnZiVW/t47vqKAQ44VncGD9f1G5rEATKdL96/eB Y2Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eyPFpmXS; 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 qe13-20020a17090b4f8d00b0025690b76c95si329942pjb.10.2023.08.03.09.59.37; Thu, 03 Aug 2023 09:59:59 -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=eyPFpmXS; 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 S236738AbjHCOfF (ORCPT + 99 others); Thu, 3 Aug 2023 10:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236778AbjHCOek (ORCPT ); Thu, 3 Aug 2023 10:34:40 -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 2FF0E1FCF for ; Thu, 3 Aug 2023 07:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691073154; 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=ymf0b+2Kqr9mLIxdkVxybggSGs/fK9hNLVEJOY2Qbdo=; b=eyPFpmXSeHauC7MqPDQgoBLhm80jhyXE7uHxG9Cv/U1BMDAiTtfRhXeQowhon+D+zjHDMN ATQKXFVHH7QE4Tp7NE6hoCyHESCncJm74ofMDiapxhg/JiDcSGBigi8M5Ok9anuW71dSJA zHW8eEs7te37q27mqTyrdXIpwEZlZwE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-0ded6q7sOS-M6lJ3orix1Q-1; Thu, 03 Aug 2023 10:32:30 -0400 X-MC-Unique: 0ded6q7sOS-M6lJ3orix1Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FD4C857FD1; Thu, 3 Aug 2023 14:32:29 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4653F201F11C; Thu, 3 Aug 2023 14:32:26 +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 , Mel Gorman Subject: [PATCH v3 5/7] pgtable: improve pte_protnone() comment Date: Thu, 3 Aug 2023 16:32:06 +0200 Message-ID: <20230803143208.383663-6-david@redhat.com> In-Reply-To: <20230803143208.383663-1-david@redhat.com> References: <20230803143208.383663-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=unavailable 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" part is wrong: doing an mprotect(PROT_NONE) will end up marking all PTEs on x86_64 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. Acked-by: Mel Gorman 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 6005b5dff0c1..222a33b9600d 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1446,12 +1446,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