From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384790; b=K1mt5nDnM1Ipd2EhujNbvb3hoji2Wl5bA8HtEdPTNvaakARinhQRJ3MjyBBzLmfdtkB8 Azhy8baSq0vP9wFmevZDNxLNVn4CKKM7qrRiSwiQpNi5BLaURHKipzVkS6X2L8PTY9b2X PEN4iSH7O/KPhoLg66bp9n53rBl+UkvEIKi6i7yNMlw+OEa5EH8aOUjY53HAOtokpBohe wPpSVqt5XUUnv4SH0Ccfv1l+vLvHR+ujBYh65Wys8Au9g3ZuYmTvZAwwRfK4MQN08FtDb y8MUOXhQ1KBPNdYwXOBUA0gy1BdR2s2OCMTJsj3TxlzaSWnvP1Yjy6Z7u32tYCOHRxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384790; 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=2tQysf2XxPTzJtyUKf3F27foeZ/Ih6noisPsRES+/2A=; b=NkNJfmNNHnbAxW2MkCDaMWs0xIx0JPr1ZEhjJNYHR9qDC+yAHeZg4764L//V1yXeySRc xVO75dWafd/g9uXr4Y6kCYB71B8mPDl6Jvn3bIPysZz+mPszXl8ng+bt62rhx2/v4H70D oyUi/6PH9BT5/rP3w5ibJh0mTPxNafeaIzcnnZIgV9pMm19YfkwUflGApHUl0BAkxwR6q 5JT1zAXna7Jcfmd5LzPJstQXwUNxkODpcs5GCcMwUrAGW+F48TY85et0RNVQuxiB6LUsi gzywfrpBU1B/h48zGyvHR4ctoTQsjN5xkMUH1PbX67BFidhKInfc14p4ZrdXJZIiRCQ== 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=yQTBwsjj; arc=none smtp.remote-ip=209.85.128.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 0C635606A322 for ; Fri, 4 Dec 2026 11:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0C635606A322 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=yQTBwsjj Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4a214c5c4c0so7869525e9.3 for ; Fri, 04 Dec 2026 03:46:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796384788; x=1796989588; 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=2tQysf2XxPTzJtyUKf3F27foeZ/Ih6noisPsRES+/2A=; b=yQTBwsjjMDdOCTqYhBka6sulIY7aOxkk+F8bpSzFVs2rJ9URFP4bd2Imn2YxkaXNqI kItTKwaw6E7TFv+zBZcLeP79L8zxO0T6s/aSFTfp2uQxiC2/ABQFWXpolBWbw8SOnLTd zgqQLoERWK1+Cqxz/bU+Nqt4Q6+KnzqENLDZ3Zx2PABY1ba19DhlVpGfIM1/QTv7vTCn kk5qv+QtiCdgCh6JTFAiZJT018tPZBtLiblNNHj7RyFWh0Q/tX9uAtfhmG8efCMjOgDM RO8q4rQmglelqc0VuFHFKOKP5Qh98rcYgdwCTz+kLD3pqaEsB06ahWrR0vIkN01AuXRg gEBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796384788; x=1796989588; 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=2tQysf2XxPTzJtyUKf3F27foeZ/Ih6noisPsRES+/2A=; b=JN5yRHinnJ7eTA/jKOCAsUCPihzy5uhqiFX0BW+XGH8cv5eu5dZ377cAE5sATiNdVh zadaXVYjc3z1ODhhvuWatWNyUVhGApSli9CcLJd+u6lGfzfSrZSPHIsU6Hyl7kYu0feI r8FS/66Wxl7jolp7X+YwKna81Wzbr5fuX3uONVFwHQU5f55rdRMhGCWsfYfdh/BJcTuM s+VQ7HRQiLeIDWdtR78iUmXShAnwR1YCA4wRQGeqwnFOKRv/1LKs4YR5K8xBnguGMk1T RBluGSAFw94gkxgJWsemuemVZCL4mo/eSeli5/Xy/XtI99RPSQbhIiDM9xe9dwp0owPw kp4A== X-Forwarded-Encrypted: i=1; AL+hErFRKZZqr8u3VbKcOubpKwPKOy5hOk+Fj1YE3+8z98nhLZXZZaZMSScOdOOQXnxbf+spaB3W3G4=@vger.kernel.org X-Gm-Message-State: APuU4Z9BBt3N19MuCo++tFtySy3rPPjHdTiOr+e4FWnnWRdzaXlBuzHs YIkMBWlAjPzMXTf2MfZafqA3QaTsrw//y0hhepzVqarB/OzcK1ih46vC X-Gm-Gg: AZFdTZeI+xtAjN6T5QXVQ9VFj6UHQH0ZABAV1e6RwdVuS9CsSWrSZPbAUZ0RSvWLmRp 6jmYi294YcE4w6IRw3chofdu+jaaC4H74bnS9HJ/58n09rpEwJK0bFf+fqf0S1Yu2xzjc+zwkM3 oWGN8pc09LsMu6mAydJsKOKiVKpICU7OlWfnf9VRu+VaZ+1qm4dArH5Zt4XNFf8NBcxfb6RgLaw tRTj5oaDYuCJtDO5eSzybtvcExbEo6Olq9vxHAFTmjNkSHumySDvT3uO0MbeA9UCWcMJLgd0U9p c9tkergfEWfnDWeQQGUHxSasckL7as88G8n9IE8oEqmgCBTqBJzaBUX6O4dx1/lz+NwgHhNivs1 94oJcenU/6eUiTp43gtna+SOF/NlBfWyGsp6Kim/zEAmM73QmD4NNNFT6Ura5+6GUXNxO1aUHS6 De31Il2ZpJZtNHKzSKePrIBphj7ZkM0ogoifVVYJr3DWuK42J8oHW4hHEcNfiIa8KDI6OUISczn WwLkiMnl2me/tI55uqXMFSAmuqgX2B8JvM56XkQ9zv0tvTDizTz2fj/hLGnggyhLDzPA+AlMaCG moFG6k2iGo5d+ETORbDrGMC1GaJhKfrX+py/be0+9/2UqVNb00g1E7w= X-Received: by 2002:a05:600c:4689:b0:4bb:6861:657d with SMTP id 5b1f17b1804b1-4bbeb8dd83emr32754765e9.21.1796384788259; Fri, 04 Dec 2026 03:46:28 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17302b0d4sm5122713f8f.29.2026.12.04.03.46.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 03:46:27 -0800 (PST) Message-ID: <92969ab2-a74b-4a3e-b02c-69d822f7205f@gmail.com> Date: Fri, 4 Dec 2026 12:46:24 +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 v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails To: "David Hildenbrand (Arm)" , Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , stable@vger.kernel.org References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-30-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-30-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote: > From: Chris Mason > > If we split a VMA that has shared PMD page tables mapped, and allocating > the hugetlb VMA lock for the new VMA fails, a fault in the new VMA can > race with a hole punch and access page tables that were already freed. > > __split_vma() calls hugetlb_vm_op_open() for the new VMA, which > allocates its hugetlb VMA lock in hugetlb_vma_lock_alloc(). If that > allocation fails, the new VMA is left without a lock. > > A VMA that has shared PMD page tables needs the hugetlb VMA lock, since > the lock synchronizes huge_pmd_unshare() with concurrent page table > walks, including faults. > > want_pmd_share() and page_table_shareable() prevent new sharing without > the lock, but a split leaves previously shared page tables in place for > the new VMA, and hugetlb_vm_op_open() can't currently return an error if > the allocation fails. > > This can, for example, happen for an OOM victim. Then, nothing prevents > a hole punch from unsharing the page table of the new VMA while a fault > in the new VMA is still using it, and the last other sharer from freeing > it: > > fault in the new VMA hole punch, then munmap() > ==================== ========================= > hugetlb_vma_lock_read() > no lock, does nothing > huge_pte_alloc() > pointer into shared table > folio_zero_user() > hugetlb_vma_trylock_write() > no lock, returns 1 > huge_pmd_unshare(new VMA) > pud_clear() > last sharer frees the table > huge_pte_lock() > set_huge_pte_at() > > Let's fix it by unsharing the PMD page tables of a new VMA that has no > lock. Also, exit hugetlb_split() early if the original VMA has no lock, > as it cannot have shared PMD page tables then. > > This has low urgency, as it requires allocating the hugetlb VMA lock to > fail during a split, which is practically only possible for OOM victims, > and a race with a hole punch. > > Fixes: 131a79b474e9 ("hugetlb: fix vma lock handling during split vma and range unmapping") > Cc: > Signed-off-by: Chris Mason > [ david: return early if the original VMA has no lock, adjust comment > and description ] > Signed-off-by: David Hildenbrand (Arm) with sashiko's arm/parisc atomic context point addressed feel free to add: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a