From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795985243; b=UnuGqmEnjO29Lwl+XMg+9664965wMYg9YxhgBpFU3rU4lXHG72iiv4XGP6nbgF/lhY3q NWIfExKIZmq1dZK0yIgS83mmG0dYDB6aRuo3uqD4I+k6NDGnRbckjL9S0c1EVtq7xY2ub aSpPWjrgfmIbhI+d4g81cprQeAmFd3DHOr1NIf7Wyh5lf9/mj1Flkdei6A2iFNec89MO5 Fv7DuIsXevIuSF+zSTolTYphPaz0dadC2BHkIrWhjSIZejsxBMtxH+Y4ll3hd4Ys7KCWn dnJjNtADylPuteat7G3phd+wQuimVxqbWsSLJTxUxvKOmgHHIG1aDr5KICqp141k+Yg== 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=L8S4rmiczNjiss/q5H7XNOrcCDN8VXTAnxExteGQyOBVXuVklpAY3RWpibeutIJOeyT9 zDJYJIEEtl0000JlZgSrpLuxIl5KFmqpno6EAFA0Is+LbdOL1y0S1W31uQBKkSdbxalCI OYkvnPG+5Ma844xwMLNzps0dORDUK+b/rdVppbCoxTDBIr/EB357fn2RFjFBRctPVNvSP EozivhbE7/l9Fm+X+erdsEJgdWRc2y0VuXeS0L/dX/n+M5T+gFINydM8/vtMicFtaZth6 bnj/ajqNwCJ1+ZyT5xolKBwV3beAyYUtuxqmwerlZYfUXophh93z2YTgYvlvJy35VWg== 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=Qoqevl6F; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 CA7A6606A32A for ; Sun, 29 Nov 2026 20:47:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA7A6606A32A 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=Qoqevl6F Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4b79502c27aso97840355e9.1 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=lists.linux.dev; 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=Qoqevl6FvSBA1Z6UXO2C119Y5Tso7hnpptunKCTtQwkfNYY+NWwqJ0RAkHMNIJ8opc 3QZceZb28r078LQ65krgis0Z/NFLBPn206NRycCBCX2xYVYghOrJeQYhXIXIuNjBNWqo ZQwMax8GlNn0Py1q3MtWOzaBU7E/xHXGnZSlZaVBOlD+abdi1hWgj7HgF1AtSzdtXkhk R+WRrCl8k9/0PpsdjqEcfAo+bZzSrqKKY6t754cVKrMHQOFq0TBktPBMJg+K44Hr0UVj efBzqlI/GY1tYwqSA9xYgHW0Kk4uQi5S0DFxjv4bP3eQedxV+Q4MuxOXSCd3YUTUjs03 LlNg== 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=v2H8v4x0uleDkgHjLW9e0ldtvNvjxzEgIV2wUAcDjwTnuH0VnDMZHeXb7p6OvP9XpR k/JAuDLIQg61IcF27WK5L4/UhZcITcasJXgUKIAQllDl748XdIFCd5rvmh8bv1qFCKIG uO8BP2DWjyNEBUOWVjbWDP/wBoHW4SFgghFrc81rgUH6ceqoSqq25Eole73V+6JtgpR1 HSmazlkr049kxfSignfKryS9lR8L2DedfJp9KR4LtcSS1egXTYrt+RlLJUsmRrA7s9L+ LwGgqbg/QVvgDFrvOBLVg7OCo4sTdU5FkPxAoWExYMOv6usituI61/nz5DJVotWV+lXM dtDg== X-Forwarded-Encrypted: i=1; AL+hErEPHklaTfWseRPRMXCOBplmLeQtM+PlJpgLP3J+nYfsw52jLDlCffwOJm53xYxmMY28bL4S1Es+FxrOWFIyFQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+OvosXtk5RXrITRNTfSbg0r88TOke7eNYt9ULnfKqxuoLntvWr 8JOcPo6EE+GQYCHnHGOqCAlJCMW1XoPC5GKFLgqxN3XkojEKszYZss6x X-Gm-Gg: AZFdTZfGppmpogfUaJRHHm5CF8DVSoaNM8pg5fHYkOfLeHHceZuPSdtzL6Rr87S3BiJ 7oaO6zgupzvzrJb2XOqg+5yFCEZtZ7WdXuif8viq7iEGNy5fxDz/4eyFCL6cyDcuzsaoovHQIp+ DS6nE3s/mcnXXUJB6gh5za/0IrYUvUfRLD1whkrtGaY+o236cweN80IT7pbAzVHFWWAMeu179BS fKE8oomUoNGK84YOCuwLCpeRWOaqiAyuzvs8IVr/UPHcjTYZ8aCqA14/x77wDBUhG7AOKysl2cI KSxcsESBSHiRoaeWh6U7XeLIYGQEKXBDuCLc6nnK/A9C7ICWjPcaQJZCkaG7XvqHk2YBF7P7Nip HoNoPgMjKc4UdSppVlFHk5l69n/H1WinenD7Q5C2zfXVYqCEq4pd9r52od8QBVLZ0lWziD0oUSH bIkiXvLVj58o0rwE5YWQRkpfvtGOeTpfBqua5BL+2iWta+HQ/5DyK0BpwZYUL4aPk3cRaWk+RyN WxAO6uNjpaipqnUcDykvUBTTrxJRbI5jU4QZDrxpBHYox1JP/ljlpIH0VqHXJ81GfSckdWTWGo7 xkTlyQ0TBfo4yThatZ43sj1k 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-rt-devel@lists.linux.dev 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