From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08DE11BBBE0 for ; Mon, 13 Jan 2025 17:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.57 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736790895; cv=none; b=P/2sNQ6/fHk6+C1qlbuXcrYdD+xrC8nKzYpjELpk9FeWmGUy1S8woy6wde86MRuZZHEI0oys9tDzxFRabZk1AH6NbMjNJ+02dkZnvApYkEM5FHe2HrrjyUeOsq+3JU8b8v5kED6gRCFfWKh1RllPNygEwxnIss2bAjs3/U0FTqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736790895; c=relaxed/simple; bh=vma8F+QGByo24iMbWHwLKw9xrT0EWRZcCz2jHUUzhj4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UA/1Dkn+NMjagXho8A2qbhYA3LbVTCkSRBH791Xl0iFdukO4uuVaNZh4i4PEO29QvluEh/WdsvWjhjOe0r5nB/rQeGlMiGUUXl+RfUFTn3wTb1s09LWoJtg/hoVY58h40c66nFGmzFAwPYZrQOZitYXdo8hWXXlxgL1tXHXULnE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strace.io; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strace.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 1B60E72C8CC; Mon, 13 Jan 2025 20:54:53 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id F21AA7CCB3A; Mon, 13 Jan 2025 19:54:52 +0200 (IST) Date: Mon, 13 Jan 2025 19:54:52 +0200 From: "Dmitry V. Levin" To: Christophe Leroy Cc: Oleg Nesterov , Michael Ellerman , Eugene Syromyatnikov , Mike Frysinger , Renzo Davoli , Davide Berardi , strace-devel@lists.strace.io, Madhavan Srinivasan , Nicholas Piggin , Naveen N Rao , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/7] powerpc: properly negate error in syscall_set_return_value() Message-ID: <20250113175452.GA646@strace.io> References: <20250113171054.GA589@strace.io> <6558110c-c2cb-4aa3-9472-b3496f71ebb8@csgroup.eu> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6558110c-c2cb-4aa3-9472-b3496f71ebb8@csgroup.eu> On Mon, Jan 13, 2025 at 06:34:44PM +0100, Christophe Leroy wrote: > Le 13/01/2025 à 18:10, Dmitry V. Levin a écrit : > > Bring syscall_set_return_value() in sync with syscall_get_error(), > > and let upcoming ptrace/set_syscall_info selftest pass on powerpc. > > > > This reverts commit 1b1a3702a65c ("powerpc: Don't negate error in > > syscall_set_return_value()"). > > There is a clear detailed explanation in that commit of why it needs to > be done. > > If you think that commit is wrong you have to explain why with at least > the same level of details. I'm sorry, I'm not by any means a powerpc expert to explain why that commit was added in the first place, I wish Michael would be able to do it himself. All I can say is that for some mysterious reason current syscall_set_return_value() implementation assumes that in case of an error regs->gpr[3] has to be negative, while, according to well-tested syscall_get_error(), it has to be positive. This is very visible with PTRACE_SET_SYSCALL_INFO that exposes syscall_set_return_value() to userspace, and, in particular, with the architecture-agnostic ptrace/set_syscall_info selftest added later in the series. > > diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h > > index 3dd36c5e334a..422d7735ace6 100644 > > --- a/arch/powerpc/include/asm/syscall.h > > +++ b/arch/powerpc/include/asm/syscall.h > > @@ -82,7 +82,11 @@ static inline void syscall_set_return_value(struct task_struct *task, > > */ > > if (error) { > > regs->ccr |= 0x10000000L; > > - regs->gpr[3] = error; > > + /* > > + * In case of an error regs->gpr[3] contains > > + * a positive ERRORCODE. > > + */ > > + regs->gpr[3] = -error; > > } else { > > regs->ccr &= ~0x10000000L; > > regs->gpr[3] = val; -- ldv