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 58869C71136 for ; Tue, 17 Jun 2025 15:44:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F42E6B00B0; Tue, 17 Jun 2025 11:44:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87D2A6B00B1; Tue, 17 Jun 2025 11:44:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71DC46B00B2; Tue, 17 Jun 2025 11:44:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 565F76B00B0 for ; Tue, 17 Jun 2025 11:44:25 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 293851D3DFB for ; Tue, 17 Jun 2025 15:44:25 +0000 (UTC) X-FDA: 83565314490.25.653D389 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id E3F63140006 for ; Tue, 17 Jun 2025 15:44:22 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZRG/gVMW"; spf=pass (imf09.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750175062; 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=YLVJGNARtVFI5B2J8se/8/6UXe4Uo6I4yV7PyVAOlF8=; b=1iA8mmHCByWFTpXBt26x3QzJq6RFbr9YiADLnQ2d2jgl3wOV2WW4jdNpOcpmZ7XE/cZmIC ojlnoT9id2FeFSLNgWXm+7VF1B/FtRDV4FpPhFEQvRc0BPq6CpAWpfvUOjQHBDCBSgnjlK an78luJxo5KEaQSZ2FE6MD8g+bqqzlA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZRG/gVMW"; spf=pass (imf09.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750175063; a=rsa-sha256; cv=none; b=QlLwgOZrrG8i0j2ENi9WSYaM7mwWUaEP6HDcasdi6dhlRxWpHCu5+os+lJZuN4D9OCnwx0 v9RW6RNu8C8F26wym0w1gvSfuIhu2C1FIEiYPMhTDotL0PUWFkRsdrHWSbUrt0AdcTA0vO +JEnj6Gc5w+FiWTVRaAjUyrkLqZglGo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750175062; 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=YLVJGNARtVFI5B2J8se/8/6UXe4Uo6I4yV7PyVAOlF8=; b=ZRG/gVMWSKCWzz7MfaRJi8elLrkIpzWGSW0BwqeUV61/XNif5DDlYpTo/H5j8SBmH9ganE lQz6jdRmX0yIU8IEEespoyhG7LmvSX5D23mrkgTPMPiit9O56O7fTxHKeWO26gYXHzRK90 +dw/G6yQaX3KpyD0cUUpJ5yvOxgPMsc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-OKhkvnH0PG26ajYpu3aBSQ-1; Tue, 17 Jun 2025 11:44:21 -0400 X-MC-Unique: OKhkvnH0PG26ajYpu3aBSQ-1 X-Mimecast-MFC-AGG-ID: OKhkvnH0PG26ajYpu3aBSQ_1750175060 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a5780e8137so1596942f8f.1 for ; Tue, 17 Jun 2025 08:44:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750175060; x=1750779860; 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=YLVJGNARtVFI5B2J8se/8/6UXe4Uo6I4yV7PyVAOlF8=; b=n4QkAAGpXLfm/tqn6VhmLtmrrlNT2iixVlokuj8y+dbvtVpZbXtvJWOscXlQWsoEkk Z2m9EIGtS8CLGLwhyCVUTzyGLc1QdoI7pPmvBCOmCj8PAuc/pTLlra1nKxMH9P3AK0b+ vxt0vNIzKonNgNL3ifvHa/bJP1FER2VUWyHq4z2sv29SdJKMTBn99KVIk+L/mi8kxuoA tdTdOU42wk2PePFN6JONomBrFffAI+xegbybikxeJMeMf0HqpvfnYkYk+QLqoo8kY77L 3LHiFUb+X0Ch2AT32TT0EtR8jG+FVaGZknjCwWydLxHLwdA4fW4Ax+WesZcZf/fMXor/ +tTA== X-Forwarded-Encrypted: i=1; AJvYcCVZBU4DVdEwpRpoUxKAj1xwooz9E/pqvJ+1FAGZDGKPlIugWWsjtp1LzodKaEsAOTQKrBQiaPGpIQ==@kvack.org X-Gm-Message-State: AOJu0YxLA4VxxaXC4UjYZxnKcbc9pce+Jf6CK7jCLeV6w2OMIu0gFqlD 5/3KO0NHT1GqhUF/TdqG8PPemUKxQBOZhtK+Uya/HDYu2J4zv0RVmN9iNbGzRTBsKxov2jsJ1La 08pq1G8Dj9woWHDGSFfG4PN1ujyaXK8Q28UbTk7pToFxU3K4GyBHQ X-Gm-Gg: ASbGncv4gHhI5F4SWxDzLwBBJuCklV+AAZKhWLpTSWIsiXgSEQY6emCK6HNtaKDUmjy YXny06DNJobXn5OONPSuKjUnj/N7ul8DQFHAR9lp6NvZThzHKTlRili/WLrPXiy6KZhKIay9K9V yjX0iZ59Opf2eN8MjF8QIGBxSQ25McSLOA7PegaFRfw9jwJr2y2A+Apw0y8ewZ1TCCt5vAqPXA7 dMgz6R8yPxmjMex3Vs2rYQyr8oDpD1kn5S9bahZrj4Ggg3MabkIf1hvo0g/A7XUe6bDXBZ7nrqX V4s55sFNYrTl27IRIZYnK8XoxfNn/3BMfGkD9vZQ7QQX7BMumLBknU3Oxw/2SgCG7weaXee0xfR APZRHUA== X-Received: by 2002:a05:6000:40d9:b0:3a4:e238:6496 with SMTP id ffacd0b85a97d-3a56d827f55mr10918540f8f.18.1750175059822; Tue, 17 Jun 2025 08:44:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQg7GY1Gsteo7GdT4ckbEy0SNxYC91KxvGox3B/Jtg2LOmOg//Pt1oxMAZKf077YGN9lBupw== X-Received: by 2002:a05:6000:40d9:b0:3a4:e238:6496 with SMTP id ffacd0b85a97d-3a56d827f55mr10918494f8f.18.1750175059294; Tue, 17 Jun 2025 08:44:19 -0700 (PDT) Received: from localhost (p200300d82f3107003851c66ab6b93490.dip0.t-ipconnect.de. [2003:d8:2f31:700:3851:c66a:b6b9:3490]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a568b4c969sm14100737f8f.85.2025.06.17.08.44.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jun 2025 08:44:18 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, David Hildenbrand , Andrew Morton , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Dan Williams , Alistair Popple , Matthew Wilcox , Jan Kara , Alexander Viro , Christian Brauner , Zi Yan , Baolin Wang , Lorenzo Stoakes , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , David Vrabel Subject: [PATCH RFC 14/14] mm: rename vm_ops->find_special_page() to vm_ops->find_normal_page() Date: Tue, 17 Jun 2025 17:43:45 +0200 Message-ID: <20250617154345.2494405-15-david@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617154345.2494405-1-david@redhat.com> References: <20250617154345.2494405-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: OaXJymteJt-euNLEjk_nhlEwz05sWgFdsYVaRA57foA_1750175060 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: E3F63140006 X-Stat-Signature: aed4doo5n4m4hsgmgbcytwz9buog8714 X-HE-Tag: 1750175062-495152 X-HE-Meta: U2FsdGVkX1/vUxzrWJfOCA4xkxWnfL6Md3qPXvhQi5k71Y8fAfIxAYaMhB8LeWuIPL2DjHNdfrH71cW1mKR5yTIciplNpoV/xn9TZO5B/AYwrxuv55hlZJaucGUlvS8/yp2fuFZAwY45PiINBCu3UnN8Y1ibOsCFMVljlq3+mQONrcKwe5debTIgkkI0fIhUemyugJG+gawZlb4NcaaS9KYyDDHyjikz0Dxi7WK0yAyJOmolMkvXrVh/4hPWBWpSSripSVudeqBibApJrJbPIOknV+hwria4+DESZCibDdwo3DJj3UvYsuE9pH/ph9OPZXPYcgzUvWgq9jfDET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3/Oxst3gyVtyzGhMiQLxKzk2v0fjtJbEhgDYdXaVou4a9cima8llZjlkZ0Ff0Ev8Pza/YNzZJOXTSgJZkrpRVLsX9krffkK80lxUkeuUr0noAzewKUoaDD7is3Vsm+J4jrKg== 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 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 | 10 ++++++++-- tools/testing/vma/vma_internal.h | 18 +++++++++++++----- 6 files changed, 40 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 022e8ef2c78ef..b01475f3dca99 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -646,13 +646,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 c6194d1f9d170..607a3f9672bdb 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1390,6 +1390,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 6c65f51248250..1eba95fcde096 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -619,6 +619,10 @@ static inline struct page *vm_normal_page_pfn(struct vm_area_struct *vma, * If an architecture does not support pte_special(), this function is less * trivial and more expensive in some cases. * + * With CONFIG_FIND_NORMAL_PAGE, we might have pte_special() set on PTEs that + * actually map "normal" pages: however, that page cannot be looked up through + * pte_pfn(), but instead will be looked up through vm_ops->find_normal_page(). + * * 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. @@ -639,8 +643,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 51dd122b8d501..c5bf041036dd7 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -470,13 +470,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.49.0