From patchwork Tue Mar 17 11:47:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 11442585 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10FFD159A for ; Tue, 17 Mar 2020 11:49:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0C80206EC for ; Tue, 17 Mar 2020 11:49:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eWdg7Fuu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0C80206EC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 11E556B0005; Tue, 17 Mar 2020 07:49:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0CFFD6B0006; Tue, 17 Mar 2020 07:49:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F267B6B0007; Tue, 17 Mar 2020 07:49:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id D7A5A6B0005 for ; Tue, 17 Mar 2020 07:49:49 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 97FC24DC0 for ; Tue, 17 Mar 2020 11:49:49 +0000 (UTC) X-FDA: 76604684898.29.arm08_72dc5bcaf7d2c X-Spam-Summary: 2,0,0,a14233d2614683a7,d41d8cd98f00b204,kernelfans@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1345:1359:1431:1437:1535:1542:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2731:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:4250:4321:4385:5007:6261:6653:6742:7514:9413:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13846:14181:14394:14687:14721:21080:21251:21444:21451:21627:21666:21990:30054:30064:30070,0,RBL:209.85.210.195:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: arm08_72dc5bcaf7d2c X-Filterd-Recvd-Size: 5374 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Mar 2020 11:49:49 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id 23so11839036pfj.1 for ; Tue, 17 Mar 2020 04:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MMK1oa7caM4FxenuRyA9kQAaY+A0jvSFKtsdxSSnm50=; b=eWdg7FuuLGf/HHPeZutN/DYRjxENPqg+VeIJz4NbSKSfjLv6CdrPv1RzaD/qLOir2Q o+m1Vv+PqzjYMbFY9kaagOU+qtTyfg4RlKmjpWxxLEPRKSntm60Tq+pfugBkVK2eEDys mtrpofcDQ4D2Liywttc4FNG5G4izeWiVb8XhS5nyi1kdMOk+e1jPYs2EsMRyDt6E+gYd rsj0ADZq9uqh5L0OQf4YtYG2gg/gxwRktAOLGWNGKhSHWs2XEb/noOsL+84foC2leXf9 PVLStKZBVq3AdMHy3m6wjUUirFfwqhGtT1BICQOcF9oCrYFb4ncRIXiLzy6UbWZ9jZib CCTA== 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:in-reply-to :references; bh=MMK1oa7caM4FxenuRyA9kQAaY+A0jvSFKtsdxSSnm50=; b=AzCu9y8e07wZed/KpBymIhV3KgJY670u8tF4ZXpaSRAVnLtyILfOEa7fWuyOVMWUI3 r2LMraLc+WGULp3TOfCz6YRONw/mYsyolDVorffvirGYHgGsvzbzyZvncpVKLfQKyDer BF2nYwQt9ZLsifDD1Vsb6O/VgJnb17G4YPxVMVchKrf4xfnABMHm/t2Jxlrkwf3KEsfK NCKiFL45FG56nU6ofe11IF3jn6m/6CUDN+Nh9300AbKAL6ldHkVLKYJBM9snpQr0lZkL IPmfBQxeEZn5460W1x9nMamO3Oc1dpXk9HcXpQlaWQebnun6k5ZmE0zOj39lcvRnZnJn 0Obw== X-Gm-Message-State: ANhLgQ1z8P4QdbSWlczy7EVTIoH4/ZxZOO/QFN5xW13x/5M0vy7WCaHS qNOmawhIbDxXQjPPzHuD3X8vzTg= X-Google-Smtp-Source: ADFU+vs30UmxxLczix5J155deIGMh7kh1xX+QCQHAyX7Z38r2hTSjuVeqqLeG6kvUoSxB6CfWyEfHg== X-Received: by 2002:a62:3854:: with SMTP id f81mr4823792pfa.81.1584445787852; Tue, 17 Mar 2020 04:49:47 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id c62sm2214845pfc.136.2020.03.17.04.49.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Mar 2020 04:49:47 -0700 (PDT) From: Pingfan Liu To: linux-mm@kvack.org Cc: Pingfan Liu , Ira Weiny , Andrew Morton , Mike Rapoport , Dan Williams , Matthew Wilcox , John Hubbard , "Aneesh Kumar K.V" , Christoph Hellwig , Shuah Khan , Jason Gunthorpe , linux-kernel@vger.kernel.org Subject: [PATCHv7 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Date: Tue, 17 Mar 2020 19:47:32 +0800 Message-Id: <1584445652-30064-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> References: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> 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: FOLL_LONGTERM is a special case of FOLL_PIN. It suggests a pin which is going to be given to hardware and can't move. It would truncate CMA permanently and should be excluded. In gup slow path, slow path, where __gup_longterm_locked->check_and_migrate_cma_pages() handles FOLL_LONGTERM, but in fast path, there lacks such a check, which means a possible leak of CMA page to longterm pinned. Place a check in try_grab_compound_head() in the fast path to fix the leak, and if FOLL_LONGTERM happens on CMA, it will fall back to slow path to migrate the page. Some note about the check: Huge page's subpages have the same migrate type due to either allocation from a free_list[] or alloc_contig_range() with param MIGRATE_MOVABLE. So it is enough to check on a single subpage by is_migrate_cma_page(subpage) Signed-off-by: Pingfan Liu Cc: Ira Weiny Cc: Andrew Morton Cc: Mike Rapoport Cc: Dan Williams Cc: Matthew Wilcox Cc: John Hubbard Cc: "Aneesh Kumar K.V" Cc: Christoph Hellwig Cc: Shuah Khan Cc: Jason Gunthorpe To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- v6 -> v7: fix coding style issue mm/gup.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.5 diff --git a/mm/gup.c b/mm/gup.c index 9df77b1..0a536d7 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -89,6 +89,15 @@ static __maybe_unused struct page *try_grab_compound_head(struct page *page, int orig_refs = refs; /* + * Huge page's subpages have the same migrate type due to either + * allocation from a free_list[] or alloc_contig_range() with + * param MIGRATE_MOVABLE. So it is enough to check on a subpage. + */ + if (unlikely(flags & FOLL_LONGTERM) && + is_migrate_cma_page(page)) + return NULL; + + /* * When pinning a compound page of order > 1 (which is what * hpage_pincount_available() checks for), use an exact count to * track it, via hpage_pincount_add/_sub().