From mboxrd@z Thu Jan 1 00:00:00 1970 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 CD871C83F22 for ; Thu, 17 Jul 2025 11:52:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 255788D000F; Thu, 17 Jul 2025 07:52:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 204CA8D0009; Thu, 17 Jul 2025 07:52:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CE4C8D000F; Thu, 17 Jul 2025 07:52:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E8DDB8D0009 for ; Thu, 17 Jul 2025 07:52:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B8E13160562 for ; Thu, 17 Jul 2025 11:52:42 +0000 (UTC) X-FDA: 83673594564.10.02BFE74 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 92D641C000C for ; Thu, 17 Jul 2025 11:52:40 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkKYhiU1; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752753160; a=rsa-sha256; cv=none; b=IHadzfkrxW9mJnwu6fEJWeIdleiesnlf9pw73j3m3iZ55ZEfn0ejTOM32pR1Xtw4oK+GS7 MD78EKBOEnj+2g4GgcqFnwpbopJQKhHQ9yzaIQev4GQnm7jSD54mOMqzDz5WqnGi5rX0MT sj9Yze0b7k67ZuTqEnn4d7dH8VuluS4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkKYhiU1; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752753160; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+EJnWBjNqAGa4cESjiW0EJbmUIJ/RdvXL+0h/9uaJzw=; b=Zo22g2JysG1FZKoyYRlnAn0GxUT0aMa3hRNFjj7lEZvQXp+By5R+oRaYsRIPht56yEpWSB 4JEDDwPAkuvvCpsJ1o2C1EjKLs3xc0t/H9j0hdvTjNckejz4G85bOhVxgffukND1RqYePJ 5otYMkKnVuVW+MTz3CeYRenx5aonYRA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752753160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EJnWBjNqAGa4cESjiW0EJbmUIJ/RdvXL+0h/9uaJzw=; b=CkKYhiU1WfKlCG7sHsi6bBqvvcbAyvvCAfD1o308FkwauImjzUfqbWaLHk44YSQkqrmnOJ 67aUXzh3gimR+goH+DABAhNs4KVih5nPwwWUPxt4HexHV/beTmhsWHRm5G7UUlgauqLPIo iLlZOyeKBuDakljulG6XvlrictqFmK0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-eC71Y8JQNvGBGRPn3Ckd7A-1; Thu, 17 Jul 2025 07:52:38 -0400 X-MC-Unique: eC71Y8JQNvGBGRPn3Ckd7A-1 X-Mimecast-MFC-AGG-ID: eC71Y8JQNvGBGRPn3Ckd7A_1752753157 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-451d3f03b74so5321185e9.3 for ; Thu, 17 Jul 2025 04:52:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752753157; x=1753357957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+EJnWBjNqAGa4cESjiW0EJbmUIJ/RdvXL+0h/9uaJzw=; b=WK3JZkS8awkMaj9eY6RPQ/ig0x7XV/g9p0QORieYuO/bsyMp1TmLMJgPr1V+QzkPGX 3IUvzJZPYhD7oefFVQ8dtPdxX7iP1Zy8LWO/q1sLHIAxzUdjSpSYR35IBfaU8gFh3Nf6 gDUhNEccWUOJ8r5OcFR491uYZgskvFM6ydIKrOUrrYAeSxdFDdjNpLJYZJ2vzu4Evn7V 9x5IzMzJo/fXty7eiAl3KvmCGbVefgdbF4ApUWN1hrJ15vWdo6AhjbbwbrLBxqNF2eLS NTdMADI7ISEKvfGK9yQE5UIjtzmEwXCC5cseIKxMY04ZWO5tPqvTFowtjCRGI0fMJScx 4k3Q== X-Gm-Message-State: AOJu0YxPALYC2xVkF0/Q0Uw+M88x4KWSV0NXL9rQjFovgyzQFXCXlCd6 0GxwRsZeC3FgCxTdKcSWkZMn2efFfX3yTI/dQvRVvJ0wiEBSJFW88m3bAJC+xRJAKptRBEsy/Xn mAoJQWpprvTrXhl1Hc86nzISCzm9Q80fdMda6pU3TUdhR+kV2j0Ia X-Gm-Gg: ASbGnctGsw6RQ7e4eqdl+YQvKgPpKgs7J18YopZ3QgjQWBDN2nkuR/R3Or9LaQRT7KH cyjMd36FdUWmRNu57bcuvGDZutlHUO8QFDd8ZvImDiPPggNoLAHEvigfUji50tM8cHDfpNkArvT X5oJD7LXFiT/G7UFhbjf5yQoXHho+YbKZ3E4N4ePj0UJeI559RMznjb6N8xKXdCxhGPUaO5Yocs tUgjUsur5ui1XB3F1Z8JjOR9RiPR2cFaKMZzWkVRmxgS2G3NY3dkIo10BiTCPqCMf5g1eV+QSn4 rAzYQHP1gglY0nRDwozwdPAuuJ0V6QbNoLQ694U3EebaCiJXZc5drFXTkjcKpYIfoaNQ8VRZ7+H +VsgvAUgo4PSnA0NrfyLv6JE= X-Received: by 2002:a05:600c:870e:b0:456:285b:db3c with SMTP id 5b1f17b1804b1-456352d2ab1mr20377955e9.3.1752753157333; Thu, 17 Jul 2025 04:52:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3Vszf6T0cq3aQuR+QDmUBqbteOugAuzaA8OTawN8Aj0cx9bUSNlZT+0u55FTlbIHJovWeIQ== X-Received: by 2002:a05:600c:870e:b0:456:285b:db3c with SMTP id 5b1f17b1804b1-456352d2ab1mr20377615e9.3.1752753156790; Thu, 17 Jul 2025 04:52:36 -0700 (PDT) Received: from localhost (p200300d82f1f36000dc826ee9aa9fdc7.dip0.t-ipconnect.de. [2003:d8:2f1f:3600:dc8:26ee:9aa9:fdc7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3b5e8dc22a8sm20945546f8f.34.2025.07.17.04.52.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jul 2025 04:52:36 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, xen-devel@lists.xenproject.org, linux-fsdevel@vger.kernel.org, nvdimm@lists.linux.dev, David Hildenbrand , Andrew Morton , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Dan Williams , Matthew Wilcox , Jan Kara , Alexander Viro , Christian Brauner , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Jann Horn , Pedro Falcato , Hugh Dickins , Oscar Salvador , Lance Yang , David Vrabel Subject: [PATCH v2 9/9] mm: rename vm_ops->find_special_page() to vm_ops->find_normal_page() Date: Thu, 17 Jul 2025 13:52:12 +0200 Message-ID: <20250717115212.1825089-10-david@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250717115212.1825089-1-david@redhat.com> References: <20250717115212.1825089-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: dAvAJV92VxLRINiwzmWm2Qva_iXCE-QB_zkMFlfoENc_1752753157 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 92D641C000C X-Stat-Signature: jr9mrtmg7ndhzzsg1sqk7e74ousgdmnq X-Rspam-User: X-HE-Tag: 1752753160-576124 X-HE-Meta: U2FsdGVkX19baJcr4D5fdms7HkaoUsaMjfZPKw9gSuI6KF8boz/rhfyPNGBojZYJtOt7g0biYl0ud1TsVEDFsx7PWzsOSoOkcnDzyuPyc7qNhB06Pr45RJJop7M6GI1yVDZsc3ayXgkPuZpQvd9g0ibjhISGSBc+fl/NAS+cIewjV9FDrWsyq9FHiE9yBXrYdOf3uR2vx+hyqs/CCFZprYGU7PUBc1IpC3WXqUjm2tg+m0ahSlC4xuicwkq7nPPb4MsUo4EFaN4Q7+0XGECk7b+f5Qigy7rdHgUAXVjFtyym6v6b5Q9CxEJGDQmpbg1ZyHm+EIZPhJ8U4WCsZ5M/V7mjQBT0W8V8bT5CFyr6vEXtm0t6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ywZ3zg+q/fPFLKNsW2ZXw2oB6i5NYFF3mQQW6YZ+b0EGcPma+TODApL6rqvSyWqm51QkB83TbefpVgLXeHzt/sN/2N+k5MdIB24Si9DRUv+EnvzutJ81Z08C8x8P3LPXgFgKkgV5ubkIFgbkMaYZcE07nDM+4krJod2ttwlc5I9PUw== 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: ... and hide it behind a kconfig option. There is really no need for any !xen code to perform this check. The naming is a bit off: we want to find the "normal" page when a PTE was marked "special". So it's really not "finding a special" page. Improve the documentation, and add a comment in the code where XEN ends up performing the pte_mkspecial() through a hypercall. More details can be found in commit 923b2919e2c3 ("xen/gntdev: mark userspace PTEs as special on x86 PV guests"). Cc: David Vrabel Reviewed-by: Oscar Salvador Signed-off-by: David Hildenbrand --- drivers/xen/Kconfig | 1 + drivers/xen/gntdev.c | 5 +++-- include/linux/mm.h | 18 +++++++++++++----- mm/Kconfig | 2 ++ mm/memory.c | 12 ++++++++++-- tools/testing/vma/vma_internal.h | 18 +++++++++++++----- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index 24f485827e039..f9a35ed266ecf 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig @@ -138,6 +138,7 @@ config XEN_GNTDEV depends on XEN default m select MMU_NOTIFIER + select FIND_NORMAL_PAGE help Allows userspace processes to use grants. diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 61faea1f06630..d1bc0dae2cdf9 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -309,6 +309,7 @@ static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) BUG_ON(pgnr >= map->count); pte_maddr = arbitrary_virt_to_machine(pte).maddr; + /* Note: this will perform a pte_mkspecial() through the hypercall. */ gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, map->grants[pgnr].ref, map->grants[pgnr].domid); @@ -516,7 +517,7 @@ static void gntdev_vma_close(struct vm_area_struct *vma) gntdev_put_map(priv, map); } -static struct page *gntdev_vma_find_special_page(struct vm_area_struct *vma, +static struct page *gntdev_vma_find_normal_page(struct vm_area_struct *vma, unsigned long addr) { struct gntdev_grant_map *map = vma->vm_private_data; @@ -527,7 +528,7 @@ static struct page *gntdev_vma_find_special_page(struct vm_area_struct *vma, static const struct vm_operations_struct gntdev_vmops = { .open = gntdev_vma_open, .close = gntdev_vma_close, - .find_special_page = gntdev_vma_find_special_page, + .find_normal_page = gntdev_vma_find_normal_page, }; /* ------------------------------------------------------------------ */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 0eb991262fbbf..036800514aa90 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -648,13 +648,21 @@ struct vm_operations_struct { struct mempolicy *(*get_policy)(struct vm_area_struct *vma, unsigned long addr, pgoff_t *ilx); #endif +#ifdef CONFIG_FIND_NORMAL_PAGE /* - * Called by vm_normal_page() for special PTEs to find the - * page for @addr. This is useful if the default behavior - * (using pte_page()) would not find the correct page. + * Called by vm_normal_page() for special PTEs in @vma at @addr. This + * allows for returning a "normal" page from vm_normal_page() even + * though the PTE indicates that the "struct page" either does not exist + * or should not be touched: "special". + * + * Do not add new users: this really only works when a "normal" page + * was mapped, but then the PTE got changed to something weird (+ + * marked special) that would not make pte_pfn() identify the originally + * inserted page. */ - struct page *(*find_special_page)(struct vm_area_struct *vma, - unsigned long addr); + struct page *(*find_normal_page)(struct vm_area_struct *vma, + unsigned long addr); +#endif /* CONFIG_FIND_NORMAL_PAGE */ }; #ifdef CONFIG_NUMA_BALANCING diff --git a/mm/Kconfig b/mm/Kconfig index 0287e8d94aea7..82c281b4f6937 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1397,6 +1397,8 @@ config PT_RECLAIM Note: now only empty user PTE page table pages will be reclaimed. +config FIND_NORMAL_PAGE + def_bool n source "mm/damon/Kconfig" diff --git a/mm/memory.c b/mm/memory.c index 00a0d7ae3ba4a..52804ca343261 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -613,6 +613,12 @@ static void print_bad_page_map(struct vm_area_struct *vma, * trivial. Secondly, an architecture may not have a spare page table * entry bit, which requires a more complicated scheme, described below. * + * With CONFIG_FIND_NORMAL_PAGE, we might have the "special" bit set on + * page table entries that actually map "normal" pages: however, that page + * cannot be looked up through the PFN stored in the page table entry, but + * instead will be looked up through vm_ops->find_normal_page(). So far, this + * only applies to PTEs. + * * A raw VM_PFNMAP mapping (ie. one that is not COWed) is always considered a * special mapping (even if there are underlying and valid "struct pages"). * COWed pages of a VM_PFNMAP are always normal. @@ -710,8 +716,10 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn = pte_pfn(pte); if (unlikely(pte_special(pte))) { - if (vma->vm_ops && vma->vm_ops->find_special_page) - return vma->vm_ops->find_special_page(vma, addr); +#ifdef CONFIG_FIND_NORMAL_PAGE + if (vma->vm_ops && vma->vm_ops->find_normal_page) + return vma->vm_ops->find_normal_page(vma, addr); +#endif /* CONFIG_FIND_NORMAL_PAGE */ if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) return NULL; if (is_zero_pfn(pfn)) diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index 0fe52fd6782bf..8646af15a5fc0 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -467,13 +467,21 @@ struct vm_operations_struct { struct mempolicy *(*get_policy)(struct vm_area_struct *vma, unsigned long addr, pgoff_t *ilx); #endif +#ifdef CONFIG_FIND_NORMAL_PAGE /* - * Called by vm_normal_page() for special PTEs to find the - * page for @addr. This is useful if the default behavior - * (using pte_page()) would not find the correct page. + * Called by vm_normal_page() for special PTEs in @vma at @addr. This + * allows for returning a "normal" page from vm_normal_page() even + * though the PTE indicates that the "struct page" either does not exist + * or should not be touched: "special". + * + * Do not add new users: this really only works when a "normal" page + * was mapped, but then the PTE got changed to something weird (+ + * marked special) that would not make pte_pfn() identify the originally + * inserted page. */ - struct page *(*find_special_page)(struct vm_area_struct *vma, - unsigned long addr); + struct page *(*find_normal_page)(struct vm_area_struct *vma, + unsigned long addr); +#endif /* CONFIG_FIND_NORMAL_PAGE */ }; struct vm_unmapped_area_info { -- 2.50.1