From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795985243; b=oS1TLAmOq456VgetEeIdm8nAN2DuNuIBiEpRC4Ib82V7lwWLqtBasetDBdPQAAW31ZZC QiC9GcDM0sdrNOOuiynFlzFs2APN1sHyncApPVTOsmfRKw31YpTi93B6BkyvTwMuXwy2h JsJYUTfUeim8Jqvq2uLTJXopdX7NGE6HuHcbMNhBW8YoAsxCHAK+1v/dSHGVEEMLxcauI OCIjV6YbIonhR0jG6XjQGwuSdbNFiVe4qKk4GykiJvAD0CkOydCOodk9gHfBcB2X881PB FPK9VyShdZ5TWoRkH52UE4mPgljviwzQ+PF7fjzRDDRl5j+ASZ5TJfQ6HY9Udc45JVA== 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=JsgD1MlLGIgJ4VLCyr4kiLhFVI9M4oaixodaTbjqKJ3RmXYybcPiEkiz0wqUpgJpGlng rVzZrBA5sz5K7DiL6s5uQZAjPjY90ABgR6i8xYT1E80PEqqCURtWK9YATGPP/s/jt5lpT Dm+J0GnRR5VC5F6gLhadLcMmuOmvQkyvXoGNgrS6pYkZoYMPwX8HDPb/JPEM1HD332Vyz rErkbQyXXL+oVVdr5hoANdZvAJb5nPnFeOVDRl9OXHbWAsEy6Cxzymko6O/bJlthqLjVU zOIpdrZJ9EX/N3wPocwq7x/ImrIPJm+YI5QOxAVEMgPyTqTBmn7zp1CvVSdQbnBDMxg== 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.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 CB5D2606A32C for ; Sun, 29 Nov 2026 20:47:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CB5D2606A32C 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-f41.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so83840685e9.0 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=kS1zYDq18WZUwElPyUABZ/lvkwbzQD15tVuMSQ/lV7du5xn4udEVumxhZVq64Jcwdm O/+f65uwn/dGvfQOBYR76Ze0ji3L5w4qBpqBBTPsXw/lCQU79YZdjJeWg++Qc4nXxMYq J4vQGh1yuGtoYvdkpOsQP1P6hNeTBgj7G5kFss87lVI6EYSrgLz9cs49LP9Gno1QLbym PwoxtI7a27iqFx7z+CzUDCWp9dfWvcdIT3PoQzUXYBdHm9QUyRD/d+fAxBDPKLzzKIzt uKrzYlSUb5og1VQ0dEiqildk/BygyxWJTvqDwXE/TmpTHIzSwVfMAjQk5K3hEgXQN4bj 0Oxw== X-Forwarded-Encrypted: i=1; AL+hErFaRgP2Xxni6STk/yOPuJiY555Jl1fsgYHcVl43il+dnYG1PdwLw5gEBHhd3VSCRcGJoFS/aZ8TcgZZrNp0@vger.kernel.org X-Gm-Message-State: APuU4Z+H9o/06y3Vnkjrta1OY3xUmjS5ooqE4s5GaQBaOo/DCbf5cYXZ y7V2In5b7Q02MZDjoj1RqpyZspyIutOFNg/QAzZ+odhVtD8iJeiF5bri X-Gm-Gg: AZFdTZeua3+a576gbAiKCFKynF3c4BBi+N3F7gm+m55qoNpMBBWtAV2qr2YBOREkFg0 ji3JH4moL4Ix839ZgLPBhc0e8q0F0orY/ohoLNm6hD1UCqidbMWOSezvXqYe4xcnoTiRUaeAt7k /D1Qc2Rm7bpAFnyRq3HHra3wJ3q0f/fO28zVj/0qEC94u7LDGJMnwZxXZkEeysgNBF1xxAlt/k1 5fk3mdiUZ18v756V+a7cHTQR0BKD5Y+jA10DleLovChvx/CFcxKXbUS681Vh/h21HOYQFlXhOBc C5Q3aEFWYJuKBmQOu5gHjZsSBHk85bSqjAA3C99SUonnqCSvn5SCq6IKDV7bebXjInHX4P6GU5C qo8zKw8bbUHy+HY9B15nLogPFC9CXTXMZcORFm8X9BiZnvgPJg10WggP8fhQmM5yXq96OOiox4u IQUVgDde/VjMyVdiuwiC2l3ioonqRJczyW1f6twRtsCo2Udntef1q6kYwqmT32QaRBv8PAURFpF tf89g2ZQebAcuCQoisMpMTiC8PH/6QNuAXDQ8/FW0fEjx/2EbBuskBdUDbFKU/j7pZewKyX78kd J1m+me69NiNaB0gv/a0pVo4g 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-fsdevel@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