From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384790; b=aJLUJl76eR8pubbY24OlTE+UwCXAKGfFWgVOHkNJ2fK7q9JA9ogsHPr1qIpKd0J0SWDd sIgLWJAvzgL1J+To4xvhoFTLURBl4np4ZrWv0pMFbsTcgsfh10X5PHEnKYxb0xYimqCt3 5uwcmN7akSMeWl4NXVUTD+iwNS7UWpDtQRbQQiAUTYycHdIvIIWRt0U4ugZ9+A0pjvhGG 5Re+U1F9Me5ku2xnCylmv5EzW+Kau4qrENGV4p39o1jSaCHms2IMQuYcH3gieEQx6+5kz 6FL2gxGN5woyJVRPdEM6aRu+SnntIg4QZRHgzgrZDzlCVbjKpDe6KkXUatP1yWNgCmg== 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=w1KTBVNqD4TGNfxyuRtuKX069n/OfYBVKac2nlvW+VeGuewASnnThNWPIv1/KirNIEXO Pk8Djlx8s6bpiwtPmvPtZ0lFOMWfMbVHNSas1MRe+RveTU3Pcm9IgDPanbjkQ5HXd7jnZ ECi9qZlYCBG4a0T8HiSInRkcVLKELygacFnXXsq1YcjVddB//Wu7soc4TjxFp9gr2LpyN e6aOhV9JsWJuuoA9uTe8/KmduRZQJgcf5ZZUYip+oxlVOcB3cL9pyleQuxI8EN+Lmq/pt YQyxWwxUHkjebn8PaRlkJCMVhJhpl7afV7dPP9WV7bI6HOoRY5Wk8TwCF6gN42RZRxA== 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.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 00EFE606A332 for ; Fri, 4 Dec 2026 11:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 00EFE606A332 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-f52.google.com with SMTP id 5b1f17b1804b1-4a1fbd52ab6so5729695e9.0 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=gGH50Hiuky1OlsllekIZFuS47xA1TBxRguS1ieQoN399PuR+N5YwTTTN8gLmixhF6m pvaJA7kfDyjRyZyrjCly+moAGp9DitDUSrSDP0H9hspWqR0oT8INnViuX04U4JQcmO8I gt08j24U+FdqQbuy0dQ70mrftWI2TVFzkeJK2zQzL9TektLthv3G/TZFnNSSayDvpZvU jvhBYXvXppy/GOsqL/CXGPtgZlDbUuzpiNCZ7f4HFHFCkH2Uj2Dqg9xta1MKckNiJfzF MLyzmrjAxsWaLfrqjUXtvsxrLc0R018hjXaJT22X+xNWX/eXHhVTE5I9Ksj79TujlHfX R+ZA== X-Forwarded-Encrypted: i=1; AL+hErHekO/wWUdjn1AaYEN8m729YXajMr4coenSrTTq6pNv1/p+BqN23wPvBwaII6ohoAqu73rntvq1rMNF9SI=@vger.kernel.org X-Gm-Message-State: APuU4Z9VFonyXoL980yBEq2IDcl+FeX192gzpgCjcQUI6aRuSDofzEXz Y5FhQJFvp8aXvYD1UTielaqRSTvra1h7QFA2OlNBLA9sKZ5wEePe4XTD X-Gm-Gg: AZFdTZcPb6pZCIZ4lDyntTbRgLMBU3rvGGaZZDPKnxay5BisG83zCdfWaT51qYryOAo Wm0pV1GuOWNwlKu7gJ22uCKhKLcSoQNxFG9oHmt6kVjX23P1sh4fzBRCU3fBiTq5QZ8Zd1N27zV y5rNLzIM2eKlkZsCFaH2e+TIzGhdp491cIAeTrUIHan21sMaTUP+ZK7bPVnQ2TptzsbyblnFs36 CpU7hADjq39MhE1XQK4CPkzShOB0rqLeUk8hwGQJ9lv1CpTGobuvExfOSCeeYqAUaK4ZV2IaWw9 m6ekWiXzUIpzZWPh7uhfuTFELz+CMz5UH3cruc243T1Yv/tmhbKVSI9dvVnTifFPXhsscUQA5Om cR7g0llqhu5QDKoF74/X+KXah7Alz3ooGlceHeiM9zH8KwntLBNrdlxffsNeg7Xn4bUPSs47WkY dL3N+rHUwI3WDif9sSR6sdVo//WQENPL0Jbwswdei62UCqp++w3LqOsFJXBhrn7071Fr8SjYglx UtAO1JIljPvqbBMxxPfUP9yOU7eg1ofLHuWlR1+YYhTW93WFy9rBPo5sDUdJfJy164iJUp8raVV 7vhBxEahK9rxgX/E+fNGcjV7uojKvc917Erlc2WBL4uQ4FQ5WJTAC6U= 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: 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 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