From patchwork Sun Mar 22 11:32:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 11451641 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 538DE1667 for ; Sun, 22 Mar 2020 11:34:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F80120719 for ; Sun, 22 Mar 2020 11:34:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZCgbAm/i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F80120719 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 4EF4E6B0007; Sun, 22 Mar 2020 07:34:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 49FC06B0008; Sun, 22 Mar 2020 07:34:48 -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 38ECE6B000A; Sun, 22 Mar 2020 07:34:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 232A36B0007 for ; Sun, 22 Mar 2020 07:34:48 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 051A4180AD815 for ; Sun, 22 Mar 2020 11:34:48 +0000 (UTC) X-FDA: 76622791056.18.trip22_81295d8fe2835 X-Spam-Summary: 2,0,0,86593e5f2f82132d,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:14096:14181:14394:14687:14721:21080:21251:21444:21451:21627:21666:21990:30054:30064:30070,0,RBL:209.85.215.195:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.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:24,LUA_SUMMARY:none X-HE-Tag: trip22_81295d8fe2835 X-Filterd-Recvd-Size: 5355 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Sun, 22 Mar 2020 11:34:47 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id a32so5645244pga.4 for ; Sun, 22 Mar 2020 04:34:47 -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=/1SM3867y5SxnAk5W+nCWfh5uFmnZCup8fknvMevl8I=; b=ZCgbAm/iPixhzfGPOch7scTLnnbNH0Ce/QnnMs3JENoqXF8vBILnIV1dIn7EILxnTk /WOGRkxPYmqz+eb7gUU0jx0g3JN8FGy49bJdoGQBqCSMcXdfjO3i04D/V9LGkeJCqUZo HR4ISjeBbOCKuX9PYVLMInFsw7kMt4iiHEy/MMyi5n3uOlYSsTlnEhnhkI2p6iyLpeD1 k6zkgSjySq8VK3DAd2P7+Q+HwhzrhwqE1eDX1Unf32kwsA++x/a9IizdDHpyMBje1kc1 cv5Xhub/coe6nHFJOa7R2yacoJlYTd3Ac/BbvT7UZbPZ/FSPEUEZv3nxM0ZffXwy6APt UeSA== 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=/1SM3867y5SxnAk5W+nCWfh5uFmnZCup8fknvMevl8I=; b=MNezWXjCkMe7zPdk0vhDzEyYAgQorZyFMFgzRw5KfAHtJDfwm437ZAd+tH4pexz+8b UWU5WGGBrypP7YOmZaP6+1D/VwM9IkwPcrolJXjvO2XUTyO1ceHcAyLvGBjxVwG0CwYk L3HaddbzZjWrRlikDbbVA44q+Cl2aRtX/zmxZknUdhflJr7zP99D1MiYRfMvioOB8xe5 bvtlLiDBsPYGRf8p6j4UD+3PzibgAD/n4w/0jIXlGe/OLUEO93JG0HbsrPjkW61FN/if YIfIckJcPwh9L7/OQuBHM2B5PUY4jhgHoRNfmUBwPiRj3oEg0JtLfrIrkUfuGsLoTLxU qoOg== X-Gm-Message-State: ANhLgQ1QrrvUP5h2l8t3FbGRWzx9cgr92ddsVQB+YvB96pMyClLBdnEy LfH0bIL0RHSpBJ2Z7QhMsJKb39Y= X-Google-Smtp-Source: ADFU+vt2Orqn/hOvqJdCrhDZmh7HfFtpy6+z9jOFDkLUvT9xMsriKqGJktpP2gjGP7sprCZLp7doWQ== X-Received: by 2002:aa7:8bda:: with SMTP id s26mr18467747pfd.142.1584876886209; Sun, 22 Mar 2020 04:34:46 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i23sm10474445pfq.157.2020.03.22.04.34.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Mar 2020 04:34:45 -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: [PATCHv8 2/2] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Date: Sun, 22 Mar 2020 19:32:13 +0800 Message-Id: <1584876733-17405-3-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1584876733-17405-1-git-send-email-kernelfans@gmail.com> References: <1584876733-17405-1-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, 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 Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe 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: John Hubbard --- mm/gup.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.5 diff --git a/mm/gup.c b/mm/gup.c index 02a95b1..3fe75c4 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -89,6 +89,14 @@ static __maybe_unused struct page *try_grab_compound_head(struct page *page, int orig_refs = refs; /* + * Can't do FOLL_LONGTERM + FOLL_PIN with CMA in the gup fast + * path, so fail and let the caller fall back to the slow path. + */ + 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().