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 D7537C3601B for ; Thu, 3 Apr 2025 09:10:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8E6D280003; Thu, 3 Apr 2025 05:10:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3BDD280001; Thu, 3 Apr 2025 05:10:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D02D5280003; Thu, 3 Apr 2025 05:10:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B1607280001 for ; Thu, 3 Apr 2025 05:10:02 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7ADB9C1E0F for ; Thu, 3 Apr 2025 09:10:02 +0000 (UTC) X-FDA: 83292160644.25.D1A1103 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf03.hostedemail.com (Postfix) with ESMTP id 364782000B for ; Thu, 3 Apr 2025 09:09:59 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Jf2ctPoL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=r74Dtkjs; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Jf2ctPoL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=r74Dtkjs; dmarc=none; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743671400; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Zs6atIuqWpPN4lEFGJe1apHKHtKrhoP192orQSgXjdE=; b=vDfL0NinhwJ4dDPSJm62U4OdGMCeiLNyIebunYKOBdXFaeFXUrfn5J1y2jR2kmjBXQo+wv NwSLx/G4DrlOk1C5R5ceNYzuNt6vIxsQYhRiQs/Y/4cmqpMNenF8k3smaU+WFYv4q1nNCR lXgLMYWQBR2di+Njn0cP0Xczp6aWPQ8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Jf2ctPoL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=r74Dtkjs; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Jf2ctPoL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=r74Dtkjs; dmarc=none; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743671400; a=rsa-sha256; cv=none; b=3vG6hVXuxkKIV5GR9yMLDXagW+9IJP8ifXJBO7xoVK9yCUrcxaHnkwqZLRd2GYXG+IGXXC CS2qpNpbMWDl9cjHF6WwO/y260ApCg4LEkur5NCuGC210e5cZl0a0h7IMEnv8NN+CpinkH YNb5VDhiyiFh+WUzeOMd831jKs22YvM= Received: from imap1.dmz-prg2.suse.org (unknown [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 69F661F385; Thu, 3 Apr 2025 09:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1743671398; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zs6atIuqWpPN4lEFGJe1apHKHtKrhoP192orQSgXjdE=; b=Jf2ctPoLw+9eqnbDiBxwHWRRYdaAokyiPC6zyUFxb394F715kljGMU5IHg2ZrFd3cHgLwi 2ScUKkUDX4RuD1EWBz0g78imjTFrVZ3rQuzl+pQjPXoIskbrx7SUOgj5zEvjZb/O9n90iS JM95pblnr7x5kors/5rEQVbEudmW+4k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1743671398; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zs6atIuqWpPN4lEFGJe1apHKHtKrhoP192orQSgXjdE=; b=r74Dtkjs4whoZ8fRok7/dhf+dGMIPKcf3Vj1vlBZptk1vRnrK8L13Vsr3bde6ds1S1HrSm Io/aN/mAxspXMHAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1743671398; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zs6atIuqWpPN4lEFGJe1apHKHtKrhoP192orQSgXjdE=; b=Jf2ctPoLw+9eqnbDiBxwHWRRYdaAokyiPC6zyUFxb394F715kljGMU5IHg2ZrFd3cHgLwi 2ScUKkUDX4RuD1EWBz0g78imjTFrVZ3rQuzl+pQjPXoIskbrx7SUOgj5zEvjZb/O9n90iS JM95pblnr7x5kors/5rEQVbEudmW+4k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1743671398; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zs6atIuqWpPN4lEFGJe1apHKHtKrhoP192orQSgXjdE=; b=r74Dtkjs4whoZ8fRok7/dhf+dGMIPKcf3Vj1vlBZptk1vRnrK8L13Vsr3bde6ds1S1HrSm Io/aN/mAxspXMHAg== 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 4BFAE13A2C; Thu, 3 Apr 2025 09:09:58 +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 wRqNEGZQ7meBZwAAD6G6ig (envelope-from ); Thu, 03 Apr 2025 09:09:58 +0000 Message-ID: <5feaf4c7-4970-4d9b-84a2-fcba2cbe0bc4@suse.cz> Date: Thu, 3 Apr 2025 11:09:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t type Content-Language: en-US To: Alexei Starovoitov Cc: Sebastian Andrzej Siewior , Linus Torvalds , bpf , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Andrew Morton , Peter Zijlstra , Steven Rostedt , Shakeel Butt , Michal Hocko , linux-mm , LKML References: <20250401005134.14433-1-alexei.starovoitov@gmail.com> <20250402073032.rqsmPfJs@linutronix.de> <62dd026d-1290-49cb-a411-897f4d5f6ca7@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam01 X-Stat-Signature: 5hwk8ne6os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PnlG1kUV+rrPr6Z6ByBzTTNHDKIQMHKWZ4scB7fI/VTTsh7vKhc3A9cJuUXuJ7KrAsX/hLbVBsiWHzf9/Gw8Q== 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 4/2/25 23:35, Alexei Starovoitov wrote: > On Wed, Apr 2, 2025 at 2:02 AM Vlastimil Babka wrote: > > This is because the macro specifies the type: > DEFINE_GUARD(local_lock, local_lock_t __percpu*, > > and that type is used to define two static inline functions > with that type, > so by the time our __local_lock_acquire() macro is used > it sees 'local_lock_t *' and not the actual type of memcg.stock_lock. Hm but I didn't even try to instantiate any guard. In fact the compilation didn't even error on compiling my slub.o but earlier in compiling arch/x86/kernel/asm-offsets.c I think the problem is rather that the guard creates static inline functions and _Generic() only works via macros as you pointed out in the reply to Andrew? I guess it's solvable if we care in the future, but it means more code duplication - move the _Generic() dispatch outside the whole implementation to choose between two variants, have guards use use the specific variant directly without _Generic()? Or maybe there's a simpler way I'm just not familiar with both the guards and _Generic() enough. > Your macro can be hacked with addition of: > local_lock_t *l = NULL; > ... > l = (void *)this_cpu_ptr(lock); > ... > tl = (void *)this_cpu_ptr(lock); > ... > DEFINE_GUARD(local_lock, void __percpu*, > > then > guard(local_lock)(&memcg_stock.stock_lock); > > will compile without warnings with both > typeof(stock_lock) = local_lock_t and local_trylock_t, > > but the generated code will take default:(void)0) path > and will pass NULL into local_lock_acquire(NULL); > > In other words guard(local_lock) can only support one > specific type. It cannot be made polymorphic with _Generic() trick. > This is an unfortunate tradeoff with this approach. > Thankfully there are no users of it in the tree: > git grep 'guard(local'|wc -l > 0 > > so I think it's ok that guard(local_lock) can only be used with local_lock_t.