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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 778EEC07E99 for ; Mon, 12 Jul 2021 14:48:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B80561042 for ; Mon, 12 Jul 2021 14:48:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B80561042 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 DC4166B00AE; Mon, 12 Jul 2021 10:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D4D186B00B0; Mon, 12 Jul 2021 10:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC6768D0001; Mon, 12 Jul 2021 10:48:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 8E1966B00AE for ; Mon, 12 Jul 2021 10:48:26 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 87E401812A447 for ; Mon, 12 Jul 2021 14:48:25 +0000 (UTC) X-FDA: 78354216570.35.EE52064 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id C6F481005841 for ; Mon, 12 Jul 2021 14:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=IrfkZtyTnZQpIyer0CcC3C6fDw3PExEkEtu69JUtc0s=; b=U/SK4tSIHbq1WitEwAfv5g+wDp +4GzF6Rp3n25A5DbY7XwQ4nfYNAq6O5FJWKh4msl6Btk9Tz1zb4FUPs4vI969HMLHCB8KwVpyVFyK WKO4WqnJTvS7xMvQ162YQNq8R1Pfp0uEWEGTaILcWaCFtoecwCnEJuOpumWxm0XVct1l5hIU4x9Af cfGJEtn3ecLcm0jECeSKVjCUTYfUa2lkjHf+FJK72RrmifuHb+v/DUz99wPHgcP7R8NtmP3ByD9xM V1Md6kjxTwBqOc82R3m1ls9o2FjF0vfIiFC8RZTrUURQRa1We9YTOw7mvaQBz5TK61MIcDYe8nYp7 2t4n0Aew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2xE3-0008Dx-AH; Mon, 12 Jul 2021 14:48:05 +0000 Date: Mon, 12 Jul 2021 15:48:03 +0100 From: Matthew Wilcox To: Andrew Morton Cc: almasrymina@google.com, axelrasmussen@google.com, linux-mm@kvack.org, mike.kravetz@oracle.com, mm-commits@vger.kernel.org, peterx@redhat.com, torvalds@linux-foundation.org, yuehaibing@huawei.com Subject: Re: [patch 023/192] mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY Message-ID: References: <20210630184624.9ca1937310b0dd5ce66b30e7@linux-foundation.org> <20210701014819.Vm-gaPGHW%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210701014819.Vm-gaPGHW%akpm@linux-foundation.org> Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="U/SK4tSI"; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C6F481005841 X-Stat-Signature: u4dca6xopr8zd7chwhzh85h7hxwjdmp6 X-HE-Tag: 1626101304-290814 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 Wed, Jun 30, 2021 at 06:48:19PM -0700, Andrew Morton wrote: > From: Mina Almasry > Subject: mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY > > On UFFDIO_COPY, if we fail to copy the page contents while holding the > hugetlb_fault_mutex, we will drop the mutex and return to the caller after > allocating a page that consumed a reservation. In this case there may be > a fault that double consumes the reservation. To handle this, we free the > allocated page, fix the reservations, and allocate a temporary hugetlb > page and return that to the caller. When the caller does the copy outside > of the lock, we again check the cache, and allocate a page consuming the > reservation, and copy over the contents. But you only copy over the contents *IF* CONFIG_MIGRATION is enabled! Now, maybe there aren't many configs out there that enable HUGETLBFS and disable MIGRATION, but this is sloppy. > +++ a/include/linux/migrate.h > @@ -51,6 +51,7 @@ extern int migrate_huge_page_move_mappin > struct page *newpage, struct page *page); > extern int migrate_page_move_mapping(struct address_space *mapping, > struct page *newpage, struct page *page, int extra_count); > +extern void copy_huge_page(struct page *dst, struct page *src); > #else > > static inline void putback_movable_pages(struct list_head *l) {} > @@ -77,6 +78,9 @@ static inline int migrate_huge_page_move > return -ENOSYS; > } > > +static inline void copy_huge_page(struct page *dst, struct page *src) > +{ > +} > #endif /* CONFIG_MIGRATION */ > > #ifdef CONFIG_COMPACTION