From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C6FCC43331 for ; Thu, 2 Apr 2020 04:06:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED93A20747 for ; Thu, 2 Apr 2020 04:06:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="GGf185pw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED93A20747 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9BF318E0034; Thu, 2 Apr 2020 00:06:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9707E8E000D; Thu, 2 Apr 2020 00:06:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 887428E0034; Thu, 2 Apr 2020 00:06:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id 6FC4C8E000D for ; Thu, 2 Apr 2020 00:06:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3E58045B3 for ; Thu, 2 Apr 2020 04:06:06 +0000 (UTC) X-FDA: 76661577132.02.flock33_3542ce631991b X-HE-Tag: flock33_3542ce631991b X-Filterd-Recvd-Size: 3858 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 2 Apr 2020 04:06:05 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A1F862074D; Thu, 2 Apr 2020 04:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585800365; bh=d9YDxnBoruFXu8QqWKNfPGu31ZbMnB9/lrkPm6DTank=; h=Date:From:To:Subject:In-Reply-To:From; b=GGf185pw4284s6B8JRppZNty6dMwNNrZAY8c8mv4xW9eZtFA4X9iYSbgS0LNBZbqc glAs16yDA0QHvDpHuYnhYkFlkW7xMijUMgcVtOV6XiwZ5jGROR8ntuO7zNAxLFgyF5 l9yDViI83i2lVUcaGidCpJeH/KmS5Y3m6oisPfec= Date: Wed, 01 Apr 2020 21:06:04 -0700 From: Andrew Morton To: akpm@linux-foundation.org, aneesh.kumar@linux.ibm.com, dan.j.williams@intel.com, hch@infradead.org, hch@lst.de, ira.weiny@intel.com, jgg@mellanox.com, jgg@ziepe.ca, jhubbard@nvidia.com, kernelfans@gmail.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, rppt@linux.ibm.com, shuah@kernel.org, torvalds@linux-foundation.org, willy@infradead.org Subject: [patch 052/155] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Message-ID: <20200402040604.BdOzOv4y_%akpm@linux-foundation.org> In-Reply-To: <20200401210155.09e3b9742e1c6e732f5a7250@linux-foundation.org> User-Agent: s-nail v14.8.16 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: From: Pingfan Liu Subject: mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path 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) Link: http://lkml.kernel.org/r/1584876733-17405-3-git-send-email-kernelfans@gmail.com Signed-off-by: Pingfan Liu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Cc: Ira Weiny 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 Signed-off-by: Andrew Morton --- mm/gup.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/mm/gup.c~mm-gup-fix-omission-of-check-on-foll_longterm-in-gup-fast-path +++ a/mm/gup.c @@ -89,6 +89,14 @@ static __maybe_unused struct page *try_g 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(). _