From patchwork Thu Jul 27 21:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13330788 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 38CE9C001DC for ; Thu, 27 Jul 2023 21:29:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0B196B007E; Thu, 27 Jul 2023 17:29:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB95B6B0080; Thu, 27 Jul 2023 17:29:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA7AC6B0081; Thu, 27 Jul 2023 17:29:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9BEA96B007E for ; Thu, 27 Jul 2023 17:29:06 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6D399A0597 for ; Thu, 27 Jul 2023 21:29:06 +0000 (UTC) X-FDA: 81058682292.16.6EB1EDF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 9934240002 for ; Thu, 27 Jul 2023 21:29:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="R/1mr44B"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1690493344; a=rsa-sha256; cv=none; b=8ioIy/lrAeLBatTKg/+jLZvAvJBKaKb8+PfmrKja4trjeQE+VzdqfjuovS7WriuR0qvuTO fGjEH9PXdptMNjMFvNgZ5tqRwiqN7LjwtIpOW1CejJ3Wr7RACiC2XJ2ekxFIzKrrl6A+Ss IxpcUKGbEJTyZq1tkpEMOOWCSm9WTQg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="R/1mr44B"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1690493344; 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=jGnguQzUAnXSgoEJGq4aUCEYI9GBqFjghH3nhnid2s4=; b=qNu3X2jBtdABjPNZlfEVbbhguz8OkicJinGvtDNXaGGPOVHwWIQO2HT49vb95okMqpidKm O+L/7RotKnPSFdzq41+4pV+xHbP4c7mrYlk7YSt5nIWdSOyoEAhI/M2wbninKtGEkTvY74 iCUv0QGcLaMCuQCffY8K3R+srgayR2c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690493343; 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=jGnguQzUAnXSgoEJGq4aUCEYI9GBqFjghH3nhnid2s4=; b=R/1mr44BxsoYK3kTd/YUuYd7AiN+lZD9VeYE2LUTBrZ1FB8w8Sp4fNBwkysmAjNbHl5lbz PZAGvC5FhFWVbU3e93eaScNlIDtvg8C1+fj3Z2BBTSBNOyVNzERzO1pBhaqlmzii4KiDMT a2KlYW8J2LDFdOceaOJR9+P4Y4c64XE= 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-49-u7XBChHRONmnMfoWeq8OoQ-1; Thu, 27 Jul 2023 17:29:00 -0400 X-MC-Unique: u7XBChHRONmnMfoWeq8OoQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C80A3856F66; Thu, 27 Jul 2023 21:28:59 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDA6240C2063; Thu, 27 Jul 2023 21:28:57 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Linus Torvalds , liubo , Peter Xu , Matthew Wilcox , Hugh Dickins , Jason Gunthorpe , John Hubbard Subject: [PATCH v1 4/4] mm/gup: document FOLL_FORCE behavior Date: Thu, 27 Jul 2023 23:28:45 +0200 Message-ID: <20230727212845.135673-5-david@redhat.com> In-Reply-To: <20230727212845.135673-1-david@redhat.com> References: <20230727212845.135673-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9934240002 X-Stat-Signature: cuis75cpdch4cmdjuj44fghoksjoqtnd X-HE-Tag: 1690493344-44242 X-HE-Meta: U2FsdGVkX1+v/Jb/7YTGDQunrUNT+TKv0Olxe0wXcwfaWcZBJMUCMGyOFQaIkKNxqRSLRsroPQKK7We4rRgphYsa72J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Y3HVvB2KDQ2UEPIfpFx1JbLypU/ysVvKnVx7th5GbS+9ileLUQhMVkx 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: As suggested by Peter, let's document FOLL_FORCE handling and make it clear that without FOLL_FORCE, we will always trigger NUMA-hinting faults when stumbling over a PROT_NONE-mapped PTE. Also add a comment regarding follow_page() and its interaction with FOLL_FORCE. Let's place the doc next to the definition, where it certainly can't be missed. Signed-off-by: David Hildenbrand --- include/linux/mm_types.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 2fa6fcc740a1..96cf78686c29 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1243,7 +1243,30 @@ enum { FOLL_GET = 1 << 1, /* give error on hole if it would be zero */ FOLL_DUMP = 1 << 2, - /* get_user_pages read/write w/o permission */ + /* + * Make get_user_pages() and friends ignore some VMA+PTE permissions. + * + * This flag should primarily only be used by ptrace and some + * GUP-internal functionality, such as for mlock handling. + * + * Without this flag, these functions always trigger page faults + * (such as NUMA hinting faults) when stumbling over a + * PROT_NONE-mapped PTE. + * + * !FOLL_WRITE: succeed even if the PTE is PROT_NONE + * * Rejected if the VMA is currently not readable and it cannot + * become readable + * + * FOLL_WRITE: succeed even if the PTE is not writable. + * * Rejected if the VMA is currently not writable and + * * it is a hugetlb mapping + * * it is not a COW mapping that could become writable + * + * Note: follow_page() does not accept FOLL_FORCE. Historically, + * follow_page() behaved similar to FOLL_FORCE without FOLL_WRITE: + * succeed even if the PTE is PROT_NONE and FOLL_WRITE is not set. + * However, VMA permissions are not checked. + */ FOLL_FORCE = 1 << 3, /* * if a disk transfer is needed, start the IO and return without waiting