linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Matthew Wilcox <willy@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>
Subject: Re: [RFC PATCH 0/1] mm/debug_vm_pgtable: Use a swp_entry_t input value for swap tests
Date: Mon, 23 Jun 2025 21:06:52 +0200	[thread overview]
Message-ID: <15891cf8-4866-476c-867f-8027693cacfb@redhat.com> (raw)
In-Reply-To: <20250623184321.927418-1-gerald.schaefer@linux.ibm.com>

On 23.06.25 20:43, Gerald Schaefer wrote:
> Hi,
> 
> currently working on enabling THP_SWAP and THP_MIGRATION support for s390,
> and stumbling over the WARN_ON(args->fixed_pmd_pfn != pmd_pfn(pmd)) in
> debug_vm_pgtable pmd_swap_tests(). The problem is that pmd_pfn() on s390
> will use different shift values for leaf (large) and non-leaf PMDs. And
> when used on swapped PMDs, for which pmd_leaf() will always return false
> because !pmd_present(), the result is not really well defined.
> 
> I think that pmd_pfn() is not safe or ever meant to be called on swapped
> PMD entries,

Exactly that. Just like pte_pfn() on a swap entry is bogus.

Instead, we can test for is_pfn_swap_entry() and then use 
swp_offset_pfn/pfn_swap_entry_to_page/pfn_swap_entry_folio.

Code in task_mmu.c uses something like

	swp_entry_t entry = pmd_to_swp_entry(*pmd);

	if (is_pfn_swap_entry(entry))
		page = pfn_swap_entry_to_page(entry);

and it doesn't seem to be used in that way anywhere else but
> debug_vm_pgtable. Also, the whole logic to test the various swap helpers
> on normal PTE/PMD entries seems wrong to me. It just works by chance,
> because e.g. __pmd_to_swp_entry() and __swp_entry_to_pmd() are just no-ops
> on other architectures (also on s390, but only for PTEs), and also
> pmd_pfn() does not have any dependency on leaf/non-leaf entries there.
> 
> So, I started with a small patch to make pmd_swap_tests() use a proper
> swapped PMD entry as input value, similar to how it is already done in
> pte_swap_exclusive_tests(), and not use pmd_pfn() for compare but rather
> compare the whole entries, again similar to pte_swap_exclusive_tests().
> 
> But then I noticed that such a change would probably also make sense for
> the other swap tests, and also a small inconsistency in Documentation,
> where it says e.g.
> 
> __pte_to_swp_entry        | Creates a swapped entry (arch) from a mapped PTE
> 
> I think this is wrong, those helpers should never operate on present and
> mapped PTEs, and they certainly don't create any swapped entry from a
> mapped entry, given that they are just no-ops on most architectures.

"mapped" is probably misleading. Probably "mapped" as in "this PTE is in 
the page tables", not "mapped" as in "maps a present page".

In any case, it should be clarified.

-- 
Cheers,

David / dhildenb



  parent reply	other threads:[~2025-06-23 19:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 18:43 Gerald Schaefer
2025-06-23 18:43 ` [RFC PATCH 1/1] " Gerald Schaefer
2025-06-23 19:10   ` David Hildenbrand
2025-06-24 10:40     ` Gerald Schaefer
2025-06-25  4:28   ` Anshuman Khandual
2025-06-25 16:28     ` Gerald Schaefer
2025-06-25 16:47       ` David Hildenbrand
2025-06-30  4:18         ` Anshuman Khandual
2025-06-30 14:38           ` David Hildenbrand
2025-06-23 19:06 ` David Hildenbrand [this message]
2025-06-24  7:50 ` [RFC PATCH 0/1] " Anshuman Khandual
2025-06-24 10:35   ` Gerald Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15891cf8-4866-476c-867f-8027693cacfb@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox