From patchwork Mon May 9 15:34:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12843801 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 B5273C433EF for ; Mon, 9 May 2022 15:34:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B05D6B0072; Mon, 9 May 2022 11:34:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 139816B0073; Mon, 9 May 2022 11:34:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECE486B0074; Mon, 9 May 2022 11:34:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DAF526B0072 for ; Mon, 9 May 2022 11:34:36 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 9F9BF121043 for ; Mon, 9 May 2022 15:34:36 +0000 (UTC) X-FDA: 79446601752.21.BE07EF9 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf26.hostedemail.com (Postfix) with ESMTP id 6B73C14009B for ; Mon, 9 May 2022 15:34:33 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id t11-20020a17090ad50b00b001d95bf21996so17333692pju.2 for ; Mon, 09 May 2022 08:34:35 -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=DE1jmNjs85V5CTa5WQUk35TCdHBAzNHaFi6DV+lnzC8=; b=kuUed4ZDtei1sNHuLqnP2mbZbAQhfBoTdrhujD92pkb0wYj2OL/SkTq1zv1rBtNVTw uqGNSSDpIOFBO3AuPkHYieUnhJNi60k1aUAX4NM6ayj/W+3F7q3H+8kPsNbJrvWkpqOT AII1JLFRr1fZSZa1aq4hAxEXhHI1VI7nAoxGMEWdffCccp5GDKEZa3vA9vlU+bjqDlpV k3+8exwx7C2CpDs55FlCG2qEfo+pc1iNRpLIO4BxK0yCAQA166p4TPWUlZW2+lBzD7KK xHt1+7lKHrIRZyrYY54C24s+yIrr0DLl6XV7P5m7ZUAP+Afr62xju6q6I2k+5zPTZ+Zq ZeVQ== 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=DE1jmNjs85V5CTa5WQUk35TCdHBAzNHaFi6DV+lnzC8=; b=Ws+4yXEg13G6WJ3f8eMbiJXl65j8krxPyz5XFzQXvfyeR2fo7WDkGjCNMZ+s/KjtST E0eglO+yYDqYAvCcm2R0cIlWg947t/b+iQCjIjxzj+J25u2zcIT7FKTI/Zfjq6QdYE3V Po2cZV/gDL0KJR03FG/NgOafBZLO/1EacvKEvYYXDP4uPP/Foqbo+DaPUYaeqOwsF2GK fWT4Tz1mWBimc8DhDry66DW+PfkklMD7paxsqN/SHX7nSk9Ox0DcklLjjOlYA7ErOCPj 6rEzcmpJjpmhwT6kblLgMWwUsUlILQOPzrxl2MsWM5lXZDSe5rKDuONMeI8osVEP/gAQ YFmg== X-Gm-Message-State: AOAM533J92z+62y+0CQ6PvHgY5EsFlMZ0BNR5a12Bq5UKLU2hbJGRa1p T+KAfhbOGMmer20w1fu3sMQ= X-Google-Smtp-Source: ABdhPJxpN71sFFNooVDNrb89u73puoo/Wz+fiBc52qR64aQ13OIKDZt8zPKAyDB1tLJnxRMqR2XD3w== X-Received: by 2002:a17:902:f652:b0:156:701b:9a2a with SMTP id m18-20020a170902f65200b00156701b9a2amr16633471plg.14.1652110474859; Mon, 09 May 2022 08:34:34 -0700 (PDT) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:3704:694b:acc0:e064]) by smtp.gmail.com with ESMTPSA id t14-20020a17090a5d8e00b001cd4989fee6sm12592035pji.50.2022.05.09.08.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 08:34:34 -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 v3] mm: fix is_pinnable_page against on cma page Date: Mon, 9 May 2022 08:34:30 -0700 Message-Id: <20220509153430.4125710-1-minchan@kernel.org> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog MIME-Version: 1.0 X-Rspamd-Queue-Id: 6B73C14009B X-Stat-Signature: j8756ayh6tirykpr1fcnrtt5t8owp6hg Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kuUed4ZD; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf26.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1652110473-584772 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 putting CMA pages longterm pinning possible on pin_user_pages APIs so CMA allocation fails. 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 type. Thus, we don't need zone->lock but just checks the migratype in either of (MIGRATE_ISOLATE and MIGRATE_CMA). Adding the MIGRATE_ISOLATE check in is_pinnable_page could cause rejecting of pinning the page on MIGRATE_ISOLATE pageblock even thouth it's neither CMA nor movable zone if the page is temporarily unmovable. However, the migration failure is general issue, not only come from MIGRATE_ISOLATE and the MIGRATE_ISOLATE is also transient state like other temporal refcount holding of pages. Cc: David Hildenbrand Signed-off-by: Minchan Kim --- * 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)