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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 44D62C47082 for ; Mon, 7 Jun 2021 18:03:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 941F661107 for ; Mon, 7 Jun 2021 18:03:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 941F661107 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 A55536B0036; Mon, 7 Jun 2021 14:03:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A05106B006E; Mon, 7 Jun 2021 14:03:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A5476B0070; Mon, 7 Jun 2021 14:03:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 5A3DE6B0036 for ; Mon, 7 Jun 2021 14:03:45 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EEE0A801E9A7 for ; Mon, 7 Jun 2021 18:03:44 +0000 (UTC) X-FDA: 78227700768.28.67219A0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id D8D68C00CBE4 for ; Mon, 7 Jun 2021 18:03:39 +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=ZTh2RnYV27oLVt4BJj4ZhqnskEuzydcOTMgQsGZpXh4=; b=RxwF/q2Rye4NC95etr0kDbNka+ tROFkFQ+1cDU8FWiO0vAOD4ceReIB59VAIYX3i1CrWedoFgQEr93OxIGkjtMnfxcVNcxP8vaz+bNZ IZ1vpMu9XasdCayeQud6YvPpIXwAYtdtI4dFSeSBWOwuThMJmTQ/76lxj6HOgGrZ3ZgDAAA5A6lpY gXYMN2J+JZrbshybaIkbcQz1KrHScMrbK9bH3SClCJL9Yrp6379zrd01Ox60MSku9JIWi01w2wF4s zlM+UGDmMSyEhNFG4MDnVIXnJZXzs9ISLxhKn3Rr+bXmg8rZz0S1km5AR9f8rAXgvKIN6FJnynitY +bEwad1Q==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lqJat-00G67M-KS; Mon, 07 Jun 2021 18:03:29 +0000 Date: Mon, 7 Jun 2021 19:03:23 +0100 From: Matthew Wilcox To: Jann Horn Cc: Linux-MM , Zi Yan , Peter Xu , "Kirill A. Shutemov" , Konstantin Khlebnikov , Andrew Morton , chinwen.chang@mediatek.com, kernel list , syzkaller-bugs , Vlastimil Babka , Michel Lespinasse , syzbot Subject: Re: split_huge_page_to_list() races with page_mapcount() on migration entry in smaps code? [was: Re: [syzbot] kernel BUG in __page_mapcount] Message-ID: References: <00000000000017977605c395a751@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D8D68C00CBE4 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="RxwF/q2R"; dmarc=none; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Stat-Signature: jhnbonx3bt9mpzaj7jste18dw1nrwbo7 X-HE-Tag: 1623089019-568664 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, Jun 07, 2021 at 07:27:23PM +0200, Jann Horn wrote: > === Short summary === > I believe the issue here is a race between /proc/*/smaps and > split_huge_page_to_list(): > > The codepath for /proc/*/smaps walks the pagetables and (e.g. in > smaps_account()) calls page_mapcount() not just on pages from normal > PTEs but also on migration entries (since commit b1d4d9e0cbd0a > "proc/smaps: carefully handle migration entries", from Linux v3.5). > page_mapcount() expects compound pages to be stable. > > The split_huge_page_to_list() path first protects the compound page by > locking it and replacing all its PTEs with migration entries (since > the THP rewrite in v4.5, I think?), then does the actual splitting > using __split_huge_page(). > > So there's a mismatch of expectations here: > The smaps code expects that migration entries point to stable compound > pages, while the THP code expects that it's okay to split a compound > page while it has migration entries. Will it be a colossal performance penalty if we always get the page refcount after looking it up? That will cause split_huge_page() to fail to split the page if it hits this race.