From patchwork Fri May 21 02:27:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12271697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AA4AC433ED for ; Fri, 21 May 2021 02:28:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C49DC613BE for ; Fri, 21 May 2021 02:28:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C49DC613BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 085A98D0019; Thu, 20 May 2021 22:28:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 035A58D0001; Thu, 20 May 2021 22:28:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF0FC8D0019; Thu, 20 May 2021 22:28:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id AB75C8D0001 for ; Thu, 20 May 2021 22:28:05 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 36E4F181AF5C2 for ; Fri, 21 May 2021 02:28:05 +0000 (UTC) X-FDA: 78163653330.10.B558685 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf29.hostedemail.com (Postfix) with ESMTP id C0EFAD5 for ; Fri, 21 May 2021 02:28:00 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id q6so10183105pjj.2 for ; Thu, 20 May 2021 19:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E6pVI9E4XZyNnUA05HUSAzl+BEx0Xi9CHVjMCM2HStc=; b=wbD2TwG6+6TIyuYOXoAFQusX3RFjrZCcY5DBeLij4MrcEpCaONsvRwx00cpsTORLW4 /FbYohCw9EgveP4g1BxNPOu9/5FHiJt9E528iCyQEtbRanedSzFglc+9mcA1xXyJ4THl LHlLZB6nI6sYEqhJkI5CVigq/z++o6F016LEAokKgiYwt20L7kp0gyBEj5Ibv7gsw0Dx TUo3JGBhvJA/sjzE8HK17ntwHkixyNMLfIAk7FbrVHvmWA/EWOuTQmnGWrSqRmCBoGGd 3Zd3NdInCu6EFW1QuNrrFuTyIF+01FqE9IKu8rxTlM8hMvxjtPgKgs0Grvu/9VkdtQj7 T5Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E6pVI9E4XZyNnUA05HUSAzl+BEx0Xi9CHVjMCM2HStc=; b=BnCbAVMSSk1y7yAIbHUoQlCc5foJRHrREk2fZCU5mK4zNq5maxyfajE1ctw69rdp44 q2hc3Un9Mcbm+h8NsBPRfxiD3t72CniH13fgIbazUp5VdrME/NiXeoA8OzdWKhbnhlyV Omo+c69hCAmzd22eBWMNre9+hOUFpatV8PBQ1WX75zmK/qZ1oOMwVXLD5GZD22RkODrg iSe/MyWYckFbWR+vzAdb21u27wO5+xNfPyNRKvBzDFcZ+7mgArFdSUGfSF850LjbaHP1 wZBAoa9uSHnq44wh5HgezMaG5ULg+d0Z6kZHc7g3fzttWffBx62hBFVXUSayeb8xvybg 88Ig== X-Gm-Message-State: AOAM532DeysrSPusEObM2VjMleVDZsCYD7KqCl2/p2CnsgiCNQeIJ4i/ jh1I5uz4yj6HSvS+Z0C+FRMYsA== X-Google-Smtp-Source: ABdhPJxHrGkmUEN7q5DYXrV6yJFfzWQ+XDoTInbxNYDBWmBHVvTEfJMflfp4sgMTY62OJP2Mv1XUUw== X-Received: by 2002:a17:90a:8902:: with SMTP id u2mr8073003pjn.143.1621564082696; Thu, 20 May 2021 19:28:02 -0700 (PDT) Received: from bogon.bytedance.net ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id 136sm2892642pfu.195.2021.05.20.19.27.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 May 2021 19:28:02 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org, osalvador@suse.de, mike.kravetz@oracle.com, mhocko@suse.com, david@redhat.com, willy@infradead.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, zhengqi.arch@bytedance.com, fam.zheng@bytedance.com, Muchun Song , Anshuman Khandual , Randy Dunlap Subject: [PATCH v2] mm: migrate: fix missing update page_private to hugetlb_page_subpool Date: Fri, 21 May 2021 10:27:47 +0800 Message-Id: <20210521022747.35736-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=wbD2TwG6; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Stat-Signature: j1czcnkcueuqn4mw9iqd49w8ize9r1so X-Rspamd-Queue-Id: C0EFAD5 X-Rspamd-Server: rspam02 X-HE-Tag: 1621564080-218504 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: Since commit d6995da31122 ("hugetlb: use page.private for hugetlb specific page flags") converts page.private for hugetlb specific page flags. We should use hugetlb_page_subpool() to get the subpool pointer instead of page_private(). This 'could' prevent the migration of hugetlb pages. page_private(hpage) is now used for hugetlb page specific flags. At migration time, the only flag which could be set is HPageVmemmapOptimized. This flag will only be set if the new vmemmap reduction feature is enabled. In addition, !page_mapping() implies an anonymous mapping. So, this will prevent migration of hugetb pages in anonymous mappings if the vmemmap reduction feature is enabled. In addition, that if statement checked for the rare race condition of a page being migrated while in the process of being freed. Since that check is now wrong, we could leak hugetlb subpool usage counts. The commit forgot to update it in the page migration routine. So fix it. Fixes: d6995da31122 ("hugetlb: use page.private for hugetlb specific page flags") Reported-by: Anshuman Khandual Reported-by: Randy Dunlap Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Tested-by: Anshuman Khandual #arm64 --- Changeslog in v2: 1. Update commit log suggested by Mike and Andrew. 2. Fix compiler error when !CONFIG_HUGETLB_PAGE reported by Randy. Thanks. include/linux/hugetlb.h | 5 +++++ mm/migrate.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 9f192ce44088..e11a2e9aa514 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -915,6 +915,11 @@ static inline bool is_hugetlb_free_vmemmap_enabled(void) #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; +static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage) +{ + return NULL; +} + static inline int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list) { diff --git a/mm/migrate.c b/mm/migrate.c index 066b1e4e8bde..0692fc2638aa 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1292,7 +1292,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, * page_mapping() set, hugetlbfs specific move page routine will not * be called and we could leak usage counts for subpools. */ - if (page_private(hpage) && !page_mapping(hpage)) { + if (hugetlb_page_subpool(hpage) && !page_mapping(hpage)) { rc = -EBUSY; goto out_unlock; }