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 DEA81C4829A for ; Tue, 13 Feb 2024 08:54:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C3EA6B0081; Tue, 13 Feb 2024 03:54:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 54C7B6B0095; Tue, 13 Feb 2024 03:54:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EDD66B0096; Tue, 13 Feb 2024 03:54:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2A5AB6B0081 for ; Tue, 13 Feb 2024 03:54:12 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EAC281408B2 for ; Tue, 13 Feb 2024 08:54:11 +0000 (UTC) X-FDA: 81786168702.17.A158838 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id BDE2880013 for ; Tue, 13 Feb 2024 08:54:09 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ksqZQxr+; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707814450; 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=yGL5RRER78TPI6/TiT3IpzYTDrtbMwQINDuYFmVqcUA=; b=19m0CJ1UMcMWMgPANC0calS5hbh3TyWOpAuGpSkWEcETbRRfM20WEL6iMm1U3LX+m4EOdA m/1ptUovmJ96nPIJxDOV6t7AuOc7dPLQkTadKXsPaXm2g8bc+BnnR56YBNkoHUxKUFVj8M mYejTBWxvIXPu4/44nyDxcwjfv5uLLc= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ksqZQxr+; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707814450; a=rsa-sha256; cv=none; b=q/IBpmwfWgKYCgvxcdfClDH5bVbhST9ni95m6pZhoOV1Y7fkyVhqHId/cz6i7kKUNvHaYT RB8rGK6+GUiuvEQnwjphjSfHc7lpqmcjztsYCyQkiXaQx4odzNvNcYEz0WBM5j63FmCAIK HWSA7KX7knd+bMPC0TX8lLJ3/XTSdZ8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=yGL5RRER78TPI6/TiT3IpzYTDrtbMwQINDuYFmVqcUA=; b=ksqZQxr+Ouc3OlY5xP98g9Wgyd BZWIl8ArFuzArbQXWvjoph8FqJbcYxuIGBeyeeP/D50cRmaHpURkm2QubuzDTd8KiXRYSljDFhLHN XDpSq0faHyyPbLudLg3JHaUHdozASMCJC2AU3+5MhDUpWV6VFlp38tJlC9vrDvrqrW/6VKqSXzRHG 3jRYlNOOgB9Ddy+PDL1sSe99jgHJ+SYz41vc5tg5LyW1L6D3YNZgLwS4gfkUbFnK0pFJqFozHGPKT Z/n4ghaL0NWvUbaudjGBFKWfV4WEDPnuC1RmVRnDs2ee3zC+FQQzEo+bYaX7nirme5L8y0CgxKPC9 Yy5c86lA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZoYG-0000000DIJX-19uR; Tue, 13 Feb 2024 08:54:04 +0000 Date: Tue, 13 Feb 2024 08:54:04 +0000 From: Matthew Wilcox To: Charan Teja Kalla Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org, vbabka@suse.cz, dhowells@redhat.com, david@redhat.com, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, # see patch description Subject: Re: [PATCH] mm/huge_memory: fix swap entry values of tail pages of THP Message-ID: References: <1707814102-22682-1-git-send-email-quic_charante@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1707814102-22682-1-git-send-email-quic_charante@quicinc.com> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BDE2880013 X-Stat-Signature: smfu6rir7p9bdjj5w7wt7uyjf7nfeufe X-HE-Tag: 1707814449-606199 X-HE-Meta: U2FsdGVkX1/QGetNPOaOt4dCp/+GYG6ANXRUEaVf3aljIt4FfQjgMldX9mXi+JjErd3Lh9UZkH3T9wPZVojglVu45tuM7xH+qvZtlYbS3sa+RqeIbXU7zqx74XdYlH250AGyRIQ0m2R1ryCbu78gm9lDUX4divtHHwOeioYLyZGOWYgsy1W+QhRr/eJ9EPSyGsyofzPkYZO2YX2EnC1GCJrd3R+dNwsjSXaoLf7TjU4CPbI9KP6xvXJUkK6lzfPo2x3StPKMsxk/FJ0unSMthcaiAzhqNFRIPEIgiZasAIS0fLH0SYWEpVdsIDXWR3dOV1VSUS2fVMwNLJcEpY2MSuIi8wZtA51Ki5GRkXAUAzaG7timAuuSlHKvHWfRWPSvH0I/UFBzXnE4KIrNmqbxdREoC1yQ0irwgH+0XlfjBJzaPqIjVY2w3UIJiS/MoXru2vIZhxqn1emrweU3G1zFlJ6D4Bt/OhncFEGd4h/aq4g6ak3U/UwlqNDk4UEO5Wh5pRHOydOgj/N9rM4yi3AW6nxGm7NBevlcvDW+pMCukpcTHPlgCKQi5oFrIJmu5MEq73biFTfEa1x1nmfJi9Bc/+kTZwSOpPYv68Eqfz9fk8G8OIXz526q+CRXO6ewvL0wshxgTbmFvEoaJubPLUR35rJpw3+ChklgWka9kypIfr7KqUAgfCKaKPObD2TU4ytJgdkvf7Dvhrs+0HvJJovEwFeO48/tXL4iK/jZQMQAHpqkw7mui0F0KcVc/Z2bgzcyVBsvf5DKynN6tWxAHuYdpjX4zPhQiLTqlNCQ5fQiwot12xpt3qjaIboxVPC6C5jCc5s6LCPldM0MF5OxrVfiPT67KaRY313vIeXodkzRZAgC8uXobBGdhe/fqbKvcmj1gNvAjeTTEGHfywCA2zXkewb1g1xQHlqXU7ssYCq+S0X7YZdonqCg/g6H7A/KiMk/He7ckRLi0bg9M3K+CIk JQjSf5uV j3Bkk0wSkMnu2XidCzyHHgaUh4fhY/UFuWrKU5xpTVntaZ263Fn+3nveBGvF/ar8FodnuOQMmcIyUC0RbeFRrIA4IdkVBY5MvkMdysU2WJHDC1nTlVtq1U/pKzPo274dfJK5RD7t0gNapYr2mWZsiV3wmW1RCF/8cUv9NYHE11luUcUYMkIHWT2E3JIzGNyevvotMSdZ+IrBaKE/eEllIqvDTg1hfDzm8QdZfmXnNffvg1u7SfQqGC1TzpgbszU6Z8GMwxKQtT9pcuKkwIWQYdCZrfgw9dkQ4MB5+C2YUNbv707blKwM/5rgzPbkwk3ozET+uZa5pb1X6QP0= 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: On Tue, Feb 13, 2024 at 02:18:10PM +0530, Charan Teja Kalla wrote: > An anon THP page is first added to swap cache before reclaiming it. > Initially, each tail page contains the proper swap entry value(stored in > ->private field) which is filled from add_to_swap_cache(). After > migrating the THP page sitting on the swap cache, only the swap entry of > the head page is filled(see folio_migrate_mapping()). > > Now when this page is tried to split(one case is when this page is again > migrated, see migrate_pages()->try_split_thp()), the tail pages > ->private is not stored with proper swap entry values. When this tail > page is now try to be freed, as part of it delete_from_swap_cache() is > called which operates on the wrong swap cache index and eventually > replaces the wrong swap cache index with shadow/NULL value, frees the > page. > > This leads to the state with a swap cache containing the freed page. > This issue can manifest in many forms and the most common thing observed > is the rcu stall during the swapin (see mapping_get_entry()). > > On the recent kernels, this issues is indirectly getting fixed with the > series[1], to be specific[2]. > > When tried to back port this series, it is observed many merge > conflicts and also seems dependent on many other changes. As backporting > to LTS branches is not a trivial one, the similar change from [2] is > picked as a fix. > > [1] https://lore.kernel.org/all/20230821160849.531668-1-david@redhat.com/ > [2] https://lore.kernel.org/all/20230821160849.531668-5-david@redhat.com/ I am deeply confused by this commit message. Are you saying there is a problem in current HEAD which this fixes, or are you saying that this problem has already been fixed, and this patch is for older kernels? > Closes: https://lore.kernel.org/linux-mm/69cb784f-578d-ded1-cd9f-c6db04696336@quicinc.com/ > Fixes: 3417013e0d18 ("mm/migrate: Add folio_migrate_mapping()") > Cc: # see patch description, applicable to <=6.1 > Signed-off-by: Charan Teja Kalla > --- > mm/huge_memory.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 5957794..cc5273f 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -2477,6 +2477,8 @@ static void __split_huge_page_tail(struct page *head, int tail, > if (!folio_test_swapcache(page_folio(head))) { > VM_WARN_ON_ONCE_PAGE(page_tail->private != 0, page_tail); > page_tail->private = 0; > + } else { > + set_page_private(page_tail, (unsigned long)head->private + tail); > } > > /* Page flags must be visible before we make the page non-compound. */ > -- > 2.7.4 >