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=1796384790; b=t31Zr0DkffcWl2KiBK2h03pf8PASX6ILKbTWfWJGoWEniqij8sdN9V9/luvx/MrfslD9 vRNKv0bvkV/GCJmNfngVkhvuMlbTpN/UyLWiry3Augw2WSJyGkk9Vr+L1pt4+pW4LFPJR 24azgnozElyI/WUe5CzDsLlibyZNcY4jYs0FbTK4RB/havei+sv4bSMBwNFchfjPg0RMF 628cJXecYfpLadwQyQgupyGezoH8nk8UArPnFSUxQrFhQKdETwiYurGGU/Q4N73/uytPU 52DJIGpWR7qSZFM+e1iwnO1JuFxvBJ+MSR06bP95rWzn+fwpj2So4ZoY7C+9B5qsbRQ== 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=ENxXweZl/HGqt+J6xnZbAxbkdbNS8rfG9y+Oag1KXz8RosEeK4XAFA0QmDYDlLy2+gKg OpStRspEOUAUvYqi6KlvDrGN7IaT6anHsxdWDoinzL07fWYXD7a7N6GsZNHtJWkdStcAY Eefq4BW++oH1ihDxncG/VUQiiHNFGKGu+clztsH6s3J97gNNzy8Z+KotG4QMAlen8QW2g ulMf24TZvc38dhrDqqXqcaZytL3UNPWJLT84athClyOHo5WUA4/LTo7Fku+6y2rAPnPoX 5HrHR9te7lTrp6Te6moHsrDc/bzZJo4LMU5GSv44MGngf66KBC35jlWStwdg1lasUIw== 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.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 00C9E606A330 for ; Fri, 4 Dec 2026 11:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 00C9E606A330 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-f53.google.com with SMTP id 5b1f17b1804b1-4a1fbd52ab6so5729775e9.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=NTm0iYVOBnSBnCuTfb+Z6IJNgsJ/z3JozLgEmSkgR6sqhHRGmEOF89s6GsPOHx7tj+ rG9RplVF5+WFmGTxFkf6PA4wqEyl/RqFjkfAUWem5lN1RG1hQ5P421or/lDft7lR4JOt mkNiXdppIiTIONmtU/ZR7fZRatbw1nsszafo5B0D8+8pfQbg9Md84cLOK+nAP6QGVOir sUYM8xTL43fbNeP3gTVkbLe3cS0yeTFosGJOYij1py8EAGx1zmRV4TM20DSTfo59kIAl dTaFas+FeXhegWLkU/ce9KK+ZuO307sCKaJoqwCpKEjM+YmuPrxLou1FybbUlnTSYBeG sKlA== X-Forwarded-Encrypted: i=1; AL+hErFK8CWgoBHKLY7A5XS8cm0DFepcor40oiyI3tncyb7LJ4eK1244fuocIANXN2ISzaAjHVKEiRDHSx8=@vger.kernel.org X-Gm-Message-State: APuU4Z/ij0zS4nIMq3LolC5WJKQnil0xcyP25cntWJvU/KLQte/a85N/ okDmuypHKOzlytE+RtzbkdyWVBi/SjB/jqJfIkqy/wzk2p7uFHgQZGIu X-Gm-Gg: AZFdTZd1ofsa9cPiTBMR8qGKLXki/8pu4hrijXviyozuZf9pdEUSpEqk4RXBV2gKiMF aP4oo0A4JXmOC0A5USdwI6KfrMlRWYmCMhNeigcK5erCft/vTJX6pu3rbMLs/y0KATd37wWPHlp FG4hKeNThqBrjEhyLSKC5wm75cIzHGp/8OFC3McZkl1IGRQ/nuwuLtCLoxmqvQ6FxRieSbIoxFC 9i8FNGu6KSdFDTV1j8DTvExnUyIpBNP3CiAvRv/kLdv6oZ9wZh9UVadsHF5spn4sMWaeeoTc2DN 7LtlGQ670qqxmklQBu5rw8/hHDNbXSv30GUvJ8ZCR3BkIq04t8wtZbzywhGnJmjmfP7x35Gkw4O 89Gup5bQNLgHTzE5uyyuNH/WBJUwV58Op24tf/qgQZiuVLvRBfz/Hq+L4F5Zs5dx3yCWZnmUfi2 RLeAgSlgackibQICeFeLCK1ac5HLzX1x8fgrKS7SPt74JMKKmjkcQquZ3cK0eKbqp/wEWwwXiyM fcBwFhNTKOAlPOWg8Hz9s7GGj9+7hTBRBvaCSomYovj8Ws29/Tz2mL2Ez1d5Z/KjUQD397FxGOY LZzqlPI4qNKhPHoJMn8H+eO4MeOgWO0W3uWOpdeU4T1L72JCIbKPkrQ= 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-doc@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