From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3EC635F191 for ; Thu, 21 May 2026 09:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779356384; cv=none; b=WaFl9W3GHOrZKTozmzu9Mdme9AL1Y3g7ifnbKlMgAPp3trORShUIfIg/+/2unXPVq0vVNtkzbNcAqlIQLqUu8qSqqFARcgVaKm2LDpNEc/X58/F2357o6KWUk6L8bs9at6D7y6yCACJ+25qI7YFXGesNLz4KSN9AG7jb0Yzq35o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779356384; c=relaxed/simple; bh=HHPN0wU+k0yP+eASQrF0/Lh7+7JHasT8pE9O9pmaARU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZT59tJuctNjRTPXJx4Uphz9teD6M+BcZbHr2pL4Tkh4S0wrpwCqVJzyiBXFYEYzR8bsxbd4uJ8aw7WwMP2Y6JMpS2bB/bcCDvVL7VL/NZ9fyjjn2L8WTZ385RtZLCoVjrQTBNcJzQF1rahsQOuSzfLPtWOGGQQun9SGc+4+hWnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KNMSiboc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KNMSiboc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48F161F000E9; Thu, 21 May 2026 09:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779356382; bh=zfwp4PpwL9D+jnoLOXIbwxG21F+nlkYoKpWMPOJkxso=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=KNMSibocozxsOEboPUh9RzwdH6/04r2b9CNhhHRp61mEbqeBdpDKtdBsxnR29HH2p T8NW7atvdWqQcoP61SdwHnZT0VOORIr3HYAfhHJ4efdT1pTPfZBLgmncH4/5Dt9Yc/ GvrIS5FzN/06GoXdVwbt6N4WOjXb+JVDHPSD57HGdw1TxMAiMD8QmnSsBibY6ovo7p kpS7MkkiTOdGclxIQtQmQocIIUYsK/ytq/NF7+zx4AL5KE7hnaATQfZ6ZseC9F44kL RdHlmxG70wrFrqXrWUhBoJy4KPvb0XIYMt2tc2aHSRRjULaL6TVJ+gMPSpMaGGmm4n Pc1E1+kRsoF3g== Date: Thu, 21 May 2026 11:39:36 +0200 From: "Oscar Salvador (SUSE)" To: yizhang089@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, william.kucharski@linux.dev, karol.wachowski@linux.intel.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, liuyongqiang13@huawei.com, wangkefeng.wang@huawei.com, yangerkun@huawei.com Subject: Re: [PATCH v3] mm: do not install PMD mappings when handling a COW fault Message-ID: References: <20260520151624.78370-1-yizhang089@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260520151624.78370-1-yizhang089@gmail.com> On Wed, May 20, 2026 at 11:16:24AM -0400, yizhang089@gmail.com wrote: > From: Zhang Yi > > When pinning a page with FOLL_LONGTERM in a CoW VMA and a PMD-aligned > (2MB on x86) large folio follow_page_mask() failed to obtain a valid > anonymous page, resulting in an infinite loop issue. The specific > triggering process is as follows: > > 1. User call mmap with a 2MB size in MAP_PRIVATE mode for a file that > has a 2MB large folio installed in the page cache. > > addr = mmap(NULL, 2*1024*1024, PROT_READ, MAP_PRIVATE, file_fd, 0); > > 2. The kernel driver pass this mapped address to pin_user_pages_fast() > in FOLL_LONGTERM mode. > > pin_user_pages_fast(addr, 512, FOLL_LONGTERM, pages); > > -> pin_user_pages_fast() > | gup_fast_fallback() > | __gup_longterm_locked() > | __get_user_pages_locked() > | __get_user_pages() > | follow_page_mask() > | follow_p4d_mask() > | follow_pud_mask() > | follow_pmd_mask() //pmd_leaf(pmdval) is true because the > | //huge PMD is installed. This is normal > | //in the first round, but it shouldn't > | //happen in the second round. > | follow_huge_pmd() //require an anonymous page > | return -EMLINK; > | faultin_page() > | handle_mm_fault() > | wp_huge_pmd() //remove PMD and fall back to PTE > | handle_pte_fault() > | do_pte_missing() > | do_fault() > | do_read_fault() //FAULT_FLAG_WRITE is not set > | finish_fault() > | do_set_pmd() //install a huge PMD again, this is wrong!!! > | do_wp_page() //create private anonymous pages > <- goto retry; > > Due to an incorrectly large PMD set in do_read_fault(), > follow_pmd_mask() always returns -EMLINK, causing an infinite loop. > > David pointed out that we can preallocate a page table and remap the PMD > to be mapped by a PTE table in wp_huge_pmd() in the future. But now we > can avoid this issue by not installing PMD mappings when handling a COW > and unshare fault in do_set_pmd(). > > Fixes: a7f226604170 ("mm/gup: trigger FAULT_FLAG_UNSHARE when R/O-pinning a possibly shared anonymous page") > Reported-by: Karol Wachowski > Closes: https://lore.kernel.org/linux-ext4/844e5cd4-462e-4b88-b3b5-816465a3b7e3@linux.intel.com/ > Suggested-by: David Hildenbrand > Signed-off-by: Zhang Yi > Acked-by: David Hildenbrand Reviewed-by: Oscar Salvador (SUSE) -- Oscar Salvador SUSE Labs