From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795985243; b=ysVJH0Y+SUYgpcBEiCtN4jLCExB2vtQbuFNBhjDCRZs3EwEg7xEeXfUoIa4gsqkdP8n0 PUv85xKU+b89hhJgKJKwy6ZDQQeQxGCgTiLqVRQia+vo3llSBWhLn6ykiC00LZCqJETAN CNO03y8RPmSaSL4Vs9BjG5J68PIzEWT8Aut1sOBG0JUbCb9Bz3o0jYOCGGDNTKrZtZ+w5 E5v+qegmXrl8HlSqHY2WEZXJLOBjJyXcxicGQOxjTGs3TDCBhXlEc+VBExd21StoCRDcY JXEgkiHFDAJze/EYksehJRcOUUgTbfU0n06Kuu2lzYDRk5fzXq9PTAvxZpw9Aw4KRRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795985243; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=APFES6StdiqxBzrxTbfgbM++Oc/4m4ShSkwR9CWVtJM=; b=lWauBadLGO+jJP0VnMqRsU6tb9c9o2piDV8RAJz5/WLEnPUFFUB5ZiUuX/Z7TY3OL/Ka i7TgfQcY8lEjuubg8ccpVwd7K7HZktR/BV7SWb5zt1+ETDRWLO2HnGe5lBPPSBmt+08mB lVJROPkll/w/O72p5Z1C7XUnYZEYm8bR/+W3+PoxTvZ3d6lKbcittcMoLxb2cgDnRkwlc ISKAi1zeCzX/FSAIYn1Dcsb/lLW+sNY4MJEl+MnXLzoGxphuKxrMUAj7jA9QWoTZwbfZ6 LGduOCmDYSJ6AYpo4JDqpABxOpoL70P7Ju/LpFy2G7cYB9SODRDxx9XhbxlrPzTbSUQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tv59ApUP; arc=none smtp.remote-ip=209.85.128.50 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB953606A31C for ; Sun, 29 Nov 2026 20:47:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB953606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tv59ApUP Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4a2153c8525so78976665e9.3 for ; Sun, 29 Nov 2026 12:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795985241; x=1796590041; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=APFES6StdiqxBzrxTbfgbM++Oc/4m4ShSkwR9CWVtJM=; b=tv59ApUP/mqrVLDWO8LpCfhzEdtAc0oqufhAZJG6nGUSH3qAOvVOsGojJsPolooPO7 EZctEYBI1UPrSAByfSK563gFxnOimloljGQCDs3iNQLfrdUpIlkTcg3wf8RyTcA3szEo /tp+sU09S/+doh0edVB3Gv6lE/KzcWevaByEaTjSZNutNOGKW8x/pRBOX/lJiYRXi0mg 5zPDX7O0WOT9dJGSQjxqOJXHj1EN8ovUqncXfPNDZhA8Dyw6DfsTOcSbOyE2UBbgabTS GlJ+ZJf4+dIeaYtVzmmpdClyN6HyuHt0B5BuK08qzVQvv+4AsjRElAn2ONedHAsiqaWO MGJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795985241; x=1796590041; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=APFES6StdiqxBzrxTbfgbM++Oc/4m4ShSkwR9CWVtJM=; b=l+tdahaKnWYEpYyC0w3bjO6W4+y3bmzj6tbJyODB7Yx6Nq5Rcync5aAb6shbdT5knU /nYpYj6Pf49NJj3/Kf79FIy8u+Diirh5IPErOOKFXDNVZidLtRBNbVY3Xd/9iFXHxmpQ w/qqZ6qasnLOSX1N553zuGOh3oUGu5dlNrBwekYlvUe5Cxam0TjsHWdr4kW/Y8TCuI1P rFTU6ithUvdGdlwr7ut43s2DvqBxLPIGCzp558TOuv70nd0Y0Pq7IIACIrHBNNpuZWKc sIw7+ancw0Pwi+RECEb7KcuHQdmsaF9STG7QUSNSAh0MHScCECDEWrZOiLuGv45oamM6 u73w== X-Forwarded-Encrypted: i=1; AL+hErHYQ37U5PyPc09xLA3RIsRHS1/tMHlF4s0/CzTbkDUSPeb8uw4wmIS6/ECU1pyMjP3xOqCBGcc=@vger.kernel.org X-Gm-Message-State: APuU4Z9/6KTdDTfsSQ/ar33Faey8wITN+js+CEjbRqhSdQOk849bT4dN 7+7pbSQUB6MOLi73xY5lW5LZ8YhMiG5AVJSpCr5B/bBTVBqwZKiTpP/h X-Gm-Gg: AZFdTZc7UmgDTLLQ3thQOKDpthP4999GZ16ergy0dqJ5jKrPOzSlap3ic7S7LcQF99Y ov6++vcuEnSM6EiI7t1VbsySqR/SAjrVnfdYvrSrZWJHLTQ2Hpb9l7y9Td06O7E1/CKFtyAu/jP zLv4VVPajKlBwgrP187Cke/2mKsXpTXsEEwVMxypX6F7337usBv2ojWN2M41OHLbY3NFm6yK0Sl d/RAJYHmrF2owEqnuf8Y0lgScN3n95ho+17tNlo+jSMAHaoo9sBeMh7KFxgPC8q5JmY2sk6sxrK jwBuBUT6TlpueOiNpZMc7AmZ4Wh9yFtwv67lugrTG/ppltc7Lu1vc4pbROr2oWFKMYmtffSUka2 +xcZHk63uK5IgxE4LhT/VMfDYNf5lsHrx7tkrnXDOYITlJ/7W8Z1ssaONf+lhOXdVi1MmmWE+4L kgEQsXfvFY6rjCzqjoRNRjLGXKxHVtatnJuT728MXCMylGdRR/xHcBqQOWQxJL1MAcNW4/cqh36 fToK/sGsZmZ1ckaxZtI1AZwznQ9afKYywhq8Kfr1sdn19K56lEKosgMhhnNBj0P5BRjvQV6rwrq HKU+w0QzINXWbPmRIlxLRxwP X-Received: by 2002:a05:600c:19d4:b0:4a1:f377:5c6c with SMTP id 5b1f17b1804b1-4bb8880ac6amr632242175e9.10.1795985240955; Sun, 29 Nov 2026 12:47:20 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm722357445e9.0.2026.11.29.12.47.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 12:47:20 -0800 (PST) Message-ID: <5a4cce05-da45-43fd-b85a-730bdc06e157@gmail.com> Date: Sun, 29 Nov 2026 21:47:16 +0100 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 16/32] mm/memory: don't clear a PUD leaf as bad in a zap To: "David Hildenbrand (Arm)" , Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , stable@vger.kernel.org, Chris Mason References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-16-f66094116801@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261129-fixes_core_3-v1-16-f66094116801@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/29/26 11:06 AM, David Hildenbrand (Arm) wrote: > A zap can race with a page fault that installs a PUD leaf, for example > with device-dax or VFIO huge pfnmaps: MADV_DONTNEED only holds the VMA > lock in read mode, and unmap_mapping_range() only the i_mmap_rwsem in > read mode. > > zap_pud_range() reads the PUD entry multiple times without holding the > PUD lock. If it first observes an empty entry, but a concurrent fault > installs a leaf before pud_none_or_clear_bad(), pud_bad() will be true > for the leaf, and pud_clear_bad() will clear it: > > zap_pud_range() __handle_mm_fault() > =============== =================== > pud_trans_huge(*pud) is false > create_huge_pud() > insert_pud() > set_pud_at() > pud_none_or_clear_bad() > pud_bad(*pud) is true > pud_clear_bad() > > Consequently, this leaves a stale TLB entry behind, leaks the folio > reference, etc. Worse, a concurrent zap_huge_pud() or __split_huge_pud() > can then read the cleared entry, and drop the mapcount and a reference > of an unrelated folio. > > Let's fix it by reading the PUD entry once, and by reading it again only > after we split the leaf or failed to zap it. Skip a PUD leaf just like an > empty entry. > > Note that, in contrast to zap_pmd_range(), there is no need to retry if > we find a PUD leaf after we split the leaf or failed to zap it: there is > no collapse that could move mapped PTEs into a PUD leaf, so such a leaf > was installed by a concurrent fault. > > Keep falling through after splitting a PUD leaf, so we would zap any > page table that a split might install in the future. > > This has medium urgency, as it can result in a use-after-free, but > requires PUD mappings, such as device-dax or VFIO huge pfnmaps. > > Fixes: a00cc7d9dd93 ("mm, x86: add support for PUD-sized transparent hugepages") > Cc: stable@vger.kernel.org > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a