From patchwork Thu Dec 19 07:30:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13914584 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 373C0E7718A for ; Thu, 19 Dec 2024 07:30:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5D826B0083; Thu, 19 Dec 2024 02:30:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0CB66B0089; Thu, 19 Dec 2024 02:30:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D4926B00A1; Thu, 19 Dec 2024 02:30:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 708476B0083 for ; Thu, 19 Dec 2024 02:30:23 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E7DF28122B for ; Thu, 19 Dec 2024 07:30:22 +0000 (UTC) X-FDA: 82910884518.26.022BE8B Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by imf03.hostedemail.com (Postfix) with ESMTP id A24E120007 for ; Thu, 19 Dec 2024 07:30:05 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=UyRUd3lW; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734593406; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=M8zYKBBFJV3f7n/1X2H/QO/djeX/cWE2BXzLzdK+uwg=; b=77Z7TEULAIc2BsB5vGDzkCSY+Blq6P6TY6nXxns0UGQC2lBpkO33ojmArkjgRiOBgKO7zP qzIaI6GSXRjGcgyPz2CGEm+xNx/cI16FOpjfuRJ6ASspp8ueWlVz9oOpnUL5d2P6rBSsaE JV50gKkT0IowVDJPY01FFYulOwIDCgs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=UyRUd3lW; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734593406; a=rsa-sha256; cv=none; b=tTyBt51ZASi5qm+qVjLgLr3r681l3CD1TLMcEsjS8sx+oFTcyzvFST924oNwtzWk5m3Ibd A0zLmJU4v/DAoCsx6s1UHACoDE6msiO2/iJMDJFw2dAJMCBdabCkW3WYFmVgDK/lQoV1cu WSK0XEYqXCHGpu5HUAF3iEjwmEiedC8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734593417; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=M8zYKBBFJV3f7n/1X2H/QO/djeX/cWE2BXzLzdK+uwg=; b=UyRUd3lWzBOY96nrVGV9o328bJXnzTt4Lq6Z8Vm3SOA7GRUAKErgrxhZHENe7M0FBk7Hp87XskG0AWNgku9iVg1hw4SeHpGEYBfECymQRVGnsJlngIghn1kjmOEx1qQ+CUQ2b1ruXy3/2V2rHnqueJhOtrSVVYQv6nyRUJA1XzA= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WLpQru._1734593415 cluster:ay36) by smtp.aliyun-inc.com; Thu, 19 Dec 2024 15:30:16 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: shmem: fix incorrect index alignment for within_size policy Date: Thu, 19 Dec 2024 15:30:08 +0800 Message-Id: <77d8ef76a7d3d646e9225e9af88a76549a68aab1.1734593154.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: A24E120007 X-Stat-Signature: z6prbt5o6np5w3fn8jtn9zj777m73wcr X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734593405-222503 X-HE-Meta: U2FsdGVkX1/sJxqSty7w4M1dijVPg0SW8kHmlnS0irBb6rpHBFPN5fgvCkQtAZ/ac8YyFk+hBbufS42enZwbES5X0HNvNx4y59bF+ZEZ8n2S0TsDaXcT51xjQPA91GcKyVAO2a/L65NVwrpVHifOSg3/SfL4cV0gmBmO5yUXMn2hE5UqAKkimRSnAWHHMP5/S5VsYInHjW6nznKFHY8EMulngdPydlJM/+g9Twb6mnc52o9f/yytI1uqIpTaOPFBhP15Ec2jqZyq20wGpQDimm5AGq5zCy+oXz5L3Sy4wj4cFU7H85pGMyEtVFvMYVxpnYfNOVktVuugy4NWToQLK5rHl07lWX1cRhiLwENJ/HUxiPYN2oFsUXck/4aWm4RvUY3xJoDH0JAzGZXTP8a64rvKGqRFmA7DyUNN2n9x2hv7+wSivc/jMDnn7Gi3QPtr2YIaxNFWoosj/XFxmvUff5l7JkuJfRdQK+NlptKsx/xm6iu2VAgkCqBRg1598jKbzkF+rbcjHaxBbL/BYi5QqpESBP1ERycLaO7xQFaMWX1qMcN1XgHO5jmaj50A/v8lMOuEwjyULElbGy4cOlJVK5ZjweoXpyxh72Q2bhLUBbx6UlgG0M78rmVQMu0C/WKHL7vS+Ys4AvXn+NE2c37/92p4T+a7pglBX3g9mSgVBgKT89WxuZy1eLIRlEVAIF4fOWUrrSUnEkSmrgMkalEBfDC92aQkIOmNjimTMzWlYegYcEz72/UurdHZYUBlxwiCb9xZxzZthLQz1KXZYLdYmSgJCWO/VTZnElzkxEkBkr1Dg9L1I74pCqjjb/2H2oazK36NjuoXjIENqq974GF2mYIK1TNPpFd5Ng7QiSNJSKzzW2zSv3TJxWMy31+aZ7kZCY+uVUWvqBawUmOSAVDTVZoPuv4Ce/8AN7f3BOe+NXTcUb7dSf6yJEmT/UaKE7FNMVG8akD421YDRlMRLgG rU+QGFvd OeJwBFmaBrMyDwGk3OQXYe76Cw5/Wc2D0Yf9J9RW5Pv6bddolvtUZ5LAYG+7iUqv5b2QjxMACxemjfTkMGkQvKKi8uEMwdwhBCg3KeGVrC8GQDyJfI2Jp73tgKatRafGJepOb4HigVyUQCpCIM12rb+WQs38tUS3Tkt4DcreM4qY8btIW9zIfN8V7WuVKp09JXtLBOw/7INmIT4RpD2ETNU/7C4LaqyvyD0J8+/g6ONXVt0G9Md4nqvPiNrKSnEAgLVOjDKMMcx//Afg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.093963, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With enabling the shmem per-size within_size policy, using an incorrect 'order' size to round_up() the index can lead to incorrect i_size checks, resulting in an inappropriate large orders being returned. Changing to use '1 << order' to round_up() the index to fix this issue. Additionally, adding an 'aligned_index' variable to avoid affecting the index checks. Fixes: e7a2ab7b3bb5 ("mm: shmem: add mTHP support for anonymous shmem") Signed-off-by: Baolin Wang Acked-by: David Hildenbrand --- Hi Andrew, These two bugfix patches are based on the mm-hotfixes-unstable branch, and this patch has a slight conflict with my previous patch set: "Support large folios for tmpfs". However, I think the conflicts are easy to resolve. If you need me to rebase and resend the "Support large folios for tmpfs" patch set, please let me know. Sorry for the troubles :) --- mm/shmem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index f6fb053ac50d..dec659e84562 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1689,6 +1689,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, unsigned long mask = READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders = READ_ONCE(huge_shmem_orders_within_size); unsigned long vm_flags = vma ? vma->vm_flags : 0; + pgoff_t aligned_index; bool global_huge; loff_t i_size; int order; @@ -1723,9 +1724,9 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, /* Allow mTHP that will be fully within i_size. */ order = highest_order(within_size_orders); while (within_size_orders) { - index = round_up(index + 1, order); + aligned_index = round_up(index + 1, 1 << order); i_size = round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >> PAGE_SHIFT >= index) { + if (i_size >> PAGE_SHIFT >= aligned_index) { mask |= within_size_orders; break; }