From patchwork Thu May 5 06:44:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12839094 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 5DD35C433EF for ; Thu, 5 May 2022 06:44:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1BF56B0071; Thu, 5 May 2022 02:44:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCD226B0073; Thu, 5 May 2022 02:44:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A934C6B0074; Thu, 5 May 2022 02:44:35 -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 9AE526B0071 for ; Thu, 5 May 2022 02:44:35 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 64FC880CD1 for ; Thu, 5 May 2022 06:44:35 +0000 (UTC) X-FDA: 79430750910.21.96860AA Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf29.hostedemail.com (Postfix) with ESMTP id DDACD12009E for ; Thu, 5 May 2022 06:44:29 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id s14so3540573plk.8 for ; Wed, 04 May 2022 23:44:34 -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=SpMxQmnSg4UVgtzsaV27Dc50ZPZ1XGAaiwMaGVOZnx4=; b=O6MdnO7Q8MeRyVhpyem9ME5F879UZYGZOWB5QcbzS5777SzYENXA4ikFQyNn26Ikc2 ALtRObfn4Uodb1hdfgtuXQLbcgIYIpKeEJ6tJe2ZGTCCiDebqQiK4eLwwRrzo6beKrMA wOoUESAL5em0iE8TcrVj4v9RNuQrVAaMtrP2lJSxyF30L0tCmfBidrW2+MW+H+hDZt1B sRYTffnr+xQ5aLVm4LYR/hqz2y7QfyvHQyKccXdYO9FZ/moRquUsHvasUW29L7NTmeyV xkf0YZddfuBXVh4RNedItJHXVWCwdOzEJph4raS9N/u3/EtLyWM2iKFE/YLKaDx36Hk+ bxUQ== 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=SpMxQmnSg4UVgtzsaV27Dc50ZPZ1XGAaiwMaGVOZnx4=; b=M14bxEyMejsvFamHo7qjwgHZCdL5E3dcS7cxjVhurt9/243O+43sYUcj4Ir4lfbV3A axwPaMHLOQ1coYj/cRL9Do9KSo3iMFICOG5CnezTmM5Ff3wHqmkIGOKNzxBcVQe4pcsg NcFmjybjB2B7h0ojsfqPLiSoMSES+4Xb7iGpJi08xznEywuvMJngIZqyJa00SiCOnjWH 73QHpn8xc8F+wUavUpNHpbACdX1VHi9uoyafM7fYwm4dmxYVd02G0oVYaQ1ZoD4Nz56q BuGO7NV4RTbSzyEAInhynEX+UvGg/I2A1Ppup8/yTEtK9qeA7qXPYFmyriesP9HYbaoX q9Tg== X-Gm-Message-State: AOAM531JNAXknvLfmjMDwX0nTayq7+GSaXlW0ukRbU/QNNBKx/1dzrvq tDD7i1OjR7CgnC4p5j7tp+n3zenPy40= X-Google-Smtp-Source: ABdhPJwmm2POHenL0J+W/qewrTiJqVSaZq1CpWud0SYupgHxX6RZuaTLuRUFBUYDYgXmxJKbcSgpHQ== X-Received: by 2002:a17:90b:4c0a:b0:1d5:2e1d:ec6 with SMTP id na10-20020a17090b4c0a00b001d52e1d0ec6mr4394269pjb.64.1651733073867; Wed, 04 May 2022 23:44:33 -0700 (PDT) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:8435:b3e7:62fc:4dfa]) by smtp.gmail.com with ESMTPSA id s19-20020a056a00195300b0050dc762812esm566289pfk.8.2022.05.04.23.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 23:44:32 -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 v2] mm: fix is_pinnable_page against on cma page Date: Wed, 4 May 2022 23:44:29 -0700 Message-Id: <20220505064429.2818496-1-minchan@kernel.org> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DDACD12009E X-Stat-Signature: gegpa3hfsg7qt6nkr4fphweqpwj6wwu8 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=O6MdnO7Q; spf=pass (imf29.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.214.171 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-HE-Tag: 1651733069-629047 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, 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 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 6acca5cecbc5..e77758e2035e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1625,8 +1625,18 @@ 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. + */ + volatile int mt = get_pageblock_migratetype(page); + + 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)