From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795985243; b=AMXQgd0RZZXc9x2Jx1Az3od0DmO9OstqlQ9Nz52108fhdyiZSVoLiazbx84BmVGI6nLi fIHLa7x+kHCpnX9i8k6tYLzhLh/OeIs/fc6sS5YQwEyUnHn93SMgESNf2Bi+b1VmugC7Q cSiTSZ19f5rzUmwdiobTpNT8BC8Pq7GLoeEcxSkqmqnKHSl9aj0opma5Y1I2FPTa3FpPu UD0SamsG6vHxFkywO4unzgFfA2LlK4eMqFe3kxacqn1FLogH1xFgOP1jOMtnoGiNwgAj4 syevPZwT8VvzUW1xmLzL6w0VclIs246QvCx8kFSPNwzAj5h1oMyG/6BTGkK9OrdUsbg== 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=5aFxuAVm4L4J87yxE0RXd+LmjfrnN1ufsEbOPTrbfhPpFtudqfgtohF38bWfDL7y3or1 pzSpItloOp6wEX3p0AGkfT8wGL/XxOdWEnswSXUztDQ7Xt1hTYRe6xgaA+zKCVFeWgH/w dNUR4pokRwCcJOC7Ze/QAPzOop/CvFXXCR+l4EUDFio2wvv7Z9HAUcpf5uNr10AsucQyT FeWMFZRfrUb2i3NjT0G7BEzcG+JsgM/KfLsWDSreWVJ5/fvxyiPy0pzx040+mp55zVme+ cXV42DHUCzztcdFl2mxP9al5Kgf5CDx2Zs1NhUiHiVc8VPRRBIK+kbD98AHqV6Q2vvQ== 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.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 C98F1606A329 for ; Sun, 29 Nov 2026 20:47:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C98F1606A329 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-f49.google.com with SMTP id 5b1f17b1804b1-4a2153c8525so78976755e9.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=AZW1nk/vATkRYZeXqOmgAbgA3xMzM2xqoAeY7rO4LpybmEj2C1EdDGNrtxX7lFEnq1 jao1UNelNxlJXE+f25G6Pc5T7eWW5vRukqoUwRlJcS8j0OrUor5ABTQpDPbaJhmvxGtc csn2lS0Ykadm1ByBSlY6WrHT/yNtJOJanFMK6JNOuMJD0Cl0+Uzu1dmH0MXy6Jdlr7JC nautyk6WxD6v8wg8MaGgmZivCmbV/ofjnD2KxaEPckIRmXTw/LItXc5vgPlHtm9MibIA IkcQVmDJUjQVt/PF9V9DmqBLJzfMfgjl+fn5zMbd8/T932CVRDcw+SMq8aCQ6hBuae7J DSNQ== X-Forwarded-Encrypted: i=1; AL+hErEvTEiRseUxy5bCMXctg1kF9Ej3RRW9EHSJyB0BUu1hD5rBO5ljGttBNe7TzW/tw9llpbIz4PzALkH/h98=@vger.kernel.org X-Gm-Message-State: APuU4Z8j/hkl2JVDkNFSVe5NaSjk7SCpIpWOBRBx4favKYkR7mBGB9VJ yI95fBtPDGTgP+b97GH5mow8H4FyeD1YI9y+mMQ1NpPBqZ70l2oCcaCo X-Gm-Gg: AZFdTZduGPht8xIm/zwZiaHpUc2r19BanQRsLG0rbFMHM1nty9aundWhFBByYtR6MCP guHYb3rj89ORNpVLkVzhxOs61xSXWKIdjgn5NUWf6Jrh+5xOrtXkWTjI9qH4i37Rd9TjSoNA4UR uOO3zJ4S3BKLPuzlcX1y1uSvRod/x9WDPiiAzXwLdkBy+KcXJLauAhQNFglquEy0gAUfLMBc70H 63jyO/eGfIgl4meoc3czh97LiDY4kDsN2HyNa9S0OvUyYLjh3Mztg5tm9TUb3sOmoWFwb7+GqBX 4vLRZ+PAQtL+0q1JlDHCo1jH9SMLYP0qpoCRa0F/qTQt0Y6Ay47p2Akwoj2SpPoKiJUPwmR+ocH yQE1lyZu/t7rV2h9cSnQ7oiPZh1I9mdCryHss5g8Tf5fpbrAdpVlotD0MSwVd3uYhIJ/HF0d9AQ +Lvs2hwtDnoT2eHrxXw1FYVipSqOkBpGNAy7Uq5Yj5XzexFFUo25Xh7rGxBhq4ENdiAshaKKipF NzgZXeAChf4jlwnrOrolCZdB7XxyLw6V6gvzIzMHYCTvxpGace3jlyhN2wvE4iLZfqKRrYnjDgI KiuO03wR8ojbYDpjWFPMNvUj 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: linux-kernel@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