Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2376650ybh; Mon, 16 Mar 2020 01:57:19 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtBAK4/grqLe7bsiqvB+Eanz76UbXW6+ifdaSI48DY3D5P9eUT55kaNlRHhpIKA8O6UaQrn X-Received: by 2002:a05:6830:14cc:: with SMTP id t12mr5986696otq.118.1584349038916; Mon, 16 Mar 2020 01:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584349038; cv=none; d=google.com; s=arc-20160816; b=WpPTc6Jq/gtNnNGQtcu/qyegqC0S/WahA8r4j+pxA4z9p8UDACcdwphFj1ceqJAl7V lOaIPI0EU9zoSK+ZBXjTQmqFNFTVAUnI+AKXEwlMKWyn8B5eE6I9lmcT39DVKpN1Qh7l QxypvJzODCcXKEUv9DzA25oQ4TjkMRND2poCv8FJJHzsRJAqlJQUC+VvG1GNM1TPwLY3 B4XWQe7NPEBp7Z37N5worOTF64S6uLiwAXQeyAmCydgR1+oZlvB1OBe+3EbLjIqcat6K jndeO+16KhVDtMyT0TTbQ4PF1ly/XyqM7w8ztAFd+w3fuA5i6Ui0YpQkRLqDnfklbpkU CExg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=yIz0C8cE2kr7lgSK5EW5SoifRX6h9DdJQZ/1L1Yr8aI=; b=U07hkbVZzZB7TZPiVMjsCX76syYt2c5tWREgxIMwd+HRQwOvDFTHoyfZ63m82WLVJf 5kT9K1OInIep6e4Fq6IADqi7dZkQzjwycEnen7LYboOBfBjgJYQ7nwjo+ZYLLKDIGNCT AEci9A9+pSi50BJAR+QWxhFEZmzCPjsUzvuBNp0WaJeo0uN/SyC08dwXxGAGio16lXLa pL0ukpUGRxG5SegHTlT2A9i/G0pkwW5lw/7Kfu9XHMfz6Sh1Xj5vNSpOsqSFQKU+3QSY TnlQvoLr3uPVRINCkACmRiBi1S2dBhwL7IqLiV6VhJ/zLCetRq4VZAhtyU7khQT3MrK3 Vrzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ajZAHp96; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si9357068otn.302.2020.03.16.01.57.05; Mon, 16 Mar 2020 01:57:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ajZAHp96; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730235AbgCPIzl (ORCPT + 99 others); Mon, 16 Mar 2020 04:55:41 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:40550 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730110AbgCPIzl (ORCPT ); Mon, 16 Mar 2020 04:55:41 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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;