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 6254AC48260 for ; Tue, 13 Feb 2024 08:49:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3E646B0082; Tue, 13 Feb 2024 03:49:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEC6F6B0093; Tue, 13 Feb 2024 03:49:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB4666B0095; Tue, 13 Feb 2024 03:49:45 -0500 (EST) 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 ABB226B0082 for ; Tue, 13 Feb 2024 03:49:45 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4CB921202AE for ; Tue, 13 Feb 2024 08:49:45 +0000 (UTC) X-FDA: 81786157530.16.1691B78 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf09.hostedemail.com (Postfix) with ESMTP id 1FBAC140015 for ; Tue, 13 Feb 2024 08:49:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="J4 PRARs"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf09.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707814183; a=rsa-sha256; cv=none; b=1JbC8yCRql2JszKaSeSEVX34RSkJXyq14Zn4y6ZFf1XNGn7A+aJwqWxAUigusL7AGv/qX0 xmN2cCCemUaHMRc3dX66iApFAoCznSK5OgEQ546ymTNxZl9G6W1Oq0PXpTHXPHt5fXkQ2v EJoFPOXcStrtSBvJkA7boCKb3/qOLYs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="J4 PRARs"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf09.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707814183; 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: references:dkim-signature; bh=kCqPcNo+Xt7o8GNLYwi+lrAM4HO++yNt6oCLnibGDyU=; b=whxlofVZGvPMAdX8QoHYdXfiQBf2WdqGRppG5M7M8v7yKmZw2X2hJZVNdnyfFcAQ4Bt5fQ R5eih08UvI6PUjy2s3fgDnSTttOSPCC+3RagB0W8ZqunlPLTMMcI6hTMORJZ34+8d1FY7m 57Xw7+yClG3fDup9PqpwsnfsZ1Gc0+E= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D8cnAc008573; Tue, 13 Feb 2024 08:49:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version:content-type; s= qcppdkim1; bh=kCqPcNo+Xt7o8GNLYwi+lrAM4HO++yNt6oCLnibGDyU=; b=J4 PRARsIiBU0uSwPXNo9MzzZTLdpMFUc80Quj0xAZWuHpmA2xWf8PQ611M6s5y1AET 8vtI2NmwbVSmmyPVcmaizRIt7JB3Qn7b7D4GEcGsn3PyxghmD7BGXYSzCzKKJb0Q GxG4FSdIUyGBcq+lqKzLb03y0FqWFFDf8AXkwS20qcvQqS2XvAol9dvVa7DnFyVI awHrfnT5EVbhA+iQiWmVU0fEUXy9p0eS6uR9xugX2op34+KzpqUjwq3luh6VS18W hbeuFaJGVVD3e/WhsuhpMkQKHgQ8olofO01OcRU2z3OwXXJAON3Bi0vVgxEZ3gDm ARyciOG6jigP0TDjOFxw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s3919c2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 08:49:35 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D8nY1Z026901 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 08:49:34 GMT Received: from hu-charante-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 13 Feb 2024 00:49:30 -0800 From: Charan Teja Kalla To: , , , , , , CC: , , Charan Teja Kalla , # see patch description Subject: [PATCH] mm/huge_memory: fix swap entry values of tail pages of THP Date: Tue, 13 Feb 2024 14:18:10 +0530 Message-ID: <1707814102-22682-1-git-send-email-quic_charante@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ExtM5oF4G8N0zHAvaPk-MHkzrH5KQYU0 X-Proofpoint-GUID: ExtM5oF4G8N0zHAvaPk-MHkzrH5KQYU0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-13_04,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1011 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130068 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1FBAC140015 X-Stat-Signature: e6u6q5ichiui6ifi84e5585mgotou7qt X-HE-Tag: 1707814182-639364 X-HE-Meta: U2FsdGVkX19HxpKDva176eW+p/g/F9QHMl3XGJYVJsGiFPutcmDX5TufMrcks/PxC3MZ9Y1snQHiTSteLVngEiiicHfXzco9tViJuXc4KoK5TIVafAYdXc2/dojuVetnuDisyb9V/UxizqvKuSYf8LMGxyBKsazb/ybJaoCT77m+u+anlTpqkXdc+jp8JODD5arBcoKasRu6N3nrjdFwJg5rUn2w1V8haMjg5dOnFY8g19XSm3H2Ucp/hgThhjCcGm1yoUi96pXYrefluh7aRMzJEAfB/oi/bnBhfCK1MP4SN5zNvoKMiQoB6SZSahJBVJYjV7kZU1+BNqkuPbzWhKKBO5SHx+VXqBNM63bPonGS/Mo3HgmQOFjzBQglM/8547sQtNPPIm+WrfSmGOd1fuyyloW26riau1fLjpbIVve1r8nNE3dZVkCYiuvCuCDl1LjZrONJm1KO1CleDNU3eIkXwn3jKFlea9AATAgqJWGhp9ppc4qYjsBhRkoXYSYWrA1MCUeOCyEgw9XKglSsaYO/PoLYhf8X7g7ZKk9tEzUTX3vBS7jGN91oH6SDzSnKE9mnaegLGsr9hhBo2173WH6KsZ1Fb8gF5Q4K/aUxPcSRRvU9G2xYHX/dX1g5cuzTdD1RdZfL33qkM6PIdNyhaj1bXLtDxnY3k6l2tQ9aXmAXbd+vov76evsbqxugpcuzOQVdCXhuWwGmur6hsAElVc6FDORrtL8Ou8nY1TRrt6qMXjhiN4zswVEt+fCO7vm94TgZl8VcIq2sbP1/vzsezkZ/TClpvhlOlCdRPlUStnHuTDRgLUdd/u1XvRBkUCzUuTH4fXoprRfNiFZM89Zcz+f78pQeUkpNUgHPbpZSePcr0lDXixioJkfrfa89QPbWBk2r8/DzE0nk8S143vAa7XZJLRa8715W25UWxCM0x6FvaGDp2tu4/etRTXtyK9GauCPRGs8LazJCENz5VHS Im4sMsCB xWtUNQ5uo/slveM+q5mFjOSenKrOlPndsKdMOYkqxxxkivMYT1X0b2kBwh5vFU6Pj9E+0vfd+JzFCWN/XhOryqAzFVV3BaHeoFg1O9iGpUDS+fQyQkveVTEPqH2SycGekvlxk3rXc6CkJfOCS7E0TPHv7KwJLpMiF/8OWXeSPmHo98/36Gu9Su2AyRh+b013muZAe7BR4zwIRn96SczHQ2DkbAV6ZLUqRA1HxQ25sQ/KFdJUDVaQr3N0DSUYBYyjwHCiD+HwdqDqEEwb6d4Lg8jbgmFGJKD2zSzDEXgjvKPdF9INX9jJPoTCtia3QNDNsECLjTzf0oWnGrflowDk+NEeg3bmU28gexKmAiT0niDIAb4/Nn4pze+mo3ZlYsYHlmLMT 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: 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/ 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