From patchwork Tue Aug 1 12:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13336680 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 19984C001DF for ; Tue, 1 Aug 2023 12:49:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB5FF940016; Tue, 1 Aug 2023 08:49:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A66BA940010; Tue, 1 Aug 2023 08:49:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92C1B940016; Tue, 1 Aug 2023 08:49:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7F42D940010 for ; Tue, 1 Aug 2023 08:49:23 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3CDA7140A59 for ; Tue, 1 Aug 2023 12:49:23 +0000 (UTC) X-FDA: 81075516606.11.9199975 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 8045E140002 for ; Tue, 1 Aug 2023 12:49:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="dqf88m/h"; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690894161; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=O8i0szRefbgJeKSL2o0qG6DrCbaDUp44uTnfIIYA8MY=; b=ZC5JPNBjzBQWfODOYyPDvpPYU7DJUohMROjoFgvCFcbc5YJNkkcp0MYddeIeHq4rX+OBa/ mMhW0jE6qRz3rBRZ/w5cofdk+SnabTGkVjTyy2Z77QXUA9ttf8nIS3fIJhCM/dMGYbW34v aVZ3Hjbjwdsu2yqOrfhTIcCZmwZx0bw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="dqf88m/h"; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690894161; a=rsa-sha256; cv=none; b=uE0emtALgaYP5L7QuKdQJjNVFUq9FdaMYeUnOovYh5LFvhtqbjgRVfIfO2TokP28P9iPNE LKqw23kZp4GcLtRC6nNrPA/uAhZjhL5b1cwruXLlreWTvmm4rjLBhW/BQMNYK/nGxhyjlB EP2Ek+fAdDCHshdAOO45XGphl1sJ61w= 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 8045E140002 X-Rspam-User: X-Stat-Signature: 7d4tc3ek118nc9x1s7d1so3gc1ntk5cc X-Rspamd-Server: rspam01 X-HE-Tag: 1690894161-134915 X-HE-Meta: U2FsdGVkX18C4bIs1ZxfEG1/ct4G/TZwM1DBH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VwNI3Ex1rgtHd72zq4uMPBlFxvifDE2ImGmeQm0sKE6onFXN4rJYM5P17hHnfLCn+cEZ7IzD3+6BnMHta3+o0jw27pbs7jNyv7FMJWncf 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: 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 Acked-by: Mel Gorman --- 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) {