From patchwork Thu Aug 3 14:32:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13340198 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 730FAEB64DD for ; Thu, 3 Aug 2023 14:32:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04C63280269; Thu, 3 Aug 2023 10:32:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3D9728022C; Thu, 3 Aug 2023 10:32:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2C95280269; Thu, 3 Aug 2023 10:32:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D34DE28022C for ; Thu, 3 Aug 2023 10:32:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9BCE64129A for ; Thu, 3 Aug 2023 14:32:39 +0000 (UTC) X-FDA: 81083034438.08.8A179CC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 9D46580031 for ; Thu, 3 Aug 2023 14:32:35 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HIt8oS7p; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691073157; 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=ymf0b+2Kqr9mLIxdkVxybggSGs/fK9hNLVEJOY2Qbdo=; b=b5YuIPsc31xBGcR/ibSsjryTn/RzUdTfrNgq+azAl9ZWpke4HrhjwgPeSow4xQ0XsVKDmB Qu8fF0+/ZVJhaKuZtB7GQUTa+jeQCb42NoVC+FBLkIgt9sPgo/e6IiU9JGxLqxvcI8TtSj uKvXEhdHsisFe9Xf6Mpb3v8GIvjAV8k= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HIt8oS7p; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691073157; a=rsa-sha256; cv=none; b=qsSwt16TozaoYPqTxINP5AM8wAP4bTWfJfNBmHKzpTuh47t2aHiGRq+0n9lARBaOY4F4Rd xUR2k3Ilv+pyy3Zln+WNvNBIdVpJ/t4ZVpTMTtWBh5aL2ZJ3Au6sMnVNNPnmeSeEbR01Fx EteBFTul4U/S1/mxw02+RoAUPE2Hnys= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691073155; 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=HIt8oS7pJVYEaVa4VuP3tEvW7/PfTGxOu6c8AVTWKnSSDoa8uv74fHMuwPI9UbvPe6q33Z U6xG01knbeglEweiKYo7LAz758BRgFZYFVWb4MFXkGmzr+Ebb2byZ1Zv9np7p+slka84ZX t3UfRx/DvqDdPgxq//2TNWI35XWGjWs= 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9D46580031 X-Stat-Signature: udcrsmuzrq73sptycd85m89yaxjng6oe X-HE-Tag: 1691073155-718587 X-HE-Meta: U2FsdGVkX1+TYGBm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2kJ+WEAdAj/o6pAqcucGzy8tFVNVymbjyFu/UUSqlBO1I+qS7ZbUaw+MZsYCp2aUVLMCx/AKmF6wGa1ueoDQNdP8by3s6C4XSBNP/H51blwOObXed/vITDF6DyFKumXD5vSgkfIl2XKp0Efudwe39qQJAoKi5GXNg== 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" 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) {