From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DDCFC8303C for ; Tue, 8 Jul 2025 07:27:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D80CC8D0002; Tue, 8 Jul 2025 03:27:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0B328D0001; Tue, 8 Jul 2025 03:27:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD19F8D0002; Tue, 8 Jul 2025 03:27:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A8BDA8D0001 for ; Tue, 8 Jul 2025 03:27:03 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2683A128B99 for ; Tue, 8 Jul 2025 07:27:03 +0000 (UTC) X-FDA: 83640265926.08.D03BAA3 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf20.hostedemail.com (Postfix) with ESMTP id CE8911C000C for ; Tue, 8 Jul 2025 07:27:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=EF1PF8Jb ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751959621; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=reVmejc4cOPygy1WONqUgsz18oI63wpfc0pQGOwsw0Y=; b=s0m5LwDCcpr5ObWn6NHTfBQoLbH0GwIAH1ch7vTRsNKfdpi/ukz7GeFH9bet5U+ukqsqTr QRO+SujIzHjCyZ1tzNIi450NPi7/vHps1bnUA2ea1Bpc7y3vF6nCJHMDAIkIIRIeh1go+z XskwxH7WDROmE3OicVPDa/2IMD0bcRs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=EF1PF8Jb; spf=none (imf20.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751959621; a=rsa-sha256; cv=none; b=YDOdZL11OhIWGSdF3z/z0OPMXI7WRuEhq0D/EPxCdE3q6qNV0BbOfUSlBvLnuuztiDM73O 3DECfeO5JLz6sm0w3extlnG+xV+KA8cjPBMftyr4pEuJUq/gYCMpiQdi8aiIthwaHrDqNJ lO9rYPOBCiXChcev3XWQm17iMBMbWAU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=reVmejc4cOPygy1WONqUgsz18oI63wpfc0pQGOwsw0Y=; b=EF1PF8Jb+36WCTmR2ZWD3H7j+n kmec4/q/ZJgK1AKlZ+X8theLxuaAf08viSvAkdiOge8rq44UU9WG3PEyqEEoiuaBQUWAeP4NqfeIn +RMmdvTkRfc/dWhOemYU4lSztyvKIVbEMaPZhv2a0bf/qRC4AaSdlpypu5i683PnzmumsMs9KPDgR V08kx/Tt0Hx4p3X0qMhEH7bmWbLnQiobyQEzbDYm6fc+bHlEJU0Rk7Gn6UY9vEH8gntufzM7GjO3F OGQ7HWDtnHAfA6XFynKgRWD/to6FE0naKYdXQGOXyPsE1045yKDIBS3jFocSLghhNl4x4BSqcsJHq /+cNhe/A==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uZ2j3-00000008hjG-3gs8; Tue, 08 Jul 2025 07:26:50 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 72B3B30065D; Tue, 08 Jul 2025 09:26:49 +0200 (CEST) Date: Tue, 8 Jul 2025 09:26:49 +0200 From: Peter Zijlstra To: Mike Rapoport Cc: "Liam R. Howlett" , Andrew Morton , Andy Lutomirski , Borislav Petkov , Daniel Gomez , Dave Hansen , Ingo Molnar , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , "H. Peter Anvin" , Petr Pavlu , Sami Tolvanen , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH 3/8] execmem: rework execmem_cache_free() Message-ID: <20250708072649.GC1613376@noisy.programming.kicks-ass.net> References: <20250704134943.3524829-1-rppt@kernel.org> <20250704134943.3524829-4-rppt@kernel.org> <20250707111102.GF1613200@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: rweur4f1y3cuf1hsf83qcnfe199kzgb7 X-Rspamd-Queue-Id: CE8911C000C X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1751959620-26281 X-HE-Meta: U2FsdGVkX1/gdzv2XnKmo0EptKI804kkkZItEMEmGV+mb8cFz6c9BchGuj7CGAZS5T/ieAuINT7+KNDpAEb3lF1NOfd7YcwFY4xeZ2gGcJG2je4DwJ4ORTL2/rOelgb4c4svYjLrp930xEMSiz7wdzaZ0y4JF5YABYFPMMaWit5VI8mmTIGsmpcyuVb4Nd3xPzrOOHuqOJ6zak+qH7HCgec1Nqlc8SWfRNjqqlGKgtmxOhAihuDBEkVhG2kEfdd2X8d6/EMufnLVeZEp3L+oabfp4kOuV+C6N3Dp2i3GPPGTJHWMJwj5EgfO7vF7Q2Ca5REFFFfkc0xkgl6Dd81SazPjxRSMtztevJXp4FUXSvNPBzLoTALe9KF6KFhJtExQt5AjbToSyHtfAEjwXWIcdaBXI4MD/8/9/iSMm2HDo0TJ5OBg1pKxrRvO+pDhOhYtXo7Xn8ApnkeRFtwkGWUlaClciAmLj3/26EpMAsDtQKzo5L6b4tmcVLJrK/SORcW+3Vye1Yk8JZWUHUyT/oH7hysCY5UnDBaHujaSzcIX/lud58EgtJ5MLgyAqGJtl3w6Zha+ziNJwNyAaQsytp0VoDsavRqeWS3I2S43lFLsQFNW7IsDgBUzSBuMTUAeoY4SMYa/2ON5fGswNl9iqb4+CBDeX6ypAPJPHEebFFgjyL4rXz5gnYY5B/3qknkdesK8m3Q5m+WMcwltYj6XiOVMtHbs4X9koHNIiM3997XPfwU5JHKjlXu8n4IjQqJ45gvEdz8q7DC16hbiB+W70VV6Ggxbxv7P5RpsSdiG3DeoykkXzNgGyvYZ0DYmMxOIwoYbAO402saoSyWBA20cKhaWYjTXhy71pUcIarPWd5HWT6kvW5jHUOuMSGBRmgVPRk8hPea4FJ8QDk0sy47odpmXQ3Ihg71EdalvwIlwDxOGCAzESW/FcT8yhywh3aCPJzHXth+dCbfzjsVK9q8qlic znk8mxWi VudcRKb7sqDtn6UfmVyP4jWMn1a9awnt6T9cqfusOswDjL/eZiWc1ZhtgNsQavrzwLIzjL5wDFmoCp3Ewk9MggeL+xtg33tZ0xhYZU/okCekic83T8NN2KKCzUrJQsCMCGnWtw8c9uqX2DE8q4T/U+1p5iBjg+LYt4h3bxM7zq3yJ3SqpfFbnIKZyka3Ees4rVXvciDLaEeisw4THxG03Te2Y1Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jul 07, 2025 at 06:12:26PM +0300, Mike Rapoport wrote: > On Mon, Jul 07, 2025 at 11:06:25AM -0400, Liam R. Howlett wrote: > > * Mike Rapoport [250707 07:32]: > > > On Mon, Jul 07, 2025 at 01:11:02PM +0200, Peter Zijlstra wrote: > > > > > > > > err = __execmem_cache_free(&mas, ptr, GFP_KERNEL | __GFP_NORETRY); > > > > if (err) { > > > > mas_store_gfp(&mas, pending_free_set(ptr), GFP_KERNEL); > > > > execmem_cache.pending_free_cnt++; > > > > schedule_delayed_work(&execmem_cache_free_work, FREE_DELAY); > > > > return true; > > > > } > > > > > > > > schedule_work(&execmem_cache_clean_work); > > > > return true; > > > > } > > > > > > > > And now I have to ask what happens if mas_store_gfp() returns an error? > > > > > > AFAIU it won't. mas points to exact slot we've got the area from, nothing else > > > can modify the tree because of the mutex, so that mas_store_gfp() > > > essentially updates the value at an existing entry. > > > > > > I'll add a comment about it. > > > > > > Added @Liam to make sure I'm not saying nonsense :) > > > > > > > Yes, if there is already a node with a value with the same range, there > > will be no allocations that will happen, so it'll just change the > > pointer for you. This is a slot store operation. > > > > But, if it's possible to have no entries (an empty tree, or a single > > value at 0), you will most likely allocate a node to store it, which is > > 256B. > > > > I don't think this is a concern in this particular case though as you > > are searching for an entry and storing, so it needs to exist. So > > really, the only scenario here is if you store 1 - ULONG_MAX (without > > having expanded a root node) or 0 - ULONG_MAX, and that seems invalid. > > Thanks for clarification, Liam! > The tree cannot be empty at that point and if it has a single value, it > won't be at 0, I'm quite sure no architecture has execmem areas at 0. Would it make sense to have something like GFP_NO_ALLOC to pass to functions like this where we know it won't actually allocate -- and which when it does reach the allocator generates a WARN and returns NULL ?