From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793021939; b=Y9e/F+uZDi0f6aEHD0sKZ/KQR5gv4xlg+gsR0Cq+wB5RGmd2DrnBmISZtz0ENen4LATP sQ5ko8zGpXDYb4tdEg/fNZsVUM0/Gb+KtkqAHswQfidKZq0NJbNO42FTAY0r4VfQuSs2e bCkItVFLYplYoZtnUAFF2QkZ4WwRla1E8xnRA+sVkCKv3eT+ko8P4P9kWhnCoub/4Ix2C fnUQq6r5bRkkfmygUvyK76hcsSMNtLj+E5TLbzhDSgMmYh7rHg90iABNCurrm79xKe4sS za55nQi+r+U8nGzAZ6o8XAIpmxq8oxpowk5efp310eZCaFjg/a3SGqEe1tRY9tj7n2g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793021939; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:DKIM-Signature: DKIM-Signature:Received:Received:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-Spamd-Result:X-Rspamd-Server:X-Rspamd-Action:X-Spam-Flag: X-Spam-Score:X-Spam-Level:X-Rspamd-Queue-Id; bh=J8msHD21z81Jfe07/YVkn5bSt0UwqtrZZbU29bnedd4=; b=MtsSR/45AMSMnHpoDl6J0TGmJPiTUDRb+8+xBoad2fQvYMFSnCN8V5Nk0Rx9hk4HccrX wQZog5ZfDPemtPw8pixIpSIF5k++As//SxqC8YK5R6ps/GCfNxGfSWUQ7ZcSG/TD3faon 15Zsfd0O9VX28/+Mh7EZMrflYm8H3bY5puT2Zw5BSjtahPRjdmSjBaemtQmWwRPwHGfqo ojKgZh4uAuHGjURHVQetZDhJuU2//0AlsXwSOr9mAsV9pbX2IFoUa+nbsAQANUcnCa0WK vrcu7/5SeSLR+SA2mCChJm1s3M4/Uj9/MMF76AuOFgkD4tE/p0Bgw19U2thYOjoLZCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fP4jfNbD; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=LiRzvW77; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fP4jfNbD; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=LiRzvW77; arc=none smtp.remote-ip=195.135.223.131 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14B726072CD6; Mon, 26 Oct 2026 13:38:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 14B726072CD6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fP4jfNbD; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=LiRzvW77; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fP4jfNbD; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=LiRzvW77 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 39DC51F786; Mon, 26 Oct 2026 13:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1793021937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J8msHD21z81Jfe07/YVkn5bSt0UwqtrZZbU29bnedd4=; b=fP4jfNbD1FR5VVI/DTKWhcq7P+Y9GJUxfi1o6dM2weL2quwWjcS5bomyCLz9jOIzLInfl0 E809AnNdxpKzM7SEbLyB3yRa6bOdj+KPb3BSanzkQqtwN2IkfLrBEWLlbQp89tdS0vycOn HMbJ+RyFbH66tgPVLHQxngpG3HrPSQ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1793021937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J8msHD21z81Jfe07/YVkn5bSt0UwqtrZZbU29bnedd4=; b=LiRzvW77nvqygtAgd0aQr7xC3bchc4P9JJzhqnzl9AdA3W5p93SKtt+j0KKfSN45EA6vUQ iRvU9WNmUfueZsCg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fP4jfNbD; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=LiRzvW77 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1793021937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J8msHD21z81Jfe07/YVkn5bSt0UwqtrZZbU29bnedd4=; b=fP4jfNbD1FR5VVI/DTKWhcq7P+Y9GJUxfi1o6dM2weL2quwWjcS5bomyCLz9jOIzLInfl0 E809AnNdxpKzM7SEbLyB3yRa6bOdj+KPb3BSanzkQqtwN2IkfLrBEWLlbQp89tdS0vycOn HMbJ+RyFbH66tgPVLHQxngpG3HrPSQ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1793021937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J8msHD21z81Jfe07/YVkn5bSt0UwqtrZZbU29bnedd4=; b=LiRzvW77nvqygtAgd0aQr7xC3bchc4P9JJzhqnzl9AdA3W5p93SKtt+j0KKfSN45EA6vUQ iRvU9WNmUfueZsCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7048A13408; Mon, 26 Oct 2026 13:38:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id KBSoDe5X32qCAgAAD6G6ig (envelope-from ); Mon, 26 Oct 2026 13:38:54 +0000 Date: Mon, 26 Oct 2026 13:38:52 +0000 From: Pedro Falcato To: "David Hildenbrand (Arm)" Cc: Andrew Morton , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Johannes Weiner , Vladimir Davydov , Michal Hocko , Hugh Dickins , Baolin Wang , Lukas Czerner , Carlos Maiolino , Christian Brauner , Jan Kara , Daniel Verkamp , Jeff Xu , Muchun Song , Oscar Salvador , David Stevens , "Matthew Wilcox (Oracle)" , William Kucharski , Chris Li , Kairui Song , Nhat Pham , Miaohe Lin , Naoya Horiguchi , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Mason , stable@vger.kernel.org Subject: Re: [PATCH 01/16] mm/mempolicy: charge shared policy nodes Message-ID: References: <20261026-fixes_shmem-v1-0-703206d5fa0c@kernel.org> <20261026-fixes_shmem-v1-1-703206d5fa0c@kernel.org> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261026-fixes_shmem-v1-1-703206d5fa0c@kernel.org> X-Spamd-Result: default: False [-12.01 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_TWELVE(0.00)[32]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[linux-foundation.org,gourry.net,nvidia.com,gmail.com,sk.com,linux.alibaba.com,cmpxchg.org,suse.com,google.com,redhat.com,kernel.org,suse.cz,chromium.org,linux.dev,suse.de,infradead.org,oracle.com,tencent.com,huawei.com,kvack.org,vger.kernel.org]; DKIM_TRACE(0.00)[suse.de:+]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgmxzz5wwb987hpmihmge51fg)]; MISSING_XM_UA(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -12.01 X-Spam-Level: X-Rspamd-Queue-Id: 39DC51F786 On Mon, Oct 26, 2026 at 10:40:34AM +0100, David Hildenbrand (Arm) wrote: > From: Chris Mason > > Any local user can bypass memory.max with mbind() on a tmpfs file, and > allocate unbounded kernel memory. > > mbind() sets a NUMA memory policy for a range of a mapping. If the > mapping is of a shmem and friends, the kernel also stores the policy on > the inode, in a tree with one entry per range of the file. > > Each mbind() on a single page of a mapping can add one shared policy node > (struct sp_node) and one struct mempolicy to that tree. They outlive the > mapping and stay around until the inode is destroyed. The tree is not > bounded by the file size, so the file can be empty. > > Memory that user space can allocate must be charged to a memory cgroup. A > slab cache does that for all of its objects if it is created with > SLAB_ACCOUNT. numa_policy_init() creates the slab caches for both > structs without SLAB_ACCOUNT, so they are not charged to any cgroup. > > Reproduced with mbind() on single pages of an empty tmpfs file, from a > cgroup with memory.max=8M: the global OOM killer killed tasks owned by > root, and the machine panicked. > > Fix this by creating both caches with SLAB_ACCOUNT. This change implies > that mbind() can now fail when running into memcg limits. Further, > the policy_cache also serves task and VMA policies, so they are > similarly accounted now. > > Note that per-file limits are not really helpful, as the user could > simply use many files; having limits per user is tricky as well. > > Fix generated by an LLM and submitted by Chris Mason in private. > > Fixes: 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg") > Cc: stable@vger.kernel.org > Signed-off-by: Chris Mason > [ david: smaller description tweaks ] > Signed-off-by: David Hildenbrand (Arm) Acked-by: Pedro Falcato -- Pedro