From patchwork Thu Jul 27 21:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13330787 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 3BF71C00528 for ; Thu, 27 Jul 2023 21:29:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5538D6B007D; Thu, 27 Jul 2023 17:29:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DAE66B007E; Thu, 27 Jul 2023 17:29:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E37E6B0081; Thu, 27 Jul 2023 17:29:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 183196B007E for ; Thu, 27 Jul 2023 17:29:03 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D93211A01DE for ; Thu, 27 Jul 2023 21:29:02 +0000 (UTC) X-FDA: 81058682124.16.A42E529 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 200CE4000D for ; Thu, 27 Jul 2023 21:29:00 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eh0T10WH; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1690493341; 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=NHdYsiNqqxFFYOyFZT8N/uUoLYdRyRl4LhGdK5bhGpM=; b=JCuHY6qJVm+MUc5pE4Jag4M4fD4iU7BD4/Ij8QNf4+SlTe9xvtOZ7doz8TT3WicstcMMjy s+liIFfaB5NHSKdXSWjM7uInaG+CGkjdrH8Hwhwm5V4dnIQ6PgxXHVTwsrtCws2317y7o7 FETqcynE9rWj+3lio/9zXRaTtkj5y/8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690493341; a=rsa-sha256; cv=none; b=dDA74UGseiiUAajfjfJXEEdzA3im9NK3iXsrGh+LV4qPZim+Js9TH39B3F4Aa3TxcHHhKO l01aCsJ3Hb+9cZmaEBOH1ZtwpAjH2uHSfxKGjoQcIdMwEGOVBVAo5Yt1vL3YCcde2tdOnZ pp+cz7XCSk71h9Q+szgxbatr/vFQvgA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eh0T10WH; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690493340; 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=NHdYsiNqqxFFYOyFZT8N/uUoLYdRyRl4LhGdK5bhGpM=; b=eh0T10WHWVEgPCSHqoYkZMtBdSJ7MBfJ3maGZRLjWv5087hLkSo4x5lEZNH86EhCQpfKKl YUl4uHa+U08b3ERWCZb/VhbsbHLyFvktZCqGYSUDTFaiqvchDp3W8ZyrADY04VVobZkGyv fRSB4ReMm/ghDO9KXjujtVjDxCB3Qag= 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-554-F0H8AQw3M0yhKgh2HgjDcA-1; Thu, 27 Jul 2023 17:28:56 -0400 X-MC-Unique: F0H8AQw3M0yhKgh2HgjDcA-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 50B76104458B; Thu, 27 Jul 2023 21:28:55 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67C2B40C2063; Thu, 27 Jul 2023 21:28:53 +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 , stable@vger.kernel.org Subject: [PATCH v1 2/4] mm/gup: Make follow_page() succeed again on PROT_NONE PTEs/PMDs Date: Thu, 27 Jul 2023 23:28:43 +0200 Message-ID: <20230727212845.135673-3-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-Stat-Signature: wdzwgi6yu9eirdpinntd1xn9rmmqisza X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 200CE4000D X-Rspam-User: X-HE-Tag: 1690493340-89599 X-HE-Meta: U2FsdGVkX18XsL8vZRi/O98cxNPcEYC/Mb0BRtVLaNDKQi+9nSuH/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G2HmkHYskWAhtOjIj1PhJrULaKJYW8Aql4i5HNRs1p3MKZju/iD5iukRZ5ijPXQ682cIP6hixAQnGXS/p7ugBvDr7N6JvwedWRMGZIVbCc+sJhttP8OwuilGW63h67dfH5h+LXjwzfpJEyRhHOb79OudA== 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: We accidentally enforced PROT_NONE PTE/PMD permission checks for follow_page() like we do for get_user_pages() and friends. That was undesired, because follow_page() is usually only used to lookup a currently mapped page, not to actually access it. Further, follow_page() does not actually trigger fault handling, but instead simply fails. Let's restore that behavior by conditionally setting FOLL_FORCE if FOLL_WRITE is not set. This way, for example KSM and migration code will no longer fail on PROT_NONE mapped PTEs/PMDS. Handling this internally doesn't require us to add any new FOLL_FORCE usage outside of GUP code. While at it, refuse to accept FOLL_FORCE: we don't even perform VMA permission checks like in check_vma_flags(), so especially FOLL_FORCE|FOLL_WRITE would be dodgy. This issue was identified by code inspection. We'll add some documentation regarding FOLL_FORCE next. Reported-by: Peter Xu Fixes: 474098edac26 ("mm/gup: replace FOLL_NUMA by gup_can_follow_protnone()") Cc: Signed-off-by: David Hildenbrand --- mm/gup.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/gup.c b/mm/gup.c index 2493ffa10f4b..da9a5cc096ac 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -841,9 +841,17 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, if (vma_is_secretmem(vma)) return NULL; - if (WARN_ON_ONCE(foll_flags & FOLL_PIN)) + if (WARN_ON_ONCE(foll_flags & (FOLL_PIN | FOLL_FORCE))) return NULL; + /* + * Traditionally, follow_page() succeeded on PROT_NONE-mapped pages + * but failed follow_page(FOLL_WRITE) on R/O-mapped pages. Let's + * keep these semantics by setting FOLL_FORCE if FOLL_WRITE is not set. + */ + if (!(foll_flags & FOLL_WRITE)) + foll_flags |= FOLL_FORCE; + page = follow_page_mask(vma, address, foll_flags, &ctx); if (ctx.pgmap) put_dev_pagemap(ctx.pgmap); From patchwork Thu Jul 27 21:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13330786 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 7E8B7EB64DD for ; Thu, 27 Jul 2023 21:29:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 133726B0078; Thu, 27 Jul 2023 17:29:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 095C56B007D; Thu, 27 Jul 2023 17:29:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA0666B007E; Thu, 27 Jul 2023 17:29:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DD2496B0078 for ; Thu, 27 Jul 2023 17:29:02 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AAE42B1A35 for ; Thu, 27 Jul 2023 21:29:02 +0000 (UTC) X-FDA: 81058682124.16.06B03DE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id DF5321A0004 for ; Thu, 27 Jul 2023 21:29:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QHOHv/1C"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.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=1690493340; 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=Gg+vYFf2MUM715aNnpsI37yVDyYtQwBsTVNC7NmhATc=; b=34NXL0/kVusfzkaTh4JOu0sdSVw9my4D3HGhEjrcJLJJ85AjzvGtb6/ac8Xvdti1srVqXa DxC4NE5CPV4xeKPofPo+H0xUgSNOHI6BTMS1s2N4au+roRKXT9ojSgFz1N9onIZDsr8P2D UB2T2txuCWw7kHNnzfpovQyscYtapms= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QHOHv/1C"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.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=1690493341; a=rsa-sha256; cv=none; b=4VmBwcx9FrlF59my2COtvRum2KOlmx45C9qeh4gbvJcaUqvOfesSKSk2we5oe4/HYwX5v0 4Av+lELgDr3PCrGv4DAAxJc0PDn7mftNQc0Qzd4q0tAm/JJhf1UufnoQwPmWWFQd/rnXDt 89tUnyeTPBoTE/06+TD21RmujQjNijo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690493340; 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=Gg+vYFf2MUM715aNnpsI37yVDyYtQwBsTVNC7NmhATc=; b=QHOHv/1CDnhpUBLSAHulIX+UPkwIN4UVYG3o4EdKyx+ABoD7kJGKq1YzgoH6XW4Wb2Q0RG rjjTgBWepIsxL2spK0YaBonwD5eW4q+CfrJvgvsp9ODkPZs7P4g/QGb9czyIanu+uANqnF Uy9FMSpAIEvvWzqKjMSgaLl48KKRwZg= 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-359-RlyUAFoMPPO8N1iA8aE7qw-1; Thu, 27 Jul 2023 17:28:58 -0400 X-MC-Unique: RlyUAFoMPPO8N1iA8aE7qw-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 924CC805951; Thu, 27 Jul 2023 21:28:57 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91ABF40C2063; Thu, 27 Jul 2023 21:28:55 +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 3/4] smaps: use vm_normal_page_pmd() instead of follow_trans_huge_pmd() Date: Thu, 27 Jul 2023 23:28:44 +0200 Message-ID: <20230727212845.135673-4-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-Rspamd-Queue-Id: DF5321A0004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: axysdzdwjkkr8pu5cnycq9ujitadu8c3 X-HE-Tag: 1690493340-797275 X-HE-Meta: U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eo0nl3iiI0rwZCNi4QQ3hFhjr6j0BoZjiOCitIRuPZ8fM/m5gOmJz+5r1RzFilt3dDNlqgRon6eIh6t8qFAxcvFz5IvJ7cZJHGtKPeMiWe436+OGVpOOO7JbgbJVnQZrMRizW42 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: We really shouldn't be using a GUP-internal helper if it can be avoided, and avoiding the FOLL_FORCE here is certainly desirable. Similar to smaps_pte_entry() that uses vm_normal_page(), let's use vm_normal_page_pmd() -- that didn't exist back when we introduced that code -- that similarly refuses to return the huge zeropage. Signed-off-by: David Hildenbrand --- fs/proc/task_mmu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 7075ce11dc7d..b8ea270bf68b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -571,12 +571,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, bool migration = false; if (pmd_present(*pmd)) { - /* - * FOLL_DUMP will return -EFAULT on huge zero page - * FOLL_FORCE follow a PROT_NONE mapped page - */ - page = follow_trans_huge_pmd(vma, addr, pmd, - FOLL_DUMP | FOLL_FORCE); + page = vm_normal_page_pmd(vma, addr, *pmd); } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { swp_entry_t entry = pmd_to_swp_entry(*pmd); 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+TKv0Olxe0wXcwfaWcZBJMUCMGyOFQaIkKNxqRSLRsroPQKK7We4rRgphYsa72Jn5fZKtNQWr4K3UqE0wNd/XwLYFemHnUR4bb0QFA3D5CfjSfQoas0TCSdC+Mq1ZW1qb1/+K9hrF3yK+hEj+aM6JQNBHuxik2/AEn4JVfu8qCvP+udSU/ZGP3MXPbDVEWcU6Z9RyEnVaRLoQw7mc6LoNBEtDGIle5CU8NjvlfAoEuVe4iLsVvA7ohmhnsxfhWLm/m3meygfALf/nwL3D+NfNmNpH/h7RLyAIDRmzaKzHi+hFcGVUhifOqDPdOAqg+gfayoanIfSQ8whDvk7R8RvTXWybbgmZk3otraXXJhLylJulrC6ZQUpS5M7/iqPbrvoDoN5+zdgCHECG6w08Y3W3mdiNJ3BLHO7Ie22Aofs0G4SzG9OSfuVihM8pzZPtN3nTI8DplErnJ+Ky6NRMaZ0uKR2A298fehL98xZnioZwcWx7yXCtla5Gbd0a9vOitOLVJpqTAJEXGt/+pBzPisTL0PcgqFDYb9nb8F3UKR3VfaHjwEK/B0fpbkDNS0FPOEARJd7tLG84Cgb74oSh1COt4TnvkOH0KX64BMTELM+uZENPoSLCu5j0iAZWynA420p3RjymWK+0978XciXpS2T6AKG/j4j6kkkbH3gF21F9xqmnQ6NAudXNwymnyAyLYrHSS4VcCWI6kMKQmTl+Td10jsyPBcUv4OHMn385x1c4WV4MIbxYOzlz8gfAE4OHK4xzZ+GgjnICfzFfyDwcaWmHD3L95VHAd+hXdqKyIhLz97bj8LiB0xaT/GZ1XKAhp/tA9Gb/62GCvBn7LNgyV8omA3ToD8hZDx6LoQ6ZdqBi0bGQg2bPN06MjjATyy6XwOTTMRNkcXsFelrLLpITYHcTlb6/NvgaRd8OjpFbNnhVdPgYBqECnuW1PM Wr2QNFDO GNVNIpayPt9Ot+zzlYwdc1V2irTKUpBytYHj+fAdkGiUbvOG6WMX3dEQRGBRRMsg8mHoMavL8/C5YwvcruaD9Crf7ntMR19aatAjYz5Ul6vBCcfvK6VlnIM2Ctt5wFM94ICXHwHzgWKj2zSO6hyxjyGdTFBd7qH/9TsBz+3fLFqevWY3HVvB2KDQ2UEPIfpFx1JbLypU/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