Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3459265pxj; Mon, 7 Jun 2021 11:06:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsJ+7HsId4YHzaW7X1To3/ArZY4aGPfU4Ygtqfv7bpZizua6ODg8KUazb4bLF9uVY4Jdbw X-Received: by 2002:a17:906:49ce:: with SMTP id w14mr19322605ejv.273.1623089218062; Mon, 07 Jun 2021 11:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623089218; cv=none; d=google.com; s=arc-20160816; b=ZdO+PRGkzWcf14ATQsMrckkQRt4w19hMhOgdcqYT2FgkypLMeQ4+TBQwaEspUUfCoW YQbQNF4kkkFaUn8/1sNIYAOH9Aoixx6+1KWtY18RAP1akaStxUytxWDDYWM6UrJ5Ld2+ xrSi23BrcZvJivWGjqSsFwvzS6mZHLbo/ySaYH95FowNh1Ec95YoKs2RM9kuM7VH9Y4t MYcBL3LrTUYX2irbG1sK0kbGxRfTSK65C4eMT+1G1OacD/lK2JSSOvRJfVMyZJEuulmP tHgudb9bxLhHTwZmly5uUVopKo/KESEOzJtE4Xwhm1lAWJOmf8cEduL92NtqlsA+YZLT HFzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZTh2RnYV27oLVt4BJj4ZhqnskEuzydcOTMgQsGZpXh4=; b=ac+GQElLGUnv7MVNnwRCXXGY+CcTBvbCqN7xowN6WI9hfl4T5/xWHkWNS6IJM4rFiF OIctKpDwDiFfxQ3RQyaE05GoOtF8aGFO9Q+mleroh7GPDMCsK8ywjWTrivqoamHwjcpC 6n/oj7atW8cRyI5PSimicNbi5DtVZMSmdIONZB80I+GGhBoJk15Ed96toIbfnfTrRQ5o ffmrf8Kleyg8p/kC9NPpMSVkCwz/C/+NM3oRnlwBUOohrAgQI2cIbOxZ9VvaMTib602B lgM9FoRuatcTaZ7AKHyolEI+zRm/w4bvJIqFMUTsnTjO0v0F8wpQ5boEek0vnxaL3MnQ PyAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="RxwF/q2R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23si12862623ejz.732.2021.06.07.11.06.34; Mon, 07 Jun 2021 11:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="RxwF/q2R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbhFGSGK (ORCPT + 99 others); Mon, 7 Jun 2021 14:06:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbhFGSGJ (ORCPT ); Mon, 7 Jun 2021 14:06:09 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 285F4C061766 for ; Mon, 7 Jun 2021 11:04:18 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.