From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796472919; b=Mzo/tQmH9IAaMoCMYdEBqkyDCNAZRwELlY3EBXh4SfUXG8NyIS3AyUcQuNwr+KxVUr+T q5oWRoS5uhTU6yL7bx1haVcjJJ1kNA+gdILS/+aDkzQJs2xVdBXtY3j62yHvJldBm+oMJ VFQiVNGWG2zGSrjBaFQirtZvIdv7Y9Sgsx5pC7meetmEXoi7x7pUiFakgiqOuvkpr5g8Z D1YDrzymcfWibOdj2qXSe83zkaAszYAw8Osbbj3ol4aJ+ow6SQJRWcUg2QTRxXXWl1u6D kTnpu57B+zx/lh+WzKh/brzlgR2effbtFx73r/W0mfkCpvW0SKDUKdyoeK7nSZSMiCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796472919; 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:From:Subject:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=jbMVXLvwYKnhuWKZxe+kf+aMdugxjeFDaDgYMazM17I=; b=CbQVf/IKa35fltNsELKlFNMycRy2xXEZ/Jjd0zy2BV0/88xlp7J8JXfrYo2KRIp8DVyT k5m6JKPNjGOaQyiMuyGRTuxnPbCUlj8QnoGChoT6pfHH/olxiu8G9//jSgwXRc9zrJ74V hMChY/Ks9SeVVLkKogUAu6O0wn/ZGtmU8ZeItFvuI1wtOjBqX5tlxIqsXtGxfcO86Y6lb wWK79XbQit+e6R4Nm94o6Mx7uBrF/nLcJg/jnnleQFsvR8M2KM1XAd+SuyJvzc1oT3xnH imgkXYB43u03is+Hr65qB0TZUckePqu3hEmzpYoBE0on5DmBW8njVLq8emB4TEhsifA== 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=ItzA13Ia; arc=none smtp.remote-ip=209.85.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 67A6E606A330 for ; Sat, 5 Dec 2026 12:15:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67A6E606A330 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=ItzA13Ia Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so18058425e9.2 for ; Sat, 05 Dec 2026 04:15:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796472918; x=1797077718; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=jbMVXLvwYKnhuWKZxe+kf+aMdugxjeFDaDgYMazM17I=; b=ItzA13Ia08Bw/W9IUsfSm6ad7oZsQbk1MSxtd8fX8XUCF9AhOLxrFxUtKz1dVgu3oy gWczA1n0qsvWGBlkTNHgO2npk5aM07OhSd7lZDqoFIsubVcKSH3Dm0owJoyCEgQKWirL Negyjld4v1+C6IzSJ5Qbgs4EGR5qO6PvGMNop31DmcyWKCvFzELa3W6+HHzWS13WmT6G +pSCyMhetKmkYlqCttdpmhdbGSgIfDGv9os309qZs1usxixxSMRIVnFpXCUmcd6FZgQW YetuAHlqFhqf2ya1rRFJt9KYlOiy0M5ZgdaJVwS8kgkZEnXlR9mDToKpJEuDL+fcB8Lb Tw8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796472918; x=1797077718; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from: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=jbMVXLvwYKnhuWKZxe+kf+aMdugxjeFDaDgYMazM17I=; b=kFcsj/tHZARY2qaUvQBtGdAWgkDvyOIHcVkQyCjF7b/KdJ+cpETOtpW7y0Qksj0I7Q wmyxJE1QZDEd3E16aOVbdsOpC7/GQ/2psYfdFMwK4l1pWhkci4Dhc7UGggPVnYzeJzwA L0ckILdYsDjbc9Wx6gxv41Ab/WS8mxjC1pHh6mpWTK6fr2UvYLPQtRZd2XvGTZ3RwXvf uSkVZAWvEX4PhHz9I0SOjEutVvHh+M/lu093kjIcddNS/1F+pKXLaSmPKWDKnm2SiX7z Fbi749h4lR36TileMjZILf/RhoLwNDSla9fiHSryc8JLndMz2xrOEnIZoDeKvFD35yqT YTEw== X-Forwarded-Encrypted: i=1; AL+hErEGw39D2JLQOboL58ojzvev3jPKi5o6tO4b02k61SYeNPdop+NN9zp33NqEWpZhmutK3SLJTMKqT+KFzvY=@vger.kernel.org X-Gm-Message-State: APuU4Z+66BMmTtQQtKyZKYmVBBmjhYCwtj62ORlhMnnhOVl7ZzN+fSZV qxZBXHZVHTGaScV3NweUnwv9B1Mm02R3EnsKJBZny47ZQjImlKgC0mG3 X-Gm-Gg: AZFdTZdB8BZhk3jXilj5Ikg/nkmC2wjHfOoVfdj3AzpCqFiRqleeJKOLdfFezFRfZEX CkN5z4ejjdPww/53Zfx6AzRkyYtmUUWV4BOguFqkeklnlm9iWb35F1FOtI5P0gOCfbiOPTwzTMj sEvpFXs9y0FqgtmNEjHdBM/+YcilGFC1Xxfit0f588uasI2hiq0PumyT5R/Q8z2jAQ6ibiTfdSI u9BdkxUFUZxrMx4NjLfoosGZ4UKBiZLItjEVQCkOWJs7FLL4u3hiW3X5t9/QxIKYlvx/DxqAI04 n5DdSsEHZJBagpOJum1ePsnFA7WoaNGd0Fg+LZQNWNCqTwrB64scuh8sJ4DWl/yn+Qu+iRZ3aCT BspboO987yyHP7rExdvhb9WSiGTNdTJ2C8Pwjm/7Zp5uqGtNPjXGQ5utICNUeXubCti+2CmgAI1 aI31475DR1dN2E0s8vMPCcoy241CtvQhDSQK3ODor0hWkRq1F/YYhbZ+OsamRSvsdekm/wkyTub 4E0yTl17J2j15QdLX4CVU7k7X+ScAkH3WAUNU+Cdj2XjaeHrmevJR8XeeLedEtekXQrm53c3vNo VTIl0MRYfMpYBu6OWXUozjKWU6tccGUs7A7YgTSOkvhIwdeitBA8WLU= X-Received: by 2002:a05:600c:314a:b0:4b7:6aac:7406 with SMTP id 5b1f17b1804b1-4bbeb6ecd1emr86426595e9.3.1796472917530; Sat, 05 Dec 2026 04:15:17 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1724ace7csm10020067f8f.14.2026.12.05.04.15.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Dec 2026 04:15:17 -0800 (PST) Message-ID: <63224c35-36b9-4f9a-8918-c34d6631770a@gmail.com> Date: Sat, 5 Dec 2026 13:15:13 +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 From: "Jose A. Perez de Azpillaga" Subject: Re: [PATCH v2 34/35] mm/hugetlb_cgroup: charge faults to mm->owner 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 References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-34-9bbeabb555d2@kernel.org> Content-Language: en-US In-Reply-To: <20261203-hugetlb_fixes_2-v2-34-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: > We can bypass hugetlb cgroup limits when a kernel thread faults in > hugetlb pages for a user process: __hugetlb_cgroup_charge_cgroup() > charges the hugetlb cgroup of current, and kernel threads usually live > in the root cgroup, which has no limit. > > For example, a KVM's async page fault repeats a fault of a vCPU that > just failed at the limit in a kworker, which then charges the root > cgroup: > > vCPU thread kworker > =========== ======= > __kvm_mmu_faultin_pfn() > hva_to_pfn(), FOLL_NOWAIT > hugetlb_alloc_folio() > charge fails > KVM_PFN_ERR_NEEDS_IO > kvm_setup_async_pf() > async_pf_execute() > get_user_pages_remote() > hugetlb_alloc_folio() > charges the root > > Let's fix it by charging the hugetlb cgroup of mm->owner whenever we > allocate or reserve for an mm, like memcg does. If we don't allocate for > a specific mm, we use current->mm, again like memcg. Unlike memcg, which > falls back to the root cgroup, we fail the charge if the mm has no owner > (anymore), as we would otherwise bypass the limits again. As mm->owner > depends on CONFIG_MEMCG, nothing changes without it. > > This changes the charged hugetlb cgroup in these scenarios: > > (1) Kernel threads that fault on a user mm, such as KVM async page > faults, kvm_xen_set_evtchn() in the irqfd work item and > iommu_sva_handle_mm(), now charge the cgroup of mm->owner instead > of the root cgroup. > (2) vhost kthread workers, which join the cgroups of the task that > created them, now charge the cgroup of mm->owner. > (3) With cgroup v1, threads of a process that are in different hugetlb > cgroups now all charge the cgroup of mm->owner. > (4) Processes that fault on the mm of another process, such as a > userfaultfd monitor (UFFDIO_COPY) or remote GUP through ptrace, > /proc/pid/mem or process_vm_writev(), now charge the cgroup of the > target's mm->owner instead of their own cgroup. > > ... which should just be the right thing to do. > > This has low urgency, as it only affects hugetlb cgroup limits. Let's > not CC stable, as this might not be particularly easy to backport. > > Fixes: 6d76dcf40405 ("hugetlb/cgroup: add charge/uncharge routines for hugetlb cgroup") > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a