From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380185; b=kBR1wMdooDoyob0zx7J18bh9WN1pMbpupWrXJISAtl0BAJGVn56xvYNVxRGU5yhIT3Ib v/a/JYWAjbwGzjHdNblbEAcvkYMYNrR/odFC/y4N2JhA5GWvEw5wJjQDvHJXRJgyBdCzD +ifJej2eqEFNZum/P4yiQdL8cu8zarZ/dn2Oi8mz84tQWaxaZ8JsbhNqd77MgbUcPsRKV Bs6Vd15B6d8LXUpwc1UUhNQbLAMtRpKx5tWxz1trrl2Y8GPNDvGvLMhVHQ2WegQWrWXIW iJU3cdxxQNPpKCvQWvn8nKPlq3b6Tl6fQoHfVF1Y6v/gxlqggeKxYe9vvcyYxykddPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380185; 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=bcjxztZBC7nt7uOggykie7EuspGP2TjmJyfugNHmRJE=; b=1Vt93bhPacOhtnZhXeVUc74pSC887wBQRARXFIV5oB0vAtvsj3Z5OcQT8WE9fZuOXaWM dUTFSVec8PRcTTwrM6+w8kehrF7L3UYoFKLW0BhDRTLjbi8yRt79weJqQHqmRrSpV7ERc zkKyGXofS+rb7KnRrPJJhhe2ynGylEhxhLn03kJtlyjIpK6Kv+btvYpH80ZfZHXlZmPof sIQa3Op3a+ZRX7jCJPnUxR7SykikyPPD3S7LSsi/wM2ECfUM6Za0X8BIUhhKgiJe2sXdd KOamlSNf8c6+xgZpUj5vDLmCkFbAYldPPXQbvDegNIt0t7eWF3aoPZck6pH2tmbY0RQ== 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=Y3UkkTgS; arc=none smtp.remote-ip=209.85.128.48 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 AF1EF606A685 for ; Fri, 4 Dec 2026 10:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF1EF606A685 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=Y3UkkTgS Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4bb64c99d2fso6070845e9.3 for ; Fri, 04 Dec 2026 02:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796380183; x=1796984983; 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=bcjxztZBC7nt7uOggykie7EuspGP2TjmJyfugNHmRJE=; b=Y3UkkTgSusGJcvbikpgCWp5ZkO7blnqf0F3csilAYCU1j5f1ex4jE5GLbApF6vVhGi D9jOF1RyDiP7XQTgq81ATgvTDuebfuzIyzgj+1h6i2JO+SPMymr2VejVuH4ire8n+b+j oBKlLYbi5SI3CaVbBjN2QUtq3ApI56AhobJhrHopGyZB7pQqPxLzRdldrp7rvdzr9aLW oen5cfr/iAtk0gdYZlIZb6qmpfB+qO4nFwTc9PFrrv/DKPKIWj+Ym2uKSjm7GAiRAlvi xD8hOzyiGAJpwzyVjMMVs+rNgSKdGtMKXYyruzuIfPN0LjkbpaRszoNKP84FQa7/y26N aBxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796380183; x=1796984983; 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=bcjxztZBC7nt7uOggykie7EuspGP2TjmJyfugNHmRJE=; b=cmygmNy2p9R7fhdO5uBoNtZmE7+okI/5Tqi58GlGmeMMxkg0D9HInKAn0QeyEAVKWW z5aQ9kqHhBr58KXe8RrtYcsxx+nlytNm9renG9rkVsKzKWuYl7goJvirhkbMrgI7Au9B qXed+31bgiaW7Vj9CjrmKv+McpdSl74dLc4ttELbIkrMYTiV3bGY8fHiPAGivzV9LgEN mVjs1vhJKP+3X/6XGzpHV5gZIjH8ycfqI0bYrAwI/3czLUxSJCmMuIC4fVn7Ic+SbwzY 4+IBLWzt94mJXhd1Wq0jt3p8xAs5xy60G+4Di1ru47cWEa3PIBlITJGZL72u/TIxXbNq TIXA== X-Forwarded-Encrypted: i=1; AL+hErHBqP3UFxvoWPgXLmIpH9klP5yhk+deequeB1g+XG9S4++I/2nL5A07jVfSL9MGeyXms0tVjYp+xdVCDa8=@vger.kernel.org X-Gm-Message-State: APuU4Z8AVXkHT1tdJC+PqDTDS/krS/dkCpv91yq0K4Py2GPBSNOtl9PV IwLPSBn1idWrTnJ9Povorm5jXmjyt2gsNw7aU1TB2yA6tBbHaY48DVO/ X-Gm-Gg: AZFdTZdgztSLK+Dtbb7YF0ObrXuccoB+cy2ewm7V5PwkV5YtEPBNJN/rS5OBPXy699c 5x+EoIbDJ10Rc/RUThfcKEY4iDPH/kuDrVm727kyw44NhPfDNF+bPCQJ6pqfISFXKTZUz3gI63K zcxYbs+adEpatH1x3shnO+BbRxqGFP8N5AFg41Vn0twqtJna/j1YQx7nyfv0v0SLdvIsdecka6Q Zh4TQNFFSiOYiKqSr+jdcEwhLzm7r0lwmS42e8wZaRHJTt+H33iHuCOIu2Cd8zfNBmMIptjGluU xvL4hYRJl8RQjSq7BwQBK+CmJQrKCqxR0QI+UMVFfS8MQ6UOFhGmtw0nL2QWax38v/STk2HQ/II x0ZzSEcjODPVcpHWQKfk67sVy7wibsdmDsP6kbJQtk31XJbtiNc5xTUkvXxClweLnq2cGI5P8Rs M7PqrtseFC8HkM0oOIUFsqkm7ROR+tW2l+nvsVZFlVKbHT4xhMLN9DdytVwHYTcaw135GICs/7k uB/nXxG9Ci+DwBxUlX+GMTHBh+ntV8GyibEDCRQ1t5RU6S1reHjLxd653cOpUaazhEYwrZf9r7u 26dWPEFBzd9YYsE2uqFgCCJ8xtLNGbxiQSRyLVIMv8Cd/F0iqCXOQ7w= X-Received: by 2002:a05:600c:c163:b0:4a3:5aee:2c25 with SMTP id 5b1f17b1804b1-4bbeb8d09d6mr30005375e9.31.1796380182883; Fri, 04 Dec 2026 02:29:42 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00792c9sm151759815e9.3.2026.12.04.02.29.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 02:29:42 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 11:29:39 +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 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() 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 , Sashiko , stable@vger.kernel.org References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-5-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-5-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: > memfd_alloc_folio() uses hugetlb_reserve_pages() to reserve the index > of the folio it is about to allocate. If allocating the folio or adding > it to the page cache fails, it undoes that reservation, but only if > hugetlb_reserve_pages() reported that it actually performed the > reservation. > > If the index was already reserved, for example through an mmap() of the > same file, memfd_alloc_folio() must not undo that reservation. > > However, if hugetlb_reserve_pages() races with another reservation for > the same index, region_add_limited() can reserve fewer pages than > region_chg() counted. hugetlb_reserve_pages() will then hand back the > surplus charges, but still report the number of pages that region_chg() > counted. > > Consequently, after racing with hugetlbfs_file_mmap() reserving the same > index, memfd_alloc_folio() will undo the reservation of the mmap() caller > on error, and a later fault at that index can fail with SIGBUS. > > Reproduced by artificially delaying hugetlb_reserve_pages() after > region_chg() during IOMMU_IOAS_MAP_FILE of a hugetlb memfd, while another > process mmap()s the memfd, and failing the page cache insertion with > fault injection. Once all unreserved huge pages are in use, the mmap() > caller gets SIGBUS on fault. > > Let's fix it by only reporting the reservations that we actually added. > Other callers are not affected, as they only care about error vs. > success, not the actual number of reserved pages. > > This has low urgency, as it requires an allocation failure after racing > with an mmap() of the same file. > > Fixes: 717cf9357325 ("mm/memfd: reserve hugetlb folios before allocation") > Reported-by: Sashiko > Cc: stable@vger.kernel.org > Signed-off-by: David Hildenbrand (Arm) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a