From patchwork Tue May 10 21:17:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12845548 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 BE0AFC433EF for ; Tue, 10 May 2022 21:17:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2127F6B0071; Tue, 10 May 2022 17:17:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BEBB6B0072; Tue, 10 May 2022 17:17:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 060756B0073; Tue, 10 May 2022 17:17:49 -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 E7A346B0071 for ; Tue, 10 May 2022 17:17:48 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A010932443 for ; Tue, 10 May 2022 21:17:48 +0000 (UTC) X-FDA: 79451095416.03.959AC0F Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf02.hostedemail.com (Postfix) with ESMTP id DF3CF800A5 for ; Tue, 10 May 2022 21:17:40 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id p8so227539pfh.8 for ; Tue, 10 May 2022 14:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=M3iS8vaaqUD8jfRE0NHdoQBHIwBnV2ugHoNQ4Z+Efx8=; b=cocBJOXiSqOkGGCNk9vDNCQQromh/mWnuC+KMasoT9HGNJtSh3PKZH/eXlf1MGxv2F Is1s24zAzJD01Gp0dG8sxbzC7wMFtiuh42LCRFmPe5+0Ti2p7CU9Ux0izG8VSpZcCnWd cDB3vIOlJt1xhiDB+uVmPm6ElIEsY52Dr6/90nJw4pQ1eWOHdwOfT3p6GTeAO/x7u14w pp2P2w5PBZkcACDjHKzqwSP0qTlEoqLRQVEXEgXrBH5oAg/0YN+IWl+QyV4hioH683zx gwliS5xHmZ0wysoH5R9CipYm1N3AhJRRYkLhKo24V4SGi7OlTjnCKQ2BToBM0uJQ7V83 g2jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=M3iS8vaaqUD8jfRE0NHdoQBHIwBnV2ugHoNQ4Z+Efx8=; b=SHqgL48rOGzDxya1gPRywYF19TjhG/OgHnd2HJ25Lw6nQiQEdQG4d/6o8oqFFELV4M TdvRzyObgKAhvfI7827BH/T0KJ8BjrarFieOxuGKIq9MPw81L+CkWTsjBiypqvcgNh/f tdozeBXbLoHHTywV3mQPyjGg7zEz9d/ybLVXaufBx5LfPnvLOc0J1G9Iz/LeRtAvAXy9 v81dxpjMm9Z/comdank5ENNLTuDTYWBC0l6QhMGXHkP8dk3ZRSnem16i4miSBXFOJ977 pdkO42QNbmzF584RqhYtSK5jiOLFdcmKToV26z1eZXvhJvouZqvrzxcLIZpFP/L5Lgz6 xG7w== X-Gm-Message-State: AOAM530XSarWROT0hi7FNdq4wXm5aij9xfZxcwoQTFKhetbRE7nBqZd1 dojRCBvvpAEYv24dvcw9Ax0= X-Google-Smtp-Source: ABdhPJx2Y9Xq+3njREh94u64LTI6mtZXpzrndPub0LLJisx1paZBupZB0tvPmrQAG6GfjBG0L8/Qvg== X-Received: by 2002:a63:1202:0:b0:3da:ec25:b232 with SMTP id h2-20020a631202000000b003daec25b232mr3876532pgl.163.1652217467051; Tue, 10 May 2022 14:17:47 -0700 (PDT) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:c98a:65b0:edca:b69a]) by smtp.gmail.com with ESMTPSA id q1-20020a170902bd8100b0015e8d4eb28esm67639pls.216.2022.05.10.14.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 14:17:46 -0700 (PDT) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , "Paul E . McKenney" , John Hubbard , John Dias , Minchan Kim , David Hildenbrand Subject: [PATCH v4] mm: fix is_pinnable_page against on cma page Date: Tue, 10 May 2022 14:17:43 -0700 Message-Id: <20220510211743.95831-1-minchan@kernel.org> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog MIME-Version: 1.0 X-Stat-Signature: rub3j99qxuw9eyziynqzr4ecr3rwde5w Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=cocBJOXi; spf=pass (imf02.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: DF3CF800A5 X-HE-Tag: 1652217460-404916 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: Pages on CMA area could have MIGRATE_ISOLATE as well as MIGRATE_CMA so current is_pinnable_page could miss CMA pages which has MIGRATE_ ISOLATE. It ends up pinning CMA pages as longterm at pin_user_pages APIs so CMA allocation keep failed until the pin is released. CPU 0 CPU 1 - Task B cma_alloc alloc_contig_range pin_user_pages_fast(FOLL_LONGTERM) change pageblock as MIGRATE_ISOLATE internal_get_user_pages_fast lockless_pages_from_mm gup_pte_range try_grab_folio is_pinnable_page return true; So, pinned the page successfully. page migration failure with pinned page .. .. After 30 sec unpin_user_page(page) CMA allocation succeeded after 30 sec. The CMA allocation path protects the migration type change race using zone->lock but what GUP path need to know is just whether the page is on CMA area or not rather than exact migration type. Thus, we don't need zone->lock but just checks migration type in either of (MIGRATE_ISOLATE and MIGRATE_CMA). Adding the MIGRATE_ISOLATE check in is_pinnable_page could cause rejecting of pinning pages on MIGRATE_ISOLATE pageblocks even though it's neither CMA nor movable zone if the page is temporarily unmovable. However, such a migration failure by unexpected temporal refcount holding is general issue, not only come from MIGRATE_ISOLATE and the MIGRATE_ISOLATE is also transient state like other temporal elevated refcount problem. Cc: David Hildenbrand Signed-off-by: Minchan Kim Reviewed-by: John Hubbard Acked-by: Paul E. McKenney --- * from v3 - https://lore.kernel.org/all/20220509153430.4125710-1-minchan@kernel.org/ * Fix typo and adding more description - akpm * from v2 - https://lore.kernel.org/all/20220505064429.2818496-1-minchan@kernel.org/ * Use __READ_ONCE instead of volatile - akpm * from v1 - https://lore.kernel.org/all/20220502173558.2510641-1-minchan@kernel.org/ * fix build warning - lkp * fix refetching issue of migration type * add side effect on !ZONE_MOVABLE and !MIGRATE_CMA in description - david include/linux/mm.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 6acca5cecbc5..cbf79eb790e0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1625,8 +1625,19 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, #ifdef CONFIG_MIGRATION static inline bool is_pinnable_page(struct page *page) { - return !(is_zone_movable_page(page) || is_migrate_cma_page(page)) || - is_zero_pfn(page_to_pfn(page)); +#ifdef CONFIG_CMA + /* + * use volatile to use local variable mt instead of + * refetching mt value. + */ + int __mt = get_pageblock_migratetype(page); + int mt = __READ_ONCE(__mt); + + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) + return false; +#endif + + return !(is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page))); } #else static inline bool is_pinnable_page(struct page *page)