From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384791; b=jda9LbsWS8uXWlhEzPrzqme490j3nkzPksHFbo9TC4pxlJBWe1Pd5C0XO1l7nBw3JqT4 wYIo4+vDQ5Pd8xoLS3BXGBy9vS62gildCsDK43D31Ic51CFoxSvJhzNYhoWUCaYutNXkN mwKmyESw3dQ83T4ZBBZRu14h5lbbCMKiNgSHaVymapcP7VWCvpcsSiJeZGk+16Y4gL2k3 1jgotgq8Ps3zyY8hG8SfQ2AMcw51co9o2Z08Sn9R+VMAhpTZiQGSZ1uOT5whuZ93ZFA6O IXAWE0p3Upm/NEyK82Wusd6WR266f7KqqCACt9F81nP9UH5IWUTykfJpsXVKGqruFZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384791; 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=mZ81AKEJ132IrVeHHXAgaSVTDNXKOxMcn8PjcKoLXZ4hUqM/jrrQ4BdLitCGCuCkfsQp sxuMpmdLGPvJsXnlbzJIpgtizGTED556AIQ+VxppA04pY/b5V4zSfkcv8/oM2RumNgEuP Zkz4T6oNRjaRuDizo9PlOrh+iQSaMcz849D8s/j6DBYK+H5WXI1wdRwSfOQQGsMxRAdMl 0R1ipVlCS76OfNEaXAqZdvJtGEj+X55lXAqW8SRmUBnamXorPBVQ+wUbnL+7mpvFQeOTS 88m8coDjnp/WtCaqKap2gAWXdq+HjduEMkySIcAbscQKS7yI+BHhjF13DGjSXj7Epeg== 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.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 06B09606A333 for ; Fri, 4 Dec 2026 11:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06B09606A333 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-f47.google.com with SMTP id 5b1f17b1804b1-4ba013938d7so7094165e9.2 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=jsrdQ9RlZOFEoDGa4XgOneYzr66iaVZhYg0DyZPNeeHJ5FQJiNtuubcO0209oK/+9f lGzl1+q2/sB+YVgqj2aG/IMaUFWtUGgPYMIwRbPUZDR7N8fFx4vs+3Skp/z0XJkFcAdc Lqpdqcpw94t1Cr0Rsg4zrfcC6HXAFn+56cKZQvi+GcmLkR0243lWIMsS54prYxUr93WN npVZ+ht0ofC6lm/1cYhQ9/pBedc8L+cAe56652ZlK/w9nu4bw9132TlYsxaZwelfeKNZ eIm9w2NPUYtiig2b6jx333nAoO4oVIbAh5n9PI2wUGRW9JjcYrLNTe0GnLNZgTcMEpaD gNiQ== X-Forwarded-Encrypted: i=1; AL+hErHYKBiIZea2F3jffsU/OTT69BkmVPx6wdtW9SDz49W+QYlTiNDUXyKzaCLOBNql0eILB4qlu1P8tdWnqulQ@vger.kernel.org X-Gm-Message-State: APuU4Z8I8/ykY9L7bbUYh1NGqSU8w9rpfoO4DnXpPR9CsxbGbzrBoaxO BJual3hYCu5Osy8MOzYRaT9Hap2LU33XLIRkwzVXzQZcgj4aSL1t3azZ X-Gm-Gg: AZFdTZddATUQic4AtC1Qmx1YhfdkqYgXeB1LgBN6f4s/KVupwfWWHCK7v7CVUYYaDsb Jmjrpn1ku6tXYWEtsbS8ghz0rTk5ONTnjbUxhhT6oBNFB7sBqjcKRrAGaQDAZcn2pEJMGR+KYcT bPtXjNBURmuJFB0F7V38VKA8wFyccsrDpl3YrPVkkE4jcwFbsQvwo15rJuB/YAmXuUBe6mIC/6c juuWU+zCd/lDI8A3hijViKil4arHN9FX2Wapk+WGflvncmXjIfXyfTT/rQNK7853PlgMYU5Fw1w env/KYKChnBTEt/MMp7qMHfijeedjsIf1kvMTf9fZN6qjTwqGA3frgIQI4k9vRBiVc4F1+n2eF7 OD0iLHXsfr8N9Yb7WAGUX0FCmN00bCKuEbgyjuligBY4Y0K/WwZko5PoUr5J+HQVz+jl0r1PJSi xs1xMlbYx3/xUxH8UcM65q6jiFDCKmxjLqVRq6jZ1UZvd5VWGV/YbjJzSDqx1ecpRICNjuoIZOB KyhiBtZaf113ffqLbqQimJgRsjdRCHLc4Oc9IYCKs63XrzPc5bTebFtM/WnwnHxI9QhcFpleM6k H1ynauUe6QO00u0JK9MIa86vOlRb0HfmF6BH9KDTvI2vPA1o2+XfiVc= 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-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 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