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 03747C7EE31 for ; Tue, 24 Jun 2025 07:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FF036B00B3; Tue, 24 Jun 2025 03:50:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D5B16B00B4; Tue, 24 Jun 2025 03:50:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8123A6B00B5; Tue, 24 Jun 2025 03:50:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 700AC6B00B3 for ; Tue, 24 Jun 2025 03:50:51 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ECBBABFCB2 for ; Tue, 24 Jun 2025 07:50:50 +0000 (UTC) X-FDA: 83589522660.19.39FE98D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id EC457180003 for ; Tue, 24 Jun 2025 07:50:48 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750751449; 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; bh=0jcMz/Yh0AGwps1Z38doWUpaOc2qxQ/HeezQGOyd4ho=; b=w1UUmwPCpgsUqbb7E5PVSVQ3qBExJshZNFPKKnFTVfB6eJsNt2VL7GyGPZRftY9xJ0hvkq VA5nUTz5A5ZXH4GE98pw2Zy7V/BNAL+NdCXz5D6PObBFpeOnwC7HWnWYZQeT3LNxkEWwPW zbCBCcJSFc9+/1tGLbSYjAwzRJEmpzI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750751449; a=rsa-sha256; cv=none; b=zDN97vH6PUA9vI9fjf4ZmyAmH4g29bUpLjlBwGh5fzvdd8TsU/hLp3ROB5V+hK6/BWwmQ1 lXpVh11APOQMZaeiMJpknGlE5yjUcACZK6VpkC5qzXaoZ17p8xygxnqugArHvKckUfki94 Pz+XcCwKxOBcfzKJTEV+S3iO5o6xjuQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 446E6106F; Tue, 24 Jun 2025 00:50:30 -0700 (PDT) Received: from [10.163.38.23] (unknown [10.163.38.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 00D4D3F63F; Tue, 24 Jun 2025 00:50:45 -0700 (PDT) Message-ID: <9e220213-0d4a-4e61-b8cc-45ea21b073a6@arm.com> Date: Tue, 24 Jun 2025 13:20:42 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/1] mm/debug_vm_pgtable: Use a swp_entry_t input value for swap tests To: Gerald Schaefer , Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , LKML , linux-mm References: <20250623184321.927418-1-gerald.schaefer@linux.ibm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20250623184321.927418-1-gerald.schaefer@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EC457180003 X-Stat-Signature: abm1j9y89dfohqp5k15u7uwhxwi5jqqb X-Rspam-User: X-HE-Tag: 1750751448-942130 X-HE-Meta: U2FsdGVkX18f8E3v3Ok9pPM6+2YiACM6l6VyGR7Uu28eHlwkt5VAvi9q0fYJBUe0EjpxNmjauqA8oo++iMpE3AYU9uPain/mZfAeKukUkbQQVP0OsisCzkktlHTguXQ+RJjlSxJs9eBb8elyRVI5w4j78cSu1OmscPb5Yz3rxM6p2Mo+zqZVcIn0y9DRE1L2DQUSOI5rrLG/iQBkF4OMmbpOpP1YnoRHJaTZT7J1+hJRnRtlK7tVj2MRbUf0zy/EJnsPIHXHSE7tda/lLN/rc0QOF7EgYSEzUaVKIpBwbzxPZL6ze+X7UvW6vN67vHMXx3sWu4w616f4Vo2ih7VObrjt4L4MRmZpTcuF6u9VNVVI9jN4IaHPyDWz9UFuZBqbCA4EuqaAfxK8T6uFiJGSsjbOPPSVFf5/6ohmRUt9bp+v8qwZUd9W0ACvLKtW5gcQIZVougwtF8UP0ymsUI/XcWrlWTtfTcP6qOLjU4STcKZvPBlG9HP6bnRetw2EJcKuEchOXRH/0eAk3u/MSJ+0K4uovCt1f1HQO7nMO3BfuA8k8TrRbxrrIRijX/kZg/F44nN+Dms76rTH+iAmECsMahx/nZr9jmrexuw2wMFXLyG/9kz8Lw2pAogrSvVuFs6LfGBWCFAAqxvLjT1ND5Sh00o1TpDYiM7X0grHmqoUjizzqg3IdD2Y3mSYd7uMkViA8sDK9WP4GSi9xk2mwwU2s4/to/3+jksxdH8pKiH1IWBppUnP+/t0IyG2tRv7MoU7nBUMHlg9Mu/AOymVOA/1thcvRSkxWK4Dudwfsc8SzzAqPKWh+op7IBEhr6XFbfl6Lmq4XAYFyP3KZcWRkq/k2TZ1iGhOe8RqXCx7omtkJZ8ilNVkHljhh7pWaBFfAg0FSHlrv3GhIMT40GtPhnXxSHshr4LIFJKBgM8clRYA91FMTtMXtGzKftmKJm0qcPdVkt/5KshfGCVg9OFCwko dcVpn7K1 8C1Vhp/TgSN9DwP1uKf2dWXcoL1oKY5xyhIH9prU6Lq28fjDnp3P7KJ30so65itN2daijisjGqhlyhV1fl0h+Ra7sMsN2Q1EXR2gg01aQjPQX+0M7SHVQJyxydt8s4zR+keYEmh7hrkGod5fAHzYGf/nEuLI/OR4c8wwywZWsv0/XZPL6R/j2C42eLdfEW993VLTO 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: Hello Gerald, On 24/06/25 12:13 AM, 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. Just curious - pmd_pfn() would have otherwise worked on leaf PMD entries ? Because the PMD swap entries are not leaf entries as pmd_present() returns negative, pmd_pfn() does not work on those ? > > I think that pmd_pfn() is not safe or ever meant to be called on swapped > PMD entries, 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 But is not the pmd_pfn() called on pmd which is derived from the swap entry first. pmd = pfn_pmd(args->fixed_pmd_pfn, args->page_prot); swp = __pmd_to_swp_entry(pmd); pmd = __swp_entry_to_pmd(swp); WARN_ON(args->fixed_pmd_pfn != pmd_pfn(pmd)); > 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 Hmm, basically it just tests pfn_pmd() and pmd_pfn() conversions ? > pmd_pfn() does not have any dependency on leaf/non-leaf entries there.Could you please elaborate on that ? > > 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(). Agreed, that will make sense as well. > > 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. > Instead, in this example, it just returns the arch-dependent > representation of a swp_entry_t, which happens to be just the entry > itself on most architectures. See also pte_to_swp_entry() / > swp_entry_to_pte() in include/linux/swapops.h. Alright. > > Now it became a larger clean-up, and I hope it makes sense. This is all > rather new common code for me, so maybe I got things wrong, feedback is > welcome. A quick ran on arm64 looks just fine, will keep looking into this. > > Gerald Schaefer (1): > mm/debug_vm_pgtable: Use a swp_entry_t input value for swap tests > > Documentation/mm/arch_pgtable_helpers.rst | 8 ++-- > mm/debug_vm_pgtable.c | 55 ++++++++++++++--------- > 2 files changed, 38 insertions(+), 25 deletions(-) >