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=-6.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 DDC82C0044D for ; Mon, 16 Mar 2020 08:55:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FB52206B1 for ; Mon, 16 Mar 2020 08:55:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ajZAHp96" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FB52206B1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3B7826B0003; Mon, 16 Mar 2020 04:55:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 366FA6B0005; Mon, 16 Mar 2020 04:55:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A5356B0007; Mon, 16 Mar 2020 04:55:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 134C46B0003 for ; Mon, 16 Mar 2020 04:55:39 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D2D1A181AEF2A for ; Mon, 16 Mar 2020 08:55:38 +0000 (UTC) X-FDA: 76600617156.23.sack43_8891a6f89d22b X-HE-Tag: sack43_8891a6f89d22b X-Filterd-Recvd-Size: 4593 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Mon, 16 Mar 2020 08:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=yIz0C8cE2kr7lgSK5EW5SoifRX6h9DdJQZ/1L1Yr8aI=; b=ajZAHp96UGfDXYVzHNtI1elMuA JJ2vveSV/7WNqEUWX9314Zac4FvqjfzGg8VgxcXFhca9VuaHa/IIUl69hsZxGXS4bxSGOkT2vmLBj kxzCsLYabVJjY1YSx4Z/l/zhZJIxypw7Wh8y+FfdMhzBEC/zCF5VMNvzAoNXJlIYaAEv0ni2yLvtV wOSCx9rS196dfAup3I9rH6dVPFgirxoWINjLq8PefmR3IxvSY2085BFuMc0FKdeuOm/iUJKns1Uys I029B37TeZjhQFYhyjsXAs7JrZKf9pxkXtclN+A/sFpmu+Oa9bSB9z1bnba2ghpP40cwWuOzUZgTc dWn4mvKg==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDlX6-0004C9-20; Mon, 16 Mar 2020 08:55:36 +0000 Date: Mon, 16 Mar 2020 01:55:36 -0700 From: Christoph Hellwig To: Pingfan Liu Cc: linux-mm@kvack.org, 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: Re: [PATCHv6 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Message-ID: <20200316085536.GB1831@infradead.org> References: <1584333244-10480-1-git-send-email-kernelfans@gmail.com> <1584333244-10480-3-git-send-email-kernelfans@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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: On Mon, Mar 16, 2020 at 12:34:03PM +0800, Pingfan Liu wrote: > 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 > --- > mm/gup.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/mm/gup.c b/mm/gup.c > index 9df77b1..78132cf 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; Wrong indentation. We either align two tabs for continuation statements, or after the opening brace of the previous line. With a likely or unlikely thrown in the former IMHO looks much better. E.g. if (unlikely(flags & FOLL_LONGTERM) && is_migrate_cma_page(page)) return NULL;