Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8061336pxu; Sat, 26 Dec 2020 14:43:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcIlF0QXdtzliNyxM5b+POqvFdFe0+LQJKKyoB8g+R7tLGXgffo5dUQN5HeZ0z/EykrbqV X-Received: by 2002:a17:906:1488:: with SMTP id x8mr25169769ejc.124.1609022598710; Sat, 26 Dec 2020 14:43:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609022598; cv=none; d=google.com; s=arc-20160816; b=JMnKwmb/IDmK+IAKYCdO1BKEmHqhvkwHY8kmhouNs0IBd3sQ1bez+5c9gsCpJ28nUf f8Qdh3sWfdXR9Hpad34zmEpI0qS3OmOdNwAnC/vdljVFxANfjZAjXVimARKTX7aToFjv /OCdLFo8s3fp47Drfp4Fbl9uPXBYvAwSP4Y4RSGnjbS7HLh+/10c8zgOnKXIlFU0qUHF pSjjQbi8dLCAuBkn1BjQXdTg6SN6Tl4Mq/JQPserz6KtdUw38UnMDDNqePXKkS0+pl/W klEFF34OD+e46F1e/4NnHi22wQflGwnvN5LnRHPJ6Q8ggJ/NBP1BfBapMR8eas4Umgr4 YizQ== 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=5xV1Uwr5QvPwGAEEhmKQuNt1ecyJlCF/DYUO0nnGbJA=; b=mrn9vVKaZ5z+ufqtppusdENxWDrudX8lkQreRJTwKovAVOq1PXk3Bw+iEn/YY+tteC aUXPjQ9l/RNP6bLxBLkBJfR6KzSPFHlf1siF9vTabRnuebRsiAJPSV/XcKbAQz+ylrn/ KuxWYu8uDosh3dzB6yWNdHG635zcAmuSIell8XynFaFXbUCh5gllLpEpbAdGDJqkexLZ jOmtkdVS2f/8Rnlpg58QUgWbnWUEDG5JAkPtiZeAPTELD30O40ebOgc1700v18h5ULG1 34ygTOYYJPiekB8abL5z4VT3q15df/+PA4afFaWA1/xhaLp2VDBJ+FoairkmJSr5qJZ+ RNwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=SSDOvkJa; 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 c6si3567874ejb.666.2020.12.26.14.42.56; Sat, 26 Dec 2020 14:43:18 -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=SSDOvkJa; 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 S1726172AbgLZWlB (ORCPT + 99 others); Sat, 26 Dec 2020 17:41:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbgLZWlB (ORCPT ); Sat, 26 Dec 2020 17:41:01 -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 A0ABCC061757 for ; Sat, 26 Dec 2020 14:40:20 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id s26so16163599lfc.8 for ; Sat, 26 Dec 2020 14:40:20 -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=5xV1Uwr5QvPwGAEEhmKQuNt1ecyJlCF/DYUO0nnGbJA=; b=SSDOvkJaPZLQbLl1/R2yfC0vD8pNo/R7kwvwiR0BP96LI5plYaxX1qyeGTF5DDBAle Mo8kLCOdwcA3MLI3xds9N6DR0mR8YcPh8435LV12lTkVb7z8s/jFxu8aCFrWAzzJUUAx g/GK5Fi4t9MRDLYmUWaK9rgbfXgMXKSeAXeUa+bfRcHPK8APDNC8EGbShpG7KAI36SdC atxEb/OH8TBUcAyQcr1NCjzL/tS0AG1dM0/L+sQKDNLwl6XDx36uavQQdFqhRjWxZVXd E2OjzaZCA2OX8/82QsmFQLLMRPEVEBZN1TaKU3eQST1GmGun+pNtH/lyfbsbsWIW0YOH Nrnw== 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=5xV1Uwr5QvPwGAEEhmKQuNt1ecyJlCF/DYUO0nnGbJA=; b=TtsjOIaNCkneArMLYvx0jMH49rYeTvA5Pv3vEfKXh7H89/ARWpXYR4inzVMnxK/Uj6 4deByjkrNz9kRY2tzcAyu8GZL9XJ57Wrf92K+qIG+TNTcqZC+PcKvDeN8gQIMrM9b+vT MPJVLXJSj3INKojhnoctqwoDyc3rjcvnsf0jGQHBY2cfGEGNVlA9jskBCTFcibwKqje1 MhR3K3/NOqBn2uoVCn+kFHghRu/E2LcbUCa6gsWlp7pXZoJVSP4+JpqacXk910JNn9V7 KETE0nRGde1ppUvQPWdYPo3SRITkBRJgfKT2V798CJbU+CgoDOwrkoDMXt/88tphJ93S Ux8w== X-Gm-Message-State: AOAM532arp+x2BoJLu2UMZpYoK9E+eB0noTaVWqrSyre3mWNP15EmCFs FlqBhrBNmTE9hCg28N8UPa2QqQ== X-Received: by 2002:a05:651c:1063:: with SMTP id y3mr17737679ljm.431.1609022417964; Sat, 26 Dec 2020 14:40:17 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id y26sm5596811ljh.63.2020.12.26.14.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 14:40:17 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 9EEEC1026FB; Sun, 27 Dec 2020 01:40:16 +0300 (+03) Date: Sun, 27 Dec 2020 01:40:16 +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: <20201226224016.dxjmordcfj75xgte@box> References: <20201219124103.w6isern3ywc7xbur@box> <20201222100047.p5zdb4ghagncq2oe@box> <20201225113157.e7hmluffh56fszfc@box> <20201226204335.dikqkrkezqet6oqf@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 Sat, Dec 26, 2020 at 01:16:09PM -0800, Linus Torvalds wrote: > On Sat, Dec 26, 2020 at 1:04 PM Hugh Dickins wrote: > > > > > > Hold on. I guess this one will suffer from the same bug as the previous. > > I was about to report back, after satisfactory overnight testing of that > > version - provided that one big little bug is fixed: > > > > --- a/mm/filemap.c > > +++ b/mm/filemap.c > > @@ -2919,7 +2919,7 @@ static bool filemap_map_pmd(struct vm_fa > > > > if (pmd_none(*vmf->pmd) && > > PageTransHuge(page) && > > - do_set_pmd(vmf, page)) { > > + do_set_pmd(vmf, page) == 0) { > > unlock_page(page); > > return true; > > } > > I missed that entirely, because when just reading the patch it looks > fine and I didn't look at what do_set_pmd() function returns outside > the patch. > > And maybe it would be better to write it as > > if (pmd_none(*vmf->pmd) && PageTransHuge(page)) { > vm_fault_t ret = do_set_pmd(vmf, page); > if (!ret) { > ... > > instead to make it a bit more explicit about how that return value is > a vm_fault_t there... > > And see my other email about how I suspect there is still a leak in > that patch for the previous test-case. Ughh... Here's the fixup I have so far. It doesn't blow up immediately, but please take a closer look. Who knows what stupid mistake I did this time. :/ diff --git a/mm/filemap.c b/mm/filemap.c index 3a92aaa59b9b..c4b374678e7d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2837,16 +2837,21 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page) struct mm_struct *mm = vmf->vma->vm_mm; /* Huge page is mapped? No need to proceed. */ - if (pmd_trans_huge(*vmf->pmd)) - return true; - - if (pmd_none(*vmf->pmd) && - PageTransHuge(page) && - do_set_pmd(vmf, page)) { + if (pmd_trans_huge(*vmf->pmd)) { unlock_page(page); + put_page(page); return true; } + if (pmd_none(*vmf->pmd) && PageTransHuge(page)) { + vm_fault_t ret = do_set_pmd(vmf, page); + if (!ret) { + /* The page is mapped successfully, reference consumed. */ + unlock_page(page); + return true; + } + } + if (pmd_none(*vmf->pmd)) { vmf->ptl = pmd_lock(mm, vmf->pmd); if (likely(pmd_none(*vmf->pmd))) { @@ -2867,7 +2872,7 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page) return false; } -static struct page *next_stable_page(struct page *page, struct vm_fault *vmf, +static struct page *next_uptodate_page(struct page *page, struct vm_fault *vmf, struct xa_state *xas, pgoff_t end_pgoff) { struct address_space *mapping = vmf->vma->vm_file->f_mapping; @@ -2914,15 +2919,16 @@ static inline struct page *first_map_page(struct vm_fault *vmf, struct xa_state *xas, pgoff_t end_pgoff) { - return next_stable_page(xas_find(xas, end_pgoff), vmf, xas, end_pgoff); + return next_uptodate_page(xas_find(xas, end_pgoff), + vmf, xas, end_pgoff); } static inline struct page *next_map_page(struct vm_fault *vmf, struct xa_state *xas, pgoff_t end_pgoff) { - return next_stable_page(xas_next_entry(xas, end_pgoff), - vmf, xas, end_pgoff); + return next_uptodate_page(xas_next_entry(xas, end_pgoff), + vmf, xas, end_pgoff); } void filemap_map_pages(struct vm_fault *vmf, -- Kirill A. Shutemov