From patchwork Wed Mar 6 23:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 13584769 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 57505C54E41 for ; Wed, 6 Mar 2024 23:24:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A31796B0088; Wed, 6 Mar 2024 18:24:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A083A6B00B6; Wed, 6 Mar 2024 18:24:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EF786B0088; Wed, 6 Mar 2024 18:24:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 671956B0088 for ; Wed, 6 Mar 2024 18:24:04 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 23A6441052 for ; Wed, 6 Mar 2024 23:24:04 +0000 (UTC) X-FDA: 81868194408.30.910B9C1 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by imf19.hostedemail.com (Postfix) with ESMTP id 3E1381A0006 for ; Wed, 6 Mar 2024 23:24:01 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of richard@nod.at designates 195.201.40.130 as permitted sender) smtp.mailfrom=richard@nod.at ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709767442; 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:references; bh=YNacY+IM86DAtF9+inDf718X7FnVq7qjmzjIlLyPiUg=; b=at1feF6r5U+NOx8iDBOSYRC2IJ/XtEODkXlXZpocM/Io6SEzZLIWHKUtq8b1AAaiQHgAo/ wb9gW62KmkzhUUh3ete+zB+A48FAA872M6qAa8xWsAwmZ3VT40LHlCuBu8hqeiG9J+KfxZ I/Mq5ylEVyrDpnvE+lBlpjZjhWRq1sQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of richard@nod.at designates 195.201.40.130 as permitted sender) smtp.mailfrom=richard@nod.at ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709767442; a=rsa-sha256; cv=none; b=o0H9+Sw06aAL0aDDUOI4kgd1wD0vwnTDeKwOoKTQWqfsE+omhDZezj7fXGuk4vPsMlvaWf vwNwkfewEjVSPVbMdy6KHZ8AdvGr19n4wHlrinXiyK4M8dUcT1R4IBfqzxvi6b9GCSEHmZ hLzDl3Aq9Mz71ZutSxcm+3tFyji/PNw= Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id E696C644CE7C; Thu, 7 Mar 2024 00:23:59 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id t9XzC3CxY69m; Thu, 7 Mar 2024 00:23:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 5DD51644CE7D; Thu, 7 Mar 2024 00:23:59 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id FnKr8zZbO6FE; Thu, 7 Mar 2024 00:23:59 +0100 (CET) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id C92FE644CE7B; Thu, 7 Mar 2024 00:23:58 +0100 (CET) From: Richard Weinberger To: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, upstream+pagemap@sigma-star.at, adobriyan@gmail.com, wangkefeng.wang@huawei.com, ryan.roberts@arm.com, hughd@google.com, peterx@redhat.com, david@redhat.com, avagin@google.com, lstoakes@gmail.com, vbabka@suse.cz, akpm@linux-foundation.org, usama.anjum@collabora.com, corbet@lwn.net, Richard Weinberger Subject: [PATCH 1/2] [RFC] proc: pagemap: Expose whether a PTE is writable Date: Thu, 7 Mar 2024 00:23:38 +0100 Message-Id: <20240306232339.29659-1-richard@nod.at> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3E1381A0006 X-Stat-Signature: eg1fzrejnouwyi33ju8jidgyistddkif X-Rspam-User: X-HE-Tag: 1709767441-73959 X-HE-Meta: U2FsdGVkX1+mc66IjNcPzQpgANeTYowSoTAYKhguWyu+SwHau5bGsilOzpt03PSuPUVER4QOnIjEm0Xfizxpuxd1IWMNXKrTajq0SFJvAHKXtYkE7ad/1AfwHRhr9dWc85qCmTLqC6n3EuakF5CMda6im4SY1KWjFc4Mz+W1BhlWc8jFXN33tj/EIjEuOVG0xxWi9dnqawg0rH7bT5/e+5r6ZI9TPzlIubsk923jNpfq2vmnLQUtZ94j1bqC+rFBUVgokDxYa/LHfbhaFMuzR70FoAAMupraLgWw+H1zSDP8ijY5wpu6/YJg2D2G8ns5ldSmqSm0SfJj68ZTtM6OM/s4FddFhVVNyQODg++gZa2qg/G1fA92xm6BvI+ujANJ03wOrRdVvih1Ynb5DaE+k3DpxwimBz+hS/0tHgU+YeQIIMmMhDW/IfaNJ+KcBJs2qIfL9bDU1r6BcpuoaZaTOzP3tEGUVYXfN80PI3H3GfeWVSNZmar/mswjyG8us88JkuiwHU8+qlRtxKq5L4DxGRi5gLohajDvU2EgDDVYOV8wgn/4hN5LmSfXmLlmnJObmXs1BzN5dp76zsz9bYpYhV7jVjGogyUeyA0p2LmmFOkY6AmeqtF7IKDr5YYi0Hhk8Ov4pj9lmYp3ip8ovN3B5Ls9BmXHnFXUT81lpPlu4IpJ0yj7iyUIqKBzABdTYIrJ2YHTvu3l2uYShXPt5Qc6xqmMLFN81kW/ofn5blA51wpwkJg6IBsvqy/ZBRGQ97fAJfmQCGW80BjDowDYmhXvCa9djutNAKaYeYBUOY+YhA12z0POvcX5ahQ7uA2FVr02ejD9cwwaqyBzqy0RbgyQ7VLrsQxmsmJuXnO4ipG8EnLFele9oHqmlBvQMbAErhjPH6Fkqfb7pHNGBlLfy2KqfYUORAI4rscW7glHQrKdANtQLGiqfzQVutskVvG1GKVfnntBvuqfRge/VR8x1C4 CJ7olq63 MUu3ba/iHBSO5LCR1Lszk87k6dUaB+4qwP+gx4g1kcwDspUHmN7LhzhwCSD9k24Lg1Jn/xaJQ+P688apBIEOl3FVFSy/gkJVMP/jh3YVwN5rCzf3Ofdh1EQfYMfceH4IdZQrreJXiTS38JRoYaTLA2XidTdYEYKpl4yi7 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: List-Subscribe: List-Unsubscribe: Is a PTE present and writable, bit 58 will be set. This allows detecting CoW memory mappings and other mappings where a write access will cause a page fault. Signed-off-by: Richard Weinberger --- fs/proc/task_mmu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 3f78ebbb795f..7c7e0e954c02 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1341,6 +1341,7 @@ struct pagemapread { #define PM_SOFT_DIRTY BIT_ULL(55) #define PM_MMAP_EXCLUSIVE BIT_ULL(56) #define PM_UFFD_WP BIT_ULL(57) +#define PM_WRITE BIT_ULL(58) #define PM_FILE BIT_ULL(61) #define PM_SWAP BIT_ULL(62) #define PM_PRESENT BIT_ULL(63) @@ -1417,6 +1418,8 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, flags |= PM_SOFT_DIRTY; if (pte_uffd_wp(pte)) flags |= PM_UFFD_WP; + if (pte_write(pte)) + flags |= PM_WRITE; } else if (is_swap_pte(pte)) { swp_entry_t entry; if (pte_swp_soft_dirty(pte)) @@ -1483,6 +1486,8 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, flags |= PM_SOFT_DIRTY; if (pmd_uffd_wp(pmd)) flags |= PM_UFFD_WP; + if (pmd_write(pmd)) + flags |= PM_WRITE; if (pm->show_pfn) frame = pmd_pfn(pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); @@ -1586,6 +1591,9 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask, if (huge_pte_uffd_wp(pte)) flags |= PM_UFFD_WP; + if (pte_write(pte)) + flags |= PM_WRITE; + flags |= PM_PRESENT; if (pm->show_pfn) frame = pte_pfn(pte) +