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 E2177C00140 for ; Wed, 10 Aug 2022 06:04:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25ADA8E0002; Wed, 10 Aug 2022 02:04:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20A2C8E0001; Wed, 10 Aug 2022 02:04:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D30F8E0002; Wed, 10 Aug 2022 02:04:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F1E1A8E0001 for ; Wed, 10 Aug 2022 02:04:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C84FA80C40 for ; Wed, 10 Aug 2022 06:04:50 +0000 (UTC) X-FDA: 79782644340.18.1F97478 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf16.hostedemail.com (Postfix) with ESMTP id 27EFF180176 for ; Wed, 10 Aug 2022 06:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660111489; x=1691647489; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=E5YCWou/67pE3W1963fIKNZ34NBDTyuwKuFBri39tSI=; b=CVVLFYPHV8T6WiNzcIwIrvAe5cVNu+K3jWzJUq6a5jXBV1PxXmksGTlb oh/usxPfVmZ2VYL3UCsXI3GSfLkAr2VgSi5SR0x38tmYP9OxtLwOhtoZU gDCcncmQJ1SGmZ86bvPspEaixEXXTzt9D816kOfg/s+bi4+FdldSJMf4i 5/Sn5hOyWZ7oM7Fpce581Wnah6z2txSXKXmS+a6TaUu5zsAifYtwPHRTa ra9WVh4veZFD+PQg06+rvYOR3Je7HCjhU0QWaBs12ZOvQz+GKlTaLhZiD f3+hBQb9ho/cOEEicNS7qIwRppejO+siB+lT4nrRwlRk7kD1gZ9UjK9V4 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10434"; a="352737937" X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="352737937" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 23:04:47 -0700 X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="581103271" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 23:04:44 -0700 From: "Huang, Ying" To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , David Hildenbrand , Nadav Amit , Andrew Morton , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , Andi Kleen , "Kirill A . Shutemov" Subject: Re: [PATCH v3 3/7] mm/swap: Add swp_offset_pfn() to fetch PFN from swap entry References: <20220809220100.20033-1-peterx@redhat.com> <20220809220100.20033-4-peterx@redhat.com> Date: Wed, 10 Aug 2022 14:04:32 +0800 In-Reply-To: <20220809220100.20033-4-peterx@redhat.com> (Peter Xu's message of "Tue, 9 Aug 2022 18:00:56 -0400") Message-ID: <87bkssfxcf.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660111490; a=rsa-sha256; cv=none; b=DoUDH1QWoWht1pZEfS5mGuI6sJ62rL5VKcPMfLHrharTg3vU4yjeX9eUnlqFWRltGkiag2 iv8nMiWfryWTe3oYRF2M+EqCL9wsV1HCpmeptwzCoC1nNvyay5tli39+pmhqqhWUNrQ6mh slBz8Nc3MF8FxlCaJY0TdoVynuyWIPI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=CVVLFYPH; spf=pass (imf16.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660111490; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V6PmUTS/FrjwAaeXw4h67X+RADTpE0kW45FPUR+NMtw=; b=zFRbQQQz9lhYmcVjCigN8aFtEGVzRbXvFrD8juzU/0HAnPErzk4ob5w2CcnTofwxLsmoZZ ZbsU+TuICYmTxXTRIBt8FHxBUswZVC8+5fsd7vroC2XWmiip7oAaNN1mGdQdaDY5WvjIOw 5iEOrvGhRAfMBstv2+Tm3/iWLeWZeM4= X-Stat-Signature: wo7epmf3zaermc4hu44wsfebpryy1bfr X-Rspamd-Queue-Id: 27EFF180176 Authentication-Results: imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=CVVLFYPH; spf=pass (imf16.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1660111488-909200 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: Peter Xu writes: > We've got a bunch of special swap entries that stores PFN inside the swap > offset fields. To fetch the PFN, normally the user just calls swp_offset() > assuming that'll be the PFN. > > Add a helper swp_offset_pfn() to fetch the PFN instead, fetching only the > max possible length of a PFN on the host, meanwhile doing proper check with > MAX_PHYSMEM_BITS to make sure the swap offsets can actually store the PFNs > properly always using the BUILD_BUG_ON() in is_pfn_swap_entry(). > > One reason to do so is we never tried to sanitize whether swap offset can > really fit for storing PFN. At the meantime, this patch also prepares us > with the future possibility to store more information inside the swp offset > field, so assuming "swp_offset(entry)" to be the PFN will not stand any > more very soon. > > Replace many of the swp_offset() callers to use swp_offset_pfn() where > proper. Note that many of the existing users are not candidates for the > replacement, e.g.: > > (1) When the swap entry is not a pfn swap entry at all, or, > (2) when we wanna keep the whole swp_offset but only change the swp type. > > For the latter, it can happen when fork() triggered on a write-migration > swap entry pte, we may want to only change the migration type from > write->read but keep the rest, so it's not "fetching PFN" but "changing > swap type only". They're left aside so that when there're more information > within the swp offset they'll be carried over naturally in those cases. > > Since at it, dropping hwpoison_entry_to_pfn() because that's exactly what > the new swp_offset_pfn() is about. > > Signed-off-by: Peter Xu The patch itself looks good. But I searched swp_entry() in kernel source code, and found that we need to do more. For example, in pte_to_pagemap_entry() frame = swp_type(entry) | (swp_offset(entry) << MAX_SWAPFILES_SHIFT); If it's a migration entry, we need frame = swp_type(entry) | (swp_offset_pfn(entry) << MAX_SWAPFILES_SHIFT); So I think you need to search all swp_offset() calling in the kernel source and check whether they need to be changed. Best Regards, Huang, Ying [snip]