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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 62C04C433DB for ; Mon, 28 Dec 2020 22:12:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E3E3E2229C for ; Mon, 28 Dec 2020 22:12:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3E3E2229C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 235738D0020; Mon, 28 Dec 2020 17:12:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E6518D0018; Mon, 28 Dec 2020 17:12:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D5608D0020; Mon, 28 Dec 2020 17:12:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id EC9678D0018 for ; Mon, 28 Dec 2020 17:12:39 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A73F18249980 for ; Mon, 28 Dec 2020 22:12:39 +0000 (UTC) X-FDA: 77644091238.08.field82_01070cf27497 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 89FE31819E76B for ; Mon, 28 Dec 2020 22:12:39 +0000 (UTC) X-HE-Tag: field82_01070cf27497 X-Filterd-Recvd-Size: 5988 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Dec 2020 22:12:38 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id m25so26898981lfc.11 for ; Mon, 28 Dec 2020 14:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tveTiSW3kXI18qkd/ZaB+nQ0L/9zQTBwJzflX/XFRO4=; b=zArwFJCb5RJFbnwqQOcGRmO9THjhSHIcad6u0iuLaWRPbpzDkqfwNGoJrsxucPcimm jwI/yVKRYRBMnwUpQ2zQyOfYjlraEt7alLh8N1hmGiQB+MkzgL7kCkzi6KM8tYMnXTaR AC1tLDiH8chACCfWto4A/LsOZvqlWRSEZlLSaOjzYCWXt0r3+QtuEWvUJ2sP4jsPkRXI TiZJS0EavQZPgg80200E0VCRSE0tFLTRNrgBobsi0TgfdXhrhOlPOjnfw8h3RUS/96F3 qEYGSwlzUpvdIKwvYtvigqclnGrTxAUroQ9X1rnqoDVaa6CL4MBqc5ef+1i+D7ilblZl AAOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tveTiSW3kXI18qkd/ZaB+nQ0L/9zQTBwJzflX/XFRO4=; b=fJb0Whq86YTx4EEKO8j8fs55YPrzaIwXgxJ9Rs41ovRTagc7xYZ24Se3H89mWKWsmd TBILMQaV7mC3GdHRB+2wI0kUO8Ei0zIQb8Z8k0b+nvayN61WnKjJ2LIuEY3uTngdNfGf vMHvoKbb3t8QR43JN3PF4zV4EjNOXQdXlZerEiAc20bFKWbznLjzUjgM4pq9UzyVPMOs ubOMbXkb32CxgWwqdKJHLb/yBFRemDgyWdEN0x730yav9hcKr21Mlde+JTUeJvyz8VoW L9SsKmmjOIqZcyknVSrTJHI/xNX7UfMxnr3enCSTIwUnIRwKPmnoz3Yb6spiy/K/Uj1M 6YMw== X-Gm-Message-State: AOAM531lLeLYcBo4bZJ9Bw25fVnGFEeZXyTixu7Pr9W1G5Sh+QRvc9uI 2tKdvwrEV+aTrwSzPAwVFu4ZVg== X-Google-Smtp-Source: ABdhPJySQycOonv7NhIpwPNHFfA/dnUsLfdgmjGLC7V51EjW7hZO8cBlM/z70OqkOOFQUJSip5xYLg== X-Received: by 2002:a19:6c7:: with SMTP id 190mr21005693lfg.614.1609193557628; Mon, 28 Dec 2020 14:12:37 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id a15sm6433563lji.105.2020.12.28.14.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 14:12:36 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 15841100F3B; Tue, 29 Dec 2020 01:12:37 +0300 (+03) Date: Tue, 29 Dec 2020 01:12:37 +0300 From: "Kirill A. Shutemov" To: Linus Torvalds Cc: Hugh Dickins , Matthew Wilcox , "Kirill A. Shutemov" , Will Deacon , Linux Kernel Mailing List , Linux-MM , Linux ARM , Catalin Marinas , Jan Kara , Minchan Kim , Andrew Morton , Vinayak Menon , Android Kernel Team Subject: Re: [PATCH 1/2] mm: Allow architectures to request 'old' entries when prefaulting Message-ID: <20201228221237.6nu75kgxq7ikxn2a@box> References: <20201226224016.dxjmordcfj75xgte@box> <20201227234853.5mjyxcybucts3kbq@box> <20201228125352.phnj2x2ci3kwfld5@box> <20201228220548.57hl32mmrvvefj6q@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201228220548.57hl32mmrvvefj6q@box> 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 Tue, Dec 29, 2020 at 01:05:48AM +0300, Kirill A. Shutemov wrote: > On Mon, Dec 28, 2020 at 10:47:36AM -0800, Linus Torvalds wrote: > > On Mon, Dec 28, 2020 at 4:53 AM Kirill A. Shutemov wrote: > > > > > > So far I only found one more pin leak and always-true check. I don't see > > > how can it lead to crash or corruption. Keep looking. > > > > Well, I noticed that the nommu.c version of filemap_map_pages() needs > > fixing, but that's obviously not the case Hugh sees. > > > > No,m I think the problem is the > > > > pte_unmap_unlock(vmf->pte, vmf->ptl); > > > > at the end of filemap_map_pages(). > > > > Why? > > > > Because we've been updating vmf->pte as we go along: > > > > vmf->pte += xas.xa_index - last_pgoff; > > > > and I think that by the time we get to that "pte_unmap_unlock()", > > vmf->pte potentially points to past the edge of the page directory. > > Well, if it's true we have bigger problem: we set up an pte entry without > relevant PTL. > > But I *think* we should be fine here: do_fault_around() limits start_pgoff > and end_pgoff to stay within the page table. > > It made mw looking at the code around pte_unmap_unlock() and I think that > the bug is that we have to reset vmf->address and NULLify vmf->pte once we > are done with faultaround: > > diff --git a/mm/memory.c b/mm/memory.c Ugh.. Wrong place. Need to sleep. I'll look into your idea tomorrow. diff --git a/mm/filemap.c b/mm/filemap.c index 87671284de62..e4daab80ed81 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2987,6 +2987,8 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, unsigned long address, } while ((head = next_map_page(vmf, &xas, end_pgoff)) != NULL); pte_unmap_unlock(vmf->pte, vmf->ptl); rcu_read_unlock(); + vmf->address = address; + vmf->pte = NULL; WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret; -- Kirill A. Shutemov