From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA162382F31 for ; Fri, 3 Jul 2026 11:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783077934; cv=none; b=hViDL+SFEXNQSieSYYTUC1x1G6LmVflacgBW5TMKXLRrK0reJ5WDnLrm5l+vRyegCTE4/ydQQJkwPy7Qs9K0DbWANr2YddrngTsdkO2oZJPykmZQYaNxaRx7aMPSyJDu43zZRzvruNeBqQSeIunGgr87dTXZWHdhfrsIbjyHPRE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783077934; c=relaxed/simple; bh=z3pGW6hOv1fA8gmDBkYs8QU1BjeVuZL/SAlikVDpokQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eRprDe9srin/N+kM1qkivWOFId9BcqsRkGVwqNl8OlPgAuPPl3IxXrzW5ZX1VSSUFqD9my7b4LbzXwdxNUJwjky02quAixeqAH2jLpm+RhMSH6vgURtd1m8OpLt//isYAtLoWa4tObwkUwZG5Od9mecH4Q7NM4lh6+0/jRPzvNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 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 Received: from kunlun.suse.cz (unknown [IPv6:2a07:de40:b306:2000::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AEE26758B0; Fri, 3 Jul 2026 11:25:26 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Date: Fri, 3 Jul 2026 13:25:25 +0200 From: Michal =?iso-8859-1?Q?Such=E1nek?= To: Peter Zijlstra Cc: Sven Schnelle , Thomas Gleixner , "H. Peter Anvin" , Jonathan Corbet , Shuah Khan , Huacai Chen , WANG Xuerui , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Andy Lutomirski , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Andrew Donnellan , Mark Rutland , Arnd Bergmann , Jiaxun Yang , Ryan Roberts , Greg Kroah-Hartman , Mukesh Kumar Chaurasiya , Shrikanth Hegde , Zong Li , Nam Cao , Deepak Gupta , Lukas Gerlach , Rui Qi , Kees Cook , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org Subject: Re: [RFC] entry: Untangle the return value of syscall_enter_from_user_mode from syscall NR Message-ID: References: <87h5mhnjsr.ffs@fw13> <87ldbsmnie.ffs@fw13> <20260703105718.GO751831@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260703105718.GO751831@noisy.programming.kicks-ass.net> X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Flag: NO X-Spam-Score: -2.00 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-2.00 / 50.00]; REPLY(-4.00)[]; RDNS_NONE(2.00)[]; TAGGED_RCPT(0.00)[kernel] X-Rspamd-Queue-Id: AEE26758B0 X-Rspamd-Action: no action On Fri, Jul 03, 2026 at 12:57:18PM +0200, Peter Zijlstra wrote: > On Fri, Jul 03, 2026 at 11:59:07AM +0200, Sven Schnelle wrote: > > Thomas Gleixner writes: > > > > > On Fri, Jul 03 2026 at 08:26, Sven Schnelle wrote: > > >> Thomas Gleixner writes: > > >>> It's less than obvious and I have no objections to clean that up and > > >>> make it more intuitive, but I still fail to see what Michal is actually > > >>> trying to solve and what the magic flag is for. If s390 requires it, > > >>> then that's an s390 problem, but definitely x86 does not. > > >> > > >> The difference between x86 and s390 is that on s390, regs->gprs[2] is > > >> used for both the syscall number and the syscall return value. > > >> That was a design mistake early in the begin about 25 years ago, but > > >> it's ABI now, so it cannot be changed. > > > > > > Cute. > > > > > >> When seccomp decides to skip a syscall, it write a return value into > > >> regs->gprs[2]. When syscall_enter_from_user_mode_work() returns, it > > >> returns this number. If it's negative all is good - the 'if (likely(nr < > > >> NR_syscalls))' conditiion would just catch it and skip the syscall. > > >> > > >> But if it's a positive number, the code cannot distinguish whether > > >> that's a return value or a syscall number. > > >> > > >> So I introduced PIF_SYSCALL_RET_SET when converting s390 to generic > > >> entry. This flag tells the syscall code that a return value was set in > > >> ptregs and the syscall should be skipped. > > > > > > You also could have added a 'syscall_ret' member to pt_regs, operate > > > on that for the return values (seccomp, syscall...) and swap it into > > > gprs[2] right before returning to user space. > > > > That would likely also work, but I found it easier to read and > > understand to have an additional flag with a descriptive name than having > > yet another 'somehow-related-to-gpr2' member in ptregs. > > I find this very odd; I would think that having both syscall-nr and > syscall-ret in separate (virtual) registers for most of the normal cycle > would be most obvious and less surprising -- given that this is what all > other architectures do. > > Entry either grabs a copy of gpr2 and preserves it in orig_gpr2 as the > syscall nr, or as Thomas suggests, you keep syscall_ret and copy that > into gpr2 on return to userspace (and ptrace and signal and whatever > other surface bits are affected). > > Either way around you then have separate values for the entire range of > at least the C part of the kernel syscall handling -- just like every > other arch. How is munging things in a single value and a flag easier? The same could be asked of syscall_enter_from_user_mode. I find it very odd. Why does it conflate the syscall number with its return value? It never uses the syscall number passed in except when returning it unchanged. When it pokes the registers it reads the syscall number from them. If the caller of syscall_enter_from_user_mode only read the syscall number from the registers when syscall_enter_from_user_mode returns and indicates the syscall should be still executed this whole shenigan would be avoided. Thanks Michal