Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4712007iob; Sun, 8 May 2022 22:55:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVrNGn3RP4EhJ7cabb/+8FPVjMp4j1fE0y29w09d5XNFut+seYSzOJ28/bTxucVzpEk69m X-Received: by 2002:a17:902:b906:b0:14f:76a0:ad48 with SMTP id bf6-20020a170902b90600b0014f76a0ad48mr15121005plb.79.1652075750622; Sun, 08 May 2022 22:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652075750; cv=none; d=google.com; s=arc-20160816; b=i6B5LfCoY56vkJWpxpvuE9KjTzItq7gFzZ9/4URyTB4Q9QH/HaPS2z82yrTKt34fS/ ONYEGflnz/zDvVYJ8k1aKoFTTvQHZaZlZiwAYgX7LlN5tn1UiYHHU0qtgoV6ROpDyCi/ upBJQeYJ2H7KRS7hFR6k3BFuChzqSg4GAU2ojXVXhTRH1YqQtk/NMbR0n1cxDgW72ttL LdHzNFRZsXCozrPS7iRRAlTdnADhbP6c/z9iKeDHhtTfewhBIWblD5YJWoIas+4mWRlo XXzu3lEWSJiyI10u++cCv0WaQLWs3gAHeAS3CfrJqSeUzo7Tr39A8C1C9mMFtxAGXbku kdYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=SpMxQmnSg4UVgtzsaV27Dc50ZPZ1XGAaiwMaGVOZnx4=; b=zPmDgLcK0z3CLW1tW5+UUV1xi9ytgFgcA7cczEDHKd+C/jf2wZ4Je9MJJkwgG79JrI CFyTokIK3JjzpkZ3tI9wBjVZw7e1k89l+HYGw33+SonIKX+yQhHPJBXCYAap3OR6vGau hDpdtj98AU1EJYwCDrd5Esr7yMEAqGKs4cxgCNV2VijS5YoqFxKDVEUS/Tyi0CwBXP5q /A0r1D5n6LP80pdvTwL6iyc8Mge6Ldg1uEOp1Z2WZiIKWAJ8aoWzSXw5BNmnFZyNJ7+t yAkp7tG6wLSmPA7lmgAYhJ+SHFF7oUIVuMQl5Qb/42uEp1Sui86LcLKJnE+VAvlRya9A S11A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O6MdnO7Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i69-20020a638748000000b003c6ab6a4b69si4307365pge.285.2022.05.08.22.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:55:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O6MdnO7Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C52371D30E; Sun, 8 May 2022 22:50:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238184AbiEEGsP (ORCPT + 99 others); Thu, 5 May 2022 02:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233151AbiEEGsN (ORCPT ); Thu, 5 May 2022 02:48:13 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6079747396 for ; Wed, 4 May 2022 23:44:34 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id iq10so3356743pjb.0 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=Ef+iVzLR9JUal11drQ/oWACLgkNXNpKs1ronS9U8cc5VlyMVndudvVf2Gdr9V7TEf8 LUysSHvVZf59sWKTH8ffQpqlqR29oq2bzw//YinbUIpLIWEHFQDFq6Uj7AUYwvuA5Lln /X4qNOEHlnnzK8R8GBJtwmEWdG6DPR+Zhlnl26SdtYFwnigtq9FvcW9j3pFDoA+GnzIi QRg36ThGr6MKDkszOQCntCV0s0Bs686NKwnyxbcPK97xr6FVj6j0n6acOfHcPo7oAkFw 3QjEki0CdIgQV1qCNZgRLXxxxW7BGLKQlq7kgTUjdmJFMpZ+GAeq+6asxGXzJLxorSq8 vRpg== X-Gm-Message-State: AOAM530sVTlkA98i086DqQivTm0Y/NnTRIYGqmSkZxpaTk5/UCWMst8t CGEHbh+vW0buoGP0ZOFQwo0= 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) Sender: Minchan Kim 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.36.0.512.ge40c2bad7a-goog