Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9463628pxu; Mon, 28 Dec 2020 17:28:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxt8UOLUITaZPECgv+77Fs7zZkXYJwfamy7F2hbRnsARruqIZj8r5YCvYXSfpi1W1v13D2 X-Received: by 2002:a05:6402:1c96:: with SMTP id cy22mr43453909edb.339.1609205301991; Mon, 28 Dec 2020 17:28:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609205301; cv=none; d=google.com; s=arc-20160816; b=LK9IOFcfbCyhsKLEKX8nYUDBhIK7QN7LWVpFaOTEUl5ZWputJmTLCQWZFWLB5U0f2P wheLE37KD8xjIzNArmdDQHyvmUW03flEJRI3VUUpM84aQh9N9+/AdPxv0Qqss9DAFFDa GDs6oED5SernyVRpmmR/xvKX8c7LBp/ATWFbWatRn0ifHloYHBRRbD2Wm8pwf0/zv30x Tt+J1R2SowmfgLqmV5v1flc7IKQHzYAMmURRO37cUKIjpIuKhNDvW3D7n6lcZ+q38ZYr k3jPMLHuS9tYLDyYCMkKSqT9ABil+jdqzealn9nFB0P84DYAdChHAkMwFrX0UWlNBMVb 5hfA== 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=tveTiSW3kXI18qkd/ZaB+nQ0L/9zQTBwJzflX/XFRO4=; b=cc9rpdVB08LSbBUh6H84pZEeloKeUEzon8Hq5HCCQpWr/Vb71SshhKw6GIg/U1QEXH eqOMGxSTTd1XJOSnCkRVo2Y2xMhfzoCT4pctTtWjU2hfCKvzR0AmOqHFgwf+JGL/Ho+Z H6mbXajUKhkhETDuv/XxvObWXnAid3Nw8suxoX/UIQUuYPYT+2/OnT0PTYttv7j8wGZS CLssNDv9b9P7UXAAVLxr+IcFTumsdtEROZwhb/cZZacQjGc/pUhVgjCDZajei5royT6c ddxqeKEQYVyvNxXbWv2CiKXBUxA5U6mNdBpqP1pJzQHmyxhtn4W9WJgJKcjKBmYx5tba ctrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=zArwFJCb; 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 dn9si20690885edb.347.2020.12.28.17.28.00; Mon, 28 Dec 2020 17:28:21 -0800 (PST) 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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=zArwFJCb; 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 S1731981AbgL1W4Z (ORCPT + 99 others); Mon, 28 Dec 2020 17:56:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729615AbgL1WNT (ORCPT ); Mon, 28 Dec 2020 17:13:19 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B510C0613D6 for ; Mon, 28 Dec 2020 14:12:39 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id x20so26883306lfe.12 for ; Mon, 28 Dec 2020 14:12:39 -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=On6QvKtUNc3L/lvXXkv41s5NUOgTWuPy97PrPFt3RzVeRnEILVOpgPKRF61D9FA8HU arSJR5X9VmjC+IpWjhUAb9QGz7RQHRnoX/dcriXuWEqV37CBM8ixcEf/mGVvzRiJxKML e35dp9IkwWpTU11bhzUW1greXG+FuFZhmYdjNsrYn4RC2pV/KlrZ1GrVSgAllmI44SDn ruuMLE8fMZ9t6WBu18ikm6h1xsNG1/KMySK6YPgqh5nmHmo+UYssKrpDumhbZsTUr8UE eR5B9i/lKlebeeMi22onabtRvnrzkLRGP7NOBN7onFk64wfQp22tvNIwqk900Z4Be//g hNHg== X-Gm-Message-State: AOAM5302SE175Tblzx/aCgq/C2JBIplSQWBKCtVSrcHrh4u3n54io3Q8 elMJsplcgLMv2Y4qd+D/pDmFsA== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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