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 077E8C433E9 for ; Mon, 28 Dec 2020 22:59:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D557C222F9 for ; Mon, 28 Dec 2020 22:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731964AbgL1W4Z (ORCPT ); Mon, 28 Dec 2020 17:56:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729605AbgL1WGb (ORCPT ); Mon, 28 Dec 2020 17:06:31 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D097EC0613D6 for ; Mon, 28 Dec 2020 14:05:50 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id b26so26892190lff.9 for ; Mon, 28 Dec 2020 14:05:50 -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=45Sdgq0CvgKJkbdvj9B0AvWNpX2stNzecfKpH4b08Jg=; b=oAmJY6msYX1EpCEynkntpDs7jp9Oc6Cr7Uy+4IUlBAbzp3PzdkgwMrT3sW/O61d5UT WL6UP77ndWZiZh1lQC9+5Y4pyR+zx+HTiBI+/vgnbpJ68W3+TuBJ32AwIfScBZLJ5iin QceIKle+JBIuBv4A4PNh+5vsox0fTRco2EuxqVfVJ8LKCjeQpmZSus9EY+vRuSCU+rxL 2lqUTb3JF7AV8EVnVFf+qyHOsk4PHT+vUkyKAhoj25HiYehljSFGMpLeVdhBcv4I6wp8 hZ66dOubRcc2xyegz9Kd8S8GKX6e4d7kEgf9EwyysSaI8OtBm4lHRg3ZxoHxo0VUbSik D9rw== 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=45Sdgq0CvgKJkbdvj9B0AvWNpX2stNzecfKpH4b08Jg=; b=lp8M3BSB65HD5KMv55DwzXn1y8g4fnP1GzmK6GYPr8ZOvFitWSCfPipK2C+vHv1jX2 4z6ylC4zkyGRXx19wd4WwXohqjeVTDO+WBp2VjsBk3CTCGelUU0qHqzfVG6Twxx4dxkY U9WXpCfz1iyZfsQIJAzIDlPc6ry8oEUjLIomr2bAVd5bhAJ86+0qSRGy0/WS/YjbF/Gm tnZyho0GRSZpOWBLIJqlOyRriB2fNaQSljqCcaaq+dLFUGgvpSnCr3ldNGr0cpu9donz siOLHRD5JSsvnKdT1G26XaN4J6PX8asSaChQCdSGwX/ZPNZnvdSRMO3egCDV+9OQAsLS CgFA== X-Gm-Message-State: AOAM530P230USI0iOrmy/M5qbjAv3TmZBb2/CnzoCL6W0KxU26fj7/zY XGBlghrgNGUgn4A4fKyV8umPGw== X-Google-Smtp-Source: ABdhPJyEJGC2U7ia1xM2nzW0J4rVQGFTB1NrQKckztfI4yAFTmBNyMtDPQHGY76jNfz9uKdGzvS/Xw== X-Received: by 2002:a2e:81cb:: with SMTP id s11mr22732457ljg.377.1609193149174; Mon, 28 Dec 2020 14:05:49 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id s1sm30141ljs.0.2020.12.28.14.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 14:05:48 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 7B45E100F3B; Tue, 29 Dec 2020 01:05:48 +0300 (+03) Date: Tue, 29 Dec 2020 01:05:48 +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: <20201228220548.57hl32mmrvvefj6q@box> References: <20201226224016.dxjmordcfj75xgte@box> <20201227234853.5mjyxcybucts3kbq@box> <20201228125352.phnj2x2ci3kwfld5@box> 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, 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 index 829f5056dd1c..405f5c73ce3e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3794,6 +3794,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf) update_mmu_tlb(vma, vmf->address, vmf->pte); pte_unmap_unlock(vmf->pte, vmf->ptl); + vmf->address = address; + vmf->pte = NULL; return ret; } -- Kirill A. Shutemov 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.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 E66B4C433E0 for ; Mon, 28 Dec 2020 22:07:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98CB322242 for ; Mon, 28 Dec 2020 22:07:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98CB322242 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/pu2A1qULc7MvPe/G7t+ZoxRkSvF7/k/KpvjdHvv7uw=; b=I3jQSVcEUTn1rG2nxDOIVtKd6 YdrXKsEZFTeDJj3bLodcmofu+xVSNbNEVMICATuEHNX+6plhJuAEMGXD5JKP0z9JT7LrR3zy2VzNL oSSGOR0ho3afoWcKQlbKsJYijnyhbwmj+Yf7U1JswdocHwprB1h05wedEvKRVE0B3C22qvIAFWycd eI5L34ctOKbEd+ww3PPtk55f6mvibsvjwVIQy4YaseTn1ijUdZpG2qrOCxo1xWqcWmzZoYqk09nr7 qefoJhmNwOfb+zyEINpUzJ8d9sO6km44V1g+BhmM+ZC3Uk5lCLi5GiRVB57/49RWJgjTpZI5q6fXB 3gf/1J8mA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ku0eK-0006nX-9j; Mon, 28 Dec 2020 22:05:56 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ku0eG-0006lK-3C for linux-arm-kernel@lists.infradead.org; Mon, 28 Dec 2020 22:05:53 +0000 Received: by mail-lf1-x12b.google.com with SMTP id h22so26980404lfu.2 for ; Mon, 28 Dec 2020 14:05:50 -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=45Sdgq0CvgKJkbdvj9B0AvWNpX2stNzecfKpH4b08Jg=; b=oAmJY6msYX1EpCEynkntpDs7jp9Oc6Cr7Uy+4IUlBAbzp3PzdkgwMrT3sW/O61d5UT WL6UP77ndWZiZh1lQC9+5Y4pyR+zx+HTiBI+/vgnbpJ68W3+TuBJ32AwIfScBZLJ5iin QceIKle+JBIuBv4A4PNh+5vsox0fTRco2EuxqVfVJ8LKCjeQpmZSus9EY+vRuSCU+rxL 2lqUTb3JF7AV8EVnVFf+qyHOsk4PHT+vUkyKAhoj25HiYehljSFGMpLeVdhBcv4I6wp8 hZ66dOubRcc2xyegz9Kd8S8GKX6e4d7kEgf9EwyysSaI8OtBm4lHRg3ZxoHxo0VUbSik D9rw== 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=45Sdgq0CvgKJkbdvj9B0AvWNpX2stNzecfKpH4b08Jg=; b=AgjOzY/gLfix0CrJhvH8nsXdzewQeMfgMTa8QJGMXy0HDNgo0tXzARBkHc04EYKwUt ndjgF2Kn0trf4rLba3uocBjR0ZcjrFAKeg2Rw4R8GhwP07feLm4d3aStzI5mFb7pluOl ufZFPe1M/9RGUbsYfpd4mCp9Xk2nxVPZ4MjjNBGiqGsOX2F5Qg+v/yfMwVRsCF1fp7to r5skP7s8PWvxzA9KCJ7p33wezcTy+nXPXsXGQYfWb+tfY2OlYXU46B1XOA/1c+byhJA2 M7aGZ2z8Ei4iqUTdbL4EjhfeLzpSqHT9hfwCs+ay2ATW0xL1zqwCkMPJ29qc/Wmlt+Xt GalQ== X-Gm-Message-State: AOAM531tKCOLzymVSCSONsQjosIAJ6dn9MC4a/T2pSKDNMvRyOgr1meA xqUzJ3jER2GI760/t12IvDE8QA== X-Google-Smtp-Source: ABdhPJyEJGC2U7ia1xM2nzW0J4rVQGFTB1NrQKckztfI4yAFTmBNyMtDPQHGY76jNfz9uKdGzvS/Xw== X-Received: by 2002:a2e:81cb:: with SMTP id s11mr22732457ljg.377.1609193149174; Mon, 28 Dec 2020 14:05:49 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id s1sm30141ljs.0.2020.12.28.14.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 14:05:48 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 7B45E100F3B; Tue, 29 Dec 2020 01:05:48 +0300 (+03) Date: Tue, 29 Dec 2020 01:05:48 +0300 From: "Kirill A. Shutemov" To: Linus Torvalds Subject: Re: [PATCH 1/2] mm: Allow architectures to request 'old' entries when prefaulting Message-ID: <20201228220548.57hl32mmrvvefj6q@box> References: <20201226224016.dxjmordcfj75xgte@box> <20201227234853.5mjyxcybucts3kbq@box> <20201228125352.phnj2x2ci3kwfld5@box> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201228_170552_408937_063D883C X-CRM114-Status: GOOD ( 21.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Android Kernel Team , Jan Kara , Minchan Kim , Catalin Marinas , Hugh Dickins , Linux Kernel Mailing List , Matthew Wilcox , Linux-MM , Vinayak Menon , Linux ARM , Andrew Morton , Will Deacon , "Kirill A. Shutemov" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 index 829f5056dd1c..405f5c73ce3e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3794,6 +3794,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf) update_mmu_tlb(vma, vmf->address, vmf->pte); pte_unmap_unlock(vmf->pte, vmf->ptl); + vmf->address = address; + vmf->pte = NULL; return ret; } -- Kirill A. Shutemov _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel